Annotation of coherent/b/lib/libc/XSTDIO/fwrite.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * libc/stdio/fwrite.c
                      3:  * ANSI-compliant C standard i/o library.
                      4:  * fwrite()
                      5:  * ANSI 4.9.8.2.
                      6:  * Write nmemb items of given size from ptr to stream.
                      7:  */
                      8: 
                      9: #include <stdio.h>
                     10: #include <stdlib.h>
                     11: 
                     12: size_t
                     13: fwrite(ptr, size, nmemb, stream) const Void *ptr; size_t size, nmemb; register FILE *stream;
                     14: {
                     15:        register size_t nb, n;
                     16:        register unsigned char *p;
                     17: 
                     18:        n = nb = size * nmemb;
                     19: 
                     20:        /* Throw away ungotten character if present. */
                     21:        if (stream->_ff2 & _FUNGOT)
                     22:                (*stream->_f2p->_gt)(stream);
                     23: 
                     24:        /* If unbuffered, write() will work, otherwise use putc(). */
                     25:        /* putc() sets _FERR as required, write() does not. */
                     26:        if (stream->_mode == _MODE_FBUF || stream->_mode == _MODE_LBUF) {
                     27:                for (p = ptr; nb && putc(*p++, stream) != EOF; nb--)
                     28:                        ;
                     29:                if (nb)
                     30:                        return (n - nb) / size;
                     31:        } else if ((nb = write(fileno(stream), ptr, nb)) != n) {
                     32:                stream->_ff1 |= _FERR;
                     33:                return nb / size;
                     34:        }
                     35:        return nmemb;
                     36: }
                     37: 
                     38: /* end of libc/stdio/fwrite.c */

unix.superglobalmegacorp.com

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