1 #include "stdio_impl.h"
3 /* The basic idea of this implementation is to open a new FILE,
4 * hack the necessary parts of the new FILE into the old one, then
5 * close the new FILE. */
7 /* Locking is not necessary because, in the event of failure, the stream
8 * passed to freopen is invalid as soon as freopen is called. */
10 FILE *freopen(const char *filename, const char *mode, FILE *f)
18 f2 = fopen("/dev/null", mode);
20 fl = __syscall_fcntl(f2->fd, F_GETFL, 0);
21 if (fl < 0 || __syscall_fcntl(f->fd, F_SETFL, fl) < 0)
24 f2 = fopen(filename, mode);
26 if (__syscall_dup2(f2->fd, f->fd) < 0)
30 f->flags = (f->flags & F_PERM) | f2->flags;