]> pd.if.org Git - pdclib/blob - functions/stdio/_PDCLIB_fillbuffer.c
dos2unix
[pdclib] / functions / stdio / _PDCLIB_fillbuffer.c
1 /* _PDCLIB_fillbuffer( FILE * stream )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <stdio.h>
8
9 #ifndef REGTEST
10 #include "_PDCLIB_glue.h"
11 #include "_PDCLIB_io.h"
12
13 int _PDCLIB_fillbuffer( FILE * stream )
14 {
15     size_t bytesRead;
16     bool ok = stream->ops->read( stream->handle, stream->buffer, stream->bufsize,
17                         &bytesRead);
18
19     if( ok ) {
20         if( bytesRead == 0 ) {
21             stream->status |= _PDCLIB_EOFFLAG;
22             return EOF;
23         }
24         stream->pos.offset += bytesRead;
25         stream->bufend = bytesRead;
26         stream->bufidx = 0;
27         return 0;
28     } else {
29         stream->status |= _PDCLIB_ERRORFLAG;
30         return EOF;
31     }
32 }
33
34 #endif
35
36 #ifdef TEST
37 #include "_PDCLIB_test.h"
38
39 int main( void )
40 {
41     /* Testing covered by ftell.c */
42     return TEST_RESULTS;
43 }
44
45 #endif
46