]> pd.if.org Git - pdclib/commitdiff
(merge)
authorOwen Shepherd <owen.shepherd@e43.eu>
Tue, 14 Aug 2012 14:54:36 +0000 (15:54 +0100)
committerOwen Shepherd <owen.shepherd@e43.eu>
Tue, 14 Aug 2012 14:54:36 +0000 (15:54 +0100)
64 files changed:
Jamfile
Jamrules
functions/_PDCLIB/atomax.c
functions/_PDCLIB/closeall.c
functions/_PDCLIB/digits.c
functions/_PDCLIB/errno.c
functions/_PDCLIB/filemode.c
functions/_PDCLIB/prepread.c
functions/_PDCLIB/prepwrite.c
functions/_PDCLIB/print.c
functions/_PDCLIB/scan.c
functions/_PDCLIB/strtox_main.c
functions/_PDCLIB/strtox_prelim.c
functions/stdio/_PDCLIB_fdopen.c [new file with mode: 0644]
functions/stdio/fopen.c
functions/string/strndup.c
functions/wchar/wcschr.c [new file with mode: 0644]
functions/wchar/wcscpy.c [new file with mode: 0644]
functions/wchar/wcslen.c [new file with mode: 0644]
functions/wchar/wcsrchr.c [new file with mode: 0644]
includes/stddef.h
includes/stdio.h
includes/wchar.h [new file with mode: 0644]
internals/_PDCLIB_aux.h
opt/nothread/call_once.c
opt/nothread/cnd_init.c
opt/nothread/cnd_signal.c
opt/nothread/cnd_wait.c
opt/nothread/mtx_destroy.c
opt/nothread/mtx_init.c
opt/nothread/mtx_lock.c
opt/nothread/mtx_timedlock.c
opt/nothread/mtx_trylock.c
opt/nothread/mtx_unlock.c
opt/nothread/thrd_yield.c
opt/nothread/tss_create.c
opt/nothread/tss_delete.c
opt/nothread/tss_get.c
opt/nothread/tss_set.c
platform/example/functions/stdio/tmpfile.c
platform/win32/Config.jam [new file with mode: 0644]
platform/win32/Jamfile [new file with mode: 0644]
platform/win32/Readme.txt [new file with mode: 0644]
platform/win32/crt0.c [new file with mode: 0644]
platform/win32/functions/_PDCLIB/_PDCLIB_Exit.c [new file with mode: 0644]
platform/win32/functions/_PDCLIB/_PDCLIB_allocpages.c [new file with mode: 0644]
platform/win32/functions/_PDCLIB/_PDCLIB_close.c [new file with mode: 0644]
platform/win32/functions/_PDCLIB/_PDCLIB_fillbuffer.c [new file with mode: 0644]
platform/win32/functions/_PDCLIB/_PDCLIB_flushbuffer.c [new file with mode: 0644]
platform/win32/functions/_PDCLIB/_PDCLIB_freepages.c [new file with mode: 0644]
platform/win32/functions/_PDCLIB/_PDCLIB_open.c [new file with mode: 0644]
platform/win32/functions/_PDCLIB/_PDCLIB_rename.c [new file with mode: 0644]
platform/win32/functions/_PDCLIB/_PDCLIB_seek.c [new file with mode: 0644]
platform/win32/functions/_PDCLIB/_PDCLIB_stdinit.c [new file with mode: 0644]
platform/win32/functions/_PDCLIB/_PDCLIB_w32errno.c [new file with mode: 0644]
platform/win32/functions/signal/raise.c [new file with mode: 0644]
platform/win32/functions/signal/signal.c [new file with mode: 0644]
platform/win32/functions/stdio/remove.c [new file with mode: 0644]
platform/win32/functions/stdio/tmpfile.c [new file with mode: 0644]
platform/win32/functions/stdlib/getenv.c [new file with mode: 0644]
platform/win32/functions/stdlib/system.c [new file with mode: 0644]
platform/win32/includes/float.h [new file with mode: 0644]
platform/win32/includes/signal.h [new file with mode: 0644]
platform/win32/internals/_PDCLIB_config.h [new file with mode: 0644]

diff --git a/Jamfile b/Jamfile
index 971e21da8f80a2727673d8e7893a2e36651fe98f..99441d9b4dffe3fcd56012cfdc3c1671564cd7fd 100644 (file)
--- a/Jamfile
+++ b/Jamfile
@@ -1,4 +1,8 @@
 SubDir PDCLIB_TOP ;\r
