Annotation of coherent/b/lib/libc/stdio/fread.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * libc/stdio/fread.c
                      3:  * ANSI-compliant C standard i/o library.
                      4:  * fread()
                      5:  * ANSI 4.9.8.1.
                      6:  * Read nmemb items of given size from stream to ptr.
                      7:  */
                      8: 
                      9: #include <stdio.h>
                     10: #include <stdlib.h>
                     11: 
                     12: size_t
                     13: fread(ptr, size, nmemb, stream) const __VOID__ *ptr; size_t size, nmemb; register FILE *stream;
                     14: {
                     15:        register size_t nb;
                     16:        register int c;
                     17:        register unsigned char *p;
                     18: 
                     19:        if ((nb = size*nmemb) == 0)
                     20:                return nb;
                     21:        p = ptr;
                     22: 
                     23:        /* Read ungotten character if present. */
                     24:        if (stream->_ff2 & _FUNGOT) {           
                     25:                *p++ = (*stream->_f2p->_gt)(stream);
                     26:                if (--nb == 0)
                     27:                        return 1;
                     28:        }
                     29: 
                     30:        /* If unbuffered, read() will work, otherwise use getc(). */
                     31:        /* getc() sets _FEOF and _FERR as required, read() does not. */
                     32:         if (stream->_mode == _MODE_FBUF || stream->_mode == _MODE_LBUF)
                     33:                for (; nb && (c = getc(stream)) != EOF; nb--)
                     34:                        *p++ = c;
                     35:        else if ((c = read(fileno(stream), p, nb)) > 0)
                     36:                nb -= c;
                     37:        else if (c == 0)
                     38:                stream->_ff1 |= _FEOF;
                     39:        else
                     40:                stream->_ff1 |= _FERR;
                     41: 
                     42:        /* Adjust seek after partial read. */
                     43:        if (nb != 0 && nb % size != 0)
                     44:                fseek(stream, (long)(nb % size - size), SEEK_CUR);
                     45: 
                     46:        return (size*nmemb-nb)/size;
                     47: }
                     48: 
                     49: /* end of libc/stdio/fread.c */

unix.superglobalmegacorp.com

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