From: Owen Shepherd Date: Mon, 31 Dec 2012 14:15:18 +0000 (+0000) Subject: Minimize the amount of internal definitions which get exposed via the user-visible... X-Git-Url: https://pd.if.org/git/?p=pdclib.old;a=commitdiff_plain;h=0e35e82c5e9a0804864839e8fc0e985b1ae41f07 Minimize the amount of internal definitions which get exposed via the user-visible headers --- diff --git a/functions/_PDCLIB/_PDCLIB_closeall.c b/functions/_PDCLIB/_PDCLIB_closeall.c index 5086d0d..bc6b417 100644 --- a/functions/_PDCLIB/_PDCLIB_closeall.c +++ b/functions/_PDCLIB/_PDCLIB_closeall.c @@ -7,14 +7,15 @@ */ #include +#include <_PDCLIB_io.h> #ifndef REGTEST -extern struct _PDCLIB_file_t * _PDCLIB_filelist; +extern _PDCLIB_file_t * _PDCLIB_filelist; void _PDCLIB_closeall( void ) { - struct _PDCLIB_file_t * stream = _PDCLIB_filelist; - struct _PDCLIB_file_t * next; + _PDCLIB_file_t * stream = _PDCLIB_filelist; + _PDCLIB_file_t * next; while ( stream != NULL ) { next = stream->next; diff --git a/functions/stdio/_PDCLIB_fillbuffer.c b/functions/stdio/_PDCLIB_fillbuffer.c index dfdfe26..70df158 100644 --- a/functions/stdio/_PDCLIB_fillbuffer.c +++ b/functions/stdio/_PDCLIB_fillbuffer.c @@ -1,4 +1,4 @@ -/* _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) +/* _PDCLIB_fillbuffer( FILE * stream ) This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -8,8 +8,9 @@ #ifndef REGTEST #include <_PDCLIB_glue.h> +#include <_PDCLIB_io.h> -int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) +int _PDCLIB_fillbuffer( FILE * stream ) { size_t bytesRead; bool ok = stream->ops->read( stream->handle, stream->buffer, stream->bufsize, diff --git a/functions/stdio/_PDCLIB_flushbuffer.c b/functions/stdio/_PDCLIB_flushbuffer.c index ffbbb4f..7ee0d93 100644 --- a/functions/stdio/_PDCLIB_flushbuffer.c +++ b/functions/stdio/_PDCLIB_flushbuffer.c @@ -9,8 +9,9 @@ #ifndef REGTEST #include <_PDCLIB_glue.h> +#include <_PDCLIB_io.h> -int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ) +int _PDCLIB_flushbuffer( FILE * stream ) { if ( ! ( stream->status & _PDCLIB_FBIN ) ) { diff --git a/functions/stdio/_PDCLIB_ftell64.c b/functions/stdio/_PDCLIB_ftell64.c index e0ea368..5be7be5 100644 --- a/functions/stdio/_PDCLIB_ftell64.c +++ b/functions/stdio/_PDCLIB_ftell64.c @@ -11,8 +11,9 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -uint_fast64_t _PDCLIB_ftell64_unlocked( struct _PDCLIB_file_t * stream ) +uint_fast64_t _PDCLIB_ftell64_unlocked( FILE * stream ) { /* ftell() must take into account: - the actual *physical* offset of the file, i.e. the offset as recognized @@ -38,7 +39,7 @@ uint_fast64_t _PDCLIB_ftell64_unlocked( struct _PDCLIB_file_t * stream ) return ( stream->pos.offset - ( ( (int)stream->bufend - (int)stream->bufidx ) + (int)stream->ungetidx ) ); } -uint_fast64_t _PDCLIB_ftell64( struct _PDCLIB_file_t * stream ) +uint_fast64_t _PDCLIB_ftell64( FILE * stream ) { flockfile( stream ); uint_fast64_t pos = _PDCLIB_ftell64_unlocked( stream ); diff --git a/functions/stdio/_PDCLIB_fvopen.c b/functions/stdio/_PDCLIB_fvopen.c index 466009b..4fc98ff 100644 --- a/functions/stdio/_PDCLIB_fvopen.c +++ b/functions/stdio/_PDCLIB_fvopen.c @@ -11,18 +11,21 @@ #ifndef REGTEST #include <_PDCLIB_glue.h> +#include <_PDCLIB_io.h> #include #include -extern struct _PDCLIB_file_t * _PDCLIB_filelist; +extern FILE * _PDCLIB_filelist; -struct _PDCLIB_file_t * _PDCLIB_fvopen( _PDCLIB_fd_t fd, - const _PDCLIB_fileops_t * ops, - int mode, - const char * _PDCLIB_restrict filename ) +FILE * _PDCLIB_fvopen( + _PDCLIB_fd_t fd, + const _PDCLIB_fileops_t *_PDCLIB_restrict ops, + int mode, + const char *_PDCLIB_restrict filename +) { size_t filename_len; - struct _PDCLIB_file_t * rc; + FILE * rc; if ( mode == NULL ) { /* Mode invalid */ @@ -36,7 +39,7 @@ struct _PDCLIB_file_t * _PDCLIB_fvopen( _PDCLIB_fd_t fd, Data buffer comes last because it might change in size ( setvbuf() ). */ filename_len = filename ? strlen( filename ) + 1 : 1; - if ( ( rc = calloc( 1, sizeof( struct _PDCLIB_file_t ) + _PDCLIB_UNGETCBUFSIZE + filename_len + BUFSIZ ) ) == NULL ) + if ( ( rc = calloc( 1, sizeof( FILE ) + _PDCLIB_UNGETCBUFSIZE + filename_len + BUFSIZ ) ) == NULL ) { /* no memory */ return NULL; @@ -51,7 +54,7 @@ struct _PDCLIB_file_t * _PDCLIB_fvopen( _PDCLIB_fd_t fd, rc->ops = ops; rc->handle = fd; /* Setting pointers into the memory block allocated above */ - rc->ungetbuf = (unsigned char *)rc + sizeof( struct _PDCLIB_file_t ); + rc->ungetbuf = (unsigned char *)rc + sizeof( FILE ); rc->filename = (char *)rc->ungetbuf + _PDCLIB_UNGETCBUFSIZE; rc->buffer = rc->filename + filename_len; /* Copying filename to FILE structure */ diff --git a/functions/stdio/_PDCLIB_prepread.c b/functions/stdio/_PDCLIB_prepread.c index cf1c2df..22158d5 100644 --- a/functions/stdio/_PDCLIB_prepread.c +++ b/functions/stdio/_PDCLIB_prepread.c @@ -1,6 +1,6 @@ /* $Id$ */ -/* _PDCLIB_prepread( struct _PDCLIB_file_t * ) +/* _PDCLIB_prepread( FILE * ) This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -12,7 +12,7 @@ #ifndef REGTEST #include <_PDCLIB_glue.h> -int _PDCLIB_prepread( struct _PDCLIB_file_t * stream ) +int _PDCLIB_prepread( FILE * stream ) { if ( ( stream->bufidx > stream->bufend ) || ( stream->status & ( _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_ERRORFLAG | _PDCLIB_WIDESTREAM | _PDCLIB_EOFFLAG ) ) || diff --git a/functions/stdio/_PDCLIB_prepwrite.c b/functions/stdio/_PDCLIB_prepwrite.c index 1b1c4b5..48440e7 100644 --- a/functions/stdio/_PDCLIB_prepwrite.c +++ b/functions/stdio/_PDCLIB_prepwrite.c @@ -1,6 +1,6 @@ /* $Id$ */ -/* _PDCLIB_prepwrite( struct _PDCLIB_file_t * ) +/* _PDCLIB_prepwrite( FILE * ) This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -10,7 +10,9 @@ #include #ifndef REGTEST -int _PDCLIB_prepwrite( struct _PDCLIB_file_t * stream ) +#include <_PDCLIB_io.h> + +int _PDCLIB_prepwrite( FILE * stream ) { if ( ( stream->bufidx < stream->bufend ) || ( stream->ungetidx > 0 ) || ( stream->status & ( _PDCLIB_FREAD | _PDCLIB_ERRORFLAG | _PDCLIB_WIDESTREAM | _PDCLIB_EOFFLAG ) ) || diff --git a/functions/stdio/_PDCLIB_seek.c b/functions/stdio/_PDCLIB_seek.c index 42c3273..52bb032 100644 --- a/functions/stdio/_PDCLIB_seek.c +++ b/functions/stdio/_PDCLIB_seek.c @@ -8,8 +8,9 @@ #include #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int_fast64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, +int_fast64_t _PDCLIB_seek( FILE * stream, int_fast64_t offset, int whence ) { diff --git a/functions/stdio/clearerr.c b/functions/stdio/clearerr.c index 2b032bd..20af80f 100644 --- a/functions/stdio/clearerr.c +++ b/functions/stdio/clearerr.c @@ -9,13 +9,14 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -void clearerr_unlocked( struct _PDCLIB_file_t * stream ) +void clearerr_unlocked( FILE * stream ) { stream->status &= ~( _PDCLIB_ERRORFLAG | _PDCLIB_EOFFLAG ); } -void clearerr( struct _PDCLIB_file_t * stream ) +void clearerr( FILE * stream ) { flockfile( stream ); clearerr_unlocked( stream ); diff --git a/functions/stdio/fclose.c b/functions/stdio/fclose.c index 3d9e257..9452413 100644 --- a/functions/stdio/fclose.c +++ b/functions/stdio/fclose.c @@ -11,15 +11,15 @@ #include #ifndef REGTEST -#include <_PDCLIB_glue.h> +#include <_PDCLIB_io.h> #include -extern struct _PDCLIB_file_t * _PDCLIB_filelist; +extern FILE * _PDCLIB_filelist; -int fclose( struct _PDCLIB_file_t * stream ) +int fclose( FILE * stream ) { - struct _PDCLIB_file_t * current = _PDCLIB_filelist; - struct _PDCLIB_file_t * previous = NULL; + FILE * current = _PDCLIB_filelist; + FILE * previous = NULL; /* Checking that the FILE handle is actually one we had opened before. */ while ( current != NULL ) { @@ -78,8 +78,8 @@ int fclose( struct _PDCLIB_file_t * stream ) int main( void ) { #ifndef REGTEST - struct _PDCLIB_file_t * file1; - struct _PDCLIB_file_t * file2; + FILE * file1; + FILE * file2; remove( testfile1 ); remove( testfile2 ); TESTCASE( _PDCLIB_filelist == stdin ); diff --git a/functions/stdio/feof.c b/functions/stdio/feof.c index ca43c75..b37c7b9 100644 --- a/functions/stdio/feof.c +++ b/functions/stdio/feof.c @@ -9,13 +9,14 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int feof_unlocked( struct _PDCLIB_file_t * stream ) +int feof_unlocked( FILE * stream ) { return stream->status & _PDCLIB_EOFFLAG; } -int feof( struct _PDCLIB_file_t * stream ) +int feof( FILE * stream ) { flockfile( stream ); int eof = feof_unlocked( stream ); diff --git a/functions/stdio/ferror.c b/functions/stdio/ferror.c index 394dcda..f683787 100644 --- a/functions/stdio/ferror.c +++ b/functions/stdio/ferror.c @@ -9,13 +9,14 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int ferror_unlocked( struct _PDCLIB_file_t * stream ) +int ferror_unlocked( FILE * stream ) { return stream->status & _PDCLIB_ERRORFLAG; } -int ferror( struct _PDCLIB_file_t * stream ) +int ferror( FILE * stream ) { flockfile( stream ); int error = ferror_unlocked( stream ); diff --git a/functions/stdio/fflush.c b/functions/stdio/fflush.c index df45880..e03079f 100644 --- a/functions/stdio/fflush.c +++ b/functions/stdio/fflush.c @@ -9,11 +9,11 @@ #include #ifndef REGTEST -#include <_PDCLIB_glue.h> +#include <_PDCLIB_io.h> -extern struct _PDCLIB_file_t * _PDCLIB_filelist; +extern FILE * _PDCLIB_filelist; -int fflush_unlocked( struct _PDCLIB_file_t * stream ) +int fflush_unlocked( FILE * stream ) { if ( stream == NULL ) { @@ -39,7 +39,7 @@ int fflush_unlocked( struct _PDCLIB_file_t * stream ) } } -int fflush( struct _PDCLIB_file_t * stream ) +int fflush( FILE * stream ) { flockfile( stream ); int res = fflush_unlocked(stream); diff --git a/functions/stdio/fgetc.c b/functions/stdio/fgetc.c index 61f52fd..56e96f5 100644 --- a/functions/stdio/fgetc.c +++ b/functions/stdio/fgetc.c @@ -9,10 +9,9 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -#include <_PDCLIB_glue.h> - -int fgetc_unlocked( struct _PDCLIB_file_t * stream ) +int fgetc_unlocked( FILE * stream ) { if ( _PDCLIB_prepread( stream ) == EOF ) { @@ -26,7 +25,7 @@ int fgetc_unlocked( struct _PDCLIB_file_t * stream ) return n == 0 ? EOF : (unsigned char) c; } -int fgetc( struct _PDCLIB_file_t * stream ) +int fgetc( FILE * stream ) { flockfile( stream ); int c = fgetc_unlocked( stream ); diff --git a/functions/stdio/fgetpos.c b/functions/stdio/fgetpos.c index 28352c8..8401406 100644 --- a/functions/stdio/fgetpos.c +++ b/functions/stdio/fgetpos.c @@ -9,16 +9,17 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int fgetpos_unlocked( struct _PDCLIB_file_t * _PDCLIB_restrict stream, struct _PDCLIB_fpos_t * _PDCLIB_restrict pos ) +int fgetpos_unlocked( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos ) { pos->offset = stream->pos.offset + stream->bufidx - stream->ungetidx; - pos->status = stream->pos.status; + pos->mbs = stream->pos.mbs; /* TODO: Add mbstate. */ return 0; } -int fgetpos( struct _PDCLIB_file_t * _PDCLIB_restrict stream, struct _PDCLIB_fpos_t * _PDCLIB_restrict pos ) +int fgetpos( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos ) { flockfile( stream ); int res = fgetpos_unlocked( stream, pos ); diff --git a/functions/stdio/fgets.c b/functions/stdio/fgets.c index 6fbc2ef..95103bb 100644 --- a/functions/stdio/fgets.c +++ b/functions/stdio/fgets.c @@ -9,10 +9,9 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -#include <_PDCLIB_glue.h> - -char * fgets_unlocked( char * _PDCLIB_restrict s, int size, struct _PDCLIB_file_t * _PDCLIB_restrict stream ) +char * fgets_unlocked( char * _PDCLIB_restrict s, int size, FILE * _PDCLIB_restrict stream ) { if ( size == 0 ) { @@ -36,7 +35,7 @@ char * fgets_unlocked( char * _PDCLIB_restrict s, int size, struct _PDCLIB_file_ } char * fgets( char * _PDCLIB_restrict s, int size, - struct _PDCLIB_file_t * _PDCLIB_restrict stream ) + FILE * _PDCLIB_restrict stream ) { flockfile( stream ); char* r = fgets_unlocked( s, size, stream ); diff --git a/functions/stdio/flockfile.c b/functions/stdio/flockfile.c index 4e80daf..9167da0 100644 --- a/functions/stdio/flockfile.c +++ b/functions/stdio/flockfile.c @@ -8,6 +8,7 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> #include #include diff --git a/functions/stdio/fopen.c b/functions/stdio/fopen.c index e806b00..5bcf5d8 100644 --- a/functions/stdio/fopen.c +++ b/functions/stdio/fopen.c @@ -10,11 +10,12 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> #include <_PDCLIB_glue.h> #include #include -extern struct _PDCLIB_file_t * _PDCLIB_filelist; +extern FILE * _PDCLIB_filelist; FILE * fopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode ) diff --git a/functions/stdio/fprintf.c b/functions/stdio/fprintf.c index 421ca52..0227cd4 100644 --- a/functions/stdio/fprintf.c +++ b/functions/stdio/fprintf.c @@ -10,8 +10,9 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int fprintf_unlocked( struct _PDCLIB_file_t * _PDCLIB_restrict stream, +int fprintf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ) { int rc; @@ -22,7 +23,7 @@ int fprintf_unlocked( struct _PDCLIB_file_t * _PDCLIB_restrict stream, return rc; } -int fprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, +int fprintf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ) { int rc; diff --git a/functions/stdio/fputc.c b/functions/stdio/fputc.c index ae998ea..2aaad4f 100644 --- a/functions/stdio/fputc.c +++ b/functions/stdio/fputc.c @@ -9,14 +9,13 @@ #include #ifndef REGTEST - -#include <_PDCLIB_glue.h> +#include <_PDCLIB_io.h> /* Write the value c (cast to unsigned char) to the given stream. Returns c if successful, EOF otherwise. If a write error occurs, the error indicator of the stream is set. */ -int fputc_unlocked( int c, struct _PDCLIB_file_t * stream ) +int fputc_unlocked( int c, FILE * stream ) { if ( _PDCLIB_prepwrite( stream ) == EOF ) { @@ -34,7 +33,7 @@ int fputc_unlocked( int c, struct _PDCLIB_file_t * stream ) return c; } -int fputc( int c, struct _PDCLIB_file_t * stream ) +int fputc( int c, FILE * stream ) { flockfile( stream ); int r = fputc_unlocked( c, stream ); diff --git a/functions/stdio/fputs.c b/functions/stdio/fputs.c index 0b1e325..0f92aaa 100644 --- a/functions/stdio/fputs.c +++ b/functions/stdio/fputs.c @@ -9,10 +9,10 @@ #include #ifndef REGTEST -#include <_PDCLIB_glue.h> +#include <_PDCLIB_io.h> int fputs_unlocked( const char * _PDCLIB_restrict s, - struct _PDCLIB_file_t * _PDCLIB_restrict stream ) + FILE * _PDCLIB_restrict stream ) { if ( _PDCLIB_prepwrite( stream ) == EOF ) { @@ -47,7 +47,7 @@ int fputs_unlocked( const char * _PDCLIB_restrict s, } int fputs( const char * _PDCLIB_restrict s, - struct _PDCLIB_file_t * _PDCLIB_restrict stream ) + FILE * _PDCLIB_restrict stream ) { flockfile( stream ); int r = fputs_unlocked( s, stream ); diff --git a/functions/stdio/fread.c b/functions/stdio/fread.c index f1ab3a9..a0c23c3 100644 --- a/functions/stdio/fread.c +++ b/functions/stdio/fread.c @@ -9,15 +9,16 @@ #include #ifndef REGTEST - -#include <_PDCLIB_glue.h> +#include <_PDCLIB_io.h> #include #include -size_t fread_unlocked( 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, + FILE * _PDCLIB_restrict stream +) { if ( _PDCLIB_prepread( stream ) == EOF ) { @@ -37,7 +38,7 @@ size_t fread_unlocked( void * _PDCLIB_restrict ptr, size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, - struct _PDCLIB_file_t * _PDCLIB_restrict stream ) + FILE * _PDCLIB_restrict stream ) { flockfile( stream ); size_t r = fread_unlocked( ptr, size, nmemb, stream ); diff --git a/functions/stdio/freopen.c b/functions/stdio/freopen.c index 741731b..c856122 100644 --- a/functions/stdio/freopen.c +++ b/functions/stdio/freopen.c @@ -9,15 +9,16 @@ #include #ifndef REGTEST - +#include <_PDCLIB_io.h> #include <_PDCLIB_glue.h> #include #include -struct _PDCLIB_file_t * freopen( - const char * _PDCLIB_restrict filename, - const char * _PDCLIB_restrict mode, - struct _PDCLIB_file_t * _PDCLIB_restrict stream ) +FILE * freopen( + const char * _PDCLIB_restrict filename, + const char * _PDCLIB_restrict mode, + FILE * _PDCLIB_restrict stream +) { flockfile( stream ); diff --git a/functions/stdio/fseek.c b/functions/stdio/fseek.c index c897325..35b6416 100644 --- a/functions/stdio/fseek.c +++ b/functions/stdio/fseek.c @@ -9,10 +9,9 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -#include <_PDCLIB_glue.h> - -int fseek_unlocked( struct _PDCLIB_file_t * stream, long loffset, int whence ) +int fseek_unlocked( FILE * stream, long loffset, int whence ) { _PDCLIB_int64_t offset = loffset; if ( stream->status & _PDCLIB_FWRITE ) @@ -37,7 +36,7 @@ int fseek_unlocked( 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 ) +int fseek( FILE * stream, long loffset, int whence ) { flockfile( stream ); int r = fseek_unlocked( stream, loffset, whence ); diff --git a/functions/stdio/fsetpos.c b/functions/stdio/fsetpos.c index aa2f8e6..ed3c0a8 100644 --- a/functions/stdio/fsetpos.c +++ b/functions/stdio/fsetpos.c @@ -9,10 +9,10 @@ #include #ifndef REGTEST -#include <_PDCLIB_glue.h> +#include <_PDCLIB_io.h> -int fsetpos_unlocked( struct _PDCLIB_file_t * stream, - const struct _PDCLIB_fpos_t * pos ) +int fsetpos_unlocked( FILE * stream, + const _PDCLIB_fpos_t * pos ) { if ( stream->status & _PDCLIB_FWRITE ) { @@ -25,13 +25,13 @@ int fsetpos_unlocked( struct _PDCLIB_file_t * stream, { return EOF; } - stream->pos.status = pos->status; - /* TODO: Add mbstate. */ + stream->pos.mbs = pos->mbs; + return 0; } -int fsetpos( struct _PDCLIB_file_t * stream, - const struct _PDCLIB_fpos_t * pos ) +int fsetpos( FILE * stream, + const _PDCLIB_fpos_t * pos ) { flockfile( stream ); int res = fsetpos_unlocked( stream, pos ); diff --git a/functions/stdio/ftell.c b/functions/stdio/ftell.c index 74bb902..441c9fc 100644 --- a/functions/stdio/ftell.c +++ b/functions/stdio/ftell.c @@ -13,7 +13,7 @@ #ifndef REGTEST -long int ftell_unlocked( struct _PDCLIB_file_t * stream ) +long int ftell_unlocked( FILE * stream ) { uint_fast64_t off64 = _PDCLIB_ftell64_unlocked( stream ); @@ -26,7 +26,7 @@ long int ftell_unlocked( struct _PDCLIB_file_t * stream ) return off64; } -long int ftell( struct _PDCLIB_file_t * stream ) +long int ftell( FILE * stream ) { flockfile( stream ); long int off = ftell_unlocked( stream ); @@ -38,8 +38,10 @@ long int ftell( struct _PDCLIB_file_t * stream ) #ifdef TEST #include <_PDCLIB_test.h> - #include +#ifndef REGTEST +#include <_PDCLIB_io.h> +#endif int main( void ) { diff --git a/functions/stdio/ftrylockfile.c b/functions/stdio/ftrylockfile.c index cb8147a..41377da 100644 --- a/functions/stdio/ftrylockfile.c +++ b/functions/stdio/ftrylockfile.c @@ -8,6 +8,7 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> #include #include diff --git a/functions/stdio/funlockfile.c b/functions/stdio/funlockfile.c index 0845aab..648a22e 100644 --- a/functions/stdio/funlockfile.c +++ b/functions/stdio/funlockfile.c @@ -8,6 +8,7 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> #include #include diff --git a/functions/stdio/fwrite.c b/functions/stdio/fwrite.c index 9ab8a0a..9319cf7 100644 --- a/functions/stdio/fwrite.c +++ b/functions/stdio/fwrite.c @@ -9,7 +9,7 @@ #include #ifndef REGTEST - +#include <_PDCLIB_io.h> #include <_PDCLIB_glue.h> #include @@ -19,7 +19,7 @@ size_t fwrite_unlocked( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, - struct _PDCLIB_file_t * _PDCLIB_restrict stream ) + FILE * _PDCLIB_restrict stream ) { if ( _PDCLIB_prepwrite( stream ) == EOF ) { @@ -92,7 +92,7 @@ size_t fwrite_unlocked( const void * _PDCLIB_restrict ptr, size_t fwrite( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, - struct _PDCLIB_file_t * _PDCLIB_restrict stream ) + FILE * _PDCLIB_restrict stream ) { flockfile( stream ); size_t r = fwrite_unlocked( ptr, size, nmemb, stream ); diff --git a/functions/stdio/getc.c b/functions/stdio/getc.c index 9338baf..e733d0b 100644 --- a/functions/stdio/getc.c +++ b/functions/stdio/getc.c @@ -10,12 +10,12 @@ #ifndef REGTEST -int getc_unlocked( struct _PDCLIB_file_t * stream ) +int getc_unlocked( FILE * stream ) { return fgetc_unlocked( stream ); } -int getc( struct _PDCLIB_file_t * stream ) +int getc( FILE * stream ) { return fgetc( stream ); } diff --git a/functions/stdio/gets.c b/functions/stdio/gets.c index 3185396..83a261e 100644 --- a/functions/stdio/gets.c +++ b/functions/stdio/gets.c @@ -9,7 +9,7 @@ #include #ifndef REGTEST -#include <_PDCLIB_glue.h> +#include <_PDCLIB_io.h> #include char * gets( char * s ) diff --git a/functions/stdio/perror.c b/functions/stdio/perror.c index 23ce68b..5a794fb 100644 --- a/functions/stdio/perror.c +++ b/functions/stdio/perror.c @@ -9,7 +9,6 @@ #include #ifndef REGTEST - #include #include diff --git a/functions/stdio/printf.c b/functions/stdio/printf.c index a4efd6a..a12e137 100644 --- a/functions/stdio/printf.c +++ b/functions/stdio/printf.c @@ -10,6 +10,7 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> int printf( const char * _PDCLIB_restrict format, ... ) { diff --git a/functions/stdio/putc.c b/functions/stdio/putc.c index c1f3fc2..6bb2e9e 100644 --- a/functions/stdio/putc.c +++ b/functions/stdio/putc.c @@ -10,13 +10,13 @@ #ifndef REGTEST -int putc_unlocked( int c, struct _PDCLIB_file_t * stream ) +int putc_unlocked( int c, FILE * stream ) { return fputc_unlocked( c, stream ); } -int putc( int c, struct _PDCLIB_file_t * stream ) +int putc( int c, FILE * stream ) { return fputc( c, stream ); } diff --git a/functions/stdio/rename.c b/functions/stdio/rename.c index 987b78a..0ae5c6a 100644 --- a/functions/stdio/rename.c +++ b/functions/stdio/rename.c @@ -13,11 +13,11 @@ #include -extern struct _PDCLIB_file_t * _PDCLIB_filelist; +extern _PDCLIB_file_t * _PDCLIB_filelist; int rename( const char * old, const char * new ) { - struct _PDCLIB_file_t * current = _PDCLIB_filelist; + FILE * current = _PDCLIB_filelist; while ( current != NULL ) { if ( ( current->filename != NULL ) && ( strcmp( current->filename, old ) == 0 ) ) diff --git a/functions/stdio/rewind.c b/functions/stdio/rewind.c index 0a19155..53ab51d 100644 --- a/functions/stdio/rewind.c +++ b/functions/stdio/rewind.c @@ -9,14 +9,15 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -void rewind_unlocked( struct _PDCLIB_file_t * stream ) +void rewind_unlocked( FILE * stream ) { stream->status &= ~ _PDCLIB_ERRORFLAG; fseek_unlocked( stream, 0L, SEEK_SET ); } -void rewind( struct _PDCLIB_file_t * stream ) +void rewind( FILE * stream ) { flockfile(stream); rewind_unlocked(stream); diff --git a/functions/stdio/setbuf.c b/functions/stdio/setbuf.c index fe83277..f6f6f70 100644 --- a/functions/stdio/setbuf.c +++ b/functions/stdio/setbuf.c @@ -10,7 +10,7 @@ #ifndef REGTEST -void setbuf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf ) +void setbuf( FILE * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf ) { if ( buf == NULL ) { @@ -27,6 +27,9 @@ void setbuf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, char * _PDCLIB_res #ifdef TEST #include <_PDCLIB_test.h> #include +#ifndef REGTEST +#include <_PDCLIB_io.h> +#endif int main( void ) { diff --git a/functions/stdio/setvbuf.c b/functions/stdio/setvbuf.c index e3f9278..8754727 100644 --- a/functions/stdio/setvbuf.c +++ b/functions/stdio/setvbuf.c @@ -11,8 +11,9 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int setvbuf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf, int mode, size_t size ) +int setvbuf( FILE * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf, int mode, size_t size ) { switch ( mode ) { @@ -71,9 +72,10 @@ int setvbuf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, char * _PDCLIB_res #ifdef TEST #include <_PDCLIB_test.h> - #include - +#ifndef REGTEST +#include <_PDCLIB_io.h> +#endif #define BUFFERSIZE 500 int main( void ) diff --git a/functions/stdio/tmpnam.c b/functions/stdio/tmpnam.c index a9f5385..270109d 100644 --- a/functions/stdio/tmpnam.c +++ b/functions/stdio/tmpnam.c @@ -11,7 +11,7 @@ #ifndef REGTEST #include -#include <_PDCLIB_glue.h> +#include <_PDCLIB_io.h> char * tmpnam( char * s ) { diff --git a/functions/stdio/ungetc.c b/functions/stdio/ungetc.c index 4e9388b..cc6d177 100644 --- a/functions/stdio/ungetc.c +++ b/functions/stdio/ungetc.c @@ -9,8 +9,9 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int ungetc_unlocked( int c, struct _PDCLIB_file_t * stream ) +int ungetc_unlocked( int c, FILE * stream ) { if ( c == EOF || stream->ungetidx == _PDCLIB_UNGETCBUFSIZE ) { @@ -19,7 +20,7 @@ int ungetc_unlocked( int c, struct _PDCLIB_file_t * stream ) return stream->ungetbuf[stream->ungetidx++] = (unsigned char) c; } -int ungetc( int c, struct _PDCLIB_file_t * stream ) +int ungetc( int c, FILE * stream ) { flockfile( stream ); int r = ungetc_unlocked( c, stream ); diff --git a/functions/stdio/vfprintf.c b/functions/stdio/vfprintf.c index 18e9c4b..f9562d2 100644 --- a/functions/stdio/vfprintf.c +++ b/functions/stdio/vfprintf.c @@ -12,8 +12,9 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -int vfprintf_unlocked( struct _PDCLIB_file_t * _PDCLIB_restrict stream, +int vfprintf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, va_list arg ) { @@ -49,7 +50,7 @@ int vfprintf_unlocked( struct _PDCLIB_file_t * _PDCLIB_restrict stream, return status.i; } -int vfprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, +int vfprintf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, va_list arg ) { diff --git a/functions/stdio/vfscanf.c b/functions/stdio/vfscanf.c index da365bd..14bba50 100644 --- a/functions/stdio/vfscanf.c +++ b/functions/stdio/vfscanf.c @@ -11,6 +11,7 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> int vfscanf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, diff --git a/functions/stdio/vsnprintf.c b/functions/stdio/vsnprintf.c index 64a0651..fd29580 100644 --- a/functions/stdio/vsnprintf.c +++ b/functions/stdio/vsnprintf.c @@ -10,6 +10,7 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> int vsnprintf( char * _PDCLIB_restrict s, size_t n, diff --git a/functions/stdio/vsscanf.c b/functions/stdio/vsscanf.c index 99b8bad..29dd483 100644 --- a/functions/stdio/vsscanf.c +++ b/functions/stdio/vsscanf.c @@ -11,6 +11,7 @@ #ifndef REGTEST #include +#include <_PDCLIB_io.h> int vsscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, diff --git a/functions/stdlib/exit.c b/functions/stdlib/exit.c index 2dbb35c..48a5111 100644 --- a/functions/stdlib/exit.c +++ b/functions/stdlib/exit.c @@ -9,6 +9,7 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> /* TODO - "except that a function is called after any previously registered functions that had already been called at the time it was registered. diff --git a/includes/stdio.h b/includes/stdio.h index 9b68d73..8f81896 100644 --- a/includes/stdio.h +++ b/includes/stdio.h @@ -8,7 +8,7 @@ #ifndef _PDCLIB_STDIO_H #define _PDCLIB_STDIO_H _PDCLIB_STDIO_H -#include <_PDCLIB_io.h> +#include <_PDCLIB_int.h> _PDCLIB_BEGIN_EXTERN_C #ifndef _PDCLIB_SIZE_T_DEFINED @@ -27,8 +27,8 @@ typedef _PDCLIB_size_t size_t; #define _IONBF 4 /* The following are platform-dependant, and defined in _PDCLIB_config.h. */ -typedef struct _PDCLIB_fpos_t fpos_t; -typedef struct _PDCLIB_file_t FILE; +typedef _PDCLIB_fpos_t fpos_t; +typedef _PDCLIB_file_t FILE; #define EOF -1 #define BUFSIZ _PDCLIB_BUFSIZ #define FOPEN_MAX _PDCLIB_FOPEN_MAX diff --git a/includes/threads.h b/includes/threads.h index 6502153..77e39d4 100644 --- a/includes/threads.h +++ b/includes/threads.h @@ -1,5 +1,6 @@ #ifndef _PDCLIB_THREADS_H #define _PDCLIB_THREADS_H +#include <_PDCLIB_int.h> #include <_PDCLIB_threadconfig.h> #include _PDCLIB_BEGIN_EXTERN_C diff --git a/includes/uchar.h b/includes/uchar.h index 1419df6..87b5aab 100644 --- a/includes/uchar.h +++ b/includes/uchar.h @@ -7,7 +7,7 @@ #ifndef _PDCLIB_UCHAR_H #define _PDCLIB_UCHAR_H -#include <_PDCLIB_encoding.h> +#include <_PDCLIB_int.h> _PDCLIB_BEGIN_EXTERN_C /* This is mostly a placeholder. for now. This header will be completed by the diff --git a/includes/wchar.h b/includes/wchar.h index e3d8e49..0eee7a6 100644 --- a/includes/wchar.h +++ b/includes/wchar.h @@ -7,8 +7,7 @@ #ifndef _PDCLIB_WCHAR_H #define _PDCLIB_WCHAR_H -#include <_PDCLIB_io.h> -#include <_PDCLIB_encoding.h> +#include <_PDCLIB_int.h> _PDCLIB_BEGIN_EXTERN_C /* This is VASTLY incomplete. Functions being implemented as required by other portions of the library @@ -79,38 +78,38 @@ size_t wcsftime(wchar_t *_PDCLIB_restrict s, size_t maxsize, const wchar_t *_PDC #endif /* Wide character I/O */ -int fwprintf(struct _PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, ...); -int fwscanf(struct _PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, ...); +int fwprintf(_PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, ...); +int fwscanf(_PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, ...); int swprintf(wchar_t *_PDCLIB_restrict s, size_t n, const wchar_t *_PDCLIB_restrict format, ...); int swscanf(const wchar_t *_PDCLIB_restrict s, const wchar_t *_PDCLIB_restrict format, ...); -int vfwprintf(struct _PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); -int vfwscanf(struct _PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); +int vfwprintf(_PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); +int vfwscanf(_PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); int vswprintf(wchar_t *_PDCLIB_restrict s, size_t n, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); int vswscanf(const wchar_t *_PDCLIB_restrict s, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); int vwprintf(const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); int vwscanf(const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); int wprintf(const wchar_t *_PDCLIB_restrict format, ...); int wscanf(const wchar_t *_PDCLIB_restrict format, ...); -wint_t fgetwc(struct _PDCLIB_file_t *stream); -wchar_t *fgetws(wchar_t *_PDCLIB_restrict s, int n, struct _PDCLIB_file_t *_PDCLIB_restrict stream); -wint_t fputwc(wchar_t c, struct _PDCLIB_file_t *stream); -int fputws(const wchar_t *_PDCLIB_restrict s, struct _PDCLIB_file_t *_PDCLIB_restrict stream); -int fwide(struct _PDCLIB_file_t *stream, int mode); -wint_t getwc(struct _PDCLIB_file_t *stream); +wint_t fgetwc(_PDCLIB_file_t *stream); +wchar_t *fgetws(wchar_t *_PDCLIB_restrict s, int n, _PDCLIB_file_t *_PDCLIB_restrict stream); +wint_t fputwc(wchar_t c, _PDCLIB_file_t *stream); +int fputws(const wchar_t *_PDCLIB_restrict s, _PDCLIB_file_t *_PDCLIB_restrict stream); +int fwide(_PDCLIB_file_t *stream, int mode); +wint_t getwc(_PDCLIB_file_t *stream); wint_t getwchar(void); -wint_t putwc(wchar_t c, struct _PDCLIB_file_t *stream); +wint_t putwc(wchar_t c, _PDCLIB_file_t *stream); wint_t putwchar(wchar_t c); -wint_t ungetwc(wint_t c, struct _PDCLIB_file_t *stream); +wint_t ungetwc(wint_t c, _PDCLIB_file_t *stream); #if _PDCLIB_GNU_SOURCE -wint_t getwc_unlocked(struct _PDCLIB_file_t *stream); +wint_t getwc_unlocked(_PDCLIB_file_t *stream); wint_t getwchar_unlocked(void); -wint_t fgetwc_unlocked(struct _PDCLIB_file_t *stream); -wint_t fputwc_unlocked(wchar_t wc, struct _PDCLIB_file_t *stream); -wint_t putwc_unlocked(wchar_t wc, struct _PDCLIB_file_t *stream); +wint_t fgetwc_unlocked(_PDCLIB_file_t *stream); +wint_t fputwc_unlocked(wchar_t wc, _PDCLIB_file_t *stream); +wint_t putwc_unlocked(wchar_t wc, _PDCLIB_file_t *stream); wint_t putwchar_unlocked(wchar_t wc); -wchar_t *fgetws_unlocked(wchar_t *ws, int n, struct _PDCLIB_file_t *stream); -int fputws_unlocked(const wchar_t *ws, struct _PDCLIB_file_t *stream); +wchar_t *fgetws_unlocked(wchar_t *ws, int n, _PDCLIB_file_t *stream); +int fputws_unlocked(const wchar_t *ws, _PDCLIB_file_t *stream); #endif /* Wide character <-> Numeric conversions */ diff --git a/internals/_PDCLIB_aux.h b/internals/_PDCLIB_aux.h index c3e38d0..0a31e86 100644 --- a/internals/_PDCLIB_aux.h +++ b/internals/_PDCLIB_aux.h @@ -1,5 +1,5 @@ -#ifndef _PDCLIB_AUX_H -#define _PDCLIB_AUX_H +#ifndef __PDCLIB_AUX_H +#define __PDCLIB_AUX_H __PDCLIB_AUX_H /* Auxiliary PDCLib code <_PDCLIB_aux.h> diff --git a/internals/_PDCLIB_encoding.h b/internals/_PDCLIB_encoding.h index 0178b12..0b466c1 100644 --- a/internals/_PDCLIB_encoding.h +++ b/internals/_PDCLIB_encoding.h @@ -4,63 +4,27 @@ Permission is granted to use, modify, and / or redistribute at will. */ -#ifndef _PDCLIB_ENCODING_H -#define _PDCLIB_ENCODING_H _PDCLIB_ENCODING_H +#ifndef __PDCLIB_ENCODING_H +#define __PDCLIB_ENCODING_H __PDCLIB_ENCODING_H #include "_PDCLIB_int.h" -#ifndef __cplusplus -typedef _PDCLIB_int16_t _PDCLIB_char16_t; -typedef _PDCLIB_int32_t _PDCLIB_char32_t; -#else -typedef char16_t _PDCLIB_char16_t; -typedef char32_t _PDCLIB_char32_t; -#endif - -/* -------------------------------------------------------------------------- */ -/* mbstate_t */ -/* -------------------------------------------------------------------------- */ - -typedef struct _PDCLIB_mbstate_t { - union { - /* Is this the best way to represent this? Is this big enough? */ - _PDCLIB_uint64_t _St64[15]; - _PDCLIB_uint32_t _St32[31]; - _PDCLIB_uint16_t _St16[62]; - unsigned char _StUC[124]; - signed char _StSC[124]; - char _StC [124]; - }; - - union { - /* c16/related functions: Surrogate storage - * - * If zero, no surrogate pending. If nonzero, surrogate. - */ - _PDCLIB_uint16_t _Surrogate; - - /* Reserved for potential mbtoutf8/etc functions */ - unsigned char _U8[4]; - }; -} _PDCLIB_mbstate_t; - -#ifdef _PDCLIB_WCHAR_IS_UCS2 /* Must be cauued with bufsize >= 1, in != NULL, out != NULL, ps != NULL * - * Converts a wchar to a UCS4 (char32_t) value. Returns + * Converts a UTF-16 (char16_t) to a UCS4 (char32_t) value. Returns * 1, 2 : Valid character (converted to UCS-4) * -1 : Encoding error * -2 : Partial character (only lead surrogate in buffer) */ -static inline int _PDCLIB_wcrtoc32( +static inline int _PDCLIB_c16rtoc32( _PDCLIB_char32_t *_PDCLIB_restrict out, - const _PDCLIB_wchar_t *_PDCLIB_restrict in, + const _PDCLIB_char16_t *_PDCLIB_restrict in, _PDCLIB_size_t bufsize, _PDCLIB_mbstate_t *_PDCLIB_restrict ps ) { if(ps->_Surrogate) { // We already have a lead surrogate - if(*in & ~0x3FF != 0xDC00) { + if((*in & ~0x3FF) != 0xDC00) { // Encoding error return -1; } else { @@ -69,11 +33,11 @@ static inline int _PDCLIB_wcrtoc32( ps->_Surrogate = 0; return 1; } - } if(*in & ~0x3FF == 0xD800) { + } if((*in & ~0x3FF) == 0xD800) { // Lead surrogate if(bufsize >= 2) { // Buffer big enough - if(in[1] & ~0x3FF != 0xDC00) { + if((in[1] & ~0x3FF) != 0xDC00) { // Encoding error return -1; } else { @@ -92,7 +56,7 @@ static inline int _PDCLIB_wcrtoc32( } } -static inline _PDCLIB_size_t _PDCLIB_c32rtowc( +static inline _PDCLIB_size_t _PDCLIB_c32rtoc16( _PDCLIB_wchar_t *_PDCLIB_restrict out, const _PDCLIB_char32_t *_PDCLIB_restrict in, _PDCLIB_size_t bufsize, @@ -121,32 +85,8 @@ static inline _PDCLIB_size_t _PDCLIB_c32rtowc( } } } -#else -/* Dummy implementation for when wc == c32 */ -static inline _PDCLIB_size_t _PDCLIB_wcrtoc32( - _PDCLIB_char32_t *_PDCLIB_restrict out, - const _PDCLIB_wchar_t *_PDCLIB_restrict in, - _PDCLIB_size_t bufsize, - _PDCLIB_mbstate_t *_PDCLIB_restrict ps -) -{ - *out = *in; - return 1; -} - -static inline _PDCLIB_size_t _PDCLIB_c32rtowc( - _PDCLIB_wchar_t *_PDCLIB_restrict out, - const _PDCLIB_char32_t *_PDCLIB_restrict in, - _PDCLIB_size_t bufsize, - _PDCLIB_mbstate_t *_PDCLIB_restrict ps -) -{ - *out = *in; - return 1; -} -#endif -typedef struct { +struct _PDCLIB_charcodec { /* Reads at most *_P_insz code units from *_P_inbuf and writes the result * into *_P_outbuf, writing at most *_P_outsz code units. Updates * *_P_outbuf, *_P_outsz, *_P_inbuf, *_P_outsz with the resulting state @@ -198,6 +138,6 @@ typedef struct { _PDCLIB_size_t *_PDCLIB_restrict _P_insz, _PDCLIB_mbstate_t *_PDCLIB_restrict _P_ps ); -} _PDCLIB_charcodec; +}; #endif diff --git a/internals/_PDCLIB_float.h b/internals/_PDCLIB_float.h index c48d0ec..0471a30 100644 --- a/internals/_PDCLIB_float.h +++ b/internals/_PDCLIB_float.h @@ -1,5 +1,5 @@ -#ifndef _PDCLIB_PDCLIB_FLOAT_H -#define _PDCLIB_PDCLIB_FLOAT_H _PDCLIB_PDCLIB_FLOAT_H +#ifndef __PDCLIB_PDCLIB_FLOAT_H +#define __PDCLIB_PDCLIB_FLOAT_H __PDCLIB_PDCLIB_FLOAT_H /* PDCLib internal floating point logic <_PDCLIB_float.h> diff --git a/internals/_PDCLIB_glue.h b/internals/_PDCLIB_glue.h index 7f3c4fa..1d97863 100644 --- a/internals/_PDCLIB_glue.h +++ b/internals/_PDCLIB_glue.h @@ -1,7 +1,5 @@ -#ifndef _PDCLIB_GLUE_H -#define _PDCLIB_GLUE_H -/* $Id$ */ - +#ifndef __PDCLIB_GLUE_H +#define __PDCLIB_GLUE_H __PDCLIB_GLUE_H /* OS glue functions declaration <_PDCLIB_glue.h> This file is part of the Public Domain C Library (PDCLib). diff --git a/internals/_PDCLIB_int.h b/internals/_PDCLIB_int.h index c0bbe00..64d9219 100644 --- a/internals/_PDCLIB_int.h +++ b/internals/_PDCLIB_int.h @@ -1,5 +1,5 @@ -#ifndef _PDCLIB_INT_H -#define _PDCLIB_INT_H +#ifndef __PDCLIB_INT_H +#define __PDCLIB_INT_H __PDCLIB_INT_H /* PDCLib internal integer logic <_PDCLIB_int.h> @@ -294,36 +294,6 @@ struct _PDCLIB_exitfunc_t void (*func)( void ); }; -/* Structures required by malloc(), realloc(), and free(). */ -struct _PDCLIB_headnode_t -{ - struct _PDCLIB_memnode_t * first; - struct _PDCLIB_memnode_t * last; -}; - -struct _PDCLIB_memnode_t -{ - _PDCLIB_size_t size; - struct _PDCLIB_memnode_t * next; -}; - -/* Status structure required by _PDCLIB_print(). */ -struct _PDCLIB_status_t -{ - int base; /* base to which the value shall be converted */ - _PDCLIB_int_fast32_t flags; /* flags and length modifiers */ - unsigned n; /* print: maximum characters to be written */ - /* scan: number matched conversion specifiers */ - unsigned i; /* number of characters read/written */ - unsigned current;/* chars read/written in the CURRENT conversion */ - char * s; /* *sprintf(): target buffer */ - /* *sscanf(): source string */ - unsigned width; /* specified field width */ - int prec; /* specified field precision */ - struct _PDCLIB_file_t * stream; /* *fprintf() / *fscanf() stream */ - _PDCLIB_va_list arg; /* argument stack */ -}; - /* -------------------------------------------------------------------------- */ /* Declaration of helper functions (implemented in functions/_PDCLIB). */ /* -------------------------------------------------------------------------- */ @@ -339,46 +309,6 @@ _PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, _PDCL extern char _PDCLIB_digits[]; extern char _PDCLIB_Xdigits[]; -/* The worker for all printf() type of functions. The pointer spec should point - to the introducing '%' of a conversion specifier. The status structure is to - be that of the current printf() function, of which the members n, s, stream - and arg will be preserved; i will be updated; and all others will be trashed - by the function. - Returns a pointer to the first character not parsed as conversion specifier. -*/ -const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status ); - -/* The worker for all scanf() type of functions. The pointer spec should point - to the introducing '%' of a conversion specifier. The status structure is to - be that of the current scanf() function, of which the member stream will be - preserved; n, i, and s will be updated; and all others will be trashed by - the function. - Returns a pointer to the first character not parsed as conversion specifier, - or NULL in case of error. - FIXME: Should distinguish between matching and input error -*/ -const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ); - -/* Parsing any fopen() style filemode string into a number of flags. */ -unsigned int _PDCLIB_filemode( const char * mode ); - -/* Sanity checking and preparing of read buffer, should be called first thing - by any stdio read-data function. - Returns 0 on success, EOF on error. - On error, EOF / error flags and errno are set appropriately. -*/ -int _PDCLIB_prepread( struct _PDCLIB_file_t * stream ); - -/* Sanity checking, should be called first thing by any stdio write-data - function. - Returns 0 on success, EOF on error. - On error, error flags and errno are set appropriately. -*/ -int _PDCLIB_prepwrite( struct _PDCLIB_file_t * stream ); - -/* Closing all streams on program exit */ -void _PDCLIB_closeall( void ); - /* -------------------------------------------------------------------------- */ /* errno */ /* -------------------------------------------------------------------------- */ @@ -418,4 +348,75 @@ struct _PDCLIB_ctype_t unsigned char collation; }; +/* -------------------------------------------------------------------------- */ +/* locale / wchar / uchar */ +/* -------------------------------------------------------------------------- */ + +#ifndef __cplusplus +typedef _PDCLIB_int16_t _PDCLIB_char16_t; +typedef _PDCLIB_int32_t _PDCLIB_char32_t; +#else +typedef char16_t _PDCLIB_char16_t; +typedef char32_t _PDCLIB_char32_t; +#endif + +typedef struct _PDCLIB_mbstate { + union { + /* Is this the best way to represent this? Is this big enough? */ + _PDCLIB_uint64_t _St64[15]; + _PDCLIB_uint32_t _St32[31]; + _PDCLIB_uint16_t _St16[62]; + unsigned char _StUC[124]; + signed char _StSC[124]; + char _StC [124]; + }; + + union { + /* c16/related functions: Surrogate storage + * + * If zero, no surrogate pending. If nonzero, surrogate. + */ + _PDCLIB_uint16_t _Surrogate; + + /* Reserved for potential mbtoutf8/etc functions */ + unsigned char _U8[4]; + }; +} _PDCLIB_mbstate_t; + +typedef struct _PDCLIB_charcodec _PDCLIB_charcodec_t; +typedef struct _PDCLIB_locale _PDCLIB_locale_t; +typedef struct lconv _PDCLIB_lconv_t; + +/* -------------------------------------------------------------------------- */ +/* stdio */ +/* -------------------------------------------------------------------------- */ + +/* Position / status structure for getpos() / fsetpos(). */ +typedef struct _PDCLIB_fpos +{ + _PDCLIB_int_fast64_t offset; /* File position offset */ + _PDCLIB_mbstate_t mbs; /* Multibyte parsing state */ +} _PDCLIB_fpos_t; + +typedef struct _PDCLIB_fileops _PDCLIB_fileops_t; +typedef union _PDCLIB_fd _PDCLIB_fd_t; +typedef struct _PDCLIB_file _PDCLIB_file_t; // Rename to _PDCLIB_FILE? + +/* Status structure required by _PDCLIB_print(). */ +struct _PDCLIB_status_t +{ + int base; /* base to which the value shall be converted */ + _PDCLIB_int_fast32_t flags; /* flags and length modifiers */ + unsigned n; /* print: maximum characters to be written */ + /* scan: number matched conversion specifiers */ + unsigned i; /* number of characters read/written */ + unsigned current;/* chars read/written in the CURRENT conversion */ + char * s; /* *sprintf(): target buffer */ + /* *sscanf(): source string */ + unsigned width; /* specified field width */ + int prec; /* specified field precision */ + _PDCLIB_file_t * stream; /* *fprintf() / *fscanf() stream */ + _PDCLIB_va_list arg; /* argument stack */ +}; + #endif diff --git a/internals/_PDCLIB_io.h b/internals/_PDCLIB_io.h index 2ece56c..e4fd94e 100644 --- a/internals/_PDCLIB_io.h +++ b/internals/_PDCLIB_io.h @@ -1,9 +1,9 @@ -#ifndef _PDCLIB_IO_H -#define _PDCLIB_IO_H +#ifndef __PDCLIB_IO_H +#define __PDCLIB_IO_H __PDCLIB_IO_H #include "_PDCLIB_int.h" #include "_PDCLIB_threadconfig.h" -/* PDCLib internal I/O logic <_PDCLIB_int.h> +/* PDCLib internal I/O logic <_PDCLIB_io.h> This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -34,7 +34,7 @@ /* stream handle should not be free()d on close (stdin, stdout, stderr) */ #define _PDCLIB_STATIC 32768u -typedef union _PDCLIB_fd +union _PDCLIB_fd { #if defined(_PDCLIB_OSFD_T) _PDCLIB_OSFD_T osfd; @@ -42,25 +42,68 @@ typedef union _PDCLIB_fd void * pointer; _PDCLIB_uintptr_t uval; _PDCLIB_intptr_t sval; -} _PDCLIB_fd_t; +}; + +/******************************************************************************/ +/* Internal functions */ +/******************************************************************************/ + +/* The worker for all printf() type of functions. The pointer spec should point + to the introducing '%' of a conversion specifier. The status structure is to + be that of the current printf() function, of which the members n, s, stream + and arg will be preserved; i will be updated; and all others will be trashed + by the function. + Returns a pointer to the first character not parsed as conversion specifier. +*/ +const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status ); + +/* The worker for all scanf() type of functions. The pointer spec should point + to the introducing '%' of a conversion specifier. The status structure is to + be that of the current scanf() function, of which the member stream will be + preserved; n, i, and s will be updated; and all others will be trashed by + the function. + Returns a pointer to the first character not parsed as conversion specifier, + or NULL in case of error. + FIXME: Should distinguish between matching and input error +*/ +const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ); + +/* Parsing any fopen() style filemode string into a number of flags. */ +unsigned int _PDCLIB_filemode( const char * mode ); + +/* Sanity checking and preparing of read buffer, should be called first thing + by any stdio read-data function. + Returns 0 on success, EOF on error. + On error, EOF / error flags and errno are set appropriately. +*/ +int _PDCLIB_prepread( _PDCLIB_file_t * stream ); + +/* Sanity checking, should be called first thing by any stdio write-data + function. + Returns 0 on success, EOF on error. + On error, error flags and errno are set appropriately. +*/ +int _PDCLIB_prepwrite( _PDCLIB_file_t * stream ); + +/* Closing all streams on program exit */ +void _PDCLIB_closeall( void ); -/* Internal functions */ /* Writes a stream's buffer. Returns 0 on success, EOF on write error. Sets stream error flags and errno appropriately on error. */ -int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ); +int _PDCLIB_flushbuffer( _PDCLIB_file_t * stream ); /* Fills a stream's buffer. Returns 0 on success, EOF on read error / EOF. Sets stream EOF / error flags and errno appropriately on error. */ -int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ); +int _PDCLIB_fillbuffer( _PDCLIB_file_t * stream ); /* Repositions within a file. Returns new offset on success, -1 / errno on error. */ -_PDCLIB_int_fast64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, +_PDCLIB_int_fast64_t _PDCLIB_seek( _PDCLIB_file_t * stream, _PDCLIB_int_fast64_t offset, int whence ); /* File backend I/O operations @@ -68,7 +111,7 @@ _PDCLIB_int_fast64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, * PDCLib will call through to these methods as needed to implement the stdio * functions. */ -typedef struct _PDCLIB_fileops +struct _PDCLIB_fileops { /*! Read length bytes from the file into buf; returning the number of bytes * actually read in *numBytesRead. @@ -123,17 +166,10 @@ typedef struct _PDCLIB_fileops */ _PDCLIB_bool (*wwrite)( _PDCLIB_fd_t self, const _PDCLIB_wchar_t * buf, _PDCLIB_size_t length, _PDCLIB_size_t * numCharsWritten ); -} _PDCLIB_fileops_t; - -/* Position / status structure for getpos() / fsetpos(). */ -struct _PDCLIB_fpos_t -{ - _PDCLIB_int_fast64_t offset; /* File position offset */ - int status; /* Multibyte parsing state (unused, reserved) */ }; /* FILE structure */ -struct _PDCLIB_file_t +struct _PDCLIB_file { const _PDCLIB_fileops_t * ops; _PDCLIB_fd_t handle; /* OS file handle */ @@ -142,18 +178,18 @@ struct _PDCLIB_file_t _PDCLIB_size_t bufsize; /* Size of buffer */ _PDCLIB_size_t bufidx; /* Index of current position in buffer */ _PDCLIB_size_t bufend; /* Index of last pre-read character in buffer */ - struct _PDCLIB_fpos_t pos; /* Offset and multibyte parsing state */ _PDCLIB_size_t ungetidx; /* Number of ungetc()'ed characters */ unsigned char * ungetbuf; /* ungetc() buffer */ unsigned int status; /* Status flags; see above */ /* multibyte parsing status to be added later */ + _PDCLIB_fpos_t pos; /* Offset and multibyte parsing state */ char * filename; /* Name the current stream has been opened with */ - struct _PDCLIB_file_t * next; /* Pointer to next struct (internal) */ + _PDCLIB_file_t * next; /* Pointer to next struct (internal) */ }; static inline _PDCLIB_size_t _PDCLIB_getchars( char * out, _PDCLIB_size_t n, int stopchar, - struct _PDCLIB_file_t * stream ) + _PDCLIB_file_t * stream ) { _PDCLIB_size_t i = 0; int c; diff --git a/opt/basecodecs/_PDCLIB_ascii.c b/opt/basecodecs/_PDCLIB_ascii.c index a705a7a..e84563f 100644 --- a/opt/basecodecs/_PDCLIB_ascii.c +++ b/opt/basecodecs/_PDCLIB_ascii.c @@ -7,6 +7,7 @@ #include #ifndef REGTEST #include +#include <_PDCLIB_encoding.h> static bool asciitoc32( char32_t **restrict p_outbuf, @@ -58,7 +59,7 @@ static bool c32toascii( return true; } -_PDCLIB_charcodec _PDCLIB_ascii_codec = { +_PDCLIB_charcodec_t _PDCLIB_ascii_codec = { .__mbstoc32s = asciitoc32, .__c32stombs = c32toascii, }; diff --git a/opt/basecodecs/_PDCLIB_latin1.c b/opt/basecodecs/_PDCLIB_latin1.c index f78574f..2990360 100644 --- a/opt/basecodecs/_PDCLIB_latin1.c +++ b/opt/basecodecs/_PDCLIB_latin1.c @@ -7,6 +7,7 @@ #include #ifndef REGTEST #include +#include <_PDCLIB_encoding.h> static bool latin1toc32( char32_t **restrict p_outbuf, @@ -56,7 +57,7 @@ static bool c32tolatin1( return true; } -_PDCLIB_charcodec _PDCLIB_latin1_codec = { +_PDCLIB_charcodec_t _PDCLIB_latin1_codec = { .__mbstoc32s = latin1toc32, .__c32stombs = c32tolatin1, }; diff --git a/opt/basecodecs/_PDCLIB_utf8.c b/opt/basecodecs/_PDCLIB_utf8.c index 8183aef..65f76e0 100644 --- a/opt/basecodecs/_PDCLIB_utf8.c +++ b/opt/basecodecs/_PDCLIB_utf8.c @@ -9,6 +9,7 @@ #include #include #include +#include <_PDCLIB_encoding.h> /* Use of the mbstate: * @@ -227,7 +228,7 @@ static bool c32toutf8( END_CONVERSION; } -_PDCLIB_charcodec _PDCLIB_utf8_codec = { +_PDCLIB_charcodec_t _PDCLIB_utf8_codec = { .__mbstoc32s = utf8toc32, .__c32stombs = c32toutf8, }; diff --git a/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c b/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c index a3c9e8b..4c4ba4a 100644 --- a/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c +++ b/platform/posix/functions/_PDCLIB/_PDCLIB_stdinit.c @@ -16,6 +16,7 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> #include /* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file @@ -32,42 +33,39 @@ static unsigned char _PDCLIB_serr_ungetbuf[_PDCLIB_UNGETCBUFSIZE]; extern _PDCLIB_fileops_t _PDCLIB_fileops; -static struct _PDCLIB_file_t _PDCLIB_serr = { +static FILE _PDCLIB_serr = { .ops = &_PDCLIB_fileops, .handle = { .sval = 2 }, .buffer = _PDCLIB_serr_buffer, .bufsize = BUFSIZ, .bufidx = 0, .bufend = 0, - .pos = { 0, 0 }, .ungetidx = 0, .ungetbuf = _PDCLIB_serr_ungetbuf, .status = _IONBF | _PDCLIB_FWRITE | _PDCLIB_STATIC, .filename = NULL, .next = NULL, }; -static struct _PDCLIB_file_t _PDCLIB_sout = { +static FILE _PDCLIB_sout = { .ops = &_PDCLIB_fileops, .handle = { .sval = 1 }, .buffer = _PDCLIB_sout_buffer, .bufsize = BUFSIZ, .bufidx = 0, .bufend = 0, - .pos = { 0, 0 }, .ungetidx = 0, .ungetbuf = _PDCLIB_sout_ungetbuf, .status = _IOLBF | _PDCLIB_FWRITE | _PDCLIB_STATIC, .filename = NULL, .next = &_PDCLIB_serr }; -static struct _PDCLIB_file_t _PDCLIB_sin = { +static FILE _PDCLIB_sin = { .ops = &_PDCLIB_fileops, .handle = { .sval = 0 }, .buffer = _PDCLIB_sin_buffer, .bufsize = BUFSIZ, .bufidx = 0, .bufend = 0, - .pos = { 0, 0 }, .ungetidx = 0, .ungetbuf = _PDCLIB_sin_ungetbuf, .status = _IOLBF | _PDCLIB_FREAD | _PDCLIB_STATIC, @@ -75,9 +73,9 @@ static struct _PDCLIB_file_t _PDCLIB_sin = { .next = &_PDCLIB_sout }; -struct _PDCLIB_file_t * stdin = &_PDCLIB_sin; -struct _PDCLIB_file_t * stdout = &_PDCLIB_sout; -struct _PDCLIB_file_t * stderr = &_PDCLIB_serr; +FILE * stdin = &_PDCLIB_sin; +FILE * stdout = &_PDCLIB_sout; +FILE * stderr = &_PDCLIB_serr; /* Todo: Better solution than this! */ __attribute__((constructor)) void init_stdio(void) @@ -88,7 +86,7 @@ __attribute__((constructor)) void init_stdio(void) } /* FIXME: This approach is a possible attack vector. */ -struct _PDCLIB_file_t * _PDCLIB_filelist = &_PDCLIB_sin; +FILE * _PDCLIB_filelist = &_PDCLIB_sin; /* "C" locale - defaulting to ASCII-7. 1 kByte (+ 4 byte) of data. diff --git a/platform/posix/functions/stdio/remove.c b/platform/posix/functions/stdio/remove.c index f4f63fe..d4a0184 100644 --- a/platform/posix/functions/stdio/remove.c +++ b/platform/posix/functions/stdio/remove.c @@ -12,16 +12,16 @@ #include #ifndef REGTEST - +#include <_PDCLIB_io.h> #include -extern struct _PDCLIB_file_t * _PDCLIB_filelist; +extern FILE * _PDCLIB_filelist; extern int unlink( const char * pathname ); int remove( const char * pathname ) { - struct _PDCLIB_file_t * current = _PDCLIB_filelist; + FILE * current = _PDCLIB_filelist; while ( current != NULL ) { if ( ( current->filename != NULL ) && ( strcmp( current->filename, pathname ) == 0 ) ) diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_stdinit.c b/platform/win32/functions/_PDCLIB/_PDCLIB_stdinit.c index 6ff9608..1c8a7b6 100644 --- a/platform/win32/functions/_PDCLIB/_PDCLIB_stdinit.c +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_stdinit.c @@ -16,6 +16,7 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> extern const _PDCLIB_fileops_t _PDCLIB_fileops;