]> pd.if.org Git - pdclib/blobdiff - functions/stdio/fread.c
PDCLIB-18: Add _PDCLIB_getchars to _PDCLIB_io.h. Change fread & fgets to go through...
[pdclib] / functions / stdio / fread.c
index 1fdc75326c887ac6bcfc76717e0f20ce38114954..f1ab3a9adeb84745336a2043e8d0d4c8e95a8882 100644 (file)
@@ -27,18 +27,10 @@ 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;
 }