X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Ffputc.c;fp=functions%2Fstdio%2Ffputc.c;h=e9036112297875ab33a8d4ef6dd26503cea30fc1;hb=f603f88b4456cf9b7ab1328bf657ede22a0c9940;hp=8f9737884b43f972beaa2cc56d7d1fe0d11b979c;hpb=ed4d5abcad8b07c4a06d2483497066c2c621a6d7;p=pdclib 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; }