]> pd.if.org Git - pdclib/blob - platform/win32/functions/_PDCLIB/_PDCLIB_flushbuffer.c
Initial pass at a port to win32
[pdclib] / platform / win32 / functions / _PDCLIB / _PDCLIB_flushbuffer.c
1 /* $Id$ */
2
3 /* _PDCLIB_flushbuffer( struct _PDCLIB_file_t * )
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 implementation of _PDCLIB_flushbuffer
10 */
11
12 #include <stdio.h>
13 #include <string.h>
14
15 #ifndef REGTEST
16 #include <_PDCLIB_glue.h>
17 #include <errno.h>
18 #include <windows.h>
19
20 int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream )
21 {
22     if ( ! ( stream->status & _PDCLIB_FBIN ) )
23     {
24         /* TODO: Text stream conversion here */
25     }
26
27     DWORD written = 0;
28
29
30     while(written != stream->bufidx) {
31         DWORD justWrote;
32         DWORD toWrite = stream->bufidx - written;
33         BOOL res = WriteFile( stream->handle, stream->buffer + written, 
34                               toWrite, &justWrote, NULL);
35         written += justWrote;
36
37         if(!res) {
38             stream->status |=_PDCLIB_ERRORFLAG;
39             stream->bufidx -= written;
40             memmove( stream->buffer, stream->buffer + written, stream->bufidx );
41             _PDCLIB_w32errno();
42             return EOF;
43         }
44     }
45
46     stream->bufidx = 0;
47     return 0;
48 }
49
50 #endif
51
52
53 #ifdef TEST
54 #include <_PDCLIB_test.h>
55
56 int main( void )
57 {
58     /* Testing covered by ftell.c */
59     return TEST_RESULTS;
60 }
61
62 #endif
63