]> pd.if.org Git - pdclib/blobdiff - functions/stdio/vfscanf.c
PDCLIB-16: Add _unlocked variations of all I/O routines; move work into these versions
[pdclib] / functions / stdio / vfscanf.c
index fbf5356d78673667b741fca010ea4af5cfc9adbe..da365bdb618eb3b2f8aa8ab74ad31b71c3c79cdc 100644 (file)
@@ -12,7 +12,9 @@
 
 #ifndef REGTEST
 
-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 +44,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 +52,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 +87,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