From: Owen Shepherd Date: Tue, 14 Aug 2012 14:54:36 +0000 (+0100) Subject: (merge) X-Git-Url: https://pd.if.org/git/?p=pdclib;a=commitdiff_plain;h=5fd032eae66fba700cb9927840222b068c62361e;hp=543e05b0338f6ed34d6e7556b4d418bb6c794aaf (merge) --- diff --git a/Jamfile b/Jamfile index 971e21d..99441d9 100644 --- a/Jamfile +++ b/Jamfile @@ -1,4 +1,8 @@ SubDir PDCLIB_TOP ; +if $(PDCLIB_PLATFORM) { + SubInclude PDCLIB_TOP platform $(PDCLIB_PLATFORM) ; + SubDir PDCLIB_TOP ; +} PDCLibConfig ; PDCLIB_SOURCES = [ RecursiveGlob $(PDCLIB_TOP) : [ FDirName functions ] : *.c ] ; @@ -25,11 +29,12 @@ if ! $(PDCLIB_NO_TEST) { Object $(testfile).o : $(file) ; Object $(regtestfile).o : $(file) ; - MainFromObjects $(testfile) : $(testfile).o ; + MainFromObjects $(testfile) : $(testfile).o $(CRT0) ; MainFromObjects $(regtestfile) : $(regtestfile).o ; CCFLAGS on $(testfile).o += -DTEST $(PDCLIB_TEST_CCFLAGS) ; CCFLAGS on $(regtestfile).o += -DTEST -DREGTEST $(PDCLIB_REGTEST_CCFLAGS) ; + CCHDRS on $(regtestfile).o = [ FIncludes [ FDirName testing ] ] ; LINKFLAGS on $(testfile)$(SUFEXE) += $(PDCLIB_TEST_LINKFLAGS) ; LINKFLAGS on $(regtestfile)$(SUFEXE) += $(PDCLIB_REGTEST_LINKFLAGS) ; diff --git a/Jamrules b/Jamrules index 8657cc9..dd0e406 100644 --- a/Jamrules +++ b/Jamrules @@ -32,14 +32,14 @@ if ! $(PDCLIB_HAVE_PLATFORM) && ! $(PDCLIB_PLATFORM) { -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes ; PDCLIB_CCFLAGS = -ffreestanding - -nostdinc + #-nostdinc -std=c11 -g -D_PDCLIB_BUILD $(PDCLIB_WARNINGS) ; PDCLIB_C++FLAGS = -ffreestanding - -nostdinc + #-nostdinc -std=c++11 -g -D_PDCLIB_BUILD diff --git a/functions/_PDCLIB/atomax.c b/functions/_PDCLIB/atomax.c index 45095e7..58a8e58 100644 --- a/functions/_PDCLIB/atomax.c +++ b/functions/_PDCLIB/atomax.c @@ -6,6 +6,7 @@ Permission is granted to use, modify, and / or redistribute at will. */ +#ifndef REGTEST #include <_PDCLIB_int.h> #include #include @@ -26,16 +27,19 @@ _PDCLIB_intmax_t _PDCLIB_atomax( const char * s ) } return ( sign == '+' ) ? rc : -rc; } +#endif #ifdef TEST #include <_PDCLIB_test.h> int main( void ) { +#ifndef REGTEST /* basic functionality */ TESTCASE( _PDCLIB_atomax( "123" ) == 123 ); /* testing skipping of leading whitespace and trailing garbage */ TESTCASE( _PDCLIB_atomax( " \n\v\t\f123xyz" ) == 123 ); +#endif return TEST_RESULTS; } diff --git a/functions/_PDCLIB/closeall.c b/functions/_PDCLIB/closeall.c index 71f6007..5086d0d 100644 --- a/functions/_PDCLIB/closeall.c +++ b/functions/_PDCLIB/closeall.c @@ -8,6 +8,7 @@ #include +#ifndef REGTEST extern struct _PDCLIB_file_t * _PDCLIB_filelist; void _PDCLIB_closeall( void ) @@ -21,6 +22,7 @@ void _PDCLIB_closeall( void ) stream = next; } } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/functions/_PDCLIB/digits.c b/functions/_PDCLIB/digits.c index ad41e5d..52a7ae3 100644 --- a/functions/_PDCLIB/digits.c +++ b/functions/_PDCLIB/digits.c @@ -6,7 +6,9 @@ Permission is granted to use, modify, and / or redistribute at will. */ +#ifndef REGTEST #include <_PDCLIB_int.h> +#endif char _PDCLIB_digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; @@ -20,8 +22,10 @@ char _PDCLIB_Xdigits[] = "0123456789ABCDEF"; int main( void ) { +#ifndef REGTEST TESTCASE( strcmp( _PDCLIB_digits, "0123456789abcdefghijklmnopqrstuvwxyz" ) == 0 ); TESTCASE( strcmp( _PDCLIB_Xdigits, "0123456789ABCDEF" ) == 0 ); +#endif return TEST_RESULTS; } diff --git a/functions/_PDCLIB/errno.c b/functions/_PDCLIB/errno.c index 7a69080..4facee5 100644 --- a/functions/_PDCLIB/errno.c +++ b/functions/_PDCLIB/errno.c @@ -6,9 +6,8 @@ Permission is granted to use, modify, and / or redistribute at will. */ -#include <_PDCLIB_int.h> - #ifndef REGTEST +#include <_PDCLIB_int.h> int _PDCLIB_errno = 0; diff --git a/functions/_PDCLIB/filemode.c b/functions/_PDCLIB/filemode.c index 0e293ab..ded5408 100644 --- a/functions/_PDCLIB/filemode.c +++ b/functions/_PDCLIB/filemode.c @@ -8,6 +8,7 @@ #include +#ifndef REGTEST /* Helper function that parses the C-style mode string passed to fopen() into the PDCLib flags FREAD, FWRITE, FAPPEND, FRW (read-write) and FBIN (binary mode). @@ -53,12 +54,14 @@ unsigned int _PDCLIB_filemode( char const * const mode ) /* Longer than three chars - invalid. */ return 0; } +#endif #ifdef TEST #include <_PDCLIB_test.h> int main( void ) { +#ifndef REGTEST TESTCASE( _PDCLIB_filemode( "r" ) == _PDCLIB_FREAD ); TESTCASE( _PDCLIB_filemode( "w" ) == _PDCLIB_FWRITE ); TESTCASE( _PDCLIB_filemode( "a" ) == ( _PDCLIB_FAPPEND | _PDCLIB_FWRITE ) ); @@ -78,6 +81,7 @@ int main( void ) TESTCASE( _PDCLIB_filemode( "r++" ) == 0 ); TESTCASE( _PDCLIB_filemode( "wbb" ) == 0 ); TESTCASE( _PDCLIB_filemode( "a+bx" ) == 0 ); +#endif return TEST_RESULTS; } diff --git a/functions/_PDCLIB/prepread.c b/functions/_PDCLIB/prepread.c index 6ce38d9..cf1c2df 100644 --- a/functions/_PDCLIB/prepread.c +++ b/functions/_PDCLIB/prepread.c @@ -9,6 +9,7 @@ #include #include +#ifndef REGTEST #include <_PDCLIB_glue.h> int _PDCLIB_prepread( struct _PDCLIB_file_t * stream ) @@ -35,6 +36,7 @@ int _PDCLIB_prepread( struct _PDCLIB_file_t * stream ) return 0; } } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/functions/_PDCLIB/prepwrite.c b/functions/_PDCLIB/prepwrite.c index 0b31529..1b1c4b5 100644 --- a/functions/_PDCLIB/prepwrite.c +++ b/functions/_PDCLIB/prepwrite.c @@ -9,6 +9,7 @@ #include #include +#ifndef REGTEST int _PDCLIB_prepwrite( struct _PDCLIB_file_t * stream ) { if ( ( stream->bufidx < stream->bufend ) || ( stream->ungetidx > 0 ) || @@ -26,6 +27,7 @@ int _PDCLIB_prepwrite( struct _PDCLIB_file_t * stream ) stream->status |= _PDCLIB_FWRITE | _PDCLIB_BYTESTREAM; return 0; } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/functions/_PDCLIB/print.c b/functions/_PDCLIB/print.c index 72db66b..124496c 100644 --- a/functions/_PDCLIB/print.c +++ b/functions/_PDCLIB/print.c @@ -12,6 +12,8 @@ #include #include +#ifndef REGTEST + /* Using an integer's bits as flags for both the conversion flags and length modifiers. */ @@ -506,12 +508,15 @@ const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status return ++spec; } +#endif + #ifdef TEST #define _PDCLIB_FILEID "_PDCLIB/print.c" #define _PDCLIB_STRINGIO #include <_PDCLIB_test.h> +#ifndef REGTEST static int testprintf( char * buffer, const char * format, ... ) { /* Members: base, flags, n, i, current, s, width, prec, stream, arg */ @@ -535,13 +540,16 @@ static int testprintf( char * buffer, const char * format, ... ) va_end( status.arg ); return status.i; } +#endif #define TEST_CONVERSION_ONLY int main( void ) { +#ifndef REGTEST char target[100]; #include "printf_testcases.h" +#endif return TEST_RESULTS; } diff --git a/functions/_PDCLIB/scan.c b/functions/_PDCLIB/scan.c index 6910aef..57f9831 100644 --- a/functions/_PDCLIB/scan.c +++ b/functions/_PDCLIB/scan.c @@ -16,6 +16,8 @@ #include #include +#ifndef REGTEST + /* Using an integer's bits as flags for both the conversion flags and length modifiers. */ @@ -588,7 +590,7 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) /* TODO: Floats. */ return NULL; } - +#endif #ifdef TEST #define _PDCLIB_FILEID "_PDCLIB/scan.c" @@ -596,6 +598,7 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) #include <_PDCLIB_test.h> +#ifndef REGTEST static int testscanf( char const * s, char const * format, ... ) { struct _PDCLIB_status_t status; @@ -612,13 +615,16 @@ static int testscanf( char const * s, char const * format, ... ) va_end( status.arg ); return status.n; } +#endif #define TEST_CONVERSION_ONLY int main( void ) { +#ifndef REGTEST char source[100]; #include "scanf_testcases.h" +#endif return TEST_RESULTS; } diff --git a/functions/_PDCLIB/strtox_main.c b/functions/_PDCLIB/strtox_main.c index 1556ec4..86b6d42 100644 --- a/functions/_PDCLIB/strtox_main.c +++ b/functions/_PDCLIB/strtox_main.c @@ -6,12 +6,13 @@ Permission is granted to use, modify, and / or redistribute at will. */ -#include <_PDCLIB_int.h> #include #include #include #include +#ifndef REGTEST +#include <_PDCLIB_int.h> _PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, uintmax_t error, uintmax_t limval, int limdigit, char * sign ) { _PDCLIB_uintmax_t rc = 0; @@ -43,6 +44,7 @@ _PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, uintm } return rc; } +#endif #ifdef TEST #include <_PDCLIB_test.h> @@ -50,6 +52,7 @@ _PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, uintm int main( void ) { +#ifndef REGTEST const char * p; char test[] = "123_"; char fail[] = "xxx"; @@ -77,6 +80,7 @@ int main( void ) sign = '-'; TESTCASE( _PDCLIB_strtox_main( &p, 10u, (uintmax_t)999, (uintmax_t)99, 8, &sign ) == 0 ); TESTCASE( p == NULL ); +#endif return TEST_RESULTS; } diff --git a/functions/_PDCLIB/strtox_prelim.c b/functions/_PDCLIB/strtox_prelim.c index 29b7919..7be4030 100644 --- a/functions/_PDCLIB/strtox_prelim.c +++ b/functions/_PDCLIB/strtox_prelim.c @@ -9,7 +9,7 @@ #include #include #include - +#ifndef REGTEST const char * _PDCLIB_strtox_prelim( const char * p, char * sign, int * base ) { /* skipping leading whitespace */ @@ -50,12 +50,14 @@ const char * _PDCLIB_strtox_prelim( const char * p, char * sign, int * base ) } return ( ( *base >= 2 ) && ( *base <= 36 ) ) ? p : NULL; } +#endif #ifdef TEST #include <_PDCLIB_test.h> int main( void ) { +#ifndef REGTEST int base = 0; char sign = '\0'; char test1[] = " 123"; @@ -83,6 +85,7 @@ int main( void ) TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == NULL ); base = 37; TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == NULL ); +#endif return TEST_RESULTS; } diff --git a/functions/stdio/_PDCLIB_fdopen.c b/functions/stdio/_PDCLIB_fdopen.c new file mode 100644 index 0000000..8556327 --- /dev/null +++ b/functions/stdio/_PDCLIB_fdopen.c @@ -0,0 +1,92 @@ +/* $Id$ */ + +/* _PDCLIB_fdopen( _PDCLIB_fd_t fd, const char * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#include + +#ifndef REGTEST +#include <_PDCLIB_glue.h> +#include + +extern struct _PDCLIB_file_t * _PDCLIB_filelist; + +struct _PDCLIB_file_t * _PDCLIB_fdopen( _PDCLIB_fd_t fd, + int mode, + const char * _PDCLIB_restrict filename ) +{ + size_t filename_len; + struct _PDCLIB_file_t * rc; + if ( mode == NULL ) + { + /* Mode invalid */ + return NULL; + } + /* To reduce the number of malloc calls, all data fields are concatenated: + * the FILE structure itself, + * ungetc buffer, + * filename buffer, + * data buffer. + 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 ) + { + /* no memory */ + return NULL; + } + rc->status = mode; + rc->handle = fd; + /* Setting pointers into the memory block allocated above */ + rc->ungetbuf = (unsigned char *)rc + sizeof( struct _PDCLIB_file_t ); + rc->filename = (char *)rc->ungetbuf + _PDCLIB_UNGETCBUFSIZE; + rc->buffer = rc->filename + filename_len; + /* Copying filename to FILE structure */ + if(filename) strcpy( rc->filename, filename ); + /* Initializing the rest of the structure */ + rc->bufsize = BUFSIZ; + rc->bufidx = 0; + rc->ungetidx = 0; + /* Setting buffer to _IOLBF because "when opened, a stream is fully + buffered if and only if it can be determined not to refer to an + interactive device." + */ + rc->status |= _IOLBF; + /* TODO: Setting mbstate */ + /* Adding to list of open files */ + rc->next = _PDCLIB_filelist; + _PDCLIB_filelist = rc; + return rc; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + /* Some of the tests are not executed for regression tests, as the libc on + my system is at once less forgiving (segfaults on mode NULL) and more + forgiving (accepts undefined modes). + */ + FILE * fh; + remove( testfile ); + TESTCASE_NOREG( fopen( NULL, NULL ) == NULL ); + TESTCASE( fopen( NULL, "w" ) == NULL ); + TESTCASE_NOREG( fopen( "", NULL ) == NULL ); + TESTCASE( fopen( "", "w" ) == NULL ); + TESTCASE( fopen( "foo", "" ) == NULL ); + TESTCASE_NOREG( fopen( testfile, "wq" ) == NULL ); /* Undefined mode */ + TESTCASE_NOREG( fopen( testfile, "wr" ) == NULL ); /* Undefined mode */ + TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL ); + TESTCASE( fclose( fh ) == 0 ); + TESTCASE( remove( testfile ) == 0 ); + return TEST_RESULTS; +} + +#endif diff --git a/functions/stdio/fopen.c b/functions/stdio/fopen.c index 7c0b81a..18b7b3a 100644 --- a/functions/stdio/fopen.c +++ b/functions/stdio/fopen.c @@ -12,64 +12,26 @@ #ifndef REGTEST #include <_PDCLIB_glue.h> #include +#include extern struct _PDCLIB_file_t * _PDCLIB_filelist; -struct _PDCLIB_file_t * fopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode ) +FILE * fopen( const char * _PDCLIB_restrict filename, + const char * _PDCLIB_restrict mode ) { - struct _PDCLIB_file_t * rc; - size_t filename_len; - if ( mode == NULL || filename == NULL || filename[0] == '\0' ) - { - /* Mode or filename invalid */ + int imode = _PDCLIB_filemode( mode ); + _PDCLIB_fd_t fd = _PDCLIB_open( filename, imode ); + if(fd == _PDCLIB_NOHANDLE) { return NULL; } - /* To reduce the number of malloc calls, all data fields are concatenated: - * the FILE structure itself, - * ungetc buffer, - * filename buffer, - * data buffer. - Data buffer comes last because it might change in size ( setvbuf() ). - */ - filename_len = strlen( filename ) + 1; - if ( ( rc = calloc( 1, sizeof( struct _PDCLIB_file_t ) + _PDCLIB_UNGETCBUFSIZE + filename_len + BUFSIZ ) ) == NULL ) - { - /* no memory */ - return NULL; - } - if ( ( rc->status = _PDCLIB_filemode( mode ) ) == 0 ) - { - /* invalid mode */ - free( rc ); - return NULL; - } - rc->handle = _PDCLIB_open( filename, rc->status ); - if ( rc->handle == _PDCLIB_NOHANDLE ) - { - /* OS open() failed */ - free( rc ); - return NULL; + + FILE * f = _PDCLIB_fdopen( fd, imode, filename ); + if(!f) { + int saveErrno = errno; + _PDCLIB_close( fd ); + errno = saveErrno; } - /* Setting pointers into the memory block allocated above */ - rc->ungetbuf = (unsigned char *)rc + sizeof( struct _PDCLIB_file_t ); - rc->filename = (char *)rc->ungetbuf + _PDCLIB_UNGETCBUFSIZE; - rc->buffer = rc->filename + filename_len; - /* Copying filename to FILE structure */ - strcpy( rc->filename, filename ); - /* Initializing the rest of the structure */ - rc->bufsize = BUFSIZ; - rc->bufidx = 0; - rc->ungetidx = 0; - /* Setting buffer to _IOLBF because "when opened, a stream is fully - buffered if and only if it can be determined not to refer to an - interactive device." - */ - rc->status |= _IOLBF; - /* TODO: Setting mbstate */ - /* Adding to list of open files */ - rc->next = _PDCLIB_filelist; - _PDCLIB_filelist = rc; - return rc; + return f; } #endif diff --git a/functions/string/strndup.c b/functions/string/strndup.c index e25c7ed..e50f419 100644 --- a/functions/string/strndup.c +++ b/functions/string/strndup.c @@ -31,6 +31,8 @@ char *strndup( const char * s, size_t len ) int main( void ) { +#ifndef REGTEST + /* Missing on Windows. Maybe use conditionals? */ const char *teststr = "Hello, world"; const char *teststr2 = "\xFE\x8C\n"; char *testres, *testres2; @@ -49,7 +51,8 @@ int main( void ) TESTCASE(strcmp(testres2, teststr2) == 0); free(testres); free(testres2); - +#endif + return TEST_RESULTS; } diff --git a/functions/wchar/wcschr.c b/functions/wchar/wcschr.c new file mode 100644 index 0000000..51d20a4 --- /dev/null +++ b/functions/wchar/wcschr.c @@ -0,0 +1,32 @@ +/* wcschr( const wchar_t *, wchar_t ); + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#include + +#ifndef REGTEST + +wchar_t *wcschr(const wchar_t * haystack, wchar_t needle) +{ + while(*haystack) { + if(*haystack == needle) return (wchar_t*) haystack; + haystack++; + } + return NULL; +} + + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif diff --git a/functions/wchar/wcscpy.c b/functions/wchar/wcscpy.c new file mode 100644 index 0000000..02394ee --- /dev/null +++ b/functions/wchar/wcscpy.c @@ -0,0 +1,33 @@ +/* wchar_t * wcscpy( wchar_t restrict *, const wchar_t restrict * ); + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +wchar_t *wcscpy( wchar_t * _PDCLIB_restrict dest, + const wchar_t * _PDCLIB_restrict src) +{ + wchar_t * rv = dest; + while(*src) { + *(dest++) = *(src++); + } + + return rv; +} + + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif diff --git a/functions/wchar/wcslen.c b/functions/wchar/wcslen.c new file mode 100644 index 0000000..d5d878d --- /dev/null +++ b/functions/wchar/wcslen.c @@ -0,0 +1,29 @@ +/* wcslen( const wchar_t * ); + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +size_t wcslen( const wchar_t * str ) +{ + size_t n = 0; + while(*(str++)) n++; + return n; +} + + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif diff --git a/functions/wchar/wcsrchr.c b/functions/wchar/wcsrchr.c new file mode 100644 index 0000000..396da4f --- /dev/null +++ b/functions/wchar/wcsrchr.c @@ -0,0 +1,35 @@ +/* $Id$ */ + +/* wcsrchr( const wchar_t *, wchar_t ); + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#include + +#ifndef REGTEST + +wchar_t *wcsrchr(const wchar_t * haystack, wchar_t needle) +{ + wchar_t *found = NULL; + while(*haystack) { + if(*haystack == needle) found = haystack; + haystack++; + } + return found; +} + + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif diff --git a/includes/stddef.h b/includes/stddef.h index 6d8c03a..1d5e3af 100644 --- a/includes/stddef.h +++ b/includes/stddef.h @@ -20,8 +20,11 @@ typedef _PDCLIB_size_t size_t; #endif #ifndef __cplusplus +#ifndef _PDCLIB_WCHAR_T_DEFINED +#define _PDCLIB_WCHAR_T_DEFINED _PDCLIB_WCHAR_T_DEFINED typedef _PDCLIB_wchar_t wchar_t; #endif +#endif #ifndef _PDCLIB_NULL_DEFINED #define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED diff --git a/includes/stdio.h b/includes/stdio.h index 1d7c0bf..12b7f0a 100644 --- a/includes/stdio.h +++ b/includes/stdio.h @@ -36,10 +36,28 @@ typedef struct _PDCLIB_file_t FILE; #define L_tmpnam _PDCLIB_L_tmpnam #define TMP_MAX _PDCLIB_TMP_MAX -/* See fseek(), third argument */ -#define SEEK_CUR _PDCLIB_SEEK_CUR -#define SEEK_END _PDCLIB_SEEK_END -#define SEEK_SET _PDCLIB_SEEK_SET +/* See fseek(), third argument + * + * Some system headers (e.g. windows) also define the SEEK_* values. Check for + * this and validate that they're the same value + */ +#if !defined(SEEK_CUR) + #define SEEK_CUR _PDCLIB_SEEK_CUR +#elif SEEK_CUR != _PDCLIB_SEEK_CUR + #error SEEK_CUR != _PDCLIB_SEEK_CUR +#endif + +#if !defined(SEEK_END) + #define SEEK_END _PDCLIB_SEEK_END +#elif SEEK_END != _PDCLIB_SEEK_END + #error SEEK_END != _PDCLIB_SEEK_END +#endif + +#if !defined(SEEK_SET) + #define SEEK_SET _PDCLIB_SEEK_SET +#elif SEEK_SET != _PDCLIB_SEEK_SET + #error SEEK_SET != _PDCLIB_SEEK_SET +#endif extern FILE * stdin; extern FILE * stdout; @@ -155,6 +173,11 @@ int fflush( FILE * stream ); */ FILE * fopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode ); +/* Creates a stream connected to the file descriptor \p fd with mode \p mode. + Mode must match the mode with which the file descriptor was opened. +*/ +FILE * _PDCLIB_fdopen( _PDCLIB_fd_t fd, int mode, const char* filename ); + /* Close any file currently associated with the given stream. Open the file identified by the given filename with the given mode (equivalent to fopen()), and associate it with the given stream. If filename is a NULL pointer, diff --git a/includes/wchar.h b/includes/wchar.h new file mode 100644 index 0000000..eab2984 --- /dev/null +++ b/includes/wchar.h @@ -0,0 +1,35 @@ +/* 7. + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + + +#ifndef _PDCLIB_WCHAR_H +#define _PDCLIB_WCHAR_H +#include <_PDCLIB_int.h> +_PDCLIB_BEGIN_EXTERN_C +/* This is VASTLY incomplete. Functions being implemented as required by other + portions of the library + */ + +#ifndef _PDCLIB_SIZE_T_DEFINED +#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED +typedef _PDCLIB_size_t size_t; +#endif + +#ifndef __cplusplus +#ifndef _PDCLIB_WCHAR_T_DEFINED +#define _PDCLIB_WCHAR_T_DEFINED _PDCLIB_WCHAR_T_DEFINED +typedef _PDCLIB_wchar_t wchar_t; +#endif +#endif + +wchar_t *wcschr( const wchar_t * haystack, wchar_t needle ); +wchar_t *wcsrchr( const wchar_t * haystack, wchar_t needle ); +size_t wcslen( const wchar_t * string); +wchar_t *wcscpy( wchar_t * _PDCLIB_restrict dest, + const wchar_t * _PDCLIB_restrict src); + +_PDCLIB_END_EXTERN_C +#endif diff --git a/internals/_PDCLIB_aux.h b/internals/_PDCLIB_aux.h index 8990ed8..e7e908a 100644 --- a/internals/_PDCLIB_aux.h +++ b/internals/_PDCLIB_aux.h @@ -194,7 +194,7 @@ #define _PDCLIB_CXX_MAX(max) _PDCLIB_CXX_MINMAX(0, max) #define _PDCLIB_XOPEN_MAX(max) _PDCLIB_XOPEN_MINMAX(0, max) #define _PDCLIB_POSIX_MAX(max) _PDCLIB_POSIX_MINMAX(0, max) -#if defined(_PDCLIB_ALL) || defined(_PDCLIB_BUILD) +#if defined(_PDCLIB_EXTENSIONS) || defined(_PDCLIB_BUILD) #define _PDCLIB_C_MINMAX(min, max) 1 #define _PDCLIB_CXX_MINMAX(min, max) 1 #define _PDCLIB_POSIX_MINMAX(min, max) 1 diff --git a/opt/nothread/call_once.c b/opt/nothread/call_once.c index be1ed2e..8320170 100644 --- a/opt/nothread/call_once.c +++ b/opt/nothread/call_once.c @@ -1,3 +1,4 @@ +#ifndef REGTEST #include void _PDCLIB_call_once(_PDCLIB_once_flag *flag, void (*func)(void)) @@ -7,20 +8,24 @@ void _PDCLIB_call_once(_PDCLIB_once_flag *flag, void (*func)(void)) *flag = _PDCLIB_ONCE_FLAG_DONE; } } +#endif #ifdef TEST #include <_PDCLIB_test.h> +#ifndef REGTEST static int count = 0; -once_flag once = ONCE_FLAG_INIT; +static once_flag once = ONCE_FLAG_INIT; static void do_once(void) { count++; } +#endif int main( void ) { +#ifndef REGTEST TESTCASE(count == 0); call_once(&once, do_once); TESTCASE(count == 1); @@ -28,6 +33,7 @@ int main( void ) TESTCASE(count == 1); do_once(); TESTCASE(count == 2); +#endif return TEST_RESULTS; } diff --git a/opt/nothread/cnd_init.c b/opt/nothread/cnd_init.c index 379f28f..2d3fc7e 100644 --- a/opt/nothread/cnd_init.c +++ b/opt/nothread/cnd_init.c @@ -1,3 +1,4 @@ +#ifndef REGTEST #include int cnd_init(cnd_t *cond) @@ -5,6 +6,7 @@ int cnd_init(cnd_t *cond) /* does nothing */ return thrd_success; } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/opt/nothread/cnd_signal.c b/opt/nothread/cnd_signal.c index 05cbcf6..363806e 100644 --- a/opt/nothread/cnd_signal.c +++ b/opt/nothread/cnd_signal.c @@ -1,9 +1,11 @@ +#ifndef REGTEST #include int cnd_signal(cnd_t *cond) { return thrd_success; } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/opt/nothread/cnd_wait.c b/opt/nothread/cnd_wait.c index 4c632cc..be2fcbb 100644 --- a/opt/nothread/cnd_wait.c +++ b/opt/nothread/cnd_wait.c @@ -1,9 +1,11 @@ +#ifndef REGTEST #include int cnd_wait(cnd_t *cond, mtx_t *mtx) { return thrd_error; } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/opt/nothread/mtx_destroy.c b/opt/nothread/mtx_destroy.c index 75baec2..5227274 100644 --- a/opt/nothread/mtx_destroy.c +++ b/opt/nothread/mtx_destroy.c @@ -1,7 +1,9 @@ +#ifndef REGTEST #include void mtx_destroy(mtx_t *mtx) {} +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/opt/nothread/mtx_init.c b/opt/nothread/mtx_init.c index 922c942..76b3eeb 100644 --- a/opt/nothread/mtx_init.c +++ b/opt/nothread/mtx_init.c @@ -1,3 +1,4 @@ +#ifndef REGTEST #include int mtx_init(mtx_t *mtx, int type) @@ -5,6 +6,7 @@ int mtx_init(mtx_t *mtx, int type) *mtx = 0; return thrd_success; } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/opt/nothread/mtx_lock.c b/opt/nothread/mtx_lock.c index 121444e..d086986 100644 --- a/opt/nothread/mtx_lock.c +++ b/opt/nothread/mtx_lock.c @@ -1,5 +1,5 @@ +#ifndef REGTEST #include -#include int mtx_lock(mtx_t *mtx) { @@ -8,6 +8,7 @@ int mtx_lock(mtx_t *mtx) return thrd_success; } else return thrd_error; } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/opt/nothread/mtx_timedlock.c b/opt/nothread/mtx_timedlock.c index e3cd4fb..6ab7dfb 100644 --- a/opt/nothread/mtx_timedlock.c +++ b/opt/nothread/mtx_timedlock.c @@ -1,9 +1,11 @@ +#ifndef REGTEST #include int mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts) { return mtx_lock(mtx); } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/opt/nothread/mtx_trylock.c b/opt/nothread/mtx_trylock.c index 3333a86..bffc8b8 100644 --- a/opt/nothread/mtx_trylock.c +++ b/opt/nothread/mtx_trylock.c @@ -1,3 +1,4 @@ +#ifndef REGTEST #include int mtx_trylock(mtx_t *mtx) @@ -9,6 +10,7 @@ int mtx_trylock(mtx_t *mtx) return thrd_success; } } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/opt/nothread/mtx_unlock.c b/opt/nothread/mtx_unlock.c index 1c11401..214a063 100644 --- a/opt/nothread/mtx_unlock.c +++ b/opt/nothread/mtx_unlock.c @@ -1,3 +1,4 @@ +#ifndef REGTEST #include int mtx_unlock(mtx_t *mtx) @@ -7,6 +8,7 @@ int mtx_unlock(mtx_t *mtx) return thrd_success; } else return thrd_error; } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/opt/nothread/thrd_yield.c b/opt/nothread/thrd_yield.c index 840157b..c92c495 100644 --- a/opt/nothread/thrd_yield.c +++ b/opt/nothread/thrd_yield.c @@ -1,9 +1,11 @@ +#ifndef REGTEST #include void thrd_yield(void) { /* does nothing */ } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/opt/nothread/tss_create.c b/opt/nothread/tss_create.c index 2a28fca..e7ad53a 100644 --- a/opt/nothread/tss_create.c +++ b/opt/nothread/tss_create.c @@ -1,3 +1,4 @@ +#ifndef REGTEST #include int tss_create(tss_t *key, tss_dtor_t dtor) @@ -6,6 +7,7 @@ int tss_create(tss_t *key, tss_dtor_t dtor) key->value = NULL; return thrd_success; } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/opt/nothread/tss_delete.c b/opt/nothread/tss_delete.c index 5d251f4..758209f 100644 --- a/opt/nothread/tss_delete.c +++ b/opt/nothread/tss_delete.c @@ -1,9 +1,11 @@ +#ifndef REGTEST #include void tss_delete(tss_t key) { key.self->self = NULL; } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/opt/nothread/tss_get.c b/opt/nothread/tss_get.c index 3e9917b..c302fff 100644 --- a/opt/nothread/tss_get.c +++ b/opt/nothread/tss_get.c @@ -1,23 +1,29 @@ +#ifndef REGTEST #include void *tss_get(tss_t key) { return key.value; } +#endif #ifdef TEST #include <_PDCLIB_test.h> +#ifndef REGTEST static tss_t key; static char v; +#endif int main( void ) { +#ifndef REGTEST TESTCASE(tss_create(&key, NULL) == thrd_success); TESTCASE(tss_get(key) == NULL); TESTCASE(tss_set(key, &v) == thrd_success); TESTCASE(tss_get(key) == &v); tss_delete(key); +#endif return TEST_RESULTS; } diff --git a/opt/nothread/tss_set.c b/opt/nothread/tss_set.c index 7de3ec5..d8ae84b 100644 --- a/opt/nothread/tss_set.c +++ b/opt/nothread/tss_set.c @@ -1,3 +1,4 @@ +#ifndef REGTEST #include int tss_set(tss_t key, void *val) @@ -5,6 +6,7 @@ int tss_set(tss_t key, void *val) key.self->value = val; return thrd_success; } +#endif #ifdef TEST #include <_PDCLIB_test.h> diff --git a/platform/example/functions/stdio/tmpfile.c b/platform/example/functions/stdio/tmpfile.c index 2d52f60..3f384e7 100644 --- a/platform/example/functions/stdio/tmpfile.c +++ b/platform/example/functions/stdio/tmpfile.c @@ -20,7 +20,7 @@ extern struct _PDCLIB_file_t * _PDCLIB_filelist; struct _PDCLIB_file_t * tmpfile( void ) { errno = ENOTSUP; - return 1; + return NULL; } #endif diff --git a/platform/win32/Config.jam b/platform/win32/Config.jam new file mode 100644 index 0000000..c02174f --- /dev/null +++ b/platform/win32/Config.jam @@ -0,0 +1,12 @@ +rule PDCLibTargetConfig { } +rule PDCLibTargetHeaders { + SubDirHdrs $(PDCLIB_TOP) platform win32 includes ; + SubDirHdrs $(PDCLIB_TOP) platform win32 internals ; +} + +PDCLIB_TEST_LINKFLAGS += -nostdlib ; +PDCLIB_TEST_LINKLIBS += -lgcc -lkernel32 -lshell32 ; + +PDCLIB_OPTIONS = nothread notime dlmalloc ; + +CRT0 = [ FDirName platform win32 crt0$(SUFOBJ) ] ; \ No newline at end of file diff --git a/platform/win32/Jamfile b/platform/win32/Jamfile new file mode 100644 index 0000000..35b8dea --- /dev/null +++ b/platform/win32/Jamfile @@ -0,0 +1,6 @@ +SubDir PDCLIB_TOP platform win32 ; +PDCLibConfig ; + +Object $(CRT0) : $(CRT0:S=.c) ; + +DEPENDS all : $(CRT0) ; \ No newline at end of file diff --git a/platform/win32/Readme.txt b/platform/win32/Readme.txt new file mode 100644 index 0000000..5ec24bd --- /dev/null +++ b/platform/win32/Readme.txt @@ -0,0 +1,24 @@ +$Id$ + +"Example" Platform Overlay +========================== + +This is an example platform overlay, as described in the main Readme.txt of +this archive. For ease of development, it applies (and tests) correctly on the +machine of the author; no other guarantees can be given. +It should give you a good idea of what is REQUIRED to make a copy of PDCLib +work. There is a lot more you could do, and even some things you SHOULD do, in +order to experience anything but abysmal performance: + +- Read / write operations on binary streams, and even on text streams for + machines that do not do any text conversion, can be made much more efficient + by using some sort of page buffer instead of the linear buffer implemented + here. It requires some special and platform-dependent manipulations, though, + which is why it is not done by default. + +- Anything relating to floating point logic is written in generic C. While + this is (hopefully) highly portable and should get you started on your + platform of choice, it is also highly inefficient and should be replaced by + inline assembly. Just make sure that your assembly keeps all the promises + the C library makes. + diff --git a/platform/win32/crt0.c b/platform/win32/crt0.c new file mode 100644 index 0000000..fcdee08 --- /dev/null +++ b/platform/win32/crt0.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +static char ** argvToAnsi( wchar_t ** wargv, int argc ) +{ + char ** argv = malloc( sizeof( *argv ) * argc ); + for ( int i = 0; i != argc; ++i ) { + int sz = WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK | WC_SEPCHARS, + wargv[i], -1, NULL, 0, NULL, NULL ); + if(!(argv[i] = malloc(sz))) { + fputs("Error in C runtime initialization: " + "unable to allocate buffer for argument", stderr); + abort(); + } + + int rv = WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK | WC_SEPCHARS, + wargv[i], -1, argv[i], sz, NULL, NULL ); + + if(rv != sz) { + fputs("Error in C runtime initialization: " + "size mismatch during character set conversion", stderr); + } + } + return argv; +} + +static int argc; +static wchar_t * cl; +static wchar_t ** wargv; +static char ** argv; + +static void freeArgs( void ) +{ + for(int i = 0; i != argc; i++) { + free( argv[i] ); + } + free( argv ); + LocalFree( wargv ); +} + +extern int main( int argc, char ** argv, char ** envp ); +_PDCLIB_noreturn void mainCRTStartup( void ) +{ + stdin->handle = GetStdHandle(STD_INPUT_HANDLE); + stdout->handle = GetStdHandle(STD_OUTPUT_HANDLE); + stderr->handle = GetStdHandle(STD_ERROR_HANDLE); + + cl = GetCommandLineW(); + wargv = CommandLineToArgvW(cl, &argc); + argv = argvToAnsi(wargv, argc); + atexit(freeArgs); + + int exitStatus = main(argc, argv, NULL); + exit(exitStatus); +} diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_Exit.c b/platform/win32/functions/_PDCLIB/_PDCLIB_Exit.c new file mode 100644 index 0000000..fa50a41 --- /dev/null +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_Exit.c @@ -0,0 +1,39 @@ +/* $Id$ */ + +/* _PDCLIB_exit( int ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is a stub implementation of _PDCLIB_Exit +*/ + +#include + +#ifndef REGTEST +#include <_PDCLIB_glue.h> +#include +#include + +void _PDCLIB_Exit( int status ) +{ + ExitProcess( status ); +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ +#ifndef REGTEST + int UNEXPECTED_RETURN = 0; + _PDCLIB_Exit( 0 ); + TESTCASE( UNEXPECTED_RETURN ); +#endif + return TEST_RESULTS; +} + +#endif diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_allocpages.c b/platform/win32/functions/_PDCLIB/_PDCLIB_allocpages.c new file mode 100644 index 0000000..48e4bab --- /dev/null +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_allocpages.c @@ -0,0 +1,40 @@ +/* $Id$ */ + +/* _PDCLIB_allocpages( int const ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is a stub implementation of _PDCLIB_allocpages +*/ + +#ifndef REGTEST +#include +#include +#include <_PDCLIB_glue.h> +#include +#include + +void _PDCLIB_w32errno(void); + +void * _PDCLIB_allocpages( size_t n ) +{ + void * rv = VirtualAlloc(NULL, n * _PDCLIB_MALLOC_PAGESIZE, MEM_COMMIT, + PAGE_READWRITE); + if(!rv) { + _PDCLIB_w32errno(); + } + return rv; +} +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_close.c b/platform/win32/functions/_PDCLIB/_PDCLIB_close.c new file mode 100644 index 0000000..7fc10a3 --- /dev/null +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_close.c @@ -0,0 +1,39 @@ +/* $Id$ */ + +/* _PDCLIB_close( _PDCLIB_fd_t fd ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is a stub example implementation of _PDCLIB_close() +*/ + +#include + +#ifndef REGTEST +#include <_PDCLIB_glue.h> +#include +#include + +void _PDCLIB_w32errno(void); +int _PDCLIB_close( HANDLE fd ) +{ + if(CloseHandle((HANDLE) fd)) + return 0; + _PDCLIB_w32errno(); + return 1; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + /* No testdriver; tested in driver for _PDCLIB_open(). */ + return TEST_RESULTS; +} + +#endif diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_fillbuffer.c b/platform/win32/functions/_PDCLIB/_PDCLIB_fillbuffer.c new file mode 100644 index 0000000..c6a2b6b --- /dev/null +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_fillbuffer.c @@ -0,0 +1,54 @@ +/* $Id$ */ + +/* _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is a stub version of _PDCLIB_fillbuffer +*/ + +#include + +#ifndef REGTEST +#include <_PDCLIB_glue.h> +#include +#include + +void _PDCLIB_w32errno(void); +int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) +{ + DWORD nBytesRead; + BOOL ok = ReadFile( stream->handle, stream->buffer, stream->bufsize, + &nBytesRead, NULL ); + + if( ok ) { + if( nBytesRead == 0 ) { + stream->status |= _PDCLIB_EOFFLAG; + return EOF; + } + stream->pos.offset += nBytesRead; + stream->bufend = nBytesRead; + stream->bufidx = 0; + return 0; + } else { + _PDCLIB_w32errno(); + stream->status |= _PDCLIB_ERRORFLAG; + return EOF; + } +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + /* Testing covered by ftell.c */ + return TEST_RESULTS; +} + +#endif + diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_flushbuffer.c b/platform/win32/functions/_PDCLIB/_PDCLIB_flushbuffer.c new file mode 100644 index 0000000..82e36a0 --- /dev/null +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_flushbuffer.c @@ -0,0 +1,63 @@ +/* $Id$ */ + +/* _PDCLIB_flushbuffer( struct _PDCLIB_file_t * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is a stub implementation of _PDCLIB_flushbuffer +*/ + +#include +#include + +#ifndef REGTEST +#include <_PDCLIB_glue.h> +#include +#include + +int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ) +{ + if ( ! ( stream->status & _PDCLIB_FBIN ) ) + { + /* TODO: Text stream conversion here */ + } + + DWORD written = 0; + + + while(written != stream->bufidx) { + DWORD justWrote; + DWORD toWrite = stream->bufidx - written; + BOOL res = WriteFile( stream->handle, stream->buffer + written, + toWrite, &justWrote, NULL); + written += justWrote; + + if(!res) { + stream->status |=_PDCLIB_ERRORFLAG; + stream->bufidx -= written; + memmove( stream->buffer, stream->buffer + written, stream->bufidx ); + _PDCLIB_w32errno(); + return EOF; + } + } + + stream->bufidx = 0; + return 0; +} + +#endif + + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + /* Testing covered by ftell.c */ + return TEST_RESULTS; +} + +#endif + diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_freepages.c b/platform/win32/functions/_PDCLIB/_PDCLIB_freepages.c new file mode 100644 index 0000000..3d8a254 --- /dev/null +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_freepages.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* _PDCLIB_allocpages( int const ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is a stub implementation of _PDCLIB_allocpages +*/ + +#include +#include +#include +#ifndef REGTEST +#include <_PDCLIB_glue.h> + +void _PDCLIB_freepages( void * p, size_t n ) +{ + return; +} +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_open.c b/platform/win32/functions/_PDCLIB/_PDCLIB_open.c new file mode 100644 index 0000000..bfdb897 --- /dev/null +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_open.c @@ -0,0 +1,94 @@ +/* $Id$ */ + +/* _PDCLIB_open( char const * const, int ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is a stub implementation of open. +*/ + +#include +#include + +#ifndef REGTEST +#include <_PDCLIB_glue.h> +#include + +void _PDCLIB_w32errno(void); +HANDLE _PDCLIB_open( char const * const filename, unsigned int mode ) +{ + DWORD desiredAccess; + DWORD creationDisposition; + + switch(mode & ( _PDCLIB_FREAD | _PDCLIB_FWRITE | _PDCLIB_FAPPEND + | _PDCLIB_FRW )) + { + case _PDCLIB_FREAD: /* "r" */ + desiredAccess = GENERIC_READ; + creationDisposition = OPEN_EXISTING; + break; + case _PDCLIB_FWRITE: /* "w" */ + desiredAccess = GENERIC_WRITE; + creationDisposition = CREATE_ALWAYS; + break; + case _PDCLIB_FAPPEND: /* "a" */ + desiredAccess = GENERIC_WRITE; + creationDisposition = OPEN_ALWAYS; + break; + case _PDCLIB_FREAD | _PDCLIB_FRW: /* "r+" */ + desiredAccess = GENERIC_READ | GENERIC_WRITE; + creationDisposition = OPEN_EXISTING; + break; + case _PDCLIB_FWRITE | _PDCLIB_FRW: /* "w+" */ + desiredAccess = GENERIC_WRITE | GENERIC_READ; + creationDisposition = CREATE_ALWAYS; + break; + case _PDCLIB_FAPPEND | _PDCLIB_FRW: /* "a+" */ + desiredAccess = GENERIC_WRITE | GENERIC_READ; + creationDisposition = OPEN_ALWAYS; + break; + default: /* Invalid mode */ + errno = EINVAL; + return NULL; + } + + HANDLE fd = CreateFileA(filename, desiredAccess, + FILE_SHARE_READ | FILE_SHARE_DELETE, + NULL, creationDisposition, FILE_ATTRIBUTE_NORMAL, NULL); + + if(fd == INVALID_HANDLE_VALUE) { + _PDCLIB_w32errno(); + return NULL; + } + + if(mode & _PDCLIB_FAPPEND) { + LARGE_INTEGER offs; + offs.QuadPart = 0; + BOOL ok = SetFilePointerEx(fd, offs, NULL, FILE_END); + if(!ok) { + _PDCLIB_w32errno(); + CloseHandle(fd); + return NULL; + } + } + + return fd; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +#include +#include + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif + diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_rename.c b/platform/win32/functions/_PDCLIB/_PDCLIB_rename.c new file mode 100644 index 0000000..a65715d --- /dev/null +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_rename.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* _PDCLIB_rename( const char *, const char * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST +#include <_PDCLIB_glue.h> +#include + +int _PDCLIB_rename( const char * old, const char * new ) +{ + errno = ENOTSUP; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +#include + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_seek.c b/platform/win32/functions/_PDCLIB/_PDCLIB_seek.c new file mode 100644 index 0000000..c4c25f8 --- /dev/null +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_seek.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* int64_t _PDCLIB_seek( FILE *, int64_t, int ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#include +#ifndef REGTEST +#include <_PDCLIB_glue.h> + +_PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence ) +{ + errno = ENOTSUP; + return EOF; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + /* Testing covered by ftell.c */ + return TEST_RESULTS; +} + +#endif + diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_stdinit.c b/platform/win32/functions/_PDCLIB/_PDCLIB_stdinit.c new file mode 100644 index 0000000..bc40470 --- /dev/null +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_stdinit.c @@ -0,0 +1,355 @@ +/* $Id$ */ + +/* _PDCLIB_stdinit + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is an example initialization of stdin, stdout and stderr to the integer + file descriptors 0, 1, and 2, respectively. This applies for a great variety + of operating systems, including POSIX compliant ones. +*/ + +#include +#include +#include + +#ifndef REGTEST + +/* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file + descriptors 0, 1, and 2 respectively. +*/ +/* TODO: This is proof-of-concept, requires finetuning. */ +static char _PDCLIB_sin_buffer[BUFSIZ]; +static char _PDCLIB_sout_buffer[BUFSIZ]; +static char _PDCLIB_serr_buffer[BUFSIZ]; + +static unsigned char _PDCLIB_sin_ungetbuf[_PDCLIB_UNGETCBUFSIZE]; +static unsigned char _PDCLIB_sout_ungetbuf[_PDCLIB_UNGETCBUFSIZE]; +static unsigned char _PDCLIB_serr_ungetbuf[_PDCLIB_UNGETCBUFSIZE]; + +static struct _PDCLIB_file_t _PDCLIB_serr = { NULL, _PDCLIB_serr_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_serr_ungetbuf, _IONBF | _PDCLIB_FWRITE | _PDCLIB_STATIC, NULL, NULL }; +static struct _PDCLIB_file_t _PDCLIB_sout = { NULL, _PDCLIB_sout_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_sout_ungetbuf, _IOLBF | _PDCLIB_FWRITE | _PDCLIB_STATIC, NULL, &_PDCLIB_serr }; +static struct _PDCLIB_file_t _PDCLIB_sin = { NULL, _PDCLIB_sin_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_sin_ungetbuf, _IOLBF | _PDCLIB_FREAD | _PDCLIB_STATIC, NULL, &_PDCLIB_sout }; + +struct _PDCLIB_file_t * stdin = &_PDCLIB_sin; +struct _PDCLIB_file_t * stdout = &_PDCLIB_sout; +struct _PDCLIB_file_t * stderr = &_PDCLIB_serr; + +/* FIXME: This approach is a possible attack vector. */ +struct _PDCLIB_file_t * _PDCLIB_filelist = &_PDCLIB_sin; + +/* "C" locale - defaulting to ASCII-7. + 1 kByte (+ 4 byte) of data. + Each line: flags, lowercase, uppercase, collation. +*/ +static struct _PDCLIB_ctype_t _ctype[] = { + { /* EOF */ 0, 0, 0, 0 }, + { /* NUL */ _PDCLIB_CTYPE_CNTRL, 0x00, 0x00, 0x00 }, + { /* SOH */ _PDCLIB_CTYPE_CNTRL, 0x01, 0x01, 0x01 }, + { /* STX */ _PDCLIB_CTYPE_CNTRL, 0x02, 0x02, 0x02 }, + { /* ETX */ _PDCLIB_CTYPE_CNTRL, 0x03, 0x03, 0x03 }, + { /* EOT */ _PDCLIB_CTYPE_CNTRL, 0x04, 0x04, 0x04 }, + { /* ENQ */ _PDCLIB_CTYPE_CNTRL, 0x05, 0x05, 0x05 }, + { /* ACK */ _PDCLIB_CTYPE_CNTRL, 0x06, 0x06, 0x06 }, + { /* BEL */ _PDCLIB_CTYPE_CNTRL, 0x07, 0x07, 0x07 }, + { /* BS */ _PDCLIB_CTYPE_CNTRL, 0x08, 0x08, 0x08 }, + { /* HT */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_BLANK | _PDCLIB_CTYPE_SPACE, 0x09, 0x09, 0x09 }, + { /* LF */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE, 0x0A, 0x0A, 0x0A }, + { /* VT */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE, 0x0B, 0x0B, 0x0B }, + { /* FF */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE, 0x0C, 0x0C, 0x0C }, + { /* CR */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE, 0x0D, 0x0D, 0x0D }, + { /* SO */ _PDCLIB_CTYPE_CNTRL, 0x0E, 0x0E, 0x0E }, + { /* SI */ _PDCLIB_CTYPE_CNTRL, 0x0F, 0x0F, 0x0F }, + { /* DLE */ _PDCLIB_CTYPE_CNTRL, 0x10, 0x10, 0x10 }, + { /* DC1 */ _PDCLIB_CTYPE_CNTRL, 0x11, 0x11, 0x11 }, + { /* DC2 */ _PDCLIB_CTYPE_CNTRL, 0x12, 0x12, 0x12 }, + { /* DC3 */ _PDCLIB_CTYPE_CNTRL, 0x13, 0x13, 0x13 }, + { /* DC4 */ _PDCLIB_CTYPE_CNTRL, 0x14, 0x14, 0x14 }, + { /* NAK */ _PDCLIB_CTYPE_CNTRL, 0x15, 0x15, 0x15 }, + { /* SYN */ _PDCLIB_CTYPE_CNTRL, 0x16, 0x16, 0x16 }, + { /* ETB */ _PDCLIB_CTYPE_CNTRL, 0x17, 0x17, 0x17 }, + { /* CAN */ _PDCLIB_CTYPE_CNTRL, 0x18, 0x18, 0x18 }, + { /* EM */ _PDCLIB_CTYPE_CNTRL, 0x19, 0x19, 0x19 }, + { /* SUB */ _PDCLIB_CTYPE_CNTRL, 0x1A, 0x1A, 0x1A }, + { /* ESC */ _PDCLIB_CTYPE_CNTRL, 0x1B, 0x1B, 0x1B }, + { /* FS */ _PDCLIB_CTYPE_CNTRL, 0x1C, 0x1C, 0x1C }, + { /* GS */ _PDCLIB_CTYPE_CNTRL, 0x1D, 0x1D, 0x1D }, + { /* RS */ _PDCLIB_CTYPE_CNTRL, 0x1E, 0x1E, 0x1E }, + { /* US */ _PDCLIB_CTYPE_CNTRL, 0x1F, 0x1F, 0x1F }, + { /* SP */ _PDCLIB_CTYPE_BLANK | _PDCLIB_CTYPE_SPACE, 0x20, 0x20, 0x20 }, + { /* '!' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x21, 0x21, 0x21 }, + { /* '"' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x22, 0x22, 0x22 }, + { /* '#' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x23, 0x23, 0x23 }, + { /* '$' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x24, 0x24, 0x24 }, + { /* '%' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x25, 0x25, 0x25 }, + { /* '&' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x26, 0x26, 0x26 }, + { /* ''' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x27, 0x27, 0x27 }, + { /* '(' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x28, 0x28, 0x28 }, + { /* ')' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x29, 0x29, 0x29 }, + { /* '*' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2A, 0x2A, 0x2A }, + { /* '+' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2B, 0x2B, 0x2B }, + { /* ',' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2C, 0x2C, 0x2C }, + { /* '-' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2D, 0x2D, 0x2D }, + { /* '.' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2E, 0x2E, 0x2E }, + { /* '/' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2F, 0x2F, 0x2F }, + { /* '0' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x30, 0x30, 0x30 }, + { /* '1' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x31, 0x31, 0x31 }, + { /* '2' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x32, 0x32, 0x32 }, + { /* '3' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x33, 0x33, 0x33 }, + { /* '4' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x34, 0x34, 0x34 }, + { /* '5' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x35, 0x35, 0x35 }, + { /* '6' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x36, 0x36, 0x36 }, + { /* '7' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x37, 0x37, 0x37 }, + { /* '8' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x38, 0x38, 0x38 }, + { /* '9' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x39, 0x39, 0x39 }, + { /* ':' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3A, 0x3A, 0x3A }, + { /* ';' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3B, 0x3B, 0x3B }, + { /* '<' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3C, 0x3C, 0x3C }, + { /* '=' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3D, 0x3D, 0x3D }, + { /* '>' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3E, 0x3E, 0x3E }, + { /* '?' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3F, 0x3F, 0x3F }, + { /* '@' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x40, 0x40, 0x40 }, + { /* 'A' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x41, 0x61, 0x41 }, + { /* 'B' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x42, 0x62, 0x42 }, + { /* 'C' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x43, 0x63, 0x43 }, + { /* 'D' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x44, 0x64, 0x44 }, + { /* 'E' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x45, 0x65, 0x45 }, + { /* 'F' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x46, 0x66, 0x46 }, + { /* 'G' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x47, 0x67, 0x47 }, + { /* 'H' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x48, 0x68, 0x48 }, + { /* 'I' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x49, 0x69, 0x49 }, + { /* 'J' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4A, 0x6A, 0x4A }, + { /* 'K' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4B, 0x6B, 0x4B }, + { /* 'L' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4C, 0x6C, 0x4C }, + { /* 'M' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4D, 0x6D, 0x4D }, + { /* 'N' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4E, 0x6E, 0x4E }, + { /* 'O' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4F, 0x6F, 0x4F }, + { /* 'P' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x50, 0x70, 0x50 }, + { /* 'Q' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x51, 0x71, 0x51 }, + { /* 'R' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x52, 0x72, 0x52 }, + { /* 'S' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x53, 0x73, 0x53 }, + { /* 'T' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x54, 0x74, 0x54 }, + { /* 'U' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x55, 0x75, 0x55 }, + { /* 'V' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x56, 0x76, 0x56 }, + { /* 'W' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x57, 0x77, 0x57 }, + { /* 'X' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x58, 0x78, 0x58 }, + { /* 'Y' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x59, 0x79, 0x59 }, + { /* 'Z' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x5A, 0x7A, 0x5A }, + { /* '[' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5B, 0x5B, 0x5B }, + { /* '\' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5C, 0x5C, 0x5C }, + { /* ']' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5D, 0x5D, 0x5D }, + { /* '^' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5E, 0x5E, 0x5E }, + { /* '_' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5F, 0x5F, 0x5F }, + { /* '`' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x60, 0x60, 0x60 }, + { /* 'a' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x41, 0x61, 0x61 }, + { /* 'b' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x42, 0x62, 0x62 }, + { /* 'c' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x43, 0x63, 0x63 }, + { /* 'd' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x44, 0x64, 0x64 }, + { /* 'e' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x45, 0x65, 0x65 }, + { /* 'f' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x46, 0x66, 0x66 }, + { /* 'g' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x47, 0x67, 0x67 }, + { /* 'h' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x48, 0x68, 0x68 }, + { /* 'i' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x49, 0x69, 0x69 }, + { /* 'j' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4A, 0x6A, 0x6A }, + { /* 'k' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4B, 0x6B, 0x6B }, + { /* 'l' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4C, 0x6C, 0x6C }, + { /* 'm' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4D, 0x6D, 0x6D }, + { /* 'n' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4E, 0x6E, 0x6E }, + { /* 'o' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4F, 0x6F, 0x6F }, + { /* 'p' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x50, 0x70, 0x70 }, + { /* 'q' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x51, 0x71, 0x71 }, + { /* 'r' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x52, 0x72, 0x72 }, + { /* 's' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x53, 0x73, 0x73 }, + { /* 't' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x54, 0x74, 0x74 }, + { /* 'u' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x55, 0x75, 0x75 }, + { /* 'v' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x56, 0x76, 0x76 }, + { /* 'w' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x57, 0x77, 0x77 }, + { /* 'x' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x58, 0x78, 0x78 }, + { /* 'y' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x59, 0x79, 0x79 }, + { /* 'z' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x5A, 0x7A, 0x7A }, + { /* '{' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x7B, 0x7B, 0x7B }, + { /* '|' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x7C, 0x7C, 0x7C }, + { /* '}' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x7D, 0x7D, 0x7D }, + { /* '~' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x7E, 0x7E, 0x7E }, + { /* DEL */ _PDCLIB_CTYPE_CNTRL, 0x7F, 0x7F, 0x7F }, + { 0x00, 0x80, 0x80, 0x80 }, + { 0x00, 0x81, 0x81, 0x81 }, + { 0x00, 0x82, 0x82, 0x82 }, + { 0x00, 0x83, 0x83, 0x83 }, + { 0x00, 0x84, 0x84, 0x84 }, + { 0x00, 0x85, 0x85, 0x85 }, + { 0x00, 0x86, 0x86, 0x86 }, + { 0x00, 0x87, 0x87, 0x87 }, + { 0x00, 0x88, 0x88, 0x88 }, + { 0x00, 0x89, 0x89, 0x89 }, + { 0x00, 0x8A, 0x8A, 0x8A }, + { 0x00, 0x8B, 0x8B, 0x8B }, + { 0x00, 0x8C, 0x8C, 0x8C }, + { 0x00, 0x8D, 0x8D, 0x8D }, + { 0x00, 0x8E, 0x8E, 0x8E }, + { 0x00, 0x8F, 0x8F, 0x8F }, + { 0x00, 0x90, 0x90, 0x90 }, + { 0x00, 0x91, 0x91, 0x91 }, + { 0x00, 0x92, 0x92, 0x92 }, + { 0x00, 0x93, 0x93, 0x93 }, + { 0x00, 0x94, 0x94, 0x94 }, + { 0x00, 0x95, 0x95, 0x95 }, + { 0x00, 0x96, 0x96, 0x96 }, + { 0x00, 0x97, 0x97, 0x97 }, + { 0x00, 0x98, 0x98, 0x98 }, + { 0x00, 0x99, 0x99, 0x99 }, + { 0x00, 0x9A, 0x9A, 0x9A }, + { 0x00, 0x9B, 0x9B, 0x9B }, + { 0x00, 0x9C, 0x9C, 0x9C }, + { 0x00, 0x9D, 0x9D, 0x9D }, + { 0x00, 0x9E, 0x9E, 0x9E }, + { 0x00, 0x9F, 0x9F, 0x9F }, + { 0x00, 0xA0, 0xA0, 0xA0 }, + { 0x00, 0xA1, 0xA1, 0xA1 }, + { 0x00, 0xA2, 0xA2, 0xA2 }, + { 0x00, 0xA3, 0xA3, 0xA3 }, + { 0x00, 0xA4, 0xA4, 0xA4 }, + { 0x00, 0xA5, 0xA5, 0xA5 }, + { 0x00, 0xA6, 0xA6, 0xA6 }, + { 0x00, 0xA7, 0xA7, 0xA7 }, + { 0x00, 0xA8, 0xA8, 0xA8 }, + { 0x00, 0xA9, 0xA9, 0xA9 }, + { 0x00, 0xAA, 0xAA, 0xAA }, + { 0x00, 0xAB, 0xAB, 0xAB }, + { 0x00, 0xAC, 0xAC, 0xAC }, + { 0x00, 0xAD, 0xAD, 0xAD }, + { 0x00, 0xAE, 0xAE, 0xAE }, + { 0x00, 0xAF, 0xAF, 0xAF }, + { 0x00, 0xB0, 0xB0, 0xB0 }, + { 0x00, 0xB1, 0xB1, 0xB1 }, + { 0x00, 0xB2, 0xB2, 0xB2 }, + { 0x00, 0xB3, 0xB3, 0xB3 }, + { 0x00, 0xB4, 0xB4, 0xB4 }, + { 0x00, 0xB5, 0xB5, 0xB5 }, + { 0x00, 0xB6, 0xB6, 0xB6 }, + { 0x00, 0xB7, 0xB7, 0xB7 }, + { 0x00, 0xB8, 0xB8, 0xB8 }, + { 0x00, 0xB9, 0xB9, 0xB9 }, + { 0x00, 0xBA, 0xBA, 0xBA }, + { 0x00, 0xBB, 0xBB, 0xBB }, + { 0x00, 0xBC, 0xBC, 0xBC }, + { 0x00, 0xBD, 0xBD, 0xBD }, + { 0x00, 0xBE, 0xBE, 0xBE }, + { 0x00, 0xBF, 0xBF, 0xBF }, + { 0x00, 0xC0, 0xC0, 0xC0 }, + { 0x00, 0xC1, 0xC1, 0xC1 }, + { 0x00, 0xC2, 0xC2, 0xC2 }, + { 0x00, 0xC3, 0xC3, 0xC3 }, + { 0x00, 0xC4, 0xC4, 0xC4 }, + { 0x00, 0xC5, 0xC5, 0xC5 }, + { 0x00, 0xC6, 0xC6, 0xC6 }, + { 0x00, 0xC7, 0xC7, 0xC7 }, + { 0x00, 0xC8, 0xC8, 0xC8 }, + { 0x00, 0xC9, 0xC9, 0xC9 }, + { 0x00, 0xCA, 0xCA, 0xCA }, + { 0x00, 0xCB, 0xCB, 0xCB }, + { 0x00, 0xCC, 0xCC, 0xCC }, + { 0x00, 0xCD, 0xCD, 0xCD }, + { 0x00, 0xCE, 0xCE, 0xCE }, + { 0x00, 0xCF, 0xCF, 0xCF }, + { 0x00, 0xD0, 0xD0, 0xD0 }, + { 0x00, 0xD1, 0xD1, 0xD1 }, + { 0x00, 0xD2, 0xD2, 0xD2 }, + { 0x00, 0xD3, 0xD3, 0xD3 }, + { 0x00, 0xD4, 0xD4, 0xD4 }, + { 0x00, 0xD5, 0xD5, 0xD5 }, + { 0x00, 0xD6, 0xD6, 0xD6 }, + { 0x00, 0xD7, 0xD7, 0xD7 }, + { 0x00, 0xD8, 0xD8, 0xD8 }, + { 0x00, 0xD9, 0xD9, 0xD9 }, + { 0x00, 0xDA, 0xDA, 0xDA }, + { 0x00, 0xDB, 0xDB, 0xDB }, + { 0x00, 0xDC, 0xDC, 0xDC }, + { 0x00, 0xDD, 0xDD, 0xDD }, + { 0x00, 0xDE, 0xDE, 0xDE }, + { 0x00, 0xDF, 0xDF, 0xDF }, + { 0x00, 0xE0, 0xE0, 0xE0 }, + { 0x00, 0xE1, 0xE1, 0xE1 }, + { 0x00, 0xE2, 0xE2, 0xE2 }, + { 0x00, 0xE3, 0xE3, 0xE3 }, + { 0x00, 0xE4, 0xE4, 0xE4 }, + { 0x00, 0xE5, 0xE5, 0xE5 }, + { 0x00, 0xE6, 0xE6, 0xE6 }, + { 0x00, 0xE7, 0xE7, 0xE7 }, + { 0x00, 0xE8, 0xE8, 0xE8 }, + { 0x00, 0xE9, 0xE9, 0xE9 }, + { 0x00, 0xEA, 0xEA, 0xEA }, + { 0x00, 0xEB, 0xEB, 0xEB }, + { 0x00, 0xEC, 0xEC, 0xEC }, + { 0x00, 0xED, 0xED, 0xED }, + { 0x00, 0xEE, 0xEE, 0xEE }, + { 0x00, 0xEF, 0xEF, 0xEF }, + { 0x00, 0xF0, 0xF0, 0xF0 }, + { 0x00, 0xF1, 0xF1, 0xF1 }, + { 0x00, 0xF2, 0xF2, 0xF2 }, + { 0x00, 0xF3, 0xF3, 0xF3 }, + { 0x00, 0xF4, 0xF4, 0xF4 }, + { 0x00, 0xF5, 0xF5, 0xF5 }, + { 0x00, 0xF6, 0xF6, 0xF6 }, + { 0x00, 0xF7, 0xF7, 0xF7 }, + { 0x00, 0xF8, 0xF8, 0xF8 }, + { 0x00, 0xF9, 0xF9, 0xF9 }, + { 0x00, 0xFA, 0xFA, 0xFA }, + { 0x00, 0xFB, 0xFB, 0xFB }, + { 0x00, 0xFC, 0xFC, 0xFC }, + { 0x00, 0xFD, 0xFD, 0xFD }, + { 0x00, 0xFE, 0xFE, 0xFE }, + { 0x00, 0xFF, 0xFF, 0xFF } +}; + +struct lconv _PDCLIB_lconv = { + /* _PDCLIB_ctype */ _ctype + 1, + /* _PDCLIB_errno_texts */ + { + /* no error */ (char *)"", + /* ERANGE */ (char *)"ERANGE (Range error)", + /* EDOM */ (char *)"EDOM (Domain error)", + /* EILSEQ */ (char *)"EILSEQ (Illegal sequence)" + }, + /* decimal_point */ (char *)".", + /* thousands_sep */ (char *)"", + /* grouping */ (char *)"", + /* mon_decimal_point */ (char *)"", + /* mon_thousands_sep */ (char *)"", + /* mon_grouping */ (char *)"", + /* positive_sign */ (char *)"", + /* negative_sign */ (char *)"", + /* currency_symbol */ (char *)"", + /* int_curr_symbol */ (char *)"", + /* frac_digits */ CHAR_MAX, + /* p_cs_precedes */ CHAR_MAX, + /* n_cs_precedes */ CHAR_MAX, + /* p_sep_by_space */ CHAR_MAX, + /* n_sep_by_space */ CHAR_MAX, + /* p_sign_posn */ CHAR_MAX, + /* n_sign_posn */ CHAR_MAX, + /* int_frac_digits */ CHAR_MAX, + /* int_p_cs_precedes */ CHAR_MAX, + /* int_n_cs_precedes */ CHAR_MAX, + /* int_p_sep_by_space */ CHAR_MAX, + /* int_n_sep_by_space */ CHAR_MAX, + /* int_p_sign_posn */ CHAR_MAX, + /* int_n_sign_posn */ CHAR_MAX, +}; + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + /* Testing covered by several other testdrivers using stdin / stdout / + stderr. + */ + return TEST_RESULTS; +} + +#endif diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_w32errno.c b/platform/win32/functions/_PDCLIB/_PDCLIB_w32errno.c new file mode 100644 index 0000000..5e03ef5 --- /dev/null +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_w32errno.c @@ -0,0 +1,56 @@ +/* $Id$ */ + +/* _PDCLIB_allocpages( int const ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is a stub implementation of _PDCLIB_allocpages +*/ + +#ifndef REGTEST +#include +#include + +void _PDCLIB_w32errno(void) +{ + // Not exhaustive + switch(GetLastError()) { + case ERROR_SUCCESS: + return; + case ERROR_FILE_NOT_FOUND: + case ERROR_PATH_NOT_FOUND: + case ERROR_INVALID_DRIVE: + errno = ENOENT; break; + case ERROR_TOO_MANY_OPEN_FILES: + errno = EMFILE; break; + case ERROR_ACCESS_DENIED: + case ERROR_WRITE_PROTECT: + errno = EPERM; break; + case ERROR_INVALID_HANDLE: + errno = EBADF; break; + case ERROR_NOT_ENOUGH_MEMORY: + case ERROR_OUTOFMEMORY: + errno = ENOMEM; break; + case ERROR_NOT_READY: + errno = EAGAIN; break; + case ERROR_BAD_LENGTH: + errno = EINVAL; break; + default: + // TODO: reconsider what to use here? + errno = ENOSYS; break; + } +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/platform/win32/functions/signal/raise.c b/platform/win32/functions/signal/raise.c new file mode 100644 index 0000000..8d7080b --- /dev/null +++ b/platform/win32/functions/signal/raise.c @@ -0,0 +1,114 @@ +/* $Id$ */ + +/* raise( int ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +#include +#include + +extern void (*_PDCLIB_sigabrt)( int ); +extern void (*_PDCLIB_sigfpe)( int ); +extern void (*_PDCLIB_sigill)( int ); +extern void (*_PDCLIB_sigint)( int ); +extern void (*_PDCLIB_sigsegv)( int ); +extern void (*_PDCLIB_sigterm)( int ); + +int raise( int sig ) +{ + void (*sighandler)( int ); + char const * message; + switch ( sig ) + { + case SIGABRT: + sighandler = _PDCLIB_sigabrt; + message = "Abnormal termination (SIGABRT)"; + break; + case SIGFPE: + sighandler = _PDCLIB_sigfpe; + message = "Arithmetic exception (SIGFPE)"; + break; + case SIGILL: + sighandler = _PDCLIB_sigill; + message = "Illegal instruction (SIGILL)"; + break; + case SIGINT: + sighandler = _PDCLIB_sigint; + message = "Interactive attention signal (SIGINT)"; + break; + case SIGSEGV: + sighandler = _PDCLIB_sigsegv; + message = "Invalid memory access (SIGSEGV)"; + break; + case SIGTERM: + sighandler = _PDCLIB_sigterm; + message = "Termination request (SIGTERM)"; + break; + default: + fprintf( stderr, "Unknown signal #%d\n", sig ); + _Exit( EXIT_FAILURE ); + } + if ( sighandler == SIG_DFL ) + { + fputs( message, stderr ); + _Exit( EXIT_FAILURE ); + } + else if ( sighandler != SIG_IGN ) + { + sighandler = signal( sig, SIG_DFL ); + sighandler( sig ); + } + return 0; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +#include + +static volatile sig_atomic_t flag = 0; + +static int expected_signal = 0; + +static void test_handler( int sig ) +{ + TESTCASE( sig == expected_signal ); + flag = 1; +} + +int main( void ) +{ + /* Could be other than SIG_DFL if you changed the implementation. */ + TESTCASE( signal( SIGABRT, SIG_IGN ) == SIG_DFL ); + /* Should be ignored. */ + TESTCASE( raise( SIGABRT ) == 0 ); + /* Installing test handler, old handler should be returned */ + TESTCASE( signal( SIGABRT, test_handler ) == SIG_IGN ); + /* Raising and checking SIGABRT */ + expected_signal = SIGABRT; + TESTCASE( raise( SIGABRT ) == 0 ); + TESTCASE( flag == 1 ); + /* Re-installing test handler, should have been reset to default */ + /* Could be other than SIG_DFL if you changed the implementation. */ + TESTCASE( signal( SIGABRT, test_handler ) == SIG_DFL ); + /* Raising and checking SIGABRT */ + flag = 0; + TESTCASE( raise( SIGABRT ) == 0 ); + TESTCASE( flag == 1 ); + /* Installing test handler for different signal... */ + TESTCASE( signal( SIGTERM, test_handler ) == SIG_DFL ); + /* Raising and checking SIGTERM */ + expected_signal = SIGTERM; + TESTCASE( raise( SIGTERM ) == 0 ); + TESTCASE( flag == 1 ); + return TEST_RESULTS; +} +#endif diff --git a/platform/win32/functions/signal/signal.c b/platform/win32/functions/signal/signal.c new file mode 100644 index 0000000..e07877d --- /dev/null +++ b/platform/win32/functions/signal/signal.c @@ -0,0 +1,75 @@ +/* $Id$ */ + +/* signal( int sig, void (*func)( int ) ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +#include + +void (*_PDCLIB_sigabrt)( int ) = SIG_DFL; +void (*_PDCLIB_sigfpe)( int ) = SIG_DFL; +void (*_PDCLIB_sigill)( int ) = SIG_DFL; +void (*_PDCLIB_sigint)( int ) = SIG_DFL; +void (*_PDCLIB_sigsegv)( int ) = SIG_DFL; +void (*_PDCLIB_sigterm)( int ) = SIG_DFL; + +void (*signal( int sig, void (*func)( int ) ) )( int ) +{ + void (*oldhandler)( int ); + if ( sig <= 0 || func == SIG_ERR ) + { + return SIG_ERR; + } + switch ( sig ) + { + case SIGABRT: + oldhandler = _PDCLIB_sigabrt; + _PDCLIB_sigabrt = func; + break; + case SIGFPE: + oldhandler = _PDCLIB_sigfpe; + _PDCLIB_sigfpe = func; + break; + case SIGILL: + oldhandler = _PDCLIB_sigill; + _PDCLIB_sigill = func; + break; + case SIGINT: + oldhandler = _PDCLIB_sigint; + _PDCLIB_sigint = func; + break; + case SIGSEGV: + oldhandler = _PDCLIB_sigsegv; + _PDCLIB_sigsegv = func; + break; + case SIGTERM: + oldhandler = _PDCLIB_sigterm; + _PDCLIB_sigterm = func; + break; + default: + /* The standard calls for an unspecified "positive value". You + will probably want to define a specific value for this. + */ + _PDCLIB_errno = 1; + return SIG_ERR; + } + return oldhandler; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + /* Testing covered by raise.c */ + return TEST_RESULTS; +} +#endif diff --git a/platform/win32/functions/stdio/remove.c b/platform/win32/functions/stdio/remove.c new file mode 100644 index 0000000..913bdf3 --- /dev/null +++ b/platform/win32/functions/stdio/remove.c @@ -0,0 +1,44 @@ +/* $Id$ */ + +/* remove( const char * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is an example implementation of remove() fit for use with POSIX kernels. +*/ + +#include + +#ifndef REGTEST + +#include +#include +#include + +extern struct _PDCLIB_file_t * _PDCLIB_filelist; + +extern void _PDCLIB_w32errno( void ); +int remove( const char * pathname ) +{ + BOOL ok = DeleteFileA( pathname ); + if(!ok) { + _PDCLIB_w32errno(); + return -1; + } else return 0; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + /* Testing covered by ftell.c (and several others) */ + return TEST_RESULTS; +} + +#endif + diff --git a/platform/win32/functions/stdio/tmpfile.c b/platform/win32/functions/stdio/tmpfile.c new file mode 100644 index 0000000..f329234 --- /dev/null +++ b/platform/win32/functions/stdio/tmpfile.c @@ -0,0 +1,89 @@ +/* $Id$ */ + +/* tmpfile( void ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST +#include +#include <_PDCLIB_glue.h> +#include +#include + +static char tmpname_prefix[4] = {0, 0, 0, 0}; + +extern void _PDCLIB_w32errno( void ); +struct _PDCLIB_file_t * tmpfile( void ) +{ + if(!tmpname_prefix[0]) { + char namebuf[MAX_PATH+1]; + DWORD res = GetModuleFileNameA(NULL, namebuf, MAX_PATH+1); + if(res) { + char * basename = strrchr(namebuf, '\\'); + if(basename) { + basename += 1; + } else basename = namebuf; + + char* dot = strchr(basename, '.'); + if(dot) *dot = 0; + + strncpy(tmpname_prefix, basename, 3); + } else { + // Error getting file name + strcpy(tmpname_prefix, "PDU"); + } + } + + char tmpdir[MAX_PATH + 1]; + DWORD rv = GetTempPathA(MAX_PATH + 1, tmpdir); + if(rv == 0) { + _PDCLIB_w32errno(); + return NULL; + } + + char name[MAX_PATH + 1]; + rv = GetTempFileNameA(tmpdir, tmpname_prefix, 0, name); + if(rv == 0) { + _PDCLIB_w32errno(); + return NULL; + } + + /* OPEN_EXISTING as CreateTempFileName creates the file then closes the + handle to it (to avoid race conditions as associated with e.g. tmpnam) + */ + HANDLE fd = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_DELETE, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_TEMPORARY, NULL); + + if(fd == INVALID_HANDLE_VALUE) { + _PDCLIB_w32errno(); + return NULL; + } + + /* Set the file to delete on close */ + DeleteFile(name); + + FILE* fs = _PDCLIB_fdopen(fd, _PDCLIB_FWRITE | _PDCLIB_FRW, name); + if(!fs) { + CloseHandle(fd); + } + return fs; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> +#include + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif + diff --git a/platform/win32/functions/stdlib/getenv.c b/platform/win32/functions/stdlib/getenv.c new file mode 100644 index 0000000..a95171d --- /dev/null +++ b/platform/win32/functions/stdlib/getenv.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* getenv( const char * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is a stub implementation of getenv +*/ + +#include +#include + +#ifndef REGTEST + +char * getenv( const char * name ) +{ + return NULL; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif diff --git a/platform/win32/functions/stdlib/system.c b/platform/win32/functions/stdlib/system.c new file mode 100644 index 0000000..2cf7534 --- /dev/null +++ b/platform/win32/functions/stdlib/system.c @@ -0,0 +1,27 @@ +/* $Id$ */ + +/* system( const char * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +/* This is a stub implementation of getenv +*/ + +int system( const char * string ) +{ + return -1; +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif diff --git a/platform/win32/includes/float.h b/platform/win32/includes/float.h new file mode 100644 index 0000000..6590539 --- /dev/null +++ b/platform/win32/includes/float.h @@ -0,0 +1,76 @@ +/* $Id$ */ + +/* 7.7 Characteristics of floating types + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_FLOAT_H +#define _PDCLIB_FLOAT_H _PDCLIB_FLOAT_H +#include <_PDCLIB_config.h> + +#define FLT_ROUNDS _PDCLIB_FLT_ROUNDS +#define FLT_EVAL_METHOD _PDCLIB_FLT_EVAL_METHOD +#define DECIMAL_DIG _PDCLIB_DECIMAL_DIG + + /* Radix of exponent representation */ +#define FLT_RADIX __FLT_RADIX__ + /* Number of base-FLT_RADIX digits in the significand of a float */ +#define FLT_MANT_DIG __FLT_MANT_DIG__ + /* Number of decimal digits of precision in a float */ +#define FLT_DIG __FLT_DIG__ + /* Difference between 1.0 and the minimum float greater than 1.0 */ +#define FLT_EPSILON __FLT_EPSILON__ + /* Minimum int x such that FLT_RADIX**(x-1) is a normalised float */ +#define FLT_MIN_EXP __FLT_MIN_EXP__ + /* Minimum normalised float */ +#define FLT_MIN __FLT_MIN__ + /* Minimum int x such that 10**x is a normalised float */ +#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__ + /* Maximum int x such that FLT_RADIX**(x-1) is a representable float */ +#define FLT_MAX_EXP __FLT_MAX_EXP__ + /* Maximum float */ +#define FLT_MAX __FLT_MAX__ + /* Maximum int x such that 10**x is a representable float */ +#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__ + + /* Number of base-FLT_RADIX digits in the significand of a double */ +#define DBL_MANT_DIG __DBL_MANT_DIG__ + /* Number of decimal digits of precision in a double */ +#define DBL_DIG __DBL_DIG__ + /* Difference between 1.0 and the minimum double greater than 1.0 */ +#define DBL_EPSILON __DBL_EPSILON__ + /* Minimum int x such that FLT_RADIX**(x-1) is a normalised double */ +#define DBL_MIN_EXP __DBL_MIN_EXP__ + /* Minimum normalised double */ +#define DBL_MIN __DBL_MIN__ + /* Minimum int x such that 10**x is a normalised double */ +#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__ + /* Maximum int x such that FLT_RADIX**(x-1) is a representable double */ +#define DBL_MAX_EXP __DBL_MAX_EXP__ + /* Maximum double */ +#define DBL_MAX __DBL_MAX__ + /* Maximum int x such that 10**x is a representable double */ +#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__ + + /* Number of base-FLT_RADIX digits in the significand of a long double */ +#define LDBL_MANT_DIG __LDBL_MANT_DIG__ + /* Number of decimal digits of precision in a long double */ +#define LDBL_DIG __LDBL_DIG__ + /* Difference between 1.0 and the minimum long double greater than 1.0 */ +#define LDBL_EPSILON __LDBL_EPSILON__ + /* Minimum int x such that FLT_RADIX**(x-1) is a normalised long double */ +#define LDBL_MIN_EXP __LDBL_MIN_EXP__ + /* Minimum normalised long double */ +#define LDBL_MIN __LDBL_MIN__ + /* Minimum int x such that 10**x is a normalised long double */ +#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ + /* Maximum int x such that FLT_RADIX**(x-1) is a representable long double */ +#define LDBL_MAX_EXP __LDBL_MAX_EXP__ + /* Maximum long double */ +#define LDBL_MAX __LDBL_MAX__ + /* Maximum int x such that 10**x is a representable long double */ +#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ + +#endif diff --git a/platform/win32/includes/signal.h b/platform/win32/includes/signal.h new file mode 100644 index 0000000..9f6a1a3 --- /dev/null +++ b/platform/win32/includes/signal.h @@ -0,0 +1,86 @@ +/* $Id$ */ + +/* 7.14 Signal handling + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_SIGNAL_H +#define _PDCLIB_SIGNAL_H _PDCLIB_SIGNAL_H +#include <_PDCLIB_config.h> + +/* Signals ------------------------------------------------------------------ */ + +/* A word on signals, to the people using PDCLib in their OS projects. + + The definitions of the C standard leave about everything that *could* be + useful to be "implementation defined". Without additional, non-standard + arrangements, it is not possible to turn them into a useful tool. + + This example implementation chose to "not generate any of these signals, + except as a result of explicit calls to the raise function", which is + allowed by the standard but of course does nothing for the usefulness of + . + + A useful signal handling would: + 1) make signal() a system call that registers the signal handler with the OS + 2) make raise() a system call triggering an OS signal to the running process + 3) make provisions that further signals of the same type are blocked until + the signal handler returns (optional for SIGILL) +*/ + +/* These are the values used by Linux. */ + +/* Abnormal termination / abort() */ +#define SIGABRT 6 +/* Arithmetic exception / division by zero / overflow */ +#define SIGFPE 8 +/* Illegal instruction */ +#define SIGILL 4 +/* Interactive attention signal */ +#define SIGINT 2 +/* Invalid memory access */ +#define SIGSEGV 11 +/* Termination request */ +#define SIGTERM 15 + +/* The following should be defined to pointer values that could NEVER point to + a valid signal handler function. (They are used as special arguments to + signal().) Again, these are the values used by Linux. +*/ +#define SIG_DFL (void (*)( int ))0 +#define SIG_ERR (void (*)( int ))-1 +#define SIG_IGN (void (*)( int ))1 + +typedef _PDCLIB_sig_atomic sig_atomic_t; + +/* Installs a signal handler "func" for the given signal. + A signal handler is a function that takes an integer as argument (the signal + number) and returns void. + + Note that a signal handler can do very little else than: + 1) assign a value to a static object of type "volatile sig_atomic_t", + 2) call signal() with the value of sig equal to the signal received, + 3) call _Exit(), + 4) call abort(). + Virtually everything else is undefind. + + The signal() function returns the previous installed signal handler, which + at program start may be SIG_DFL or SIG_ILL. (This implementation uses + SIG_DFL for all handlers.) If the request cannot be honored, SIG_ERR is + returned and errno is set to an unspecified positive value. +*/ +void (*signal( int sig, void (*func)( int ) ) )( int ); + +/* Raises the given signal (executing the registered signal handler with the + given signal number as parameter). + This implementation does not prevent further signals of the same time from + occuring, but executes signal( sig, SIG_DFL ) before entering the signal + handler (i.e., a second signal before the signal handler re-registers itself + or SIG_IGN will end the program). + Returns zero if successful, nonzero otherwise. */ +int raise( int sig ); + +#endif + diff --git a/platform/win32/internals/_PDCLIB_config.h b/platform/win32/internals/_PDCLIB_config.h new file mode 100644 index 0000000..793065d --- /dev/null +++ b/platform/win32/internals/_PDCLIB_config.h @@ -0,0 +1,467 @@ +#ifndef _PDCLIB_CONFIG_H +#define _PDCLIB_CONFIG_H + +/* Internal PDCLib configuration <_PDCLIB_config.h> + (Win32 platform) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* -------------------------------------------------------------------------- */ +/* Misc */ +/* -------------------------------------------------------------------------- */ + +/* The character (sequence) your platform uses as newline. */ +#define _PDCLIB_endl "\r\n" + +/* exit() can signal success to the host environment by the value of zero or */ +/* the constant EXIT_SUCCESS. Failure is signaled by EXIT_FAILURE. Note that */ +/* any other return value is "implementation-defined", i.e. your environment */ +/* is not required to handle it gracefully. Set your definitions here. */ +#define _PDCLIB_SUCCESS 0 +#define _PDCLIB_FAILURE -1 + +/* qsort() in requires a function that swaps two memory areas. */ +/* Below is a naive implementation that can be improved significantly for */ +/* specific platforms, e.g. by swapping int instead of char. */ +#define _PDCLIB_memswp( i, j, size ) char tmp; do { tmp = *i; *i++ = *j; *j++ = tmp; } while ( --size ); + +/* Define this to some compiler directive that can be written after the */ +/* parameter list of a function declaration to indicate the function does */ +/* never return. If your compiler does not support such a directive, define */ +/* to nothing. (This is to avoid warnings with the exit functions under GCC.) */ +#define _PDCLIB_NORETURN __attribute__(( noreturn )) + +/* The maximum value that errno can be set to. This is used to set the size */ +/* of the array in struct lconv () holding error messages for the */ +/* strerror() and perror() functions. (If you change this value because you */ +/* are using additional errno values, you *HAVE* to provide appropriate error */ +/* messages for *ALL* locales.) */ +/* Default is 4 (0, ERANGE, EDOM, EILSEQ). */ +#define _PDCLIB_ERRNO_MAX 4 + +/* -------------------------------------------------------------------------- */ +/* Integers */ +/* -------------------------------------------------------------------------- */ +/* Assuming 8-bit char, two's-complement architecture here. 'short' being */ +/* 16 bit, 'int' being either 16, 32 or 64 bit, 'long' being either 32 or 64 */ +/* bit (but 64 bit only if 'int' is 32 bit), and 'long long' being 64 bit if */ +/* 'long' is not, 64 or 128 bit otherwise. */ +/* Author is quite willing to support other systems but would like to hear of */ +/* interest in such support and details on the to-be-supported architecture */ +/* first, before going to lengths about it. */ +/* -------------------------------------------------------------------------- */ + +/* Comment out (or delete) the line below if your 'char' type is unsigned. */ +#define _PDCLIB_CHAR_SIGNED 1 + +/* Width of the integer types short, int, long, and long long, in bytes. */ +/* SHRT == 2, INT >= SHRT, LONG >= INT >= 4, LLONG >= LONG - check your */ +/* compiler manuals. */ +#define _PDCLIB_SHRT_BYTES 2 +#define _PDCLIB_INT_BYTES 4 +#define _PDCLIB_LONG_BYTES 4 +#define _PDCLIB_LLONG_BYTES 8 + +/* defines the div() function family that allows taking quotient */ +/* and remainder of an integer division in one operation. Many platforms */ +/* support this in hardware / opcode, and the standard permits ordering of */ +/* the return structure in any way to fit the hardware. That is why those */ +/* structs can be configured here. */ + +struct _PDCLIB_div_t +{ + int quot; + int rem; +}; + +struct _PDCLIB_ldiv_t +{ + long int quot; + long int rem; +}; + +struct _PDCLIB_lldiv_t +{ + long long int quot; + long long int rem; +}; + +/* -------------------------------------------------------------------------- */ +/* defines a set of integer types that are of a minimum width, and */ +/* "usually fastest" on the system. (If, for example, accessing a single char */ +/* requires the CPU to access a complete int and then mask out the char, the */ +/* "usually fastest" type of at least 8 bits would be int, not char.) */ +/* If you do not have information on the relative performance of the types, */ +/* the standard allows you to define any type that meets minimum width and */ +/* signedness requirements. */ +/* The defines below are just configuration for the real typedefs and limit */ +/* definitions done in <_PDCLIB_int.h>. The uppercase define shall be either */ +/* SHRT, INT, LONG, or LLONG (telling which values to use for the *_MIN and */ +/* *_MAX limits); the lowercase define either short, int, long, or long long */ +/* (telling the actual type to use). */ +/* The third define is the length modifier used for the type in printf() and */ +/* scanf() functions (used in ). */ +/* If you require a non-standard datatype to define the "usually fastest" */ +/* types, PDCLib as-is doesn't support that. Please contact the author with */ +/* details on your platform in that case, so support can be added. */ +/* -------------------------------------------------------------------------- */ + +#define _PDCLIB_FAST8 INT +#define _PDCLIB_fast8 int +#define _PDCLIB_FAST8_CONV + +#define _PDCLIB_FAST16 INT +#define _PDCLIB_fast16 int +#define _PDCLIB_FAST16_CONV + +#define _PDCLIB_FAST32 INT +#define _PDCLIB_fast32 int +#define _PDCLIB_FAST32_CONV + +#define _PDCLIB_FAST64 LLONG +#define _PDCLIB_fast64 long long +#define _PDCLIB_FAST64_CONV ll + +/* -------------------------------------------------------------------------- */ +/* What follows are a couple of "special" typedefs and their limits. Again, */ +/* the actual definition of the limits is done in <_PDCLIB_int.h>, and the */ +/* defines here are merely "configuration". See above for details. */ +/* -------------------------------------------------------------------------- */ + +/* The result type of substracting two pointers */ +#if defined(__amd64__) || defined(_M_AMD64) + #define _PDCLIB_ptrdiff long long + #define _PDCLIB_PTRDIFF LLONG + #define _PDCLIB_PTR_CONV ll +#else + #define _PDCLIB_ptrdiff int + #define _PDCLIB_PTRDIFF INT + #define _PDCLIB_PTR_CONV +#endif + +/* An integer type that can be accessed as atomic entity (think asynchronous + interrupts). The type itself is not defined in a freestanding environment, + but its limits are. (Don't ask.) +*/ +#define _PDCLIB_sig_atomic int +#define _PDCLIB_SIG_ATOMIC INT + +/* Result type of the 'sizeof' operator (must be unsigned) */ +#if defined(__amd64__) || defined(_M_AMD64) + #define _PDCLIB_size unsigned long long + #define _PDCLIB_SIZE ULLONG +#else + #define _PDCLIB_size unsigned int + #define _PDCLIB_SIZE UINT +#endif + +/* Large enough an integer to hold all character codes of the largest supported + locale. + + XX: Windows requires wchar_t be an unsigned short, but this is not compliant. +*/ +#define _PDCLIB_wchar unsigned short +#define _PDCLIB_WCHAR USHRT + +#if defined(__amd64__) || defined(_M_AMD64) + #define _PDCLIB_intptr long long + #define _PDCLIB_INTPTR LLONG +#else + #define _PDCLIB_intptr int + #define _PDCLIB_INTPTR INT +#endif + +/* Largest supported integer type. Implementation note: see _PDCLIB_atomax(). */ +#define _PDCLIB_intmax long long int +#define _PDCLIB_INTMAX LLONG +#define _PDCLIB_MAX_CONV ll +/* You are also required to state the literal suffix for the intmax type */ +#define _PDCLIB_INTMAX_LITERAL ll + +/* defines imaxdiv(), which is equivalent to the div() function */ +/* family (see further above) with intmax_t as basis. */ + +struct _PDCLIB_imaxdiv_t +{ + _PDCLIB_intmax quot; + _PDCLIB_intmax rem; +}; + +/* : time_t + * The C standard doesn't define what representation of time is stored in + * time_t when returned by time() , but POSIX defines it to be seconds since the + * UNIX epoch and most appplications expect that. + * + * time_t is also used as the tv_sec member of struct timespec, which *is* + * defined as a linear count of seconds. + * + * time_t is defined as a "real type", so may be a floating point type, but with + * the presence of the nanosecond accurate struct timespec, and with the lack of + * any functions for manipulating more accurate values of time_t, this is + * probably not useful. + */ +#define _PDCLIB_time unsigned long long + +/* : clock_t + * + * A count of "clock ticks", where the length of a clock tick is unspecified by + * the standard. The implementation is required to provide a macro, + * CLOCKS_PER_SEC, which is the number of "clock ticks" which corresponds to one + * second. + * + * clock_t may be any real type (i.e. integral or floating), and its type on + * various systems differs. + * + * On XSI systems, CLOCKS_PER_SEC must be defined to 1000000 + */ +#define _PDCLIB_clock double +#define _PDCLIB_CLOCKS_PER_SEC 1000000 + +/* -------------------------------------------------------------------------- */ +/* Floating Point */ +/* -------------------------------------------------------------------------- */ + +/* Whether the implementation rounds toward zero (0), to nearest (1), toward + positive infinity (2), or toward negative infinity (3). (-1) signifies + indeterminable rounding, any other value implementation-specific rounding. +*/ +#define _PDCLIB_FLT_ROUNDS -1 + +/* Whether the implementation uses exact-width precision (0), promotes float + to double (1), or promotes float and double to long double (2). (-1) + signifies indeterminable behaviour, any other value implementation-specific + behaviour. +*/ +#define _PDCLIB_FLT_EVAL_METHOD -1 + +/* "Number of the decimal digits (n), such that any floating-point number in the + widest supported floating type with p(max) radix (b) digits can be rounded to + a floating-point number with (n) decimal digits and back again without change + to the value p(max) log(10)b if (b) is a power of 10, [1 + p(max) log(10)b] + otherwise." + 64bit IEC 60559 double format (53bit mantissa) is DECIMAL_DIG 17. + 80bit IEC 60559 double-extended format (64bit mantissa) is DECIMAL_DIG 21. +*/ +#define _PDCLIB_DECIMAL_DIG 17 + +/* -------------------------------------------------------------------------- */ +/* Platform-dependent macros defined by the standard headers. */ +/* -------------------------------------------------------------------------- */ + +/* The offsetof macro + Contract: Expand to an integer constant expression of type size_t, which + represents the offset in bytes to the structure member from the beginning + of the structure. If the specified member is a bitfield, behaviour is + undefined. + There is no standard-compliant way to do this. + This implementation casts an integer zero to 'pointer to type', and then + takes the address of member. This is undefined behaviour but should work on + most compilers. +*/ +#ifdef __GNUC__ + #define _PDCLIB_offsetof( type, member ) __builtin_offsetof( type, member ) +#else + #define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) ) +#endif + +/* Variable Length Parameter List Handling () + The macros defined by are highly dependent on the calling + conventions used, and you probably have to replace them with builtins of + your compiler. +*/ + +#ifdef __GNUC__ + typedef char * _PDCLIB_va_list; + #define _PDCLIB_va_arg( ap, type ) __builtin_va_arg( ap, type ) + #define _PDCLIB_va_copy( dest, src ) __builtin_va_copy( dest, src) + #define _PDCLIB_va_end( ap ) __builtin_va_end( ap ) + #define _PDCLIB_va_start( ap, parmN ) __builtin_va_start( ap, parmN ) +#else + #error Compiler support please +#endif + +/* -------------------------------------------------------------------------- */ +/* OS "glue", part 1 */ +/* These are values and data type definitions that you would have to adapt to */ +/* the capabilities and requirements of your OS. */ +/* The actual *functions* of the OS interface are declared in _PDCLIB_glue.h. */ +/* -------------------------------------------------------------------------- */ + +/* Memory management -------------------------------------------------------- */ + +/* Set this to the page size of your OS. If your OS does not support paging, set + to an appropriate value. (Too small, and malloc() will call the kernel too + often. Too large, and you will waste memory.) +*/ +#define _PDCLIB_MALLOC_PAGESIZE 4096 +#define _PDCLIB_MALLOC_ALIGN 16 +#define _PDCLIB_MALLOC_GRANULARITY 64*1024 +#define _PDCLIB_MALLOC_TRIM_THRESHOLD 2*1024*1024 +#define _PDCLIB_MALLOC_MMAP_THRESHOLD 256*1024 +#define _PDCLIB_MALLOC_RELEASE_CHECK_RATE 4095 + +/* TODO: Better document these */ + +/* I/O ---------------------------------------------------------------------- */ + +/* The type of the file descriptor returned by _PDCLIB_open(). */ +typedef void * _PDCLIB_fd_t; + +/* The value (of type _PDCLIB_fd_t) returned by _PDCLIB_open() if the operation + failed. +*/ +#define _PDCLIB_NOHANDLE NULL + +/* The default size for file buffers. Must be at least 256. */ +#define _PDCLIB_BUFSIZ 1024 + +/* The minimum number of files the implementation can open simultaneously. Must + be at least 8. Depends largely on how the bookkeeping is done by fopen() / + freopen() / fclose(). The example implementation limits the number of open + files only by available memory. +*/ +#define _PDCLIB_FOPEN_MAX 8 + +/* Length of the longest filename the implementation guarantees to support. */ +#define _PDCLIB_FILENAME_MAX 128 + +/* Maximum length of filenames generated by tmpnam(). (See tmpfile.c.) */ +#define _PDCLIB_L_tmpnam 46 + +/* Number of distinct file names that can be generated by tmpnam(). */ +#define _PDCLIB_TMP_MAX 50 + +/* The values of SEEK_SET, SEEK_CUR and SEEK_END, used by fseek(). + Since at least one platform (POSIX) uses the same symbols for its own "seek" + function, we use whatever the host defines (if it does define them). +*/ +#define _PDCLIB_SEEK_SET 0 +#define _PDCLIB_SEEK_CUR 1 +#define _PDCLIB_SEEK_END 2 + +/* The number of characters that can be buffered with ungetc(). The standard + guarantees only one (1); anything larger would make applications relying on + this capability dependent on implementation-defined behaviour (not good). +*/ +#define _PDCLIB_UNGETCBUFSIZE 1 + +/* errno -------------------------------------------------------------------- */ + +/* These are the values that _PDCLIB_errno can be set to by the library. + + By keeping PDCLib's errno in the _PDCLIB_* namespace, the library is capable + to "translate" between errno values used by the hosting operating system and + those used and passed out by the library. + + Example: In the example platform, the remove() function uses the unlink() + system call as backend. Linux sets its errno to EISDIR if you try to unlink() + a directory, but POSIX demands EPERM. Within the remove() function, you can + catch the 'errno == EISDIR', and set '_PDCLIB_errno = _PDCLIB_EPERM'. Anyone + using PDCLib's will "see" EPERM instead of EISDIR (the _PDCLIB_* + prefix removed by mechanics). + + If you do not want that kind of translation, you might want to "match" the + values used by PDCLib with those used by the host OS, as to avoid confusion. + + The C standard only defines three distinct errno values: ERANGE, EDOM, and + EILSEQ. The standard leaves it up to "the implementation" whether there are + any more beyond those three. There is some controversy as to whether errno is + such a good idea at all, so you might want to come up with a different error + reporting facility for your platform. + + Things used to say "Since errno values beyond the three defined by the + standard are not portable anyway (unless you look at POSIX), having your own + error reporting facility would not hurt anybody either." at this point. + However, then somebody birthed C++11 into the world, which copied POSIX's + errno values into C++. Yes, even EINTR. Therefore, this library defines + them. That said, thats nothing stopping you from using your own error + reporting facility for things outside the C library. + + Sometimes the standard says to set errno to indicate an error, but does not + prescribe a value. We will use a value from the following list. If POSIX + defines a value, we use that; otherwise, we use as seems suitable. + + If porting to a system which uses an errno-like reporting system (e.g. a + UNIX), you'll probably want to define them to match what the OS uses +*/ +/* C errno values */ +#define _PDCLIB_ERANGE 1 +#define _PDCLIB_EDOM 2 +#define _PDCLIB_EILSEQ 3 + +/* C++11/POSIX errno values */ +#define _PDCLIB_E2BIG 4 +#define _PDCLIB_ECONNRESET 5 +#define _PDCLIB_EISCONN 6 +#define _PDCLIB_ENOENT 7 +#define _PDCLIB_ENOTRECOVERABLE 8 +#define _PDCLIB_EROFS 9 +#define _PDCLIB_EACCES 10 +#define _PDCLIB_EDEADLK 11 +#define _PDCLIB_EISDIR 12 +#define _PDCLIB_ENOEXEC 13 +#define _PDCLIB_ENOTSOCK 14 +#define _PDCLIB_ESPIPE 15 +#define _PDCLIB_EADDRINUSE 16 +#define _PDCLIB_EDESTADDRREQ 17 +#define _PDCLIB_ELOOP 18 +#define _PDCLIB_ENOLCK 19 +#define _PDCLIB_ENOTSUPP 20 +#define _PDCLIB_ESRCH 21 +#define _PDCLIB_EADDRNOTAVAIL 22 +#define _PDCLIB_EMFILE 23 +#define _PDCLIB_ENOLINK 24 +#define _PDCLIB_ENOTTY 25 +#define _PDCLIB_ETIME 26 +#define _PDCLIB_EAFNOSUPPORT 27 +#define _PDCLIB_EEXIST 28 +#define _PDCLIB_EMLINK 29 +#define _PDCLIB_ENOMEM 30 +#define _PDCLIB_ENXIO 31 +#define _PDCLIB_ETIMEDOUT 32 +#define _PDCLIB_EAGAIN 33 +#define _PDCLIB_EFAULT 34 +#define _PDCLIB_EMSGSIZE 35 +#define _PDCLIB_ENOMSG 36 +#define _PDCLIB_EOPNOTSUPP 37 +#define _PDCLIB_ETXTBSY 38 +#define _PDCLIB_EALREADY 39 +#define _PDCLIB_EFBIG 40 +#define _PDCLIB_ENAMETOOLONG 41 +#define _PDCLIB_ENOPROTOOPT 42 +#define _PDCLIB_EOVERFLOW 43 +#define _PDCLIB_EWOULDBLOCK _PDCLIB_EAGAIN +#define _PDCLIB_EBADF 44 +#define _PDCLIB_EHOSTUNREACH 45 +#define _PDCLIB_ENETDOWN 46 +#define _PDCLIB_ENOSPC 47 +#define _PDCLIB_EOWNERDEAD 48 +#define _PDCLIB_EXDEV 49 +#define _PDCLIB_EBADMSG 50 +#define _PDCLIB_EIDRM 51 +#define _PDCLIB_ENETRESET 52 +#define _PDCLIB_ENOSR 53 +#define _PDCLIB_EPERM 54 +#define _PDCLIB_EBUSY 55 +#define _PDCLIB_ENETUNREACH 56 +#define _PDCLIB_ENOSTR 57 +#define _PDCLIB_EPIPE 58 +#define _PDCLIB_ECANCELED 59 +#define _PDCLIB_EINPROGRESS 60 +#define _PDCLIB_ENFILE 61 +#define _PDCLIB_ENOSYS 62 +#define _PDCLIB_EPROTO 63 +#define _PDCLIB_ECHILD 64 +#define _PDCLIB_EINTR 65 +#define _PDCLIB_ENOBUFS 66 +#define _PDCLIB_ENOTCONN 67 +#define _PDCLIB_EPROTONOSUPPORT 68 +#define _PDCLIB_ECONNABORTED 69 +#define _PDCLIB_EINVAL 70 +#define _PDCLIB_ENODATA 71 +#define _PDCLIB_ENOTDIR 72 +#define _PDCLIB_EPROTOTYPE 73 + +#endif