1 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
3 #include <msvcrt/sys/types.h>
4 #include <msvcrt/stdio.h>
5 #include <msvcrt/fcntl.h>
7 #include <msvcrt/internal/file.h>
10 FILE *freopen(const char *file, const char *mode, FILE *f)
15 if (file == 0 || mode == 0 || f == 0)
18 rw = (mode[1] == '+');
24 oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
27 oflags = rw ? O_RDWR : O_RDONLY;
30 oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
41 else if (tbchar == 'b')
44 oflags |= (_fmode & (O_TEXT|O_BINARY));
46 fd = _open(file, oflags, 0666);
51 lseek(fd, 0, SEEK_END);
57 f->_flag = _IOREAD | _IOWRT;
58 else if (*mode == 'r')
63 f->_base = f->_ptr = NULL;
67 FILE *_wfreopen(const wchar_t *file, const wchar_t *mode, FILE *f)
72 if (file == 0 || mode == 0 || f == 0)
75 rw = (mode[1] == L'+');
81 oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
84 oflags = rw ? O_RDWR : O_RDONLY;
87 oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
98 else if (tbchar == L'b')
101 oflags |= (_fmode & (O_TEXT|O_BINARY));
103 fd = _wopen(file, oflags, 0666);
108 lseek(fd, 0, SEEK_END);
114 f->_flag = _IOREAD | _IOWRT;
115 else if (*mode == L'r')
120 f->_base = f->_ptr = NULL;