3 /* _PDCLIB_flushbuffer( FILE * )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
13 #include <_PDCLIB_glue.h>
15 _PDCLIB_size_t _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream, _PDCLIB_size_t written, int retries )
17 _PDCLIB_size_t n = stream->bufidx - written;
18 int count = _PDCLIB_write( stream, stream->buffer + written, ( n <= INT_MAX ? (int)n : INT_MAX ) );
19 written += count; /* if count is -1, we don't need written anyway */
24 stream->status |= _PDCLIB_ERRORFLAG;
25 /* FIXME: Map host errno to PDCLib errno */
28 /* no characters written - retry */
29 if ( retries == _PDCLIB_FLUSH_RETRIES )
31 /* max. number of retries without characters being written */
32 stream->status |= _PDCLIB_ERRORFLAG;
33 /* FIXME: Set errno */
36 _PDCLIB_FLUSH_RETRY_PREP;
37 return _PDCLIB_flushbuffer( stream, written, retries + 1 );
39 /* If the following assert fails, we wrote more characters than
40 available in the buffer. (???)
42 assert( written <= stream->bufidx );
43 if ( written == stream->bufidx )
49 return _PDCLIB_flushbuffer( stream, written, 0 );
54 #include <_PDCLIB_test.h>
58 TESTCASE( NO_TESTDRIVER );