Annotation of researchv9/libc/stdio/filbuf.c, revision 1.1.1.1

1.1       root        1: /* @(#)filbuf.c        4.3 (Berkeley) 5/19/81 */
                      2: #include       <stdio.h>
                      3: char   *malloc();
                      4: 
                      5: _filbuf(iop)
                      6: register FILE *iop;
                      7: {
                      8:        static unsigned char smallbuf[_NFILE];
                      9: 
                     10:        if (iop->_flag & _IORW)
                     11:                iop->_flag |= _IOREAD;
                     12: 
                     13:        if ((iop->_flag&_IOREAD) == 0)
                     14:                return(EOF);
                     15:        if (iop->_flag&_IOSTRG)
                     16:                return(EOF);
                     17: tryagain:
                     18:        if (iop->_base==NULL) {
                     19:                if (iop->_flag&_IONBF) {
                     20:                        iop->_base = &smallbuf[fileno(iop)];
                     21:                        goto tryagain;
                     22:                }
                     23:                if ((iop->_base = (unsigned char *) malloc(BUFSIZ)) == NULL) {
                     24:                        iop->_flag |= _IONBF;
                     25:                        goto tryagain;
                     26:                }
                     27:                iop->_flag |= _IOMYBUF;
                     28:        }
                     29:        if (iop == stdin && (stdout->_flag&_IOLBF))
                     30:                fflush(stdout);
                     31:        iop->_cnt = read(fileno(iop), iop->_base, iop->_flag&_IONBF?1:BUFSIZ);
                     32:        iop->_ptr = iop->_base;
                     33:        if (--iop->_cnt < 0) {
                     34:                if (iop->_cnt == -1) {
                     35:                        iop->_flag |= _IOEOF;
                     36:                        if (iop->_flag & _IORW)
                     37:                                iop->_flag &= ~_IOREAD;
                     38:                } else
                     39:                        iop->_flag |= _IOERR;
                     40:                iop->_cnt = 0;
                     41:                return(-1);
                     42:        }
                     43:        return(*iop->_ptr++);
                     44: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.