Annotation of researchv10no/cmd/upas/libc/fread.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1980 Regents of the University of California.
        !             3:  * All rights reserved.  The Berkeley software License Agreement
        !             4:  * specifies the terms and conditions for redistribution.
        !             5:  */
        !             6: 
        !             7: #if defined(LIBC_SCCS) && !defined(lint)
        !             8: static char sccsid[] = "@(#)fread.c    5.2 (Berkeley) 3/9/86";
        !             9: #endif /*LIBC_SCCS and not lint*/
        !            10: 
        !            11: #include       <stdio.h>
        !            12: 
        !            13: fread(ptr, size, count, iop)
        !            14:        register char *ptr;
        !            15:        unsigned size, count;
        !            16:        register FILE *iop;
        !            17: {
        !            18:        register int s;
        !            19:        int c;
        !            20: 
        !            21:        s = size * count;
        !            22:        while (s > 0) {
        !            23:                if (iop->_cnt < s) {
        !            24:                        if (iop->_cnt > 0) {
        !            25:                                memcpy(ptr, iop->_ptr, iop->_cnt);
        !            26:                                ptr += iop->_cnt;
        !            27:                                s -= iop->_cnt;
        !            28:                        }
        !            29:                        /*
        !            30:                         * filbuf clobbers _cnt & _ptr,
        !            31:                         * so don't waste time setting them.
        !            32:                         */
        !            33:                        if ((c = _filbuf(iop)) == EOF)
        !            34:                                break;
        !            35:                        *ptr++ = c;
        !            36:                        s--;
        !            37:                }
        !            38:                if (iop->_cnt >= s) {
        !            39:                        memcpy(ptr, iop->_ptr, s);
        !            40:                        iop->_ptr += s;
        !            41:                        iop->_cnt -= s;
        !            42:                        return (count);
        !            43:                }
        !            44:        }
        !            45:        return (size != 0 ? count - ((s + size - 1) / size) : 0);
        !            46: }

unix.superglobalmegacorp.com

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