From b5b6c4a890795ea76f9b92b817b0a83c6bb4862c Mon Sep 17 00:00:00 2001 From: Owen Shepherd Date: Wed, 20 Feb 2013 01:21:15 +0000 Subject: [PATCH] Namespace cleanliness: Rename all ***_unlocked functions to _PDCLIB_***_unlocked. Trivial forwarders ***_unlocked -> _PDCLIB_***_unlocked will be implemented (but these functions avoid exposing the _unlocked symbols to code which is only requesting the standard-defined versions) --- functions/stdio/_PDCLIB_ftell64.c | 4 +-- functions/stdio/_PDCLIB_print.c | 3 ++- functions/stdio/clearerr.c | 8 +++--- functions/stdio/feof.c | 8 +++--- functions/stdio/ferror.c | 8 +++--- functions/stdio/fflush.c | 8 +++--- functions/stdio/fgetc.c | 8 +++--- functions/stdio/fgetpos.c | 8 +++--- functions/stdio/fgets.c | 8 +++--- functions/stdio/flockfile.c | 2 +- functions/stdio/fprintf.c | 10 +++---- functions/stdio/fputc.c | 8 +++--- functions/stdio/fputs.c | 8 +++--- functions/stdio/fread.c | 8 +++--- functions/stdio/freopen.c | 16 +++++------ functions/stdio/fscanf.c | 5 ++-- functions/stdio/fseek.c | 10 +++---- functions/stdio/fsetpos.c | 8 +++--- functions/stdio/ftell.c | 9 ++++--- functions/stdio/ftrylockfile.c | 2 +- functions/stdio/funlockfile.c | 2 +- functions/stdio/fwrite.c | 8 +++--- functions/stdio/getc.c | 7 ++--- functions/stdio/getchar.c | 5 ++-- functions/stdio/printf.c | 4 +-- functions/stdio/putc.c | 5 ++-- functions/stdio/putchar.c | 5 ++-- functions/stdio/puts.c | 10 +++---- functions/stdio/rewind.c | 10 +++---- functions/stdio/scanf.c | 5 ++-- functions/stdio/setvbuf.c | 2 +- functions/stdio/ungetc.c | 8 +++--- functions/stdio/vfprintf.c | 8 +++--- functions/stdio/vfscanf.c | 14 +++++----- functions/stdio/vprintf.c | 7 ++--- functions/stdio/vscanf.c | 6 +++-- internals/_PDCLIB_io.h | 45 ++++++++++++++++++++++++++++++- 37 files changed, 177 insertions(+), 123 deletions(-) diff --git a/functions/stdio/_PDCLIB_ftell64.c b/functions/stdio/_PDCLIB_ftell64.c index 5be7be5..f72d2f9 100644 --- a/functions/stdio/_PDCLIB_ftell64.c +++ b/functions/stdio/_PDCLIB_ftell64.c @@ -41,9 +41,9 @@ uint_fast64_t _PDCLIB_ftell64_unlocked( FILE * stream ) uint_fast64_t _PDCLIB_ftell64( FILE * stream ) { - flockfile( stream ); + _PDCLIB_flockfile( stream ); uint_fast64_t pos = _PDCLIB_ftell64_unlocked( stream ); - funlockfile( stream ); + _PDCLIB_funlockfile( stream ); return pos; } diff --git a/functions/stdio/_PDCLIB_print.c b/functions/stdio/_PDCLIB_print.c index 95fbe9c..ec7dc4a 100644 --- a/functions/stdio/_PDCLIB_print.c +++ b/functions/stdio/_PDCLIB_print.c @@ -16,6 +16,7 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> /* Using an integer's bits as flags for both the conversion flags and length modifiers. @@ -53,7 +54,7 @@ do { \ int character = x; \ if ( status->i < status->n ) { \ if ( status->stream != NULL ) \ - putc_unlocked( character, status->stream ); \ + _PDCLIB_putc_unlocked( character, status->stream ); \ else \ status->s[status->i] = character; \ } \ diff --git a/functions/stdio/clearerr.c b/functions/stdio/clearerr.c index 20af80f..a80e3e2 100644 --- a/functions/stdio/clearerr.c +++ b/functions/stdio/clearerr.c @@ -11,16 +11,16 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -void clearerr_unlocked( FILE * stream ) +void _PDCLIB_clearerr_unlocked( FILE * stream ) { stream->status &= ~( _PDCLIB_ERRORFLAG | _PDCLIB_EOFFLAG ); } void clearerr( FILE * stream ) { - flockfile( stream ); - clearerr_unlocked( stream ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + _PDCLIB_clearerr_unlocked( stream ); + _PDCLIB_funlockfile( stream ); } #endif diff --git a/functions/stdio/feof.c b/functions/stdio/feof.c index b37c7b9..772bb50 100644 --- a/functions/stdio/feof.c +++ b/functions/stdio/feof.c @@ -11,16 +11,16 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -int feof_unlocked( FILE * stream ) +int _PDCLIB_feof_unlocked( FILE * stream ) { return stream->status & _PDCLIB_EOFFLAG; } int feof( FILE * stream ) { - flockfile( stream ); - int eof = feof_unlocked( stream ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + int eof = _PDCLIB_feof_unlocked( stream ); + _PDCLIB_funlockfile( stream ); return eof; } diff --git a/functions/stdio/ferror.c b/functions/stdio/ferror.c index f683787..07ecde7 100644 --- a/functions/stdio/ferror.c +++ b/functions/stdio/ferror.c @@ -11,16 +11,16 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -int ferror_unlocked( FILE * stream ) +int _PDCLIB_ferror_unlocked( FILE * stream ) { return stream->status & _PDCLIB_ERRORFLAG; } int ferror( FILE * stream ) { - flockfile( stream ); - int error = ferror_unlocked( stream ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + int error = _PDCLIB_ferror_unlocked( stream ); + _PDCLIB_funlockfile( stream ); return error; } diff --git a/functions/stdio/fflush.c b/functions/stdio/fflush.c index e03079f..3f1a411 100644 --- a/functions/stdio/fflush.c +++ b/functions/stdio/fflush.c @@ -13,7 +13,7 @@ extern FILE * _PDCLIB_filelist; -int fflush_unlocked( FILE * stream ) +int _PDCLIB_fflush_unlocked( FILE * stream ) { if ( stream == NULL ) { @@ -41,9 +41,9 @@ int fflush_unlocked( FILE * stream ) int fflush( FILE * stream ) { - flockfile( stream ); - int res = fflush_unlocked(stream); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + int res = _PDCLIB_fflush_unlocked(stream); + _PDCLIB_funlockfile( stream ); return res; } diff --git a/functions/stdio/fgetc.c b/functions/stdio/fgetc.c index 56e96f5..114ab97 100644 --- a/functions/stdio/fgetc.c +++ b/functions/stdio/fgetc.c @@ -11,7 +11,7 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -int fgetc_unlocked( FILE * stream ) +int _PDCLIB_fgetc_unlocked( FILE * stream ) { if ( _PDCLIB_prepread( stream ) == EOF ) { @@ -27,9 +27,9 @@ int fgetc_unlocked( FILE * stream ) int fgetc( FILE * stream ) { - flockfile( stream ); - int c = fgetc_unlocked( stream ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + int c = _PDCLIB_fgetc_unlocked( stream ); + _PDCLIB_funlockfile( stream ); return c; } diff --git a/functions/stdio/fgetpos.c b/functions/stdio/fgetpos.c index 8401406..d4a717e 100644 --- a/functions/stdio/fgetpos.c +++ b/functions/stdio/fgetpos.c @@ -11,7 +11,7 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -int fgetpos_unlocked( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos ) +int _PDCLIB_fgetpos_unlocked( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos ) { pos->offset = stream->pos.offset + stream->bufidx - stream->ungetidx; pos->mbs = stream->pos.mbs; @@ -21,9 +21,9 @@ int fgetpos_unlocked( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_r int fgetpos( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos ) { - flockfile( stream ); - int res = fgetpos_unlocked( stream, pos ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + int res = _PDCLIB_fgetpos_unlocked( stream, pos ); + _PDCLIB_funlockfile( stream ); return res; } diff --git a/functions/stdio/fgets.c b/functions/stdio/fgets.c index 95103bb..fd89344 100644 --- a/functions/stdio/fgets.c +++ b/functions/stdio/fgets.c @@ -11,7 +11,7 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -char * fgets_unlocked( char * _PDCLIB_restrict s, int size, FILE * _PDCLIB_restrict stream ) +char * _PDCLIB_fgets_unlocked( char * _PDCLIB_restrict s, int size, FILE * _PDCLIB_restrict stream ) { if ( size == 0 ) { @@ -37,9 +37,9 @@ char * fgets_unlocked( char * _PDCLIB_restrict s, int size, FILE * _PDCLIB_restr char * fgets( char * _PDCLIB_restrict s, int size, FILE * _PDCLIB_restrict stream ) { - flockfile( stream ); - char* r = fgets_unlocked( s, size, stream ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + char* r = _PDCLIB_fgets_unlocked( s, size, stream ); + _PDCLIB_funlockfile( stream ); return r; } diff --git a/functions/stdio/flockfile.c b/functions/stdio/flockfile.c index 9167da0..33b2e14 100644 --- a/functions/stdio/flockfile.c +++ b/functions/stdio/flockfile.c @@ -12,7 +12,7 @@ #include #include -void flockfile( FILE * file ) +void _PDCLIB_flockfile( FILE * file ) { if( mtx_lock( &file->lock ) != thrd_success ) { abort(); diff --git a/functions/stdio/fprintf.c b/functions/stdio/fprintf.c index 0227cd4..66566a4 100644 --- a/functions/stdio/fprintf.c +++ b/functions/stdio/fprintf.c @@ -12,13 +12,13 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -int fprintf_unlocked( FILE * _PDCLIB_restrict stream, +int _PDCLIB_fprintf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ) { int rc; va_list ap; va_start( ap, format ); - rc = vfprintf( stream, format, ap ); + rc = _PDCLIB_vfprintf_unlocked( stream, format, ap ); va_end( ap ); return rc; } @@ -29,9 +29,9 @@ int fprintf( FILE * _PDCLIB_restrict stream, int rc; va_list ap; va_start( ap, format ); - flockfile( stream ); - rc = vfprintf_unlocked( stream, format, ap ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + rc = _PDCLIB_vfprintf_unlocked( stream, format, ap ); + _PDCLIB_funlockfile( stream ); va_end( ap ); return rc; } diff --git a/functions/stdio/fputc.c b/functions/stdio/fputc.c index 2aaad4f..360abc4 100644 --- a/functions/stdio/fputc.c +++ b/functions/stdio/fputc.c @@ -15,7 +15,7 @@ Returns c if successful, EOF otherwise. If a write error occurs, the error indicator of the stream is set. */ -int fputc_unlocked( int c, FILE * stream ) +int _PDCLIB_fputc_unlocked( int c, FILE * stream ) { if ( _PDCLIB_prepwrite( stream ) == EOF ) { @@ -35,9 +35,9 @@ int fputc_unlocked( int c, FILE * stream ) int fputc( int c, FILE * stream ) { - flockfile( stream ); - int r = fputc_unlocked( c, stream ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + int r = _PDCLIB_fputc_unlocked( c, stream ); + _PDCLIB_funlockfile( stream ); return r; } diff --git a/functions/stdio/fputs.c b/functions/stdio/fputs.c index 0f92aaa..3565a11 100644 --- a/functions/stdio/fputs.c +++ b/functions/stdio/fputs.c @@ -11,7 +11,7 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -int fputs_unlocked( const char * _PDCLIB_restrict s, +int _PDCLIB_fputs_unlocked( const char * _PDCLIB_restrict s, FILE * _PDCLIB_restrict stream ) { if ( _PDCLIB_prepwrite( stream ) == EOF ) @@ -49,9 +49,9 @@ int fputs_unlocked( const char * _PDCLIB_restrict s, int fputs( const char * _PDCLIB_restrict s, FILE * _PDCLIB_restrict stream ) { - flockfile( stream ); - int r = fputs_unlocked( s, stream ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + int r = _PDCLIB_fputs_unlocked( s, stream ); + _PDCLIB_funlockfile( stream ); return r; } diff --git a/functions/stdio/fread.c b/functions/stdio/fread.c index a0c23c3..9695db4 100644 --- a/functions/stdio/fread.c +++ b/functions/stdio/fread.c @@ -14,7 +14,7 @@ #include #include -size_t fread_unlocked( +size_t _PDCLIB_fread_unlocked( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, FILE * _PDCLIB_restrict stream @@ -40,9 +40,9 @@ size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, FILE * _PDCLIB_restrict stream ) { - flockfile( stream ); - size_t r = fread_unlocked( ptr, size, nmemb, stream ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + size_t r = _PDCLIB_fread_unlocked( ptr, size, nmemb, stream ); + _PDCLIB_funlockfile( stream ); return r; } diff --git a/functions/stdio/freopen.c b/functions/stdio/freopen.c index c856122..fb356a8 100644 --- a/functions/stdio/freopen.c +++ b/functions/stdio/freopen.c @@ -20,7 +20,7 @@ FILE * freopen( FILE * _PDCLIB_restrict stream ) { - flockfile( stream ); + _PDCLIB_flockfile( stream ); unsigned int status = stream->status & ( _IONBF | _IOLBF | _IOFBF | _PDCLIB_FREEBUFFER @@ -34,7 +34,7 @@ FILE * freopen( if ( ( filename == NULL ) && ( stream->filename == NULL ) ) { /* TODO: Special handling for mode changes on std-streams */ - funlockfile( stream ); + _PDCLIB_funlockfile( stream ); return NULL; } stream->ops->close(stream->handle); @@ -43,7 +43,7 @@ FILE * freopen( It does not matter with the current implementation of clearerr(), but it might start to matter if someone replaced that implementation. */ - clearerr( stream ); + _PDCLIB_clearerr_unlocked( stream ); /* The new filename might not fit the old buffer */ if ( filename == NULL ) { @@ -60,19 +60,19 @@ FILE * freopen( /* Allocate new buffer */ if ( ( stream->filename = (char *)malloc( strlen( filename ) ) ) == NULL ) { - funlockfile( stream ); + _PDCLIB_funlockfile( stream ); return NULL; } strcpy( stream->filename, filename ); } if ( ( mode == NULL ) || ( filename[0] == '\0' ) ) { - funlockfile( stream ); + _PDCLIB_funlockfile( stream ); return NULL; } if ( ( stream->status = _PDCLIB_filemode( mode ) ) == 0 ) { - funlockfile( stream ); + _PDCLIB_funlockfile( stream ); return NULL; } /* Re-add the flags we saved above */ @@ -84,10 +84,10 @@ FILE * freopen( if ( ! _PDCLIB_open( &stream->handle, &stream->ops, filename, stream->status ) ) { - funlockfile( stream ); + _PDCLIB_funlockfile( stream ); return NULL; } - funlockfile( stream ); + _PDCLIB_funlockfile( stream ); return stream; } diff --git a/functions/stdio/fscanf.c b/functions/stdio/fscanf.c index fbe280b..f9b950e 100644 --- a/functions/stdio/fscanf.c +++ b/functions/stdio/fscanf.c @@ -10,14 +10,15 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int fscanf_unlocked( FILE * _PDCLIB_restrict stream, +int _PDCLIB_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 ); + rc = _PDCLIB_vfscanf_unlocked( stream, format, ap ); va_end( ap ); return rc; } diff --git a/functions/stdio/fseek.c b/functions/stdio/fseek.c index 35b6416..44cc6fb 100644 --- a/functions/stdio/fseek.c +++ b/functions/stdio/fseek.c @@ -11,7 +11,7 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -int fseek_unlocked( FILE * stream, long loffset, int whence ) +int _PDCLIB_fseek_unlocked( FILE * stream, long loffset, int whence ) { _PDCLIB_int64_t offset = loffset; if ( stream->status & _PDCLIB_FWRITE ) @@ -30,7 +30,7 @@ int fseek_unlocked( FILE * stream, long loffset, int whence ) if ( whence == SEEK_CUR ) { whence = SEEK_SET; - offset += _PDCLIB_ftell64( stream ); + offset += _PDCLIB_ftell64_unlocked( stream ); } return ( _PDCLIB_seek( stream, offset, whence ) != EOF ) ? 0 : EOF; @@ -38,9 +38,9 @@ int fseek_unlocked( FILE * stream, long loffset, int whence ) int fseek( FILE * stream, long loffset, int whence ) { - flockfile( stream ); - int r = fseek_unlocked( stream, loffset, whence ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + int r = _PDCLIB_fseek_unlocked( stream, loffset, whence ); + _PDCLIB_funlockfile( stream ); return r; } diff --git a/functions/stdio/fsetpos.c b/functions/stdio/fsetpos.c index ed3c0a8..5a78706 100644 --- a/functions/stdio/fsetpos.c +++ b/functions/stdio/fsetpos.c @@ -11,7 +11,7 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -int fsetpos_unlocked( FILE * stream, +int _PDCLIB_fsetpos_unlocked( FILE * stream, const _PDCLIB_fpos_t * pos ) { if ( stream->status & _PDCLIB_FWRITE ) @@ -33,9 +33,9 @@ int fsetpos_unlocked( FILE * stream, int fsetpos( FILE * stream, const _PDCLIB_fpos_t * pos ) { - flockfile( stream ); - int res = fsetpos_unlocked( stream, pos ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + int res = _PDCLIB_fsetpos_unlocked( stream, pos ); + _PDCLIB_funlockfile( stream ); return res; } diff --git a/functions/stdio/ftell.c b/functions/stdio/ftell.c index 441c9fc..ba79db3 100644 --- a/functions/stdio/ftell.c +++ b/functions/stdio/ftell.c @@ -12,8 +12,9 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -long int ftell_unlocked( FILE * stream ) +long int _PDCLIB_ftell_unlocked( FILE * stream ) { uint_fast64_t off64 = _PDCLIB_ftell64_unlocked( stream ); @@ -28,9 +29,9 @@ long int ftell_unlocked( FILE * stream ) long int ftell( FILE * stream ) { - flockfile( stream ); - long int off = ftell_unlocked( stream ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + long int off = _PDCLIB_ftell_unlocked( stream ); + _PDCLIB_funlockfile( stream ); return off; } diff --git a/functions/stdio/ftrylockfile.c b/functions/stdio/ftrylockfile.c index 41377da..994b51e 100644 --- a/functions/stdio/ftrylockfile.c +++ b/functions/stdio/ftrylockfile.c @@ -12,7 +12,7 @@ #include #include -int ftrylockfile( FILE * file ) +int _PDCLIB_ftrylockfile( FILE * file ) { int res = mtx_trylock( &file->lock ); switch(res) { diff --git a/functions/stdio/funlockfile.c b/functions/stdio/funlockfile.c index 648a22e..0113390 100644 --- a/functions/stdio/funlockfile.c +++ b/functions/stdio/funlockfile.c @@ -12,7 +12,7 @@ #include #include -void funlockfile( FILE * file ) +void _PDCLIB_funlockfile( FILE * file ) { int res = mtx_unlock( &file->lock ); switch(res) { diff --git a/functions/stdio/fwrite.c b/functions/stdio/fwrite.c index 9319cf7..c9396bf 100644 --- a/functions/stdio/fwrite.c +++ b/functions/stdio/fwrite.c @@ -17,7 +17,7 @@ //TODO OS(2012-08-01): Ascertain purpose of lineend & potentially remove -size_t fwrite_unlocked( const void * _PDCLIB_restrict ptr, +size_t _PDCLIB_fwrite_unlocked( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, FILE * _PDCLIB_restrict stream ) { @@ -94,9 +94,9 @@ size_t fwrite( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, FILE * _PDCLIB_restrict stream ) { - flockfile( stream ); - size_t r = fwrite_unlocked( ptr, size, nmemb, stream ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + size_t r = _PDCLIB_fwrite_unlocked( ptr, size, nmemb, stream ); + _PDCLIB_funlockfile( stream ); return r; } diff --git a/functions/stdio/getc.c b/functions/stdio/getc.c index e733d0b..b0c56f4 100644 --- a/functions/stdio/getc.c +++ b/functions/stdio/getc.c @@ -9,10 +9,11 @@ #include #ifndef REGTEST - -int getc_unlocked( FILE * stream ) +#include <_PDCLIB_io.h> + +int _PDCLIB_getc_unlocked( FILE * stream ) { - return fgetc_unlocked( stream ); + return _PDCLIB_fgetc_unlocked( stream ); } int getc( FILE * stream ) diff --git a/functions/stdio/getchar.c b/functions/stdio/getchar.c index 406abe4..1e76176 100644 --- a/functions/stdio/getchar.c +++ b/functions/stdio/getchar.c @@ -9,10 +9,11 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int getchar_unlocked( void ) +int _PDCLIB_getchar_unlocked( void ) { - return fgetc_unlocked( stdin ); + return _PDCLIB_fgetc_unlocked( stdin ); } diff --git a/functions/stdio/printf.c b/functions/stdio/printf.c index a12e137..2b147e4 100644 --- a/functions/stdio/printf.c +++ b/functions/stdio/printf.c @@ -22,12 +22,12 @@ int printf( const char * _PDCLIB_restrict format, ... ) return rc; } -int printf_unlocked( const char * _PDCLIB_restrict format, ... ) +int _PDCLIB_printf_unlocked( const char * _PDCLIB_restrict format, ... ) { int rc; va_list ap; va_start( ap, format ); - rc = vfprintf_unlocked( stdout, format, ap ); + rc = _PDCLIB_vfprintf_unlocked( stdout, format, ap ); va_end( ap ); return rc; } diff --git a/functions/stdio/putc.c b/functions/stdio/putc.c index 6bb2e9e..026e5e0 100644 --- a/functions/stdio/putc.c +++ b/functions/stdio/putc.c @@ -9,10 +9,11 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int putc_unlocked( int c, FILE * stream ) +int _PDCLIB_putc_unlocked( int c, FILE * stream ) { - return fputc_unlocked( c, stream ); + return _PDCLIB_fputc_unlocked( c, stream ); } diff --git a/functions/stdio/putchar.c b/functions/stdio/putchar.c index 52063a5..a79932f 100644 --- a/functions/stdio/putchar.c +++ b/functions/stdio/putchar.c @@ -9,10 +9,11 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int putchar_unlocked( int c ) +int _PDCLIB_putchar_unlocked( int c ) { - return fputc_unlocked( c, stdout ); + return _PDCLIB_fputc_unlocked( c, stdout ); } int putchar( int c ) diff --git a/functions/stdio/puts.c b/functions/stdio/puts.c index 4e55226..35daf64 100644 --- a/functions/stdio/puts.c +++ b/functions/stdio/puts.c @@ -9,11 +9,11 @@ #include #ifndef REGTEST -#include <_PDCLIB_glue.h> +#include <_PDCLIB_io.h> extern char * _PDCLIB_eol; -int puts_unlocked( const char * s ) +int _PDCLIB_puts_unlocked( const char * s ) { if ( _PDCLIB_prepwrite( stdout ) == EOF ) { @@ -44,9 +44,9 @@ int puts_unlocked( const char * s ) int puts( const char * s ) { - flockfile( stdout ); - int r = puts_unlocked( s ); - funlockfile( stdout ); + _PDCLIB_flockfile( stdout ); + int r = _PDCLIB_puts_unlocked( s ); + _PDCLIB_funlockfile( stdout ); return r; } diff --git a/functions/stdio/rewind.c b/functions/stdio/rewind.c index 53ab51d..18eb6a9 100644 --- a/functions/stdio/rewind.c +++ b/functions/stdio/rewind.c @@ -11,17 +11,17 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -void rewind_unlocked( FILE * stream ) +void _PDCLIB_rewind_unlocked( FILE * stream ) { stream->status &= ~ _PDCLIB_ERRORFLAG; - fseek_unlocked( stream, 0L, SEEK_SET ); + _PDCLIB_fseek_unlocked( stream, 0L, SEEK_SET ); } void rewind( FILE * stream ) { - flockfile(stream); - rewind_unlocked(stream); - funlockfile(stream); + _PDCLIB_flockfile(stream); + _PDCLIB_rewind_unlocked(stream); + _PDCLIB_funlockfile(stream); } #endif diff --git a/functions/stdio/scanf.c b/functions/stdio/scanf.c index e11ccbd..7da1902 100644 --- a/functions/stdio/scanf.c +++ b/functions/stdio/scanf.c @@ -10,12 +10,13 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int scanf_unlocked( const char * _PDCLIB_restrict format, ... ) +int _PDCLIB_scanf_unlocked( const char * _PDCLIB_restrict format, ... ) { va_list ap; va_start( ap, format ); - return vfscanf_unlocked( stdin, format, ap ); + return _PDCLIB_vfscanf_unlocked( stdin, format, ap ); } int scanf( const char * _PDCLIB_restrict format, ... ) diff --git a/functions/stdio/setvbuf.c b/functions/stdio/setvbuf.c index d8470fc..b07d87e 100644 --- a/functions/stdio/setvbuf.c +++ b/functions/stdio/setvbuf.c @@ -15,7 +15,7 @@ int setvbuf( FILE * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf, int mode, size_t size ) { - _PDCLIB_lockfile( stream ); + _PDCLIB_flockfile( stream ); switch ( mode ) { case _IONBF: diff --git a/functions/stdio/ungetc.c b/functions/stdio/ungetc.c index cc6d177..59d2b57 100644 --- a/functions/stdio/ungetc.c +++ b/functions/stdio/ungetc.c @@ -11,7 +11,7 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -int ungetc_unlocked( int c, FILE * stream ) +int _PDCLIB_ungetc_unlocked( int c, FILE * stream ) { if ( c == EOF || stream->ungetidx == _PDCLIB_UNGETCBUFSIZE ) { @@ -22,9 +22,9 @@ int ungetc_unlocked( int c, FILE * stream ) int ungetc( int c, FILE * stream ) { - flockfile( stream ); - int r = ungetc_unlocked( c, stream ); - funlockfile( stream); + _PDCLIB_flockfile( stream ); + int r = _PDCLIB_ungetc_unlocked( c, stream ); + _PDCLIB_funlockfile( stream); return r; } diff --git a/functions/stdio/vfprintf.c b/functions/stdio/vfprintf.c index b8e9194..9be5b2d 100644 --- a/functions/stdio/vfprintf.c +++ b/functions/stdio/vfprintf.c @@ -14,7 +14,7 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -int vfprintf_unlocked( FILE * _PDCLIB_restrict stream, +int _PDCLIB_vfprintf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, va_list arg ) { @@ -54,9 +54,9 @@ int vfprintf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, va_list arg ) { - flockfile( stream ); - int r = vfprintf_unlocked( stream, format, arg ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + int r = _PDCLIB_vfprintf_unlocked( stream, format, arg ); + _PDCLIB_funlockfile( stream ); return r; } diff --git a/functions/stdio/vfscanf.c b/functions/stdio/vfscanf.c index 14bba50..bd5a681 100644 --- a/functions/stdio/vfscanf.c +++ b/functions/stdio/vfscanf.c @@ -13,7 +13,7 @@ #ifndef REGTEST #include <_PDCLIB_io.h> -int vfscanf_unlocked( FILE * _PDCLIB_restrict stream, +int _PDCLIB_vfscanf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, va_list arg ) { @@ -47,18 +47,18 @@ int vfscanf_unlocked( FILE * _PDCLIB_restrict stream, } if ( ! feof( stream ) ) { - ungetc( c, stream ); + _PDCLIB_ungetc_unlocked( c, stream ); } } else { /* Non-whitespace char in format string: Match verbatim */ - if ( ( ( c = getc( stream ) ) != *format ) || feof( stream ) ) + if ( ( ( c = _PDCLIB_getc_unlocked( stream ) ) != *format ) || feof( stream ) ) { /* Matching error */ if ( ! feof( stream ) && ! ferror( stream ) ) { - ungetc( c, stream ); + _PDCLIB_ungetc_unlocked( c, stream ); } else if ( status.n == 0 ) { @@ -92,9 +92,9 @@ 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 ); + _PDCLIB_flockfile( stream ); + int r = _PDCLIB_vfscanf_unlocked( stream, format, arg ); + _PDCLIB_funlockfile( stream ); return r; } diff --git a/functions/stdio/vprintf.c b/functions/stdio/vprintf.c index 6eba229..ae2b037 100644 --- a/functions/stdio/vprintf.c +++ b/functions/stdio/vprintf.c @@ -10,11 +10,12 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int vprintf_unlocked( const char * _PDCLIB_restrict format, - _PDCLIB_va_list arg ) +int _PDCLIB_vprintf_unlocked( const char * _PDCLIB_restrict format, + _PDCLIB_va_list arg ) { - return vfprintf_unlocked( stdout, format, arg ); + return _PDCLIB_vfprintf_unlocked( stdout, format, arg ); } int vprintf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) diff --git a/functions/stdio/vscanf.c b/functions/stdio/vscanf.c index dc3a236..3e4ada4 100644 --- a/functions/stdio/vscanf.c +++ b/functions/stdio/vscanf.c @@ -10,10 +10,12 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int vscanf_unlocked( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) +int _PDCLIB_vscanf_unlocked( const char * _PDCLIB_restrict format, + _PDCLIB_va_list arg ) { - return vfscanf_unlocked( stdin, format, arg ); + return _PDCLIB_vfscanf_unlocked( stdin, format, arg ); } int vscanf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) diff --git a/internals/_PDCLIB_io.h b/internals/_PDCLIB_io.h index e4fd94e..65b6589 100644 --- a/internals/_PDCLIB_io.h +++ b/internals/_PDCLIB_io.h @@ -168,7 +168,7 @@ struct _PDCLIB_fileops _PDCLIB_size_t length, _PDCLIB_size_t * numCharsWritten ); }; -/* FILE structure */ +/* struct _PDCLIB_file structure */ struct _PDCLIB_file { const _PDCLIB_fileops_t * ops; @@ -223,4 +223,47 @@ static inline _PDCLIB_size_t _PDCLIB_getchars( char * out, _PDCLIB_size_t n, return i; } +/* Unlocked functions - internal names + * + * We can't use the functions using their "normal" names internally because that + * would cause namespace leakage. Therefore, we use them by prefixed internal + * names + */ +void _PDCLIB_flockfile(struct _PDCLIB_file *file) _PDCLIB_nothrow; +int _PDCLIB_ftrylockfile(struct _PDCLIB_file *file) _PDCLIB_nothrow; +void _PDCLIB_funlockfile(struct _PDCLIB_file *file) _PDCLIB_nothrow; + +int _PDCLIB_getc_unlocked(struct _PDCLIB_file *stream) _PDCLIB_nothrow; +int _PDCLIB_getchar_unlocked(void) _PDCLIB_nothrow; +int _PDCLIB_putc_unlocked(int c, struct _PDCLIB_file *stream) _PDCLIB_nothrow; +int _PDCLIB_putchar_unlocked(int c) _PDCLIB_nothrow; +void _PDCLIB_clearerr_unlocked(struct _PDCLIB_file *stream) _PDCLIB_nothrow; +int _PDCLIB_feof_unlocked(struct _PDCLIB_file *stream) _PDCLIB_nothrow; +int _PDCLIB_ferror_unlocked(struct _PDCLIB_file *stream) _PDCLIB_nothrow; +int _PDCLIB_fflush_unlocked(struct _PDCLIB_file *stream) _PDCLIB_nothrow; +int _PDCLIB_fgetc_unlocked(struct _PDCLIB_file *stream) _PDCLIB_nothrow; +int _PDCLIB_fputc_unlocked(int c, struct _PDCLIB_file *stream) _PDCLIB_nothrow; +_PDCLIB_size_t _PDCLIB_fread_unlocked(void *ptr, _PDCLIB_size_t size, _PDCLIB_size_t n, struct _PDCLIB_file *stream) _PDCLIB_nothrow; +_PDCLIB_size_t _PDCLIB_fwrite_unlocked(const void *ptr, _PDCLIB_size_t size, _PDCLIB_size_t n, struct _PDCLIB_file *stream) _PDCLIB_nothrow; +char *_PDCLIB_fgets_unlocked(char *s, int n, struct _PDCLIB_file *stream) _PDCLIB_nothrow; +int _PDCLIB_fputs_unlocked(const char *s, struct _PDCLIB_file *stream) _PDCLIB_nothrow; +int _PDCLIB_fgetpos_unlocked( struct _PDCLIB_file * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos ) _PDCLIB_nothrow; +int _PDCLIB_fsetpos_unlocked( struct _PDCLIB_file * stream, const _PDCLIB_fpos_t * pos ) _PDCLIB_nothrow; +long int _PDCLIB_ftell_unlocked( struct _PDCLIB_file * stream ) _PDCLIB_nothrow; +int _PDCLIB_fseek_unlocked( struct _PDCLIB_file * stream, long int offset, int whence ) _PDCLIB_nothrow; +void _PDCLIB_rewind_unlocked( struct _PDCLIB_file * stream ) _PDCLIB_nothrow; + +int _PDCLIB_puts_unlocked( const char * s ) _PDCLIB_nothrow; +int _PDCLIB_ungetc_unlocked( int c, struct _PDCLIB_file * stream ) _PDCLIB_nothrow; + + +int _PDCLIB_printf_unlocked( const char * _PDCLIB_restrict format, ... ) _PDCLIB_nothrow; +int _PDCLIB_vprintf_unlocked( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) _PDCLIB_nothrow; +int _PDCLIB_fprintf_unlocked( struct _PDCLIB_file * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ) _PDCLIB_nothrow; +int _PDCLIB_vfprintf_unlocked( struct _PDCLIB_file * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) _PDCLIB_nothrow; +int _PDCLIB_scanf_unlocked( const char * _PDCLIB_restrict format, ... ) _PDCLIB_nothrow; +int _PDCLIB_vscanf_unlocked( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) _PDCLIB_nothrow; +int _PDCLIB_fscanf_unlocked( struct _PDCLIB_file * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ) _PDCLIB_nothrow; +int _PDCLIB_vfscanf_unlocked( struct _PDCLIB_file * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) _PDCLIB_nothrow; + #endif -- 2.40.0