X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstdio%2F_PDCLIB_flushbuffer.c;fp=platform%2Fwin32%2Ffunctions%2F_PDCLIB%2F_PDCLIB_flushbuffer.c;h=ffbbb4f088c88ef84767a056e3570fd7c78055a4;hp=c0ade01ec18251948f3ef60323f91745b2490f8c;hb=c5d49235e09fbd58416f10dec2799e61cf3431c8;hpb=4c7c56442f6b3e08c17594dd4e8095fca3aec9cf diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_flushbuffer.c b/functions/stdio/_PDCLIB_flushbuffer.c similarity index 70% rename from platform/win32/functions/_PDCLIB/_PDCLIB_flushbuffer.c rename to functions/stdio/_PDCLIB_flushbuffer.c index c0ade01..ffbbb4f 100644 --- a/platform/win32/functions/_PDCLIB/_PDCLIB_flushbuffer.c +++ b/functions/stdio/_PDCLIB_flushbuffer.c @@ -1,66 +1,56 @@ -/* $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 - -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 * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#include + +#ifndef REGTEST +#include <_PDCLIB_glue.h> + +int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ) +{ + if ( ! ( stream->status & _PDCLIB_FBIN ) ) + { + /* TODO: Text stream conversion here */ + } + + size_t written = 0; + + + while(written != stream->bufidx) { + size_t justWrote; + size_t toWrite = stream->bufidx - written; + bool res = stream->ops->write( stream->handle, stream->buffer + written, + toWrite, &justWrote); + written += justWrote; + stream->pos.offset += justWrote; + + if(!res) { + stream->status |=_PDCLIB_ERRORFLAG; + stream->bufidx -= written; + memmove( stream->buffer, stream->buffer + written, stream->bufidx ); + 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 +