+if $(PDCLIB_PLATFORM) {\r
+    SubInclude PDCLIB_TOP platform $(PDCLIB_PLATFORM) ;\r
+    SubDir PDCLIB_TOP ;\r
+}\r
 PDCLibConfig ;\r
 \r
 PDCLIB_SOURCES = [ RecursiveGlob $(PDCLIB_TOP) : [ FDirName functions ] : *.c ] ;\r
@@ -25,11 +29,12 @@ if ! $(PDCLIB_NO_TEST) {
 \r
         Object $(testfile).o    : $(file) ;\r
         Object $(regtestfile).o : $(file) ;\r
-        MainFromObjects $(testfile)    : $(testfile).o ;\r
+        MainFromObjects $(testfile)    : $(testfile).o $(CRT0) ;\r
         MainFromObjects $(regtestfile) : $(regtestfile).o ;\r
         CCFLAGS on $(testfile).o += -DTEST $(PDCLIB_TEST_CCFLAGS) ;\r
         CCFLAGS on $(regtestfile).o += -DTEST -DREGTEST \r
                                        $(PDCLIB_REGTEST_CCFLAGS) ;\r
+        CCHDRS on $(regtestfile).o = [ FIncludes [ FDirName testing ] ] ;\r
 \r
         LINKFLAGS on $(testfile)$(SUFEXE) += $(PDCLIB_TEST_LINKFLAGS) ;\r
         LINKFLAGS on $(regtestfile)$(SUFEXE) += $(PDCLIB_REGTEST_LINKFLAGS) ;\r
index 8657cc9ca0fb0dc16899c7030b36f80fa2997b8b..dd0e406826211b951d4977c6644e47a43d345a90 100644 (file)
--- a/Jamrules
+++ b/Jamrules
@@ -32,14 +32,14 @@ if ! $(PDCLIB_HAVE_PLATFORM) && ! $(PDCLIB_PLATFORM) {
       -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes ;\r
     PDCLIB_CCFLAGS  = \r
       -ffreestanding \r
-      -nostdinc \r
+      #-nostdinc \r
       -std=c11 \r
       -g \r
       -D_PDCLIB_BUILD\r
       $(PDCLIB_WARNINGS) ;\r
     PDCLIB_C++FLAGS =\r
       -ffreestanding\r
-      -nostdinc\r
+      #-nostdinc\r
       -std=c++11\r
       -g\r
       -D_PDCLIB_BUILD\r
index 45095e77256767070b35008dcc2119413b161a22..58a8e58e438c207f44870656beef9883f6e9b70c 100644 (file)
@@ -6,6 +6,7 @@
    Permission is granted to use, modify, and / or redistribute at will.
 */
 
+#ifndef REGTEST
 #include <_PDCLIB_int.h>
 #include <string.h>
 #include <ctype.h>
@@ -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;
 }
 
index 71f600790f32d944fabb47263517eb137d20d1b8..5086d0d64bb09305245cc10692cc2a291978b8a7 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <stdio.h>
 
+#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>
index ad41e5d906bdd00a8df28aa3fec1dde30f8a4b0a..52a7ae38585a13978b8069bb3066a9a5bf193271 100644 (file)
@@ -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;
 }
 
index 7a690800d45f92c6b492448f1b3238d77427c406..4facee58ad5ef33f7452fcceeaef956253ace0e7 100644 (file)
@@ -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;
 
index 0e293aba2cfc55a6a4f1487b569b20efb8cd70c7..ded5408542576274ad43a910a1e3b9d2776b4e6b 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <stddef.h>
 
+#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;
 }
 
index 6ce38d90d2779659b62b1700fe30a7dae4436cc9..cf1c2dfe53b7948d0b68619021fd72a6062b9569 100644 (file)
@@ -9,6 +9,7 @@
 #include <stdio.h>
 #include <errno.h>
 
+#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>
index 0b31529d5d74693e40c97010d8d946acb549cbf8..1b1c4b526eecceee5105e9ef544aa761d2928bcc 100644 (file)
@@ -9,6 +9,7 @@
 #include <stdio.h>
 #include <errno.h>
 
+#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>
index 72db66bed2590a275e9bb346a1bc5a06ff2c55e5..124496c4cc1e1b43a943a2dc399df7dd1c49ad5a 100644 (file)
@@ -12,6 +12,8 @@
 #include <stdlib.h>
 #include <stddef.h>
 
+#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;
 }
 
index 6910aef66f3b60586f16a164d395128a8615960e..57f9831e457cd3dc918e4341befb2add07ced794 100644 (file)
@@ -16,6 +16,8 @@
 #include <stddef.h>
 #include <limits.h>
 
+#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;
 }
 
index 1556ec4bab7a9a201740ae91de8ceb20aedb422a..86b6d42e18c4f05470a9f06c258de965b200dcf5 100644 (file)
@@ -6,12 +6,13 @@
    Permission is granted to use, modify, and / or redistribute at will.
 */
 
