]> pd.if.org Git - pdclib/blob - platform/win32/functions/_PDCLIB/_PDCLIB_flushbuffer.c
C11 7.21.6.1p8 "The result of converting a zero value with a precision of zero is...
[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 void _PDCLIB_w32errno( void );
21
22 int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream )
23 {
24     if ( ! ( stream->status & _PDCLIB_FBIN ) )
25     {
26         /* TODO: Text stream conversion here */
27     }
28
29     DWORD written = 0;
30
31
32     while(written != stream->bufidx) {
33         DWORD justWrote;
34         DWORD toWrite = stream->bufidx - written;
35         BOOL res = WriteFile( stream->handle, stream->buffer + written, 
36                               toWrite, &justWrote, NULL);
37         written += justWrote;
38         stream->pos.offset += justWrote;
39
40         if(!res) {
41             stream->status |=_PDCLIB_ERRORFLAG;
42             stream->bufidx -= written;
43             memmove( stream->buffer, stream->buffer + written, stream->bufidx );
44             _PDCLIB_w32errno();
45             return EOF;
46         }
47     }
48
49     stream->bufidx = 0;
50     return 0;
51 }
52
53 #endif
54
55
56 #ifdef TEST
57 #include <_PDCLIB_test.h>
58
59 int main( void )
60 {
61     /* Testing covered by ftell.c */
62     return TEST_RESULTS;
63 }
64
65 #endif
66