-/* $Id$ */
-
-/* _PDCLIB_flushbuffer( struct _PDCLIB_file_t * )
-
- This file is part of the Public Domain C Library (PDCLib).
- Permission is granted to use, modify, and / or redistribute at will.
-*/
-
-/* This is a stub implementation of _PDCLIB_flushbuffer
-*/
-
-#include <stdio.h>
-#include <string.h>
-
-#ifndef REGTEST
-#include <_PDCLIB_glue.h>
-#include <errno.h>
-#include <windows.h>
-
-void _PDCLIB_w32errno( void );
-
-int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream )
-{
- if ( ! ( stream->status & _PDCLIB_FBIN ) )
- {
- /* TODO: Text stream conversion here */
- }
-
- DWORD written = 0;
-
-
- while(written != stream->bufidx) {
- DWORD justWrote;
- DWORD toWrite = stream->bufidx - written;
- BOOL res = WriteFile( stream->handle, stream->buffer + written,
- toWrite, &justWrote, NULL);
- written += justWrote;
- stream->pos.offset += justWrote;
-
- if(!res) {
- stream->status |=_PDCLIB_ERRORFLAG;
- stream->bufidx -= written;
- memmove( stream->buffer, stream->buffer + written, stream->bufidx );
- _PDCLIB_w32errno();
- return EOF;
- }
- }
-
- stream->bufidx = 0;
- return 0;
-}
-
-#endif
-
-
-#ifdef TEST
-#include <_PDCLIB_test.h>
-
-int main( void )
-{
- /* Testing covered by ftell.c */
- return TEST_RESULTS;
-}
-
-#endif
-
+/* _PDCLIB_flushbuffer( struct _PDCLIB_file_t * )\r
+\r
+ This file is part of the Public Domain C Library (PDCLib).\r
+ Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+#ifndef REGTEST\r
+#include <_PDCLIB_glue.h>\r
+\r
+int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream )\r
+{\r
+ if ( ! ( stream->status & _PDCLIB_FBIN ) )\r
+ {\r
+ /* TODO: Text stream conversion here */\r
+ }\r
+\r
+ size_t written = 0;\r
+\r
+\r
+ while(written != stream->bufidx) {\r
+ size_t justWrote;\r
+ size_t toWrite = stream->bufidx - written;\r
+ bool res = stream->ops->write( stream->handle, stream->buffer + written, \r
+ toWrite, &justWrote);\r
+ written += justWrote;\r
+ stream->pos.offset += justWrote;\r
+\r
+ if(!res) {\r
+ stream->status |=_PDCLIB_ERRORFLAG;\r
+ stream->bufidx -= written;\r
+ memmove( stream->buffer, stream->buffer + written, stream->bufidx );\r
+ return EOF;\r
+ }\r
+ }\r
+\r
+ stream->bufidx = 0;\r
+ return 0;\r
+}\r
+\r
+#endif\r
+\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+ /* Testing covered by ftell.c */\r
+ return TEST_RESULTS;\r
+}\r
+\r
+#endif\r
+\r