-#include <_PDCLIB_int.h>
 #include <ctype.h>
 #include <errno.h>
 #include <string.h>
 #include <stdint.h>
 
+#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;
 }
 
index 29b79197598ace1a5890738a72b20f4052844660..7be40309ed41931c09fc0302f94a2959e4a2c09f 100644 (file)
@@ -9,7 +9,7 @@
 #include <ctype.h>
 #include <stddef.h>
 #include <string.h>
-
+#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 (file)
index 0000000..8556327
--- /dev/null
@@ -0,0 +1,92 @@
+/* $Id$ */\r
+\r
+/* _PDCLIB_fdopen( _PDCLIB_fd_t fd, const char * )\r
+\r
+   This file is part of the Public Domain C Library (PDCLib).\r
+   Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
+#ifndef REGTEST\r
+#include <_PDCLIB_glue.h>\r
+#include <string.h>\r
+\r
+extern struct _PDCLIB_file_t * _PDCLIB_filelist;\r
+\r
+struct _PDCLIB_file_t * _PDCLIB_fdopen( _PDCLIB_fd_t fd, \r
+                                        int mode,\r
+                                        const char * _PDCLIB_restrict filename )\r
+{\r
+    size_t filename_len;\r
+    struct _PDCLIB_file_t * rc;\r
+    if ( mode == NULL )\r
+    {\r
+        /* Mode invalid */\r
+        return NULL;\r
+    }\r
+    /* To reduce the number of malloc calls, all data fields are concatenated:\r
+       * the FILE structure itself,\r
+       * ungetc buffer,\r
+       * filename buffer,\r
+       * data buffer.\r
+       Data buffer comes last because it might change in size ( setvbuf() ).\r
+    */\r
+    filename_len = filename ? strlen( filename ) + 1 : 1;\r
+    if ( ( rc = calloc( 1, sizeof( struct _PDCLIB_file_t ) + _PDCLIB_UNGETCBUFSIZE + filename_len + BUFSIZ ) ) == NULL )\r
+    {\r
+        /* no memory */\r
+        return NULL;\r
+    }\r
+    rc->status = mode;\r
+    rc->handle = fd;\r
+    /* Setting pointers into the memory block allocated above */\r
+    rc->ungetbuf = (unsigned char *)rc + sizeof( struct _PDCLIB_file_t );\r
+    rc->filename = (char *)rc->ungetbuf + _PDCLIB_UNGETCBUFSIZE;\r
+    rc->buffer   = rc->filename + filename_len;\r
+    /* Copying filename to FILE structure */\r
+    if(filename) strcpy( rc->filename, filename );\r
+    /* Initializing the rest of the structure */\r
+    rc->bufsize = BUFSIZ;\r
+    rc->bufidx = 0;\r
+    rc->ungetidx = 0;\r
+    /* Setting buffer to _IOLBF because "when opened, a stream is fully\r
+       buffered if and only if it can be determined not to refer to an\r
+       interactive device."\r
+    */\r
+    rc->status |= _IOLBF;\r
+    /* TODO: Setting mbstate */\r
+    /* Adding to list of open files */\r
+    rc->next = _PDCLIB_filelist;\r
+    _PDCLIB_filelist = rc;\r
+    return rc;\r
+}\r
+\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    /* Some of the tests are not executed for regression tests, as the libc on\r
+       my system is at once less forgiving (segfaults on mode NULL) and more\r
+       forgiving (accepts undefined modes).\r
+    */\r
+    FILE * fh;\r
+    remove( testfile );\r
+    TESTCASE_NOREG( fopen( NULL, NULL ) == NULL );\r
+    TESTCASE( fopen( NULL, "w" ) == NULL );\r
+    TESTCASE_NOREG( fopen( "", NULL ) == NULL );\r
+    TESTCASE( fopen( "", "w" ) == NULL );\r
+    TESTCASE( fopen( "foo", "" ) == NULL );\r
+    TESTCASE_NOREG( fopen( testfile, "wq" ) == NULL ); /* Undefined mode */\r
+    TESTCASE_NOREG( fopen( testfile, "wr" ) == NULL ); /* Undefined mode */\r
+    TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL );\r
+    TESTCASE( fclose( fh ) == 0 );\r
+    TESTCASE( remove( testfile ) == 0 );\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif\r
index 7c0b81a6f660f47dec76c3bd676cb943c436538e..18b7b3ae4df8e2cf5646bb87fc88fc20bedc8eba 100644 (file)
 #ifndef REGTEST
 #include <_PDCLIB_glue.h>
 #include <string.h>
