1 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
3 #include <crtdll/sys/types.h>
4 #include <crtdll/stdio.h>
5 #include <crtdll/fcntl.h>
6 #include <crtdll/internal/file.h>
12 freopen(const char *file, const char *mode, FILE *f)
17 if (file == 0 || mode == 0 || f == 0)
20 rw = (mode[1] == '+');
26 oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
29 oflags = rw ? O_RDWR : O_RDONLY;
32 oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
43 else if (tbchar == 'b')
46 oflags |= (_fmode & (O_TEXT|O_BINARY));
48 fd = _open(file, oflags, 0666);
53 lseek(fd, 0, SEEK_END);
59 f->_flag = _IOREAD | _IOWRT;
60 else if (*mode == 'r')
65 f->_base = f->_ptr = NULL;