]> pd.if.org Git - pdclib/blob - functions/stdio/_PDCLIB_fillbuffer.c
PDCLIB-8: First phase of intergation of new I/O backend system (with minimal
[pdclib] / functions / stdio / _PDCLIB_fillbuffer.c
1 /* _PDCLIB_fillbuffer( struct _PDCLIB_file_t * 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 \r
12 int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream )\r
13 {\r
14     size_t bytesRead;\r
15     bool ok = stream->ops->read( stream->handle, stream->buffer, stream->bufsize,\r
16                         &bytesRead);\r
17 \r
18     if( ok ) {\r
19         if( bytesRead == 0 ) {\r
20             stream->status |= _PDCLIB_EOFFLAG;\r
21             return EOF;\r
22         }\r
23         stream->pos.offset += bytesRead;\r
24         stream->bufend = bytesRead;\r
25         stream->bufidx = 0;\r
26         return 0;\r
27     } else {\r
28         stream->status |= _PDCLIB_ERRORFLAG;\r
29         return EOF;\r
30     }\r
31 }\r
32 \r
33 #endif\r
34 \r
35 #ifdef TEST\r
36 #include <_PDCLIB_test.h>\r
37 \r
38 int main( void )\r
39 {\r
40     /* Testing covered by ftell.c */\r
41     return TEST_RESULTS;\r
42 }\r
43 \r
44 #endif\r
45 \r