+#include <errno.h>
 
 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
index e25c7ed967855955b824c27443f4f31817abc44f..e50f419ded982705b0e9e5530299f080c0a40f54 100644 (file)
@@ -31,6 +31,8 @@ char *strndup( const char * s, size_t len )
 \r
 int main( void )\r
 {\r
+#ifndef REGTEST\r
+    /* Missing on Windows. Maybe use conditionals? */\r
     const char *teststr  = "Hello, world";\r
     const char *teststr2 = "\xFE\x8C\n";\r
     char *testres, *testres2;\r
@@ -49,7 +51,8 @@ int main( void )
     TESTCASE(strcmp(testres2, teststr2) == 0);\r
     free(testres);\r
     free(testres2);\r
-    \r
+#endif\r
+\r
     return TEST_RESULTS;\r
 }\r
 \r
diff --git a/functions/wchar/wcschr.c b/functions/wchar/wcschr.c
new file mode 100644 (file)
index 0000000..51d20a4
--- /dev/null
@@ -0,0 +1,32 @@
+/* wcschr( const wchar_t *, wchar_t );\r
+\r
+   This file is part of the Public Domain C Library (PDCLib).\r
+   Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+#include <wchar.h>\r
+#include <stddef.h>\r
+\r
+#ifndef REGTEST\r
+\r
+wchar_t *wcschr(const wchar_t * haystack, wchar_t needle)\r
+{\r
+    while(*haystack) {\r
+        if(*haystack == needle) return (wchar_t*) haystack;\r
+        haystack++;\r
+    }\r
+    return NULL;\r
+}\r
+\r
+\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif\r
diff --git a/functions/wchar/wcscpy.c b/functions/wchar/wcscpy.c
new file mode 100644 (file)
index 0000000..02394ee
--- /dev/null
@@ -0,0 +1,33 @@
+/* wchar_t * wcscpy( wchar_t restrict *, const wchar_t restrict * );\r
+\r
+   This file is part of the Public Domain C Library (PDCLib).\r
+   Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+#include <wchar.h>\r
+\r
+#ifndef REGTEST\r
+\r
+wchar_t *wcscpy( wchar_t * _PDCLIB_restrict dest, \r
+                 const wchar_t * _PDCLIB_restrict src)\r
+{\r
+    wchar_t * rv = dest;\r
+    while(*src) {\r
+        *(dest++) = *(src++);\r
+    }\r
+\r
+    return rv;\r
+}\r
+\r
+\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif\r
diff --git a/functions/wchar/wcslen.c b/functions/wchar/wcslen.c
new file mode 100644 (file)
index 0000000..d5d878d
--- /dev/null
@@ -0,0 +1,29 @@
+/* wcslen( const wchar_t * );\r
+\r
+   This file is part of the Public Domain C Library (PDCLib).\r
+   Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+#include <wchar.h>\r
+\r
+#ifndef REGTEST\r
+\r
+size_t wcslen( const wchar_t * str )\r
+{\r
+    size_t n = 0;\r
+    while(*(str++)) n++;\r
+    return n;\r
+}\r
+\r
+\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif\r
diff --git a/functions/wchar/wcsrchr.c b/functions/wchar/wcsrchr.c
new file mode 100644 (file)
index 0000000..396da4f
--- /dev/null
@@ -0,0 +1,35 @@
+/* $Id$ */\r
+\r
+/* wcsrchr( const wchar_t *, wchar_t );\r
+\r
+   This file is part of the Public Domain C Library (PDCLib).\r
+   Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+#include <wchar.h>\r
+#include <stddef.h>\r
+\r
+#ifndef REGTEST\r
+\r
+wchar_t *wcsrchr(const wchar_t * haystack, wchar_t needle)\r
+{\r
+    wchar_t *found = NULL;\r
+    while(*haystack) {\r
+        if(*haystack == needle) found = haystack;\r
+        haystack++;\r
+    }\r
+    return found;\r
+}\r
+\r
+\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif\r
index 6d8c03a9e466e846cfc4df6e665d177f8a73432f..1d5e3afc7ced3b8fe5d6ab20b677f0e88265e200 100644 (file)
@@ -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
index 1d7c0bf23ecddf47979700d7dbd660005e53301e..12b7f0aea2aa1ea51a06f4b93c7d9556735f816c 100644 (file)
@@ -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 (file)
index 0000000..eab2984
--- /dev/null
@@ -0,0 +1,35 @@
+/* 7. <wchar.h>\r
+\r
+   This file is part of the Public Domain C Library (PDCLib).\r
+   Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+\r
+#ifndef _PDCLIB_WCHAR_H\r
+#define _PDCLIB_WCHAR_H\r
+#include <_PDCLIB_int.h>\r
+_PDCLIB_BEGIN_EXTERN_C\r
+/* This is VASTLY incomplete. Functions being implemented as required by other\r
+   portions of the library\r
+ */\r
+\r
+#ifndef _PDCLIB_SIZE_T_DEFINED\r
+#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED\r
+typedef _PDCLIB_size_t size_t;\r
+#endif\r
+\r
+#ifndef __cplusplus\r
+#ifndef _PDCLIB_WCHAR_T_DEFINED\r
+#define _PDCLIB_WCHAR_T_DEFINED _PDCLIB_WCHAR_T_DEFINED\r
+typedef _PDCLIB_wchar_t   wchar_t;\r
+#endif\r
+#endif\r
+\r
+wchar_t *wcschr( const wchar_t * haystack, wchar_t needle );\r
+wchar_t *wcsrchr( const wchar_t * haystack, wchar_t needle );\r
+size_t   wcslen( const wchar_t * string);\r
+wchar_t *wcscpy( wchar_t * _PDCLIB_restrict dest, \r
+                 const wchar_t * _PDCLIB_restrict src);\r
+\r
+_PDCLIB_END_EXTERN_C\r
+#endif\r
index 8990ed8da1faa443c1e9a7b10821db1fdc52724b..e7e908a66e413d70cee645fc2ad26b8e0749049d 100644 (file)
 #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
