X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstdio%2Ffread.c;h=bf3185c4cf5d66e7c6aee1d06e04d8f996a4d794;hp=1fdc75326c887ac6bcfc76717e0f20ce38114954;hb=da0f3f353d417fed71f358a48d5d5394145e460d;hpb=6ca24b75c75b9c6f22e1e69693d326b8e3330841 diff --git a/functions/stdio/fread.c b/functions/stdio/fread.c index 1fdc753..bf3185c 100644 --- a/functions/stdio/fread.c +++ b/functions/stdio/fread.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /* fwrite( void *, size_t, size_t, FILE * ) This file is part of the Public Domain C Library (PDCLib). @@ -9,15 +7,16 @@ #include #ifndef REGTEST - -#include <_PDCLIB_glue.h> +#include "_PDCLIB_io.h" #include #include -size_t fread_unlocked( void * _PDCLIB_restrict ptr, - size_t size, size_t nmemb, - struct _PDCLIB_file_t * _PDCLIB_restrict stream ) +size_t _PDCLIB_fread_unlocked( + void * _PDCLIB_restrict ptr, + size_t size, size_t nmemb, + FILE * _PDCLIB_restrict stream +) { if ( _PDCLIB_prepread( stream ) == EOF ) { @@ -27,36 +26,28 @@ size_t fread_unlocked( void * _PDCLIB_restrict ptr, size_t nmemb_i; for ( nmemb_i = 0; nmemb_i < nmemb; ++nmemb_i ) { - for ( size_t size_i = 0; size_i < size; ++size_i ) - { - if ( stream->bufidx == stream->bufend ) - { - if ( _PDCLIB_fillbuffer( stream ) == EOF ) - { - /* Could not read requested data */ - return nmemb_i; - } - } - dest[ nmemb_i * size + size_i ] = stream->buffer[ stream->bufidx++ ]; - } + size_t numread = _PDCLIB_getchars( &dest[ nmemb_i * size ], size, EOF, + stream ); + if( numread != size ) + break; } return nmemb_i; } size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, - struct _PDCLIB_file_t * _PDCLIB_restrict stream ) + FILE * _PDCLIB_restrict stream ) { - flockfile( stream ); - size_t r = fread_unlocked( ptr, size, nmemb, stream ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + size_t r = _PDCLIB_fread_unlocked( ptr, size, nmemb, stream ); + _PDCLIB_funlockfile( stream ); return r; } #endif #ifdef TEST -#include <_PDCLIB_test.h> +#include "_PDCLIB_test.h" int main( void ) {