]> pd.if.org Git - pdclib/blob - platform/win32/functions/_PDCLIB/_PDCLIB_fillbuffer.c
Initial pass at a port to win32
[pdclib] / platform / win32 / functions / _PDCLIB / _PDCLIB_fillbuffer.c
1 /* $Id$ */
2
3 /* _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 /* This is a stub version of _PDCLIB_fillbuffer
10 */
11
12 #include <stdio.h>
13
14 #ifndef REGTEST
15 #include <_PDCLIB_glue.h>
16 #include <errno.h>
17 #include <windows.h>
18
19 void _PDCLIB_w32errno(void);
20 int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream )
21 {
22     DWORD nBytesRead;
23     BOOL ok = ReadFile( stream->handle, stream->buffer, stream->bufsize,
24                         &nBytesRead, NULL );
25
26     if( ok ) {
27         if( nBytesRead == 0 ) {
28             stream->status |= _PDCLIB_EOFFLAG;
29             return EOF;
30         }
31         stream->pos.offset += nBytesRead;
32         stream->bufend = nBytesRead;
33         stream->bufidx = 0;
34         return 0;
35     } else {
36         _PDCLIB_w32errno();
37         stream->status |= _PDCLIB_ERRORFLAG;
38         return EOF;
39     }
40 }
41
42 #endif
43
44 #ifdef TEST
45 #include <_PDCLIB_test.h>
46
47 int main( void )
48 {
49     /* Testing covered by ftell.c */
50     return TEST_RESULTS;
51 }
52
53 #endif
54