]> pd.if.org Git - pdclib.old/blobdiff - functions/stdio/fflush.c
Namespace cleanliness: Rename all ***_unlocked functions to _PDCLIB_***_unlocked.
[pdclib.old] / functions / stdio / fflush.c
index 5118503c530e413232e79dc8ece526356597ccf0..3f1a4118a4d9a9ff7dc300b303e3e08badfbb4f3 100644 (file)
@@ -9,11 +9,11 @@
 #include <stdio.h>
 
 #ifndef REGTEST
-#include <_PDCLIB_glue.h>
+#include <_PDCLIB_io.h>
 
-extern struct _PDCLIB_file_t * _PDCLIB_filelist;
+extern FILE * _PDCLIB_filelist;
 
-int fflush( struct _PDCLIB_file_t * stream )
+int _PDCLIB_fflush_unlocked( FILE * stream )
 {
     if ( stream == NULL )
     {
@@ -22,9 +22,12 @@ int fflush( struct _PDCLIB_file_t * stream )
         int rc = 0;
         while ( stream != NULL )
         {
-            if ( stream->bufidx > stream->bufend )
+            if ( stream->status & _PDCLIB_FWRITE )
             {
-                rc |= _PDCLIB_fflush( stream );
+                if ( _PDCLIB_flushbuffer( stream ) == EOF )
+                {
+                    rc = EOF;
+                }
             }
             stream = stream->next;
         }
@@ -32,9 +35,17 @@ int fflush( struct _PDCLIB_file_t * stream )
     }
     else
     {
-        return _PDCLIB_fflush( stream );
+        return _PDCLIB_flushbuffer( stream );
     }
 }
+
+int fflush( FILE * stream )
+{
+    _PDCLIB_flockfile( stream );
+    int res = _PDCLIB_fflush_unlocked(stream);
+    _PDCLIB_funlockfile( stream );
+    return res;
+}
                 
 #endif
 
@@ -43,7 +54,7 @@ int fflush( struct _PDCLIB_file_t * stream )
 
 int main( void )
 {
-    TESTCASE( NO_TESTDRIVER );
+    /* Testing covered by ftell.c */
     return TEST_RESULTS;
 }