index be1ed2e07e4e956ddaa1cd87f1313c2bbd5fcd02..83201708b401fecc38e8a3bb0ffad8df89a99014 100644 (file)
@@ -1,3 +1,4 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 void _PDCLIB_call_once(_PDCLIB_once_flag *flag, void (*func)(void))\r
@@ -7,20 +8,24 @@ void _PDCLIB_call_once(_PDCLIB_once_flag *flag, void (*func)(void))
                *flag = _PDCLIB_ONCE_FLAG_DONE;\r
        }\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
 \r
+#ifndef REGTEST\r
 static int count = 0;\r
-once_flag once = ONCE_FLAG_INIT;\r
+static once_flag once = ONCE_FLAG_INIT;\r
 \r
 static void do_once(void)\r
 {\r
     count++;\r
 }\r
+#endif\r
 \r
 int main( void )\r
 {\r
+#ifndef REGTEST\r
     TESTCASE(count == 0);\r
     call_once(&once, do_once);\r
     TESTCASE(count == 1);\r
@@ -28,6 +33,7 @@ int main( void )
     TESTCASE(count == 1);\r
     do_once();\r
     TESTCASE(count == 2);\r
+#endif\r
     return TEST_RESULTS;\r
 }\r
 \r
index 379f28ff1d383b2fd8d95cff6e2f013f5319142f..2d3fc7e66536f1f61fd07d67be7ec14390ff7d59 100644 (file)
@@ -1,3 +1,4 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 int cnd_init(cnd_t *cond)\r
@@ -5,6 +6,7 @@ int cnd_init(cnd_t *cond)
        /* does nothing */\r
        return thrd_success;\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index 05cbcf6ba0059c0f2fe6ab51826a9aee2fc55af0..363806e554899d5156a10c58815390835eef8270 100644 (file)
@@ -1,9 +1,11 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 int cnd_signal(cnd_t *cond)\r
 {\r
        return thrd_success;\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index 4c632cc80216eadef4ed7ae8737b2d484b359889..be2fcbbe3d427373f1e6ed3e41be891c8ed80423 100644 (file)
@@ -1,9 +1,11 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 int cnd_wait(cnd_t *cond, mtx_t *mtx)\r
 {\r
        return thrd_error;\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index 75baec274ddce20c2c4a15b1d142a85a6e31086d..5227274469d74cc958f2565478a8efd2651ea586 100644 (file)
@@ -1,7 +1,9 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 void mtx_destroy(mtx_t *mtx)\r
 {}\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index 922c9421f45398231c3bd4619ecc24ee58b1c35e..76b3eeb10482d8393b4755d928644bec5b6bb0ec 100644 (file)
@@ -1,3 +1,4 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 int mtx_init(mtx_t *mtx, int type)\r
@@ -5,6 +6,7 @@ int mtx_init(mtx_t *mtx, int type)
        *mtx = 0;\r
        return thrd_success;\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index 121444e4b9a255d344825115c0ece923e512d3d7..d086986555dcd48c6808122333bd51bad77b55fd 100644 (file)
@@ -1,5 +1,5 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
-#include <assert.h>\r
 \r
 int mtx_lock(mtx_t *mtx)\r
 {\r
@@ -8,6 +8,7 @@ int mtx_lock(mtx_t *mtx)
                return thrd_success;\r
        } else return thrd_error;\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index e3cd4fb80b95de29bd41bc13edd978e7d07317e6..6ab7dfb8054b048ebb6d7ba7fd507978e31fea2b 100644 (file)
@@ -1,9 +1,11 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 int mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts)\r
 {\r
        return mtx_lock(mtx);\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index 3333a86f2c313071d50055f7b532661f03a003f1..bffc8b85b139b430df32c437585dd70fe06308b5 100644 (file)
@@ -1,3 +1,4 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 int mtx_trylock(mtx_t *mtx)\r
@@ -9,6 +10,7 @@ int mtx_trylock(mtx_t *mtx)
                return thrd_success;\r
        }\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index 1c11401f7931788068b98ec49bc0ec625d871a22..214a06390a51e752f109b7d53fb1561291b72b03 100644 (file)
@@ -1,3 +1,4 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 int mtx_unlock(mtx_t *mtx)\r
@@ -7,6 +8,7 @@ int mtx_unlock(mtx_t *mtx)
                return thrd_success;\r
        } else return thrd_error;\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index 840157bdaf2441cb7f80fff871ecf7f3283139a4..c92c495ef88c161db41c3b14b5edfeb2c1435a2c 100644 (file)
