X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Ffputc.c;h=e9036112297875ab33a8d4ef6dd26503cea30fc1;hb=52e702f02142dc34a476f01ca6bf8257cc9bc7e4;hp=8f9737884b43f972beaa2cc56d7d1fe0d11b979c;hpb=8404f0a1339e4be015e278e83bb1a9e3f73751a3;p=pdclib.old diff --git a/functions/stdio/fputc.c b/functions/stdio/fputc.c index 8f97378..e903611 100644 --- a/functions/stdio/fputc.c +++ b/functions/stdio/fputc.c @@ -21,13 +21,17 @@ int fputc( int c, struct _PDCLIB_file_t * stream ) */ stream->buffer[stream->bufidx++] = (char)c; if ( ( stream->bufidx == stream->bufsize ) /* _IOFBF */ - || ( ( stream->status & _IOLBF ) && (char)c == '\n' ) /* _IOLBF */ + || ( ( stream->status & _IOLBF ) && ( (char)c == '\n' ) ) /* _IOLBF */ || ( stream->status & _IONBF ) /* _IONBF */ ) { /* buffer filled, unbuffered stream, or end-of-line. */ fflush( stream ); } + else + { + stream->status |= _PDCLIB_WROTELAST; + } return c; } @@ -38,7 +42,15 @@ int fputc( int c, struct _PDCLIB_file_t * stream ) int main( void ) { - TESTCASE( NO_TESTDRIVER ); + FILE * fh; + char buffer[100]; + TESTCASE( ( fh = fopen( "testfile", "w" ) ) != NULL ); + TESTCASE( fputc( '!', fh ) == '!' ); + TESTCASE( fclose( fh ) == 0 ); + TESTCASE( ( fh = fopen( "testfile", "r" ) ) != NULL ); + TESTCASE( fread( buffer, 1, 1, fh ) == 1 ); + TESTCASE( buffer[0] == '!' ); + TESTCASE( fclose( fh ) == 0 ); return TEST_RESULTS; }