3 /* fwrite( void *, size_t, size_t, FILE * )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
13 #include <_PDCLIB_glue.h>
18 size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
20 if ( _PDCLIB_prepread( stream ) == EOF )
24 char * dest = (char *)ptr;
26 for ( nmemb_i = 0; nmemb_i < nmemb; ++nmemb_i )
28 for ( size_t size_i = 0; size_i < size; ++size_i )
30 if ( stream->bufidx == stream->bufend )
32 if ( _PDCLIB_fillbuffer( stream ) == EOF )
34 /* Could not read requested data */
38 dest[ nmemb_i * size + size_i ] = stream->buffer[ stream->bufidx++ ];
47 #include <_PDCLIB_test.h>
52 TESTCASE( ( fh = tmpfile() ) != NULL );
53 TESTCASE( fwrite( "SUCCESS testing fwrite()\n", 1, 25, fh ) == 25 );
54 /* TODO: Add readback test. */
55 TESTCASE( fclose( fh ) == 0 );