Annotation of researchv10dc/libI77/notused/fread.c, revision 1.1

1.1     ! root        1: /*     @(#)fread.c     3.11    */
        !             2: /*LINTLIBRARY*/
        !             3: /*
        !             4:  * This version reads directly from the buffer rather than looping on getc.
        !             5:  * Ptr args aren't checked for NULL because the program would be a
        !             6:  * catastrophic mess anyway.  Better to abort than just to return NULL.
        !             7:  */
        !             8: #include <stdio.h>
        !             9: #include "stdiom.h"
        !            10: 
        !            11: #define MIN(x, y)      (x < y ? x : y)
        !            12: 
        !            13: extern int _filbuf();
        !            14: extern _bufsync();
        !            15: extern char *memcpy();
        !            16: 
        !            17: int
        !            18: fread(ptr, size, count, iop)
        !            19: char *ptr;
        !            20: int size, count;
        !            21: register FILE *iop;
        !            22: {
        !            23:        register unsigned int nleft;
        !            24:        register int n;
        !            25: 
        !            26:        if (size <= 0 || count <= 0) return 0;
        !            27:        nleft = count * size;
        !            28: 
        !            29:        /* Put characters in the buffer */
        !            30:        /* note that the meaning of n when just starting this loop is
        !            31:           irrelevant.  It is defined in the loop */
        !            32:        for ( ; ; ) {
        !            33:                if (iop->_cnt <= 0) { /* empty buffer */
        !            34:                        if (_filbuf(iop) == EOF)
        !            35:                                return (count - (nleft + size - 1)/size);
        !            36:                        iop->_ptr--;
        !            37:                        iop->_cnt++;
        !            38:                }
        !            39:                n = MIN(nleft, iop->_cnt);
        !            40:                ptr = memcpy(ptr, (char *) iop->_ptr, n) + n;
        !            41:                iop->_cnt -= n;
        !            42:                iop->_ptr += n;
        !            43:                _BUFSYNC(iop);
        !            44:                if ((nleft -= n) <= 0)
        !            45:                        return (count);
        !            46:        }
        !            47: }

unix.superglobalmegacorp.com

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