1 /* _PDCLIB_flushbuffer( struct _PDCLIB_file_t * )
\r
3 This file is part of the Public Domain C Library (PDCLib).
\r
4 Permission is granted to use, modify, and / or redistribute at will.
\r
11 #include <_PDCLIB_glue.h>
\r
13 int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream )
\r
15 if ( ! ( stream->status & _PDCLIB_FBIN ) )
\r
17 /* TODO: Text stream conversion here */
\r
23 while(written != stream->bufidx) {
\r
25 size_t toWrite = stream->bufidx - written;
\r
26 bool res = stream->ops->write( stream->handle, stream->buffer + written,
\r
27 toWrite, &justWrote);
\r
28 written += justWrote;
\r
29 stream->pos.offset += justWrote;
\r
32 stream->status |=_PDCLIB_ERRORFLAG;
\r
33 stream->bufidx -= written;
\r
34 memmove( stream->buffer, stream->buffer + written, stream->bufidx );
\r
47 #include <_PDCLIB_test.h>
\r
51 /* Testing covered by ftell.c */
\r
52 return TEST_RESULTS;
\r