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;