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