]> pd.if.org Git - pdclib.old/blobdiff - functions/stdio/vfscanf.c
Minimize the amount of internal definitions which get exposed via the user-visible...
[pdclib.old] / functions / stdio / vfscanf.c
index fbf5356d78673667b741fca010ea4af5cfc9adbe..14bba50879c557a2837e78717e7bdd73de785c87 100644 (file)
 #include <ctype.h>
 
 #ifndef REGTEST
+#include <_PDCLIB_io.h>
 
-int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, va_list arg )
+int vfscanf_unlocked( FILE * _PDCLIB_restrict stream, 
+                      const char * _PDCLIB_restrict format, 
+                      va_list arg )
 {
     /* TODO: This function should interpret format as multibyte characters.  */
     struct _PDCLIB_status_t status;
@@ -42,7 +45,7 @@ int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict forma
                 {
                     ++status.i;
                 }
-                if ( ! feof( stream ) ) /* TODO: Check EOF status directly */
+                if ( ! feof( stream ) )
                 {
                     ungetc( c, stream );
                 }
@@ -50,10 +53,10 @@ int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict forma
             else
             {
                 /* Non-whitespace char in format string: Match verbatim */
-                if ( ( ( c = getc( stream ) ) != *format ) || feof( stream ) ) /* TODO: Check EOF status directly */
+                if ( ( ( c = getc( stream ) ) != *format ) || feof( stream ) )
                 {
                     /* Matching error */
-                    if ( ! feof( stream ) && ! ferror( stream ) ) /* TODO: Check EOF status directly */
+                    if ( ! feof( stream ) && ! ferror( stream ) )
                     {
                         ungetc( c, stream );
                     }
@@ -85,6 +88,16 @@ int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict forma
     return status.n;
 }
 
+int vfscanf( FILE * _PDCLIB_restrict stream, 
+             const char * _PDCLIB_restrict format, 
+             va_list arg )
+{
+    flockfile( stream );
+    int r = vfscanf_unlocked( stream, format, arg );
+    funlockfile( stream );
+    return r;
+}
+
 #endif
 
 #ifdef TEST