From 4216ca337cd95cda70bc53bbf08440244c643519 Mon Sep 17 00:00:00 2001 From: Bill Joy Date: Mon, 22 Dec 1980 00:50:12 -0800 Subject: [PATCH] date and time created 80/12/21 16:50:12 by wnj SCCS-vsn: lib/libc/stdio/filbuf.c 4.1 --- usr/src/lib/libc/stdio/filbuf.c | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 usr/src/lib/libc/stdio/filbuf.c diff --git a/usr/src/lib/libc/stdio/filbuf.c b/usr/src/lib/libc/stdio/filbuf.c new file mode 100644 index 0000000000..43054ffab6 --- /dev/null +++ b/usr/src/lib/libc/stdio/filbuf.c @@ -0,0 +1,39 @@ +/* @(#)filbuf.c 4.1 (Berkeley) %G% */ +#include +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); +} -- 2.20.1