]> pd.if.org Git - pdclib.old/blobdiff - functions/stdio/clearerr.c
Minimize the amount of internal definitions which get exposed via the user-visible...
[pdclib.old] / functions / stdio / clearerr.c
index 922f6ab9d239e18cbf5eea9d959d0102c10d9f54..20af80f298b4a1e792e6e8de80b5cce58f4e977a 100644 (file)
@@ -9,12 +9,20 @@
 #include <stdio.h>
 
 #ifndef REGTEST
+#include <_PDCLIB_io.h>
 
-void clearerr( struct _PDCLIB_file_t * stream )
+void clearerr_unlocked( FILE * stream )
 {
     stream->status &= ~( _PDCLIB_ERRORFLAG | _PDCLIB_EOFFLAG );
 }
 
+void clearerr( FILE * stream )
+{
+    flockfile( stream );
+    clearerr_unlocked( stream );
+    funlockfile( stream );
+}
+
 #endif
 
 #ifdef TEST
@@ -23,12 +31,12 @@ void clearerr( struct _PDCLIB_file_t * stream )
 int main( void )
 {
     FILE * fh;
-    remove( "testfile" );
-    TESTCASE( ( fh = fopen( "testfile", "w+" ) ) != NULL );
+    TESTCASE( ( fh = tmpfile() ) != NULL );
     /* Flags should be clear */
     TESTCASE( ! ferror( fh ) );
     TESTCASE( ! feof( fh ) );
     /* Reading from input stream - should provoke error */
+    /* FIXME: Apparently glibc disagrees on this assumption. How to provoke error on glibc? */
     TESTCASE( fgetc( fh ) == EOF );
     TESTCASE( ferror( fh ) );
     TESTCASE( ! feof( fh ) );
@@ -46,7 +54,6 @@ int main( void )
     TESTCASE( ! ferror( fh ) );
     TESTCASE( ! feof( fh ) );
     TESTCASE( fclose( fh ) == 0 );
-    remove( "testfile" );
     return TEST_RESULTS;
 }