1 /* fwrite( const void *, size_t, size_t, FILE * )
3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
10 #include <_PDCLIB_io.h>
11 #include <_PDCLIB_glue.h>
16 size_t _PDCLIB_fwrite_unlocked( const void *restrict vptr,
17 size_t size, size_t nmemb,
18 FILE * _PDCLIB_restrict stream )
20 if ( _PDCLIB_prepwrite( stream ) == EOF )
25 const char *restrict ptr = vptr;
27 for ( nmemb_i = 0; nmemb_i < nmemb; ++nmemb_i )
29 for ( size_t size_i = 0; size_i < size; ++size_i )
31 char c = ptr[ nmemb_i * size + size_i ];
32 stream->buffer[ stream->bufidx++ ] = c;
34 if ( stream->bufidx == stream->bufsize || ( c == '\n' && stream->status & _IOLBF ) )
36 if ( _PDCLIB_flushbuffer( stream ) == EOF )
38 /* Returning number of objects completely buffered */
44 if ( stream->status & _IONBF )
46 if ( _PDCLIB_flushbuffer( stream ) == EOF )
48 /* Returning number of objects completely buffered */
56 size_t fwrite( const void * _PDCLIB_restrict ptr,
57 size_t size, size_t nmemb,
58 FILE * _PDCLIB_restrict stream )
60 _PDCLIB_flockfile( stream );
61 size_t r = _PDCLIB_fwrite_unlocked( ptr, size, nmemb, stream );
62 _PDCLIB_funlockfile( stream );
69 #include <_PDCLIB_test.h>
73 /* Testing covered by fread(). */