]> pd.if.org Git - pdclib.old/commitdiff
* Test cleanups: surround the code for all functions by #ifndef REGTEST
authorOwen Shepherd <owen.shepherd@e43.eu>
Mon, 13 Aug 2012 20:11:29 +0000 (21:11 +0100)
committerOwen Shepherd <owen.shepherd@e43.eu>
Mon, 13 Aug 2012 20:11:29 +0000 (21:11 +0100)
* Don't REGTEST internal functions (it doesn't make sense)
* <stdio.h>: add _PDCLIB_fdopen, which opens a file based upon its _PDCLIB_fd_t
  file descriptor
    TODO: Should this be public or not? POSIX fdopen demonstrates utility
    TODO: Can we stop storing the file name? Is that useful?
* fopen: rewrite based upon _PDCLIB_fdopen to consolidate code
* strndup: don't REGTEST - mingw doesn't implement.
* <stddef.h>: conditional definition of wchar_t for <wchar.h>
* <wchar.h>: Add 4 simple functions for dependencies
* <_PDCLIB_aux.h>: rename _PDCLIB_ALL to _PDCLIB_EXTENSIONS
* platform/example/functions/stdio/tmpfile.c: return NULL, not 1
* Build system: SubInclude the platform directory to enable the building of
  support routines (e.g. app startup files)
* Test system: If $(CRT0) is set, link the contents of it into the tests. This
  enables the platform code to provide startup files.

40 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

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