]> pd.if.org Git - pdclib/blobdiff - functions/stdio/fputc.c
Yet closer to functional output.
[pdclib] / functions / stdio / fputc.c
index 8f9737884b43f972beaa2cc56d7d1fe0d11b979c..e9036112297875ab33a8d4ef6dd26503cea30fc1 100644 (file)
@@ -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;
 }