@@ -1,9 +1,11 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 void thrd_yield(void)\r
 {\r
        /* does nothing */\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index 2a28fcadcf76419396801c441a6baf5236efbde9..e7ad53a835231716ee19d55fb0b9ba5bef9b5bf0 100644 (file)
@@ -1,3 +1,4 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 int tss_create(tss_t *key, tss_dtor_t dtor)\r
@@ -6,6 +7,7 @@ int tss_create(tss_t *key, tss_dtor_t dtor)
        key->value = NULL;\r
        return thrd_success;\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index 5d251f4904a14b6592f694793bb21eadd5caa41e..758209f6f611c50f0f35dc39823a1cbc41bea515 100644 (file)
@@ -1,9 +1,11 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 void tss_delete(tss_t key)\r
 {\r
        key.self->self = NULL;\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index 3e9917b83c3b508fee8c211ed9f0e06732f3e154..c302fffb62c389bf4024dcd436f5b7483caced29 100644 (file)
@@ -1,23 +1,29 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 void *tss_get(tss_t key)\r
 {\r
        return key.value;\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
 \r
+#ifndef REGTEST\r
 static tss_t key;\r
 static char v;\r
+#endif\r
 \r
 int main( void )\r
 {\r
+#ifndef REGTEST\r
     TESTCASE(tss_create(&key, NULL) == thrd_success);\r
     TESTCASE(tss_get(key) == NULL);\r
     TESTCASE(tss_set(key, &v) == thrd_success);\r
     TESTCASE(tss_get(key) == &v);\r
     tss_delete(key);\r
+#endif\r
     return TEST_RESULTS;\r
 }\r
 \r
index 7de3ec5b775527d66e84f01174ce661a81b4d94a..d8ae84bd36560fb5724d58390b9e51d02a55b615 100644 (file)
@@ -1,3 +1,4 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 int tss_set(tss_t key, void *val)\r
@@ -5,6 +6,7 @@ int tss_set(tss_t key, void *val)
        key.self->value = val;\r
        return thrd_success;\r
 }\r
+#endif\r
 \r
 #ifdef TEST\r
 #include <_PDCLIB_test.h>\r
index 2d52f60b38c06e7e57712ea3f7e6949d3fa3650f..3f384e7d6ef44431ebbba5a473feb764e19cafe4 100644 (file)
@@ -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 (file)
index 0000000..c02174f
--- /dev/null
@@ -0,0 +1,12 @@
+rule PDCLibTargetConfig { }\r
+rule PDCLibTargetHeaders {\r
+    SubDirHdrs $(PDCLIB_TOP) platform win32 includes ;\r
+    SubDirHdrs $(PDCLIB_TOP) platform win32 internals ;\r
+}\r
+\r
+PDCLIB_TEST_LINKFLAGS += -nostdlib ;\r
+PDCLIB_TEST_LINKLIBS += -lgcc -lkernel32 -lshell32 ;\r
+\r
+PDCLIB_OPTIONS = nothread notime dlmalloc ;\r
+\r
+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 (file)
index 0000000..35b8dea
--- /dev/null
@@ -0,0 +1,6 @@
+SubDir PDCLIB_TOP platform win32 ;\r
+PDCLibConfig ;\r
+\r
+Object $(CRT0) : $(CRT0:S=.c) ;\r
+\r
+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 (file)
index 0000000..5ec24bd
--- /dev/null
@@ -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 (file)
index 0000000..fcdee08
--- /dev/null
@@ -0,0 +1,57 @@
+#include <windows.h>\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+static char ** argvToAnsi( wchar_t ** wargv, int argc )\r
+{\r
+    char ** argv = malloc( sizeof( *argv ) * argc );\r
+    for ( int i = 0; i != argc; ++i ) {\r
+        int sz = WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK | WC_SEPCHARS,\r
+                                      wargv[i], -1, NULL, 0, NULL, NULL );\r
+        if(!(argv[i] = malloc(sz))) {\r
+            fputs("Error in C runtime initialization: "\r
+                  "unable to allocate buffer for argument", stderr);\r
+            abort();\r
+        }\r
+\r
+        int rv = WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK | WC_SEPCHARS,\r
+                                      wargv[i], -1, argv[i], sz, NULL, NULL );\r
+\r
+        if(rv != sz) {\r
+            fputs("Error in C runtime initialization: "\r
+                  "size mismatch during character set conversion", stderr);\r
+        }\r
+    }\r
+    return argv;\r
+}\r
+\r
+static int        argc;\r
+static wchar_t *  cl;\r
+static wchar_t ** wargv;\r
+static char    ** argv;\r
+\r
+static void freeArgs( void )\r
+{\r
+    for(int i = 0; i != argc; i++) {\r
+        free( argv[i] );\r
+    }\r
+    free( argv );\r
+    LocalFree( wargv );\r
+}\r
+\r
+extern int main( int argc, char ** argv, char ** envp );\r
+_PDCLIB_noreturn void mainCRTStartup( void ) \r
+{\r
+    stdin->handle  = GetStdHandle(STD_INPUT_HANDLE);\r
+    stdout->handle = GetStdHandle(STD_OUTPUT_HANDLE);\r
+    stderr->handle = GetStdHandle(STD_ERROR_HANDLE);\r
+\r
+    cl    = GetCommandLineW();\r
+    wargv = CommandLineToArgvW(cl, &argc);\r
+    argv  = argvToAnsi(wargv, argc);\r
+    atexit(freeArgs);\r
+\r
+    int exitStatus = main(argc, argv, NULL);\r
+    exit(exitStatus);\r
+}\r
diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_Exit.c b/platform/win32/functions/_PDCLIB/_PDCLIB_Exit.c
new file mode 100644 (file)
index 0000000..fa50a41
--- /dev/null
@@ -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 <stdlib.h>
+
+#ifndef REGTEST
+#include <_PDCLIB_glue.h>
+#include <errno.h>
+#include <windows.h>
+
+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 (file)
index 0000000..48e4bab
--- /dev/null
@@ -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 <stdint.h>
+#include <stddef.h>
+#include <_PDCLIB_glue.h>
+#include <errno.h>
+#include <windows.h>
+
+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 (file)
index 0000000..7fc10a3
--- /dev/null
@@ -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 <stdio.h>
+
+#ifndef REGTEST
+#include <_PDCLIB_glue.h>
+#include <errno.h>
+#include <windows.h>
+
+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 (file)
index 0000000..c6a2b6b
--- /dev/null
@@ -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 <stdio.h>
+
+#ifndef REGTEST
+#include <_PDCLIB_glue.h>
+#include <errno.h>
+#include <windows.h>
+
+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 (file)
index 0000000..82e36a0
--- /dev/null
@@ -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 <stdio.h>
+#include <string.h>
+
+#ifndef REGTEST
+#include <_PDCLIB_glue.h>
+#include <errno.h>
+#include <windows.h>
+
+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 (file)
index 0000000..3d8a254
--- /dev/null
@@ -0,0 +1,32 @@
+/* $Id$ */\r
+\r
+/* _PDCLIB_allocpages( int const )\r
+\r
+   This file is part of the Public Domain C Library (PDCLib).\r
+   Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+/* This is a stub implementation of _PDCLIB_allocpages\r
+*/\r
+\r
+#include <stdint.h>\r
+#include <stddef.h>\r
+#include <errno.h>\r
+#ifndef REGTEST\r
+#include <_PDCLIB_glue.h>\r
+\r
+void _PDCLIB_freepages( void * p, size_t n )\r
+{\r
+    return;\r
+}\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif\r
diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_open.c b/platform/win32/functions/_PDCLIB/_PDCLIB_open.c
new file mode 100644 (file)
index 0000000..bfdb897
--- /dev/null
@@ -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 <stdio.h>
+#include <errno.h>
+
+#ifndef REGTEST
+#include <_PDCLIB_glue.h>
+#include <windows.h>
+
+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 <stdlib.h>
+#include <string.h>
+
+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 (file)
index 0000000..a65715d
--- /dev/null
@@ -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 <stdio.h>
+
+#ifndef REGTEST
+#include <_PDCLIB_glue.h>
+#include <errno.h>
+
+int _PDCLIB_rename( const char * old, const char * new )
+{
+    errno = ENOTSUP;
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+#include <stdlib.h>
+
+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 (file)
index 0000000..c4c25f8
--- /dev/null
@@ -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 <stdio.h>
+#include <errno.h>
+#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 (file)
index 0000000..bc40470
--- /dev/null
@@ -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 <stdio.h>
+#include <locale.h>
+#include <limits.h>
+
+#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 <ctype.h> 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 (file)
index 0000000..5e03ef5
--- /dev/null
@@ -0,0 +1,56 @@
+/* $Id$ */\r
+\r
+/* _PDCLIB_allocpages( int const )\r
+\r
+   This file is part of the Public Domain C Library (PDCLib).\r
+   Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+/* This is a stub implementation of _PDCLIB_allocpages\r
+*/\r
+\r
+#ifndef REGTEST\r
+#include <errno.h>\r
+#include <windows.h>\r
+\r
+void _PDCLIB_w32errno(void)\r
+{\r
+    // Not exhaustive\r
+    switch(GetLastError()) {\r
+        case ERROR_SUCCESS:\r
+            return;\r
+        case ERROR_FILE_NOT_FOUND:\r
+        case ERROR_PATH_NOT_FOUND:\r
+        case ERROR_INVALID_DRIVE:\r
+            errno = ENOENT; break;\r
+        case ERROR_TOO_MANY_OPEN_FILES:\r
+            errno = EMFILE; break;\r
+        case ERROR_ACCESS_DENIED:\r
+        case ERROR_WRITE_PROTECT:\r
+            errno = EPERM; break;\r
+        case ERROR_INVALID_HANDLE:\r
+            errno = EBADF; break;\r
+        case ERROR_NOT_ENOUGH_MEMORY:\r
+        case ERROR_OUTOFMEMORY:\r
+            errno = ENOMEM; break;\r
+        case ERROR_NOT_READY:\r
+            errno = EAGAIN; break;\r
+        case ERROR_BAD_LENGTH:\r
+            errno = EINVAL; break;\r
+        default:\r
+            // TODO: reconsider what to use here?\r
+            errno = ENOSYS; break;\r
+    }\r
+}\r
+\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#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 (file)
index 0000000..8d7080b
--- /dev/null
@@ -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 <signal.h>
+
+#ifndef REGTEST
+
+#include <stdio.h>
+#include <stdlib.h>
+
+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 <stdlib.h>
+
+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 (file)
index 0000000..e07877d
--- /dev/null
@@ -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 <signal.h>
+
+#ifndef REGTEST
+
+#include <stdlib.h>
+
+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 (file)
index 0000000..913bdf3
--- /dev/null
@@ -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 <stdio.h>
+
+#ifndef REGTEST
+
+#include <string.h>
+#include <errno.h>
+#include <windows.h>
+
+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 (file)
index 0000000..f329234
--- /dev/null
@@ -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 <stdio.h>
+
+#ifndef REGTEST
+#include <errno.h>
+#include <_PDCLIB_glue.h>
+#include <windows.h>
+#include <string.h>
+
+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 <string.h>
+
+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 (file)
index 0000000..a95171d
--- /dev/null
@@ -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 <string.h>
+#include <stdlib.h>
+
+#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 (file)
index 0000000..2cf7534
--- /dev/null
@@ -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 <stdlib.h>
+
+/* 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 (file)
index 0000000..6590539
--- /dev/null
@@ -0,0 +1,76 @@
+/* $Id$ */
+
+/* 7.7 Characteristics of floating types <float.h>
+
+   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 (file)
index 0000000..9f6a1a3
--- /dev/null
@@ -0,0 +1,86 @@
+/* $Id$ */
+
+/* 7.14 Signal handling <string.h>
+
+   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
+   <signal.h>.
+
+   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 (file)
index 0000000..793065d
--- /dev/null
@@ -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 <stdlib.h> 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 (<locale.h>) 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
+
+/* <stdlib.h> 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;
+};
+
+/* -------------------------------------------------------------------------- */
+/* <stdint.h> 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 <inttypes.h>).                                  */
+/* 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
+
+/* <inttypes.h> 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.h>: 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
+
+/* <time.h>: 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 (<stdarg.h>)
+   The macros defined by <stdarg.h> 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 <errno.h> will "see" EPERM instead of EISDIR (the _PDCLIB_*
+   prefix removed by <errno.h> 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