date and time created 80/12/21 16:50:24 by wnj
authorBill Joy <wnj@ucbvax.Berkeley.EDU>
Mon, 22 Dec 1980 08:50:24 +0000 (00:50 -0800)
committerBill Joy <wnj@ucbvax.Berkeley.EDU>
Mon, 22 Dec 1980 08:50:24 +0000 (00:50 -0800)
SCCS-vsn: lib/libc/stdio/freopen.c 4.1

usr/src/lib/libc/stdio/freopen.c [new file with mode: 0644]

diff --git a/usr/src/lib/libc/stdio/freopen.c b/usr/src/lib/libc/stdio/freopen.c
new file mode 100644 (file)
index 0000000..9fb1ca5
--- /dev/null
@@ -0,0 +1,29 @@
+/* @(#)freopen.c       4.1 (Berkeley) %G% */
+#include <stdio.h>
+
+FILE *
+freopen(file, mode, iop)
+char *file;
+register char *mode;
+register FILE *iop;
+{
+       register f;
+
+       fclose(iop);
+       if (*mode=='w')
+               f = creat(file, 0666);
+       else if (*mode=='a') {
+               if ((f = open(file, 1)) < 0)
+                       f = creat(file, 0666);
+               lseek(f, 0L, 2);
+       } else
+               f = open(file, 0);
+       if (f < 0)
+               return(NULL);
+       iop->_file = f;
+       if (*mode != 'r')
+               iop->_flag |= _IOWRT;
+       else
+               iop->_flag |= _IOREAD;
+       return(iop);
+}