X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fwin32%2Ffunctions%2F_PDCLIB%2F_PDCLIB_flushbuffer.c;fp=platform%2Fwin32%2Ffunctions%2F_PDCLIB%2F_PDCLIB_flushbuffer.c;h=82e36a0217b11190e02158a0af8d3338baf3dd3c;hb=d8928b5f31bbdac23f9ec296ef28b4b10efa31d5;hp=0000000000000000000000000000000000000000;hpb=219271fd548949abce8bd75c34dd42e519418fc4;p=pdclib diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_flushbuffer.c b/platform/win32/functions/_PDCLIB/_PDCLIB_flushbuffer.c new file mode 100644 index 0000000..82e36a0 --- /dev/null +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_flushbuffer.c @@ -0,0 +1,63 @@ +/* $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 +#include + +#ifndef REGTEST +#include <_PDCLIB_glue.h> +#include +#include + +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; + + 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 +