BSD 3 development
authorBill Joy <wnj@ucbvax.Berkeley.EDU>
Sat, 28 Jul 1979 16:05:15 +0000 (08:05 -0800)
committerBill Joy <wnj@ucbvax.Berkeley.EDU>
Sat, 28 Jul 1979 16:05:15 +0000 (08:05 -0800)
Work on file usr/src/libc/stdio/fopen.c

Synthesized-from: 3bsd

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

diff --git a/usr/src/libc/stdio/fopen.c b/usr/src/libc/stdio/fopen.c
new file mode 100644 (file)
index 0000000..ed3b998
--- /dev/null
@@ -0,0 +1,37 @@
+#include       <stdio.h>
+#include       <errno.h>
+
+FILE *
+fopen(file, mode)
+char *file;
+register char *mode;
+{
+       extern int errno;
+       register f;
+       register FILE *iop;
+       extern FILE *_lastbuf;
+
+       for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT); iop++)
+               if (iop >= _lastbuf)
+                       return(NULL);
+       if (*mode=='w')
+               f = creat(file, 0666);
+       else if (*mode=='a') {
+               if ((f = open(file, 1)) < 0) {
+                       if (errno == ENOENT)
+                               f = creat(file, 0666);
+               }
+               if (f >= 0)
+                       lseek(f, 0L, 2);
+       } else
+               f = open(file, 0);
+       if (f < 0)
+               return(NULL);
+       iop->_cnt = 0;
+       iop->_file = f;
+       if (*mode != 'r')
+               iop->_flag |= _IOWRT;
+       else
+               iop->_flag |= _IOREAD;
+       return(iop);
+}