From af55dc64b9118345203e7ba7bd262e6444573795 Mon Sep 17 00:00:00 2001 From: Owen Shepherd Date: Sun, 1 Sep 2013 23:18:08 +0100 Subject: [PATCH] Bring example platform up to date --- platform/example/Config.jam | 9 +- platform/example/Jamfile | 2 + .../functions/_PDCLIB/_PDCLIB_fileops.c | 56 +++++++++ .../_PDCLIB/{open.c => _PDCLIB_open.c} | 77 ++++++------ .../example/functions/_PDCLIB/allocpages.c | 2 - platform/example/functions/_PDCLIB/close.c | 35 ------ .../example/functions/_PDCLIB/fillbuffer.c | 37 ------ .../example/functions/_PDCLIB/flushbuffer.c | 38 ------ platform/example/functions/_PDCLIB/seek.c | 29 ----- platform/example/functions/_PDCLIB/stdinit.c | 115 ++++++++++++------ platform/example/functions/signal/signal.c | 6 +- platform/example/functions/stdio/tmpfile.c | 4 +- platform/example/internals/_PDCLIB_config.h | 48 +++++--- platform/win32/internals/_PDCLIB_config.h | 4 +- 14 files changed, 223 insertions(+), 239 deletions(-) create mode 100644 platform/example/Jamfile create mode 100644 platform/example/functions/_PDCLIB/_PDCLIB_fileops.c rename platform/example/functions/_PDCLIB/{open.c => _PDCLIB_open.c} (71%) delete mode 100644 platform/example/functions/_PDCLIB/close.c delete mode 100644 platform/example/functions/_PDCLIB/fillbuffer.c delete mode 100644 platform/example/functions/_PDCLIB/flushbuffer.c delete mode 100644 platform/example/functions/_PDCLIB/seek.c diff --git a/platform/example/Config.jam b/platform/example/Config.jam index 1eda6e8..98e9c6c 100644 --- a/platform/example/Config.jam +++ b/platform/example/Config.jam @@ -9,4 +9,11 @@ if $(PDCLIB_TOOLCHAIN) = "gcc" { PDCLIB_TEST_LINKLIBS += -lgcc ; } -PDCLIB_OPTIONS = nothread notime dlmalloc ; \ No newline at end of file +PDCLIB_OPTIONS = + nothread + notime + dlmalloc + tss_errno + basecodecs + c_locale + ; \ No newline at end of file diff --git a/platform/example/Jamfile b/platform/example/Jamfile new file mode 100644 index 0000000..444f44a --- /dev/null +++ b/platform/example/Jamfile @@ -0,0 +1,2 @@ +SubDir PDCLIB_TOP platform example ; +PDCLibConfig ; \ No newline at end of file diff --git a/platform/example/functions/_PDCLIB/_PDCLIB_fileops.c b/platform/example/functions/_PDCLIB/_PDCLIB_fileops.c new file mode 100644 index 0000000..59ff45d --- /dev/null +++ b/platform/example/functions/_PDCLIB/_PDCLIB_fileops.c @@ -0,0 +1,56 @@ +/* _PDCLIB_fileops + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef REGTEST +#include +#include +#include <_PDCLIB_glue.h> +#include + +static bool readf( _PDCLIB_fd_t self, void * buf, size_t length, + size_t * numBytesRead ) +{ + errno = ENOTSUP; + return false; +} + +static bool writef( _PDCLIB_fd_t self, const void * buf, size_t length, + size_t * numBytesWritten ) +{ + errno = ENOTSUP; + return false; +} +static bool seekf( _PDCLIB_fd_t self, int_fast64_t offset, int whence, + int_fast64_t* newPos ) +{ + errno = ENOTSUP; + return false; +} + +static void closef( _PDCLIB_fd_t self ) +{ + errno = ENOTSUP; +} + +const _PDCLIB_fileops_t _PDCLIB_fileops = { + .read = readf, + .write = writef, + .seek = seekf, + .close = closef, +}; + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + // Tested by stdio test cases + return TEST_RESULTS; +} + +#endif diff --git a/platform/example/functions/_PDCLIB/open.c b/platform/example/functions/_PDCLIB/_PDCLIB_open.c similarity index 71% rename from platform/example/functions/_PDCLIB/open.c rename to platform/example/functions/_PDCLIB/_PDCLIB_open.c index 1d292f6..b7b64fe 100644 --- a/platform/example/functions/_PDCLIB/open.c +++ b/platform/example/functions/_PDCLIB/_PDCLIB_open.c @@ -1,38 +1,39 @@ -/* $Id$ */ - -/* _PDCLIB_open( char const * const, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is a stub implementation of open. -*/ - -#include -#include - -#ifndef REGTEST -#include <_PDCLIB_glue.h> - -int _PDCLIB_open( char const * const filename, unsigned int mode ) -{ - errno = ENOTSUP; - return 1; -} - -#endif - -#ifdef TEST -#include <_PDCLIB_test.h> - -#include -#include - -int main( void ) -{ - return TEST_RESULTS; -} - -#endif - +/* $Id$ */ + +/* _PDCLIB_open( char const * const, int ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is a stub implementation of open. +*/ + +#include +#include + +#ifndef REGTEST +#include <_PDCLIB_glue.h> + +bool _PDCLIB_open( _PDCLIB_fd_t * pFd, const _PDCLIB_fileops_t ** pOps, + char const * const filename, unsigned int mode ) +{ + errno = ENOTSUP; + return false; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +#include +#include + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif + diff --git a/platform/example/functions/_PDCLIB/allocpages.c b/platform/example/functions/_PDCLIB/allocpages.c index aa997f6..bdcd525 100644 --- a/platform/example/functions/_PDCLIB/allocpages.c +++ b/platform/example/functions/_PDCLIB/allocpages.c @@ -14,8 +14,6 @@ #include <_PDCLIB_glue.h> #include -static void * membreak = NULL; - void * _PDCLIB_allocpages( size_t n ) { errno = ENOTSUP; diff --git a/platform/example/functions/_PDCLIB/close.c b/platform/example/functions/_PDCLIB/close.c deleted file mode 100644 index 1b030c9..0000000 --- a/platform/example/functions/_PDCLIB/close.c +++ /dev/null @@ -1,35 +0,0 @@ -/* $Id$ */ - -/* _PDCLIB_close( _PDCLIB_fd_t fd ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is a stub example implementation of _PDCLIB_close() -*/ - -#include - -#ifndef REGTEST -#include <_PDCLIB_glue.h> -#include - -int _PDCLIB_close( int fd ) -{ - errno = ENOTSUP; - 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/example/functions/_PDCLIB/fillbuffer.c b/platform/example/functions/_PDCLIB/fillbuffer.c deleted file mode 100644 index c961f48..0000000 --- a/platform/example/functions/_PDCLIB/fillbuffer.c +++ /dev/null @@ -1,37 +0,0 @@ -/* $Id$ */ - -/* _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is a stub version of _PDCLIB_fillbuffer -*/ - -#include - -#ifndef REGTEST -#include <_PDCLIB_glue.h> -#include - -int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) -{ - errno = ENOTSUP; - stream->status |= _PDCLIB_EOFFLAG; - 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/example/functions/_PDCLIB/flushbuffer.c b/platform/example/functions/_PDCLIB/flushbuffer.c deleted file mode 100644 index 6dc1164..0000000 --- a/platform/example/functions/_PDCLIB/flushbuffer.c +++ /dev/null @@ -1,38 +0,0 @@ -/* $Id$ */ - -/* _PDCLIB_flushbuffer( struct _PDCLIB_file_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is a stub implementation of _PDCLIB_flushbuffer -*/ - -#include -#include - -#ifndef REGTEST -#include <_PDCLIB_glue.h> -#include - -int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ) -{ - 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/example/functions/_PDCLIB/seek.c b/platform/example/functions/_PDCLIB/seek.c deleted file mode 100644 index 381baef..0000000 --- a/platform/example/functions/_PDCLIB/seek.c +++ /dev/null @@ -1,29 +0,0 @@ -/* $Id$ */ - -/* int64_t _PDCLIB_seek( FILE *, int64_t, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include <_PDCLIB_glue.h> - -_PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence ) -{ - errno = ENOTSUP; - return EOF; -} - -#ifdef TEST -#include <_PDCLIB_test.h> - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif - diff --git a/platform/example/functions/_PDCLIB/stdinit.c b/platform/example/functions/_PDCLIB/stdinit.c index 2554e9f..48259a8 100644 --- a/platform/example/functions/_PDCLIB/stdinit.c +++ b/platform/example/functions/_PDCLIB/stdinit.c @@ -16,6 +16,11 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> +#include <_PDCLIB_locale.h> +#include <_PDCLIB_encoding.h> + +extern const _PDCLIB_fileops_t _PDCLIB_fileops; /* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file descriptors 0, 1, and 2 respectively. @@ -29,22 +34,55 @@ 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 = { 2, _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 = { 1, _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 = { 0, _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; +static FILE _PDCLIB_serr = { + .ops = &_PDCLIB_fileops, + .buffer = _PDCLIB_serr_buffer, + .bufsize = BUFSIZ, + .bufidx = 0, + .bufend = 0, + .ungetidx = 0, + .ungetbuf = _PDCLIB_serr_ungetbuf, + .status = _IONBF | _PDCLIB_FWRITE | _PDCLIB_STATIC, + .filename = NULL, + .next = NULL, +}; +static FILE _PDCLIB_sout = { + .ops = &_PDCLIB_fileops, + .buffer = _PDCLIB_sout_buffer, + .bufsize = BUFSIZ, + .bufidx = 0, + .bufend = 0, + .ungetidx = 0, + .ungetbuf = _PDCLIB_sout_ungetbuf, + .status = _IOLBF | _PDCLIB_FWRITE | _PDCLIB_STATIC, + .filename = NULL, + .next = &_PDCLIB_serr +}; +static FILE _PDCLIB_sin = { + .ops = &_PDCLIB_fileops, + .buffer = _PDCLIB_sin_buffer, + .bufsize = BUFSIZ, + .bufidx = 0, + .bufend = 0, + .ungetidx = 0, + .ungetbuf = _PDCLIB_sin_ungetbuf, + .status = _IOLBF | _PDCLIB_FREAD | _PDCLIB_STATIC, + .filename = NULL, + .next = &_PDCLIB_sout +}; + +FILE *stdin = &_PDCLIB_sin; +FILE *stdout = &_PDCLIB_sout; +FILE *stderr = &_PDCLIB_serr; -/* FIXME: This approach is a possible attack vector. */ -struct _PDCLIB_file_t * _PDCLIB_filelist = &_PDCLIB_sin; +FILE *_PDCLIB_filelist = &_PDCLIB_sin; /* "C" locale - defaulting to ASCII-7. 1 kByte (+ 4 byte) of data. Each line: flags, lowercase, uppercase, collation. */ -static struct _PDCLIB_ctype_t _ctype[] = { +static const _PDCLIB_ctype_t global_ctype[] = { { /* EOF */ 0, 0, 0, 0 }, { /* NUL */ _PDCLIB_CTYPE_CNTRL, 0x00, 0x00, 0x00 }, { /* SOH */ _PDCLIB_CTYPE_CNTRL, 0x01, 0x01, 0x01 }, @@ -304,39 +342,42 @@ static struct _PDCLIB_ctype_t _ctype[] = { { 0x00, 0xFF, 0xFF, 0xFF } }; -struct lconv _PDCLIB_lconv = { - /* _PDCLIB_ctype */ _ctype + 1, - /* _PDCLIB_errno_texts */ - { +extern const struct _PDCLIB_charcodec _PDCLIB_ascii_codec; +struct _PDCLIB_locale _PDCLIB_global_locale = { + ._Codec = &_PDCLIB_ascii_codec, + ._Conv = { + /* 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, + }, + ._CType = &global_ctype[1], + ._ErrnoStr = { /* 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 diff --git a/platform/example/functions/signal/signal.c b/platform/example/functions/signal/signal.c index e07877d..aae95a9 100644 --- a/platform/example/functions/signal/signal.c +++ b/platform/example/functions/signal/signal.c @@ -11,6 +11,7 @@ #ifndef REGTEST #include +#include void (*_PDCLIB_sigabrt)( int ) = SIG_DFL; void (*_PDCLIB_sigfpe)( int ) = SIG_DFL; @@ -53,10 +54,7 @@ void (*signal( int sig, void (*func)( int ) ) )( int ) _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; + errno = EINVAL; return SIG_ERR; } return oldhandler; diff --git a/platform/example/functions/stdio/tmpfile.c b/platform/example/functions/stdio/tmpfile.c index 3f384e7..94351ca 100644 --- a/platform/example/functions/stdio/tmpfile.c +++ b/platform/example/functions/stdio/tmpfile.c @@ -13,11 +13,9 @@ #include #include <_PDCLIB_glue.h> -extern struct _PDCLIB_file_t * _PDCLIB_filelist; - /* This is a stub implementation of tmpfile */ -struct _PDCLIB_file_t * tmpfile( void ) +FILE* tmpfile( void ) { errno = ENOTSUP; return NULL; diff --git a/platform/example/internals/_PDCLIB_config.h b/platform/example/internals/_PDCLIB_config.h index 00dbc24..047fd94 100644 --- a/platform/example/internals/_PDCLIB_config.h +++ b/platform/example/internals/_PDCLIB_config.h @@ -55,7 +55,11 @@ /* compiler manuals. */ #define _PDCLIB_SHRT_BYTES 2 #define _PDCLIB_INT_BYTES 4 -#define _PDCLIB_LONG_BYTES 4 +#if defined(__LP64__) || defined(_LP64) +# define _PDCLIB_LONG_BYTES 8 +#else +# define _PDCLIB_LONG_BYTES 4 +#endif #define _PDCLIB_LLONG_BYTES 8 /* defines the div() function family that allows taking quotient */ @@ -125,8 +129,8 @@ struct _PDCLIB_lldiv_t /* -------------------------------------------------------------------------- */ /* The result type of substracting two pointers */ -#define _PDCLIB_ptrdiff int -#define _PDCLIB_PTRDIFF INT +#define _PDCLIB_ptrdiff long +#define _PDCLIB_PTRDIFF LONG #define _PDCLIB_PTR_CONV /* An integer type that can be accessed as atomic entity (think asynchronous @@ -137,8 +141,8 @@ struct _PDCLIB_lldiv_t #define _PDCLIB_SIG_ATOMIC INT /* Result type of the 'sizeof' operator (must be unsigned) */ -#define _PDCLIB_size unsigned int -#define _PDCLIB_SIZE UINT +#define _PDCLIB_size unsigned long +#define _PDCLIB_SIZE ULONG /* Large enough an integer to hold all character codes of the largest supported locale. @@ -147,8 +151,8 @@ struct _PDCLIB_lldiv_t #define _PDCLIB_wchar unsigned int #define _PDCLIB_WCHAR UINT -#define _PDCLIB_intptr int -#define _PDCLIB_INTPTR INT +#define _PDCLIB_intptr long +#define _PDCLIB_INTPTR LONG /* Largest supported integer type. Implementation note: see _PDCLIB_atomax(). */ #define _PDCLIB_intmax long long int @@ -236,6 +240,22 @@ struct _PDCLIB_imaxdiv_t */ #define _PDCLIB_DECIMAL_DIG 17 +/* Floating point types + * + * PDCLib (at present) assumes IEEE 754 floating point formats + * The following names are used: + * SINGLE: IEEE 754 single precision (32-bit) + * DOUBLE: IEEE 754 double precision (64-bit) + * EXTENDED: IEEE 754 extended precision (80-bit, as x87) + */ +#define _PDCLIB_FLOAT_TYPE SINGLE +#define _PDCLIB_DOUBLE_TYPE DOUBLE +#if defined(__i386__) || defined(__amd64__) + #define _PDCLIB_LDOUBLE_TYPE EXTENDED +#else + #define _PDCLIB_LDOUBLE_TYPE DOUBLE +#endif + /* -------------------------------------------------------------------------- */ /* Platform-dependent macros defined by the standard headers. */ /* -------------------------------------------------------------------------- */ @@ -291,15 +311,15 @@ typedef char * _PDCLIB_va_list; /* TODO: Better document these */ -/* I/O ---------------------------------------------------------------------- */ +/* Locale --------------------------------------------------------------------*/ -/* The type of the file descriptor returned by _PDCLIB_open(). */ -typedef int _PDCLIB_fd_t; +/* Locale method. See _PDCLIB_locale.h */ +/* #define _PDCLIB_LOCALE_METHOD _PDCLIB_LOCALE_METHOD_TSS */ -/* The value (of type _PDCLIB_fd_t) returned by _PDCLIB_open() if the operation - failed. -*/ -#define _PDCLIB_NOHANDLE ( (_PDCLIB_fd_t) -1 ) +/* wchar_t encoding */ +#define _PDCLIB_WCHAR_ENCODING _PDCLIB_WCHAR_ENCODING_UCS4 + +/* I/O ---------------------------------------------------------------------- */ /* The default size for file buffers. Must be at least 256. */ #define _PDCLIB_BUFSIZ 1024 diff --git a/platform/win32/internals/_PDCLIB_config.h b/platform/win32/internals/_PDCLIB_config.h index 9e69353..ea5ef47 100644 --- a/platform/win32/internals/_PDCLIB_config.h +++ b/platform/win32/internals/_PDCLIB_config.h @@ -335,7 +335,9 @@ struct _PDCLIB_imaxdiv_t /* Locale --------------------------------------------------------------------*/ -/* Locale method. See _PDCLIB_locale.h */ +/* Locale method. See _PDCLIB_locale.h. If undefined, POSIX per-thread locales + * will be disabled + */ #define _PDCLIB_LOCALE_METHOD _PDCLIB_LOCALE_METHOD_TSS /* wchar_t encoding */ -- 2.40.0