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

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

diff --git a/usr/src/lib/libc/stdio/filbuf.c b/usr/src/lib/libc/stdio/filbuf.c
new file mode 100644 (file)
index 0000000..43054ff
--- /dev/null
@@ -0,0 +1,39 @@
+/* @(#)filbuf.c        4.1 (Berkeley) %G% */
+#include       <stdio.h>
+char   *malloc();
+
+_filbuf(iop)
+register FILE *iop;
+{
+       static char smallbuf[_NFILE];
+
+       if ((iop->_flag&_IOREAD) == 0)
+               return(EOF);
+       if (iop->_flag&_IOSTRG)
+               return(EOF);
+tryagain:
+       if (iop->_base==NULL) {
+               if (iop->_flag&_IONBF) {
+                       iop->_base = &smallbuf[fileno(iop)];
+                       goto tryagain;
+               }
+               if ((iop->_base = malloc(BUFSIZ)) == NULL) {
+                       iop->_flag |= _IONBF;
+                       goto tryagain;
+               }
+               iop->_flag |= _IOMYBUF;
+       }
+       iop->_ptr = iop->_base;
+       if (iop == stdin && (stdout->_flag&_IOLBF))
+               fflush(stdout);
+       iop->_cnt = read(fileno(iop), iop->_ptr, iop->_flag&_IONBF?1:BUFSIZ);
+       if (--iop->_cnt < 0) {
+               if (iop->_cnt == -1)
+                       iop->_flag |= _IOEOF;
+               else
+                       iop->_flag |= _IOERR;
+               iop->_cnt = 0;
+               return(-1);
+       }
+       return(*iop->_ptr++&0377);
+}