]> pd.if.org Git - pdclib/commitdiff
PDCLIB-16: Add _unlocked variations of all I/O routines; move work into these versions
authorOwen Shepherd <owen.shepherd@e43.eu>
Mon, 12 Nov 2012 04:09:02 +0000 (04:09 +0000)
committerOwen Shepherd <owen.shepherd@e43.eu>
Mon, 12 Nov 2012 04:09:02 +0000 (04:09 +0000)
PDCLIB-15: Make most stdio routines lock the stream and then call through to the _unlocked version

36 files changed:
functions/stdio/_PDCLIB_fdopen.c
functions/stdio/_PDCLIB_ftell64.c
functions/stdio/clearerr.c
functions/stdio/fclose.c
functions/stdio/feof.c
functions/stdio/ferror.c
functions/stdio/fflush.c
functions/stdio/fgetc.c
functions/stdio/fgetpos.c
functions/stdio/fgets.c
functions/stdio/fprintf.c
functions/stdio/fputc.c
functions/stdio/fputs.c
functions/stdio/fread.c
functions/stdio/freopen.c
functions/stdio/fscanf.c
functions/stdio/fseek.c
functions/stdio/fsetpos.c
functions/stdio/ftell.c
functions/stdio/fwrite.c
functions/stdio/getc.c
functions/stdio/getchar.c
functions/stdio/printf.c
functions/stdio/putc.c
functions/stdio/putchar.c
functions/stdio/puts.c
functions/stdio/scanf.c
functions/stdio/ungetc.c
functions/stdio/vfprintf.c
functions/stdio/vfscanf.c
functions/stdio/vprintf.c
functions/stdio/vscanf.c
functions/stdio/vsnprintf.c
functions/stdio/vsprintf.c
functions/stdio/vsscanf.c
includes/stdio.h

index 7b539528f8a91b97c791b582aece80998962e94b..c628ebcd1e5da4ebf48131e2b9771c47c4d0cce1 100644 (file)
@@ -12,6 +12,7 @@
 #ifndef REGTEST\r
 #include <_PDCLIB_glue.h>\r
 #include <string.h>\r
+#include <threads.h>\r
 \r
 extern struct _PDCLIB_file_t * _PDCLIB_filelist;\r
 \r
index 650eda548d48051863868df176fffdb1584ecf51..e0ea368e757e35b81bcdf0d606f7a283520b8971 100644 (file)
@@ -12,7 +12,7 @@
 \r
 #ifndef REGTEST\r
 \r
-uint_fast64_t _PDCLIB_ftell64( struct _PDCLIB_file_t * stream )\r
+uint_fast64_t _PDCLIB_ftell64_unlocked( struct _PDCLIB_file_t * stream )\r
 {\r
     /* ftell() must take into account:\r
        - the actual *physical* offset of the file, i.e. the offset as recognized\r
@@ -38,6 +38,14 @@ uint_fast64_t _PDCLIB_ftell64( struct _PDCLIB_file_t * stream )
     return ( stream->pos.offset - ( ( (int)stream->bufend - (int)stream->bufidx ) + (int)stream->ungetidx ) );\r
 }\r
 \r
+uint_fast64_t _PDCLIB_ftell64( struct _PDCLIB_file_t * stream )\r
+{\r
+  flockfile( stream );\r
+  uint_fast64_t pos = _PDCLIB_ftell64_unlocked( stream );\r
+  funlockfile( stream );\r
+  return pos;\r
+}\r
+\r
 #endif\r
 \r
 #ifdef TEST\r
index af50f14f49531523784496424da245fec0c8c81f..2b032bd21833c8ff8b7e631882b6cbd1d9339c5e 100644 (file)
 
 #ifndef REGTEST
 
-void clearerr( struct _PDCLIB_file_t * stream )
+void clearerr_unlocked( struct _PDCLIB_file_t * stream )
 {
     stream->status &= ~( _PDCLIB_ERRORFLAG | _PDCLIB_EOFFLAG );
 }
 
+void clearerr( struct _PDCLIB_file_t * stream )
+{
+    flockfile( stream );
+    clearerr_unlocked( stream );
+    funlockfile( stream );
+}
+
 #endif
 
 #ifdef TEST
index dbd7f6eebbf12199ea8d7a80bbaf566f11035115..c4f5d8a1b1bdc02cb928a023960fd00968e7210c 100644 (file)
@@ -12,6 +12,7 @@
 
 #ifndef REGTEST
 #include <_PDCLIB_glue.h>
+#include <threads.h>
 
 extern struct _PDCLIB_file_t * _PDCLIB_filelist;
 
index d5cf188d23811f105c4a7eb965078dfd19912086..ca43c75532bd4d06b3c83607597575faa7d25976 100644 (file)
 
 #ifndef REGTEST
 
-int feof( struct _PDCLIB_file_t * stream )
+int feof_unlocked( struct _PDCLIB_file_t * stream )
 {
     return stream->status & _PDCLIB_EOFFLAG;
 }
 
+int feof( struct _PDCLIB_file_t * stream )
+{
+    flockfile( stream );
+    int eof = feof_unlocked( stream );
+    funlockfile( stream );
+    return eof;
+}
+
 #endif
 
 #ifdef TEST
index 7ca531ed441bb00eec8b35e59370b6928f7aa798..394dcda2bc7dd07dee9cad93b61dfd95ec50ddd1 100644 (file)
 
 #ifndef REGTEST
 
-int ferror( struct _PDCLIB_file_t * stream )
+int ferror_unlocked( struct _PDCLIB_file_t * stream )
 {
     return stream->status & _PDCLIB_ERRORFLAG;
 }
 
+int ferror( struct _PDCLIB_file_t * stream )
+{
+    flockfile( stream );
+    int error = ferror_unlocked( stream );
+    funlockfile( stream );
+    return error;
+}
+
 #endif
 
 #ifdef TEST
index b8d32ec307d45b389d3a0fa37fb79263998e9f16..df458804dc3099274f024286c3c55db2091418d8 100644 (file)
@@ -13,7 +13,7 @@
 
 extern struct _PDCLIB_file_t * _PDCLIB_filelist;
 
-int fflush( struct _PDCLIB_file_t * stream )
+int fflush_unlocked( struct _PDCLIB_file_t * stream )
 {
     if ( stream == NULL )
     {
@@ -38,6 +38,14 @@ int fflush( struct _PDCLIB_file_t * stream )
         return _PDCLIB_flushbuffer( stream );
     }
 }
+
+int fflush( struct _PDCLIB_file_t * stream )
+{
+    flockfile( stream );
+    int res = fflush_unlocked(stream);
+    funlockfile( stream );
+    return res;
+}
                 
 #endif
 
index 29522c1d64ee50d917b963a26ae12e082a2fd5c5..ae7a8356685540e2582a1c5dcc7a9b350a530c18 100644 (file)
@@ -12,7 +12,7 @@
 
 #include <_PDCLIB_glue.h>
 
-int fgetc( struct _PDCLIB_file_t * stream )
+int fgetc_unlocked( struct _PDCLIB_file_t * stream )
 {
     if ( _PDCLIB_prepread( stream ) == EOF )
     {
@@ -25,6 +25,14 @@ int fgetc( struct _PDCLIB_file_t * stream )
     return (unsigned char)stream->buffer[stream->bufidx++];
 }
 
+int fgetc( struct _PDCLIB_file_t * stream )
+{
+    flockfile( stream );
+    int c = fgetc_unlocked( stream );
+    funlockfile( stream );
+    return c;
+}
+
 #endif
 
 #ifdef TEST
index 3e41c40fd365768b7e61bb5d8f56ce52b0fec1ac..28352c87e9a3cd53767f2ec9ca65666ff40dc624 100644 (file)
@@ -10,7 +10,7 @@
 
 #ifndef REGTEST
 
-int fgetpos( struct _PDCLIB_file_t * _PDCLIB_restrict stream, struct _PDCLIB_fpos_t * _PDCLIB_restrict pos )
+int fgetpos_unlocked( struct _PDCLIB_file_t * _PDCLIB_restrict stream, struct _PDCLIB_fpos_t * _PDCLIB_restrict pos )
 {
     pos->offset = stream->pos.offset + stream->bufidx - stream->ungetidx;
     pos->status = stream->pos.status;
@@ -18,6 +18,14 @@ int fgetpos( struct _PDCLIB_file_t * _PDCLIB_restrict stream, struct _PDCLIB_fpo
     return 0;
 }
 
+int fgetpos( struct _PDCLIB_file_t * _PDCLIB_restrict stream, struct _PDCLIB_fpos_t * _PDCLIB_restrict pos )
+{
+    flockfile( stream );
+    int res = fgetpos_unlocked( stream, pos );
+    funlockfile( stream );
+    return res;
+}
+
 #endif
 
 #ifdef TEST
index 44518a3e0b0f2552a8d5b1a47c81fb7fd3bf37f0..04510583ad29e82b46671106b81caac76399594e 100644 (file)
@@ -12,7 +12,7 @@
 
 #include <_PDCLIB_glue.h>
 
-char * fgets( char * _PDCLIB_restrict s, int size, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+char * fgets_unlocked( char * _PDCLIB_restrict s, int size, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
 {
     if ( size == 0 )
     {
@@ -46,6 +46,15 @@ char * fgets( char * _PDCLIB_restrict s, int size, struct _PDCLIB_file_t * _PDCL
     return ( dest == s ) ? NULL : s;
 }
 
+char * fgets( char * _PDCLIB_restrict s, int size, 
+              struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+{
+    flockfile( stream );
+    char* r = fgets_unlocked( s, size, stream );
+    funlockfile( stream );
+    return r;
+}
+
 #endif
 
 #ifdef TEST
index cb922bad4bdd0b8621d8f8faa72666b08c2862cb..421ca5273f8e153f763c12b0b4399e1f008c1b2a 100644 (file)
@@ -11,7 +11,8 @@
 
 #ifndef REGTEST
 
-int fprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... )
+int fprintf_unlocked( struct _PDCLIB_file_t * _PDCLIB_restrict stream, 
+                      const char * _PDCLIB_restrict format, ... )
 {
     int rc;
     va_list ap;
@@ -21,6 +22,19 @@ int fprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDCL
     return rc;
 }
 
+int fprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream,
+             const char * _PDCLIB_restrict format, ... )
+{
+    int rc;
+    va_list ap;
+    va_start( ap, format );
+    flockfile( stream );
+    rc = vfprintf_unlocked( stream, format, ap );
+    funlockfile( stream );
+    va_end( ap );
+    return rc;
+}
+
 #endif
 
 #ifdef TEST
index 818d45f645057fe4c93954964eb6b9d4c526e098..ae998eaacb0562c01070589c56f4400ae9451c8c 100644 (file)
@@ -16,7 +16,7 @@
    Returns c if successful, EOF otherwise.
    If a write error occurs, the error indicator of the stream is set.
 */
-int fputc( int c, struct _PDCLIB_file_t * stream )
+int fputc_unlocked( int c, struct _PDCLIB_file_t * stream )
 {
     if ( _PDCLIB_prepwrite( stream ) == EOF )
     {
@@ -34,6 +34,14 @@ int fputc( int c, struct _PDCLIB_file_t * stream )
     return c;
 }
 
+int fputc( int c, struct _PDCLIB_file_t * stream )
+{
+    flockfile( stream );
+    int r = fputc_unlocked( c, stream );
+    funlockfile( stream );
+    return r;
+}
+
 #endif
 
 #ifdef TEST
index 2c5e1fa1e1d78b1ee7e17cd5410c1cf631536ffe..0b1e3256f3d32153d88e7e18270b3ad942590fb5 100644 (file)
@@ -11,7 +11,8 @@
 #ifndef REGTEST
 #include <_PDCLIB_glue.h>
 
-int fputs( const char * _PDCLIB_restrict s, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+int fputs_unlocked( const char * _PDCLIB_restrict s, 
+                    struct _PDCLIB_file_t * _PDCLIB_restrict stream )
 {
     if ( _PDCLIB_prepwrite( stream ) == EOF )
     {
@@ -45,6 +46,15 @@ int fputs( const char * _PDCLIB_restrict s, struct _PDCLIB_file_t * _PDCLIB_rest
     return 0;
 }
 
+int fputs( const char * _PDCLIB_restrict s,
+           struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+{
+    flockfile( stream );
+    int r = fputs_unlocked( s, stream );
+    funlockfile( stream );
+    return r;
+}
+
 #endif
 #ifdef TEST
 #include <_PDCLIB_test.h>
index 9f7d3fa0e9135f57166e656469c6e09f2100dbe2..1fdc75326c887ac6bcfc76717e0f20ce38114954 100644 (file)
@@ -15,7 +15,9 @@
 #include <stdbool.h>
 #include <string.h>
 
-size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+size_t fread_unlocked( void * _PDCLIB_restrict ptr, 
+                       size_t size, size_t nmemb, 
+                       struct _PDCLIB_file_t * _PDCLIB_restrict stream )
 {
     if ( _PDCLIB_prepread( stream ) == EOF )
     {
@@ -41,6 +43,16 @@ size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, struct _PD
     return nmemb_i;
 }
 
+size_t fread( void * _PDCLIB_restrict ptr, 
+              size_t size, size_t nmemb, 
+              struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+{
+    flockfile( stream );
+    size_t r = fread_unlocked( ptr, size, nmemb, stream );
+    funlockfile( stream );
+    return r;
+}
+
 #endif
 
 #ifdef TEST
index 682e3c6c1e8f4eee7e1839cf6e60ba2fb7f724dd..7868c95207052b3ac47f97abe79559640872aa5d 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-struct _PDCLIB_file_t * freopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+struct _PDCLIB_file_t * freopen( 
+                            const char * _PDCLIB_restrict filename, 
+                            const char * _PDCLIB_restrict mode, 
+                            struct _PDCLIB_file_t * _PDCLIB_restrict stream )
 {
+    flockfile( stream );
+
     unsigned int status = stream->status & ( _IONBF | _IOLBF | _IOFBF | _PDCLIB_FREEBUFFER | _PDCLIB_DELONCLOSE );
     /* TODO: This function can change wide orientation of a stream */
     if ( stream->status & _PDCLIB_FWRITE )
@@ -25,6 +30,7 @@ struct _PDCLIB_file_t * freopen( const char * _PDCLIB_restrict filename, const c
     if ( ( filename == NULL ) && ( stream->filename == NULL ) )
     {
         /* TODO: Special handling for mode changes on std-streams */
+        funlockfile( stream );
         return NULL;
     }
     _PDCLIB_close( stream->handle );
@@ -49,16 +55,19 @@ struct _PDCLIB_file_t * freopen( const char * _PDCLIB_restrict filename, const c
         /* Allocate new buffer */
         if ( ( stream->filename = (char *)malloc( strlen( filename ) ) ) == NULL )
         {
+            funlockfile( stream );
             return NULL;
         }
         strcpy( stream->filename, filename );
     }
     if ( ( mode == NULL ) || ( filename[0] == '\0' ) )
     {
+        funlockfile( stream );
         return NULL;
     }
     if ( ( stream->status = _PDCLIB_filemode( mode ) ) == 0 )
     {
+        funlockfile( stream );
         return NULL;
     }
     /* Re-add the flags we saved above */
@@ -69,8 +78,10 @@ struct _PDCLIB_file_t * freopen( const char * _PDCLIB_restrict filename, const c
     /* TODO: Setting mbstate */
     if ( ( stream->handle = _PDCLIB_open( filename, stream->status ) ) == _PDCLIB_NOHANDLE )
     {
+        funlockfile( stream );
         return NULL;
     }
+    funlockfile( stream );
     return stream;
 }
 
index 6c0c70b10e7ee2c1f7789666ac835c90a45ed24c..fbe280b4b6be6b0fc04a78ddb42ab194bc61f026 100644 (file)
 
 #ifndef REGTEST
 
-int fscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... )
+int fscanf_unlocked( FILE * _PDCLIB_restrict stream, 
+                     const char * _PDCLIB_restrict format, ... )
+{
+    int rc;
+    va_list ap;
+    va_start( ap, format );
+    rc = vfscanf_unlocked( stream, format, ap );
+    va_end( ap );
+    return rc;
+}
+
+int fscanf( FILE * _PDCLIB_restrict stream, 
+            const char * _PDCLIB_restrict format, ... )
 {
     int rc;
     va_list ap;
index 8e10c2ba007f49cd599c7c5fc62275995076e729..c897325509b4421e7277d8eb4f77b1dc9f5738b8 100644 (file)
@@ -12,7 +12,7 @@
 
 #include <_PDCLIB_glue.h>
 
-int fseek( struct _PDCLIB_file_t * stream, long loffset, int whence )
+int fseek_unlocked( struct _PDCLIB_file_t * stream, long loffset, int whence )
 {
     _PDCLIB_int64_t offset = loffset;
     if ( stream->status & _PDCLIB_FWRITE )
@@ -37,6 +37,14 @@ int fseek( struct _PDCLIB_file_t * stream, long loffset, int whence )
     return ( _PDCLIB_seek( stream, offset, whence ) != EOF ) ? 0 : EOF;
 }
 
+int fseek( struct _PDCLIB_file_t * stream, long loffset, int whence )
+{
+    flockfile( stream );
+    int r = fseek_unlocked( stream, loffset, whence );
+    funlockfile( stream );
+    return r;
+}
+
 #endif
 
 #ifdef TEST
index 2082b4824a74dddfc4ced451b53879a79c4cb3e4..aa2f8e655bb4a05706cb61f6bf03abf04215b335 100644 (file)
@@ -11,7 +11,8 @@
 #ifndef REGTEST
 #include <_PDCLIB_glue.h>
 
-int fsetpos( struct _PDCLIB_file_t * stream, const struct _PDCLIB_fpos_t * pos )
+int fsetpos_unlocked( struct _PDCLIB_file_t * stream, 
+                      const struct _PDCLIB_fpos_t * pos )
 {
     if ( stream->status & _PDCLIB_FWRITE )
     {
@@ -29,6 +30,15 @@ int fsetpos( struct _PDCLIB_file_t * stream, const struct _PDCLIB_fpos_t * pos )
     return 0;
 }
 
+int fsetpos( struct _PDCLIB_file_t * stream, 
+             const struct _PDCLIB_fpos_t * pos )
+{
+    flockfile( stream );
+    int res = fsetpos_unlocked( stream, pos );
+    funlockfile( stream );
+    return res;
+}
+
 #endif
 
 #ifdef TEST
index d39297f688ae9bc170360f5e5902eca020e2c4e4..74bb902407a4672dfcb3c4beacc8519b16ab11ab 100644 (file)
@@ -13,9 +13,9 @@
 
 #ifndef REGTEST
 
-long int ftell( struct _PDCLIB_file_t * stream )
+long int ftell_unlocked( struct _PDCLIB_file_t * stream )
 {
-    uint_fast64_t off64 = _PDCLIB_ftell64( stream );
+    uint_fast64_t off64 = _PDCLIB_ftell64_unlocked( stream );
 
     if ( off64 > LONG_MAX )
     {
@@ -26,6 +26,14 @@ long int ftell( struct _PDCLIB_file_t * stream )
     return off64;
 }
 
+long int ftell( struct _PDCLIB_file_t * stream )
+{
+    flockfile( stream );
+    long int off = ftell_unlocked( stream );
+    funlockfile( stream );
+    return off;
+}
+
 #endif
 
 #ifdef TEST
index 90c8f44eb3993307e5f6498da08adba71186824a..9ab8a0abfb1380df315f5565edd7c5b1d5a30871 100644 (file)
@@ -17,7 +17,9 @@
 
 //TODO OS(2012-08-01): Ascertain purpose of lineend & potentially remove
 
-size_t fwrite( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+size_t fwrite_unlocked( const void * _PDCLIB_restrict ptr, 
+               size_t size, size_t nmemb, 
+               struct _PDCLIB_file_t * _PDCLIB_restrict stream )
 {
     if ( _PDCLIB_prepwrite( stream ) == EOF )
     {
@@ -88,6 +90,16 @@ size_t fwrite( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, str
     return nmemb_i;
 }
 
+size_t fwrite( const void * _PDCLIB_restrict ptr, 
+               size_t size, size_t nmemb, 
+               struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+{
+    flockfile( stream );
+    size_t r = fwrite_unlocked( ptr, size, nmemb, stream );
+    funlockfile( stream );
+    return r;
+}
+
 #endif
 
 #ifdef TEST
index a459c22abbc50fd3a35c7b01ceb33e861bfce980..9338bafaa11114266bdb01a00bc67e577a721111 100644 (file)
 
 #ifndef REGTEST
 
+int getc_unlocked( struct _PDCLIB_file_t * stream )
+{
+    return fgetc_unlocked( stream );
+}
+
 int getc( struct _PDCLIB_file_t * stream )
 {
     return fgetc( stream );
index 16037287f9d166ada249d915bbd3c00492731a97..406abe434f9dd4fefc3899eb13bf7c6794c9265c 100644 (file)
 
 #ifndef REGTEST
 
+int getchar_unlocked( void )
+{
+    return fgetc_unlocked( stdin );
+}
+
+
 int getchar( void )
 {
     return fgetc( stdin );
index 122f8df0bf98c24d37fe564b96d39073e955cf0b..a4efd6a7015d872ddedc9bc6d3b1a3df1b93abea 100644 (file)
@@ -21,6 +21,16 @@ int printf( const char * _PDCLIB_restrict format, ... )
     return rc;
 }
 
+int printf_unlocked( const char * _PDCLIB_restrict format, ... )
+{
+    int rc;
+    va_list ap;
+    va_start( ap, format );
+    rc = vfprintf_unlocked( stdout, format, ap );
+    va_end( ap );
+    return rc;
+}
+
 #endif
 
 #ifdef TEST
index 60a4dba9294c296dd92fafd5c73f9d8a40ae0704..c1f3fc279eef8fae8b96fdb77db77829a7466fa5 100644 (file)
 
 #ifndef REGTEST
 
+int putc_unlocked( int c, struct _PDCLIB_file_t * stream )
+{
+    return fputc_unlocked( c, stream );
+}
+
+
 int putc( int c, struct _PDCLIB_file_t * stream )
 {
     return fputc( c, stream );
index 4e2d6ae7c0717b34ab5a301cb7c8e40a8c288977..52063a57f713036c09a84a1e659ba2956f4a12fb 100644 (file)
 
 #ifndef REGTEST
 
+int putchar_unlocked( int c )
+{
+    return fputc_unlocked( c, stdout );
+}
+
 int putchar( int c )
 {
     return fputc( c, stdout );
index ec67478ddace2d36a2d303c8e3943d71b4955891..4e5522695d76dafcaef018ca6ab409144921f127 100644 (file)
@@ -13,7 +13,7 @@
 
 extern char * _PDCLIB_eol;
 
-int puts( const char * s )
+int puts_unlocked( const char * s )
 {
     if ( _PDCLIB_prepwrite( stdout ) == EOF )
     {
@@ -42,6 +42,14 @@ int puts( const char * s )
     }
 }
 
+int puts( const char * s )
+{
+    flockfile( stdout );
+    int r = puts_unlocked( s );
+    funlockfile( stdout );
+    return r;
+}
+
 #endif
 
 #ifdef TEST
index 41501bc0a735c5b77c3ddf04b8f919e13fd377d5..e11ccbd653067908b8b7f7756ff3b0957ed0a803 100644 (file)
 
 #ifndef REGTEST
 
+int scanf_unlocked( const char * _PDCLIB_restrict format, ... )
+{
+    va_list ap;
+    va_start( ap, format );
+    return vfscanf_unlocked( stdin, format, ap );
+}
+
 int scanf( const char * _PDCLIB_restrict format, ... )
 {
     va_list ap;
index 001735b533c04361648b2c3eb5475cdced99faac..45b8a92a73e9fc004146ad9d46aae51bd0e9d013 100644 (file)
@@ -10,7 +10,7 @@
 
 #ifndef REGTEST
 
-int ungetc( int c, struct _PDCLIB_file_t * stream )
+int ungetc_unlocked( int c, struct _PDCLIB_file_t * stream )
 {
     if ( c == EOF || stream->ungetidx == _PDCLIB_UNGETCBUFSIZE )
     {
@@ -19,6 +19,14 @@ int ungetc( int c, struct _PDCLIB_file_t * stream )
     return stream->ungetbuf[stream->ungetidx++] = (unsigned char) c;
 }
 
+int ungetc( int c, struct _PDCLIB_file_t * stream )
+{
+    flockfile( stream );
+    int r = ungetc_unlocked( c, stream );
+    funlockfile( stream);
+    return r;
+}
+
 #endif
 
 #ifdef TEST
index cc6e7a6e40388f9c65a187c3df3bea8e7e3dff8c..ffb4bbe6e49794509ccf20d018e924e22d0ac22c 100644 (file)
@@ -12,7 +12,9 @@
 
 #ifndef REGTEST
 
-int vfprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, va_list arg )
+int vfprintf_unlocked( struct _PDCLIB_file_t * _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;
@@ -46,6 +48,16 @@ int vfprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDC
     return status.i;
 }
 
+int vfprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, 
+              const char * _PDCLIB_restrict format, 
+              va_list arg )
+{
+    flockfile( stream );
+    int r = vfprintf_unlocked( stream, format, arg );
+    funlockfile( stream );
+    return r;
+}
+
 #endif
 
 #ifdef TEST
index b9a6896ed7a54381b9e95a692486a3e881db0304..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;
@@ -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
index 48ad5576e08f150705d40c12ab8e156ee2f0f2f1..6eba229114e8fb9eb530c60a15df22b92f477da5 100644 (file)
 
 #ifndef REGTEST
 
+int vprintf_unlocked( const char * _PDCLIB_restrict format, 
+                      _PDCLIB_va_list arg )
+{
+    return vfprintf_unlocked( stdout, format, arg );
+}
+
 int vprintf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg )
 {
     return vfprintf( stdout, format, arg );
index 0b9189d69c9ab21f60e89ab3224e4c059304f01f..dc3a236a2bd552e24bed4e2c27d3a468fb6cbae6 100644 (file)
 
 #ifndef REGTEST
 
+int vscanf_unlocked( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg )
+{
+    return vfscanf_unlocked( stdin, format, arg );
+}
+
 int vscanf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg )
 {
     return vfscanf( stdin, format, arg );
index 06536d177ff5e84c4765ff3c120caa7bc62a8242..64a06517cc1a51a45d991935a8915eb9fd9ca493 100644 (file)
 
 #ifndef REGTEST
 
-int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg )
+int vsnprintf( char * _PDCLIB_restrict s, 
+               size_t n, 
+               const char * _PDCLIB_restrict format, 
+               _PDCLIB_va_list arg )
 {
     /* TODO: This function should interpret format as multibyte characters.  */
     struct _PDCLIB_status_t status;
index 3dfe3c208505fefd5a99bfe8031d10bc92870efe..5f08688b7c00825e36eaaa2914f86ccb4cbfa261 100644 (file)
@@ -12,7 +12,9 @@
 
 #ifndef REGTEST
 
-int vsprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, va_list arg )
+int vsprintf( char * _PDCLIB_restrict s, 
+              const char * _PDCLIB_restrict format, 
+              va_list arg )
 {
     return vsnprintf( s, SIZE_MAX, format, arg ); /* TODO: Replace with a non-checking call */
 }
index 4300a3eb4d9b10720cd5c702f95fed28e8702911..99b8bad20a7292e6ea4158039a6691627e2b14c4 100644 (file)
@@ -12,7 +12,9 @@
 #ifndef REGTEST
 #include <ctype.h>
 
-int vsscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, va_list arg )
+int vsscanf( const char * _PDCLIB_restrict s, 
+             const char * _PDCLIB_restrict format, 
+             va_list arg )
 {
     /* TODO: This function should interpret format as multibyte characters.  */
     struct _PDCLIB_status_t status;
index acc001228a053ca5fcb1e1540d6f460475ba7856..79a54bde2fedec9ac42e1cf8ed21baf0d9cdaa2a 100644 (file)
@@ -788,7 +788,6 @@ int fsetpos( FILE * stream, const fpos_t * pos ) _PDCLIB_nothrow;
    TODO: Implementation-defined errno setting for ftell().
 */
 long int ftell( FILE * stream ) _PDCLIB_nothrow;
-_PDCLIB_uint_fast64_t _PDCLIB_ftell64( FILE * stream ) _PDCLIB_nothrow;
 
 /* Equivalent to (void)fseek( stream, 0L, SEEK_SET ), except that the error
    indicator for the stream is also cleared.
@@ -861,5 +860,30 @@ char *fgets_unlocked(char *s, int n, FILE *stream);
 int fputs_unlocked(const char *s, FILE *stream);
 #endif
 
+#if defined(_PDCLIB_EXTENSIONS)
+int fgetpos_unlocked( FILE * _PDCLIB_restrict stream, fpos_t * _PDCLIB_restrict pos ) _PDCLIB_nothrow;
+int fsetpos_unlocked( FILE * stream, const fpos_t * pos ) _PDCLIB_nothrow;
+long int ftell_unlocked( FILE * stream ) _PDCLIB_nothrow;
+int fseek_unlocked( FILE * stream, long int offset, int whence ) _PDCLIB_nothrow;
+
+int puts_unlocked( const char * s ) _PDCLIB_nothrow;
+int ungetc_unlocked( int c, FILE * stream ) _PDCLIB_nothrow;
+
+
+int printf_unlocked( const char * _PDCLIB_restrict format, ... ) _PDCLIB_nothrow;
+int vprintf_unlocked( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) _PDCLIB_nothrow;
+int fprintf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ) _PDCLIB_nothrow;
+int vfprintf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) _PDCLIB_nothrow;
+int scanf_unlocked( const char * _PDCLIB_restrict format, ... ) _PDCLIB_nothrow;
+int vscanf_unlocked( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) _PDCLIB_nothrow;
+int fscanf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ) _PDCLIB_nothrow;
+int vfscanf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) _PDCLIB_nothrow;
+
+
+// Todo: remove prefix?
+_PDCLIB_uint_fast64_t _PDCLIB_ftell64( FILE * stream ) _PDCLIB_nothrow;
+_PDCLIB_uint_fast64_t _PDCLIB_ftell64_unlocked( FILE * stream ) _PDCLIB_nothrow;
+#endif
+
 _PDCLIB_END_EXTERN_C
 #endif