From d7f375a09a9912bb18ad42f1442fbf64311bfed6 Mon Sep 17 00:00:00 2001 From: Martin Baute Date: Sun, 13 Mar 2016 08:37:59 +0100 Subject: [PATCH] Sweeping cleanups. Sorry for the massive commit; I got sidetracked once too often. --- .../functions => functions}/signal/raise.c | 0 .../functions => functions}/signal/signal.c | 3 +- includes/assert.h | 20 +- includes/ctype.h | 12 +- includes/float.h | 85 ++++-- includes/inttypes.h | 29 +- includes/iso646.h | 3 +- includes/limits.h | 12 +- includes/locale.h | 25 +- includes/stdalign.h | 17 ++ includes/stdarg.h | 11 +- includes/stdbool.h | 9 +- includes/stddef.h | 11 +- includes/stdint.h | 49 ++- includes/stdio.h | 14 +- includes/stdlib.h | 14 +- includes/string.h | 12 +- includes/threads.h | 218 +++++++------- includes/time.h | 117 +++++--- includes/uchar.h | 87 ++---- includes/wchar.h | 282 +++++++++--------- includes/wctype.h | 112 ++++--- internals/_PDCLIB_aux.h | 10 +- internals/_PDCLIB_encoding.h | 1 + internals/_PDCLIB_float.h | 6 +- internals/_PDCLIB_glue.h | 20 +- internals/_PDCLIB_int.h | 53 ++-- internals/_PDCLIB_io.h | 13 +- internals/_PDCLIB_locale.h | 10 +- opt/c_locale/_PDCLIB_clocale.h | 8 +- opt/nothread/_PDCLIB_threadconfig.h | 8 +- opt/pthreads/_PDCLIB_threadconfig.h | 4 +- opt/tss_errno/errno.h | 10 +- platform/example/functions/signal/signal.c | 71 ----- platform/example/includes/signal.h | 2 +- platform/gandr/functions/signal/raise.c | 112 ------- platform/gandr/functions/signal/signal.c | 71 ----- platform/gandr/includes/_PDCLIB_config.h | 262 +++++++++++++--- platform/gandr/includes/signal.h | 2 +- platform/posix/functions/signal/raise.c | 112 ------- platform/posix/includes/signal.h | 2 +- platform/posix/internals/_PDCLIB_config.h | 91 ++++-- platform/win32/functions/signal/raise.c | 112 ------- platform/win32/functions/signal/signal.c | 74 ----- platform/win32/includes/signal.h | 2 +- platform/win32/internals/_PDCLIB_config.h | 130 ++++---- .../win32/internals/_PDCLIB_threadconfig.h | 8 +- 47 files changed, 1109 insertions(+), 1227 deletions(-) rename {platform/example/functions => functions}/signal/raise.c (100%) rename {platform/posix/functions => functions}/signal/signal.c (98%) create mode 100644 includes/stdalign.h delete mode 100644 platform/example/functions/signal/signal.c delete mode 100644 platform/gandr/functions/signal/raise.c delete mode 100644 platform/gandr/functions/signal/signal.c delete mode 100644 platform/posix/functions/signal/raise.c delete mode 100644 platform/win32/functions/signal/raise.c delete mode 100644 platform/win32/functions/signal/signal.c diff --git a/platform/example/functions/signal/raise.c b/functions/signal/raise.c similarity index 100% rename from platform/example/functions/signal/raise.c rename to functions/signal/raise.c diff --git a/platform/posix/functions/signal/signal.c b/functions/signal/signal.c similarity index 98% rename from platform/posix/functions/signal/signal.c rename to functions/signal/signal.c index 56aada5..e677af5 100644 --- a/platform/posix/functions/signal/signal.c +++ b/functions/signal/signal.c @@ -5,10 +5,9 @@ */ #include +#include #ifndef REGTEST -#include -#include void (*_PDCLIB_sigabrt)( int ) = SIG_DFL; void (*_PDCLIB_sigfpe)( int ) = SIG_DFL; diff --git a/includes/assert.h b/includes/assert.h index 44b30b8..ffb3948 100644 --- a/includes/assert.h +++ b/includes/assert.h @@ -1,4 +1,4 @@ -/* 7.2 Diagnostics +/* Diagnostics This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -14,22 +14,28 @@ evaluates to true; * print an error message and terminates the program if NDEBUG is not set AND the parameter expression evaluates to false. - The error message contains the parameter expression, name of the source file + The error message contains the parameter expression, name of the source file (__FILE__), line number (__LINE__), and (from C99 onward) name of the function (__func__). - The header can be included MULTIPLE times, and redefines the macro depending + The header can be included MULTIPLE times, and redefines the macro depending on the current setting of NDEBUG. */ -_PDCLIB_BEGIN_EXTERN_C - #ifndef _PDCLIB_ASSERT_H #define _PDCLIB_ASSERT_H _PDCLIB_ASSERT_H +#ifdef __cplusplus +extern "C" { +#endif + /* Functions _NOT_ tagged noreturn as this hampers debugging */ void _PDCLIB_assert99( char const * const, char const * const, char const * const ); void _PDCLIB_assert89( char const * const ); +#ifdef __cplusplus +} +#endif + #if _PDCLIB_C_VERSION >= 2011 #define static_assert _Static_assert #else @@ -54,7 +60,7 @@ void _PDCLIB_assert89( char const * const ); _PDCLIB_UNREACHABLE; \ } \ } while(0) - + #else #define assert(expression) \ do { if(!(expression)) { \ @@ -66,5 +72,3 @@ void _PDCLIB_assert89( char const * const ); } \ } while(0) #endif - -_PDCLIB_END_EXTERN_C diff --git a/includes/ctype.h b/includes/ctype.h index f0accf0..f55d18b 100644 --- a/includes/ctype.h +++ b/includes/ctype.h @@ -1,4 +1,4 @@ -/* 7.4 Character handling +/* Character handling This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -7,7 +7,10 @@ #ifndef _PDCLIB_CTYPE_H #define _PDCLIB_CTYPE_H _PDCLIB_CTYPE_H #include <_PDCLIB_int.h> -_PDCLIB_BEGIN_EXTERN_C + +#ifdef __cplusplus +extern "C" { +#endif /* Character classification functions */ @@ -90,5 +93,8 @@ int tolower( int c ) _PDCLIB_nothrow; */ int toupper( int c ) _PDCLIB_nothrow; -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} +#endif + #endif diff --git a/includes/float.h b/includes/float.h index baac7e6..fb485a4 100644 --- a/includes/float.h +++ b/includes/float.h @@ -1,4 +1,4 @@ -/* 7.7 Characteristics of floating types +/* Characteristics of floating types This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -12,63 +12,90 @@ #define FLT_EVAL_METHOD _PDCLIB_FLT_EVAL_METHOD #define DECIMAL_DIG _PDCLIB_DECIMAL_DIG - /* Radix of exponent representation */ +/* Radix of exponent representation */ #define FLT_RADIX _PDCLIB_FLT_RADIX - /* Number of base-FLT_RADIX digits in the significand of a float */ + +/* Number of base-FLT_RADIX digits in the significand of a float */ #define FLT_MANT_DIG _PDCLIB_FLT_MANT_DIG - /* Number of decimal digits of precision in a float */ + +/* Number of decimal digits of precision in a float */ #define FLT_DIG _PDCLIB_FLT_DIG - /* Difference between 1.0 and the minimum float greater than 1.0 */ + +/* Difference between 1.0 and the minimum float greater than 1.0 */ #define FLT_EPSILON _PDCLIB_FLT_EPSILON - /* Minimum int x such that FLT_RADIX**(x-1) is a normalised float */ + +/* Minimum int x such that FLT_RADIX**(x-1) is a normalised float */ #define FLT_MIN_EXP _PDCLIB_FLT_MIN_EXP - /* Minimum normalised float */ + +/* Minimum normalised float */ #define FLT_MIN _PDCLIB_FLT_MIN - /* Minimum int x such that 10**x is a normalised float */ + +/* Minimum int x such that 10**x is a normalised float */ #define FLT_MIN_10_EXP _PDCLIB_FLT_MIN_10_EXP - /* Maximum int x such that FLT_RADIX**(x-1) is a representable float */ + +/* Maximum int x such that FLT_RADIX**(x-1) is a representable float */ #define FLT_MAX_EXP _PDCLIB_FLT_MAX_EXP - /* Maximum float */ + +/* Maximum float */ #define FLT_MAX _PDCLIB_FLT_MAX - /* Maximum int x such that 10**x is a representable float */ + +/* Maximum int x such that 10**x is a representable float */ #define FLT_MAX_10_EXP _PDCLIB_FLT_MAX_10_EXP - /* Number of base-FLT_RADIX digits in the significand of a double */ + +/* Number of base-FLT_RADIX digits in the significand of a double */ #define DBL_MANT_DIG _PDCLIB_DBL_MANT_DIG - /* Number of decimal digits of precision in a double */ + +/* Number of decimal digits of precision in a double */ #define DBL_DIG _PDCLIB_DBL_DIG - /* Difference between 1.0 and the minimum double greater than 1.0 */ + +/* Difference between 1.0 and the minimum double greater than 1.0 */ #define DBL_EPSILON _PDCLIB_DBL_EPSILON - /* Minimum int x such that FLT_RADIX**(x-1) is a normalised double */ + +/* Minimum int x such that FLT_RADIX**(x-1) is a normalised double */ #define DBL_MIN_EXP _PDCLIB_DBL_MIN_EXP - /* Minimum normalised double */ + +/* Minimum normalised double */ #define DBL_MIN _PDCLIB_DBL_MIN - /* Minimum int x such that 10**x is a normalised double */ + +/* Minimum int x such that 10**x is a normalised double */ #define DBL_MIN_10_EXP _PDCLIB_DBL_MIN_10_EXP - /* Maximum int x such that FLT_RADIX**(x-1) is a representable double */ + +/* Maximum int x such that FLT_RADIX**(x-1) is a representable double */ #define DBL_MAX_EXP _PDCLIB_DBL_MAX_EXP - /* Maximum double */ + +/* Maximum double */ #define DBL_MAX _PDCLIB_DBL_MAX - /* Maximum int x such that 10**x is a representable double */ + +/* Maximum int x such that 10**x is a representable double */ #define DBL_MAX_10_EXP _PDCLIB_DBL_MAX_10_EXP - /* Number of base-FLT_RADIX digits in the significand of a long double */ + +/* Number of base-FLT_RADIX digits in the significand of a long double */ #define LDBL_MANT_DIG _PDCLIB_LDBL_MANT_DIG - /* Number of decimal digits of precision in a long double */ + +/* Number of decimal digits of precision in a long double */ #define LDBL_DIG _PDCLIB_LDBL_DIG - /* Difference between 1.0 and the minimum long double greater than 1.0 */ + +/* Difference between 1.0 and the minimum long double greater than 1.0 */ #define LDBL_EPSILON _PDCLIB_LDBL_EPSILON - /* Minimum int x such that FLT_RADIX**(x-1) is a normalised long double */ + +/* Minimum int x such that FLT_RADIX**(x-1) is a normalised long double */ #define LDBL_MIN_EXP _PDCLIB_LDBL_MIN_EXP - /* Minimum normalised long double */ + +/* Minimum normalised long double */ #define LDBL_MIN _PDCLIB_LDBL_MIN - /* Minimum int x such that 10**x is a normalised long double */ + +/* Minimum int x such that 10**x is a normalised long double */ #define LDBL_MIN_10_EXP _PDCLIB_LDBL_MIN_10_EXP - /* Maximum int x such that FLT_RADIX**(x-1) is a representable long double */ + +/* Maximum int x such that FLT_RADIX**(x-1) is a representable long double */ #define LDBL_MAX_EXP _PDCLIB_LDBL_MAX_EXP - /* Maximum long double */ + +/* Maximum long double */ #define LDBL_MAX _PDCLIB_LDBL_MAX - /* Maximum int x such that 10**x is a representable long double */ + +/* Maximum int x such that 10**x is a representable long double */ #define LDBL_MAX_10_EXP _PDCLIB_LDBL_MAX_10_EXP #endif diff --git a/includes/inttypes.h b/includes/inttypes.h index 0c6830e..f13db1b 100644 --- a/includes/inttypes.h +++ b/includes/inttypes.h @@ -1,4 +1,4 @@ -/* 7.8 Format conversion of integer types +/* Format conversion of integer types This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -7,8 +7,15 @@ #ifndef _PDCLIB_INTTYPES_H #define _PDCLIB_INTTYPES_H _PDCLIB_INTTYPES_H #include -_PDCLIB_BEGIN_EXTERN_C +#ifdef __cplusplus +extern "C" { +#endif + +/* This structure has a member quot and a member rem, of type intmax_t. + The order of the members is platform-defined to allow the imaxdiv() + function below to be implemented efficiently. +*/ typedef struct _PDCLIB_imaxdiv_t imaxdiv_t; #define PRId8 _PDCLIB_symbol2string( _PDCLIB_concat( _PDCLIB_8_CONV, d ) ) @@ -209,7 +216,7 @@ typedef struct _PDCLIB_imaxdiv_t imaxdiv_t; #define SCNxMAX _PDCLIB_symbol2string( _PDCLIB_concat( _PDCLIB_MAX_CONV, x ) ) #define SCNxPTR _PDCLIB_symbol2string( _PDCLIB_concat( _PDCLIB_PTR_CONV, x ) ) -/* 7.8.2 Functions for greatest-width integer types */ +/* Functions for greatest-width integer types */ /* Calculate the absolute value of j */ intmax_t imaxabs( intmax_t j ) _PDCLIB_nothrow; @@ -238,14 +245,24 @@ imaxdiv_t imaxdiv( intmax_t numer, intmax_t denom ) _PDCLIB_nothrow; respectively, depending on the sign of the integer representation and the return type, and errno is set to ERANGE. */ -/* This function is equivalent to strtol() / strtoul() in , but on + +/* These functions are equivalent to strtol() / strtoul() in , but on the potentially larger type. */ intmax_t strtoimax( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ) _PDCLIB_nothrow; uintmax_t strtoumax( const char * _PDCLIB_restrict nptr, char * * _PDCLIB_restrict endptr, int base ) _PDCLIB_nothrow; -/* TODO: wcstoimax(), wcstoumax() */ +/* These functions are equivalent to wcstol() / wcstoul() in , but on + the potentially larger type. +*/ +/* TODO: Not _PDCLIB_nothrow? */ +/* +intmax_t wcstoimax( const _PDCLIB_wchar_t * _PDCLIB_restrict nptr, _PDCLIB_wchar_t * * _PDCLIB_restrict endptr, int base ); +uintmax_t wcstoumax( const _PDCLIB_wchar_t * _PDCLIB_restrict nptr, _PDCLIB_wchar_t * * _PDCLIB_restrict endptr, int base ); +*/ -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} #endif +#endif diff --git a/includes/iso646.h b/includes/iso646.h index 4fd338b..3ad9f5c 100644 --- a/includes/iso646.h +++ b/includes/iso646.h @@ -1,4 +1,4 @@ -/* 7.9 Alternative spellings +/* Alternative spellings This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -22,4 +22,3 @@ #endif #endif - diff --git a/includes/limits.h b/includes/limits.h index c81ddec..e305705 100644 --- a/includes/limits.h +++ b/includes/limits.h @@ -1,4 +1,4 @@ -/* 7.10 Sizes of integer types +/* Sizes of integer types This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -8,8 +8,13 @@ #define _PDCLIB_LIMITS_H _PDCLIB_LIMITS_H #include <_PDCLIB_int.h> -/* TODO: Defined to 1 as multibyte characters are not supported yet. */ -#define MB_LEN_MAX 1 +/* MSVC 2010 defines this to 5, which is enough for UTF-8 but might rule out + stateful encodings (like ISO/IEC 2022). GCC 5.3 defines this to 16, which + is meant to ensure future compatibility. For the same reason, we go along + with GCC's definition. + http://lists.gnu.org/archive/html/bug-gnulib/2015-05/msg00001.html +*/ +#define MB_LEN_MAX 16 #define LLONG_MIN _PDCLIB_LLONG_MIN #define LLONG_MAX _PDCLIB_LLONG_MAX @@ -32,4 +37,3 @@ #define ULONG_MAX _PDCLIB_ULONG_MAX #endif - diff --git a/includes/locale.h b/includes/locale.h index 351807f..616e84e 100644 --- a/includes/locale.h +++ b/includes/locale.h @@ -1,4 +1,4 @@ -/* 7.11 Localization +/* Localization This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -7,7 +7,10 @@ #ifndef _PDCLIB_LOCALE_H #define _PDCLIB_LOCALE_H _PDCLIB_LOCALE_H #include <_PDCLIB_int.h> -_PDCLIB_BEGIN_EXTERN_C + +#ifdef __cplusplus +extern "C" { +#endif #ifndef _PDCLIB_NULL_DEFINED #define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED @@ -95,7 +98,7 @@ struct lconv * localeconv( void ) _PDCLIB_nothrow; #define LC_CTYPE_MASK (1 << LC_CTYPE) #define LC_MONETARY_MASK (1 << LC_MONETARY) #define LC_NUMERIC_MASK (1 << LC_NUMERIC) -#define LC_TIME_MASK (1 << LC_TIME) +#define LC_TIME_MASK (1 << LC_TIME) #define LC_ALL_MASK (LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MONETARY_MASK | \ LC_NUMERIC_MASK | LC_TIME_MASK) @@ -109,30 +112,32 @@ extern struct _PDCLIB_locale _PDCLIB_global_locale; #ifdef _PDCLIB_LOCALE_METHOD -locale_t newlocale(int category_mask, const char *locale, locale_t base); +locale_t newlocale(int category_mask, const char *locale, locale_t base); /* Set the thread locale to newlocale * * If newlocale is (locale_t)0, then doesn't change the locale and just returns * the existing locale. * - * If newlocale is LC_GLOBAL_LOCALE, resets the thread's locale to use the + * If newlocale is LC_GLOBAL_LOCALE, resets the thread's locale to use the * global locale. * - * Returns the previous thread locale. If the thread had no previous locale, + * Returns the previous thread locale. If the thread had no previous locale, * returns the global locale. */ -locale_t uselocale(locale_t newlocale); +locale_t uselocale( locale_t newlocale ); /* Returns a copy of loc */ -locale_t duplocale(locale_t loc); +locale_t duplocale( locale_t loc ); /* Frees the passed locale object */ -void freelocale(locale_t loc); +void freelocale( locale_t loc ); #endif #endif -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} #endif +#endif diff --git a/includes/stdalign.h b/includes/stdalign.h new file mode 100644 index 0000000..0bc20f6 --- /dev/null +++ b/includes/stdalign.h @@ -0,0 +1,17 @@ +/* Alignmend + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_STDALIGN_H +#define _PDCLIB_ALIGN_H _PDCLIB_ALIGN_H + +#define alignas _Alignas +#define alignof _Alignof + +#define __alignas_is_defined 1 +#define __alignof_is_defined 1 + +#endif + diff --git a/includes/stdarg.h b/includes/stdarg.h index bbce55a..cc63123 100644 --- a/includes/stdarg.h +++ b/includes/stdarg.h @@ -1,4 +1,4 @@ -/* 7.15 Variable arguments +/* Variable arguments This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -8,7 +8,10 @@ #define _PDCLIB_STDARG_H _PDCLIB_STDARG_H #include <_PDCLIB_aux.h> #include <_PDCLIB_config.h> -_PDCLIB_BEGIN_EXTERN_C + +#ifdef __cplusplus +extern "C" { +#endif typedef _PDCLIB_va_list va_list; @@ -17,6 +20,8 @@ typedef _PDCLIB_va_list va_list; #define va_end( ap ) _PDCLIB_va_end( ap ) #define va_start( ap, parmN ) _PDCLIB_va_start( ap, parmN ) -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} #endif +#endif diff --git a/includes/stdbool.h b/includes/stdbool.h index afe5c74..daec901 100644 --- a/includes/stdbool.h +++ b/includes/stdbool.h @@ -1,4 +1,4 @@ -/* 7.16 Boolean type and values +/* Boolean type and values This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -8,12 +8,11 @@ #define _PDCLIB_STDBOOL_H _PDCLIB_STDBOOL_H #ifndef __cplusplus -#define bool _Bool -#define true 1 -#define false 0 +#define bool _Bool +#define true 1 +#define false 0 #endif #define __bool_true_false_are_defined 1 #endif - diff --git a/includes/stddef.h b/includes/stddef.h index d18fcf6..f5c91e7 100644 --- a/includes/stddef.h +++ b/includes/stddef.h @@ -1,4 +1,4 @@ -/* 7.17 Common definitions +/* Common definitions This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -8,7 +8,10 @@ #define _PDCLIB_STDDEF_H _PDCLIB_STDDEF_H #include <_PDCLIB_config.h> #include <_PDCLIB_int.h> -_PDCLIB_BEGIN_EXTERN_C + +#ifdef __cplusplus +extern "C" { +#endif typedef _PDCLIB_ptrdiff_t ptrdiff_t; @@ -31,6 +34,8 @@ typedef _PDCLIB_wchar_t wchar_t; #define offsetof( type, member ) _PDCLIB_offsetof( type, member ) -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} #endif +#endif diff --git a/includes/stdint.h b/includes/stdint.h index 3516b96..9cb603e 100644 --- a/includes/stdint.h +++ b/includes/stdint.h @@ -1,4 +1,4 @@ -/* 7.18 Integer types +/* Integer types This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -8,7 +8,7 @@ #define _PDCLIB_STDINT_H _PDCLIB_STDINT_H #include <_PDCLIB_int.h> -/* 7.18.1.1 Exact-width integer types. */ +/* Exact-width integer types. */ typedef _PDCLIB_int8_t int8_t; typedef _PDCLIB_int16_t int16_t; @@ -20,24 +20,24 @@ typedef _PDCLIB_uint16_t uint16_t; typedef _PDCLIB_uint32_t uint32_t; typedef _PDCLIB_uint64_t uint64_t; -/* 7.18.1.2 Minimum-width integer types */ +/* Minimum-width integer types */ /* You are allowed to add more types here, e.g. int_least24_t. For the standard types, int_leastN_t is equivalent to the corresponding exact type intN_t by definition. */ -typedef int8_t int_least8_t; -typedef int16_t int_least16_t; -typedef int32_t int_least32_t; -typedef int64_t int_least64_t; +typedef _PDCLIB_int8_t int_least8_t; +typedef _PDCLIB_int16_t int_least16_t; +typedef _PDCLIB_int32_t int_least32_t; +typedef _PDCLIB_int64_t int_least64_t; -typedef uint8_t uint_least8_t; -typedef uint16_t uint_least16_t; -typedef uint32_t uint_least32_t; -typedef uint64_t uint_least64_t; +typedef _PDCLIB_uint8_t uint_least8_t; +typedef _PDCLIB_uint16_t uint_least16_t; +typedef _PDCLIB_uint32_t uint_least32_t; +typedef _PDCLIB_uint64_t uint_least64_t; -/* 7.18.1.3 Fastest minimum-width integer types */ +/* Fastest minimum-width integer types */ /* You are allowed to add more types here, e.g. int_fast24_t. */ @@ -51,17 +51,17 @@ typedef _PDCLIB_uint_fast16_t uint_fast16_t; typedef _PDCLIB_uint_fast32_t uint_fast32_t; typedef _PDCLIB_uint_fast64_t uint_fast64_t; -/* 7.18.1.4 Integer types capable of holding object pointers */ +/* Integer types capable of holding object pointers */ typedef _PDCLIB_intptr_t intptr_t; typedef _PDCLIB_uintptr_t uintptr_t; -/* 7.18.1.5 Greatest-width integer types */ +/* Greatest-width integer types */ typedef _PDCLIB_intmax_t intmax_t; typedef _PDCLIB_uintmax_t uintmax_t; -/* 7.18.2 Limits of specified-width integer types */ +/* Limits of specified-width integer types */ #ifdef __cplusplus #ifndef __STDC_LIMIT_MACROS @@ -71,7 +71,7 @@ typedef _PDCLIB_uintmax_t uintmax_t; #ifndef _PDCLIB_NO_LIMIT_MACROS -/* 7.18.2.1 Limits of exact-width integer types */ +/* Limits of exact-width integer types */ #define INT8_MIN _PDCLIB_INT8_MIN #define INT8_MAX _PDCLIB_INT8_MAX @@ -89,7 +89,7 @@ typedef _PDCLIB_uintmax_t uintmax_t; #define INT64_MAX _PDCLIB_INT64_MAX #define UINT64_MAX _PDCLIB_UINT64_MAX -/* 7.18.2.2 Limits of minimum-width integer types */ +/* Limits of minimum-width integer types */ /* For the standard widths, least and exact types are equivalent. You are allowed to add more types here, e.g. int_least24_t. @@ -111,7 +111,7 @@ typedef _PDCLIB_uintmax_t uintmax_t; #define INT_LEAST64_MAX INT64_MAX #define UINT_LEAST64_MAX UINT64_MAX -/* 7.18.2.3 Limits of fastest minimum-width integer types */ +/* Limits of fastest minimum-width integer types */ #define INT_FAST8_MIN _PDCLIB_INT_FAST8_MIN #define INT_FAST8_MAX _PDCLIB_INT_FAST8_MAX @@ -129,19 +129,19 @@ typedef _PDCLIB_uintmax_t uintmax_t; #define INT_FAST64_MAX _PDCLIB_INT_FAST64_MAX #define UINT_FAST64_MAX _PDCLIB_UINT_FAST64_MAX -/* 7.18.2.4 Limits of integer types capable of holding object pointers */ +/* Limits of integer types capable of holding object pointers */ #define INTPTR_MIN _PDCLIB_INTPTR_MIN #define INTPTR_MAX _PDCLIB_INTPTR_MAX #define UINTPTR_MAX _PDCLIB_UINTPTR_MAX -/* 7.18.2.5 Limits of greatest-width integer types */ +/* Limits of greatest-width integer types */ #define INTMAX_MIN _PDCLIB_INTMAX_MIN #define INTMAX_MAX _PDCLIB_INTMAX_MAX #define UINTMAX_MAX _PDCLIB_UINTMAX_MAX -/* 7.18.3 Limits of other integer types */ +/* Limits of other integer types */ #define PTRDIFF_MIN _PDCLIB_PTRDIFF_MIN #define PTRDIFF_MAX _PDCLIB_PTRDIFF_MAX @@ -162,7 +162,7 @@ typedef _PDCLIB_uintmax_t uintmax_t; #endif -/* 7.18.4 Macros for integer constants */ +/* Macros for integer constants */ #ifdef __cplusplus #ifndef __STDC_CONSTANT_MACROS @@ -172,7 +172,7 @@ typedef _PDCLIB_uintmax_t uintmax_t; #ifndef _PDCLIB_NO_CONSTANT_MACROS -/* 7.18.4.1 Macros for minimum-width integer constants */ +/* Macros for minimum-width integer constants */ /* As the minimum-width types - for the required widths of 8, 16, 32, and 64 bits - are expressed in terms of the exact-width types, the mechanism for @@ -196,7 +196,7 @@ typedef _PDCLIB_uintmax_t uintmax_t; #define UINT32_C( value ) _PDCLIB_concat( value, _PDCLIB_UINT32_LITERAL ) #define UINT64_C( value ) _PDCLIB_concat( value, _PDCLIB_UINT64_LITERAL ) -/* 7.18.4.2 Macros for greatest-width integer constants */ +/* Macros for greatest-width integer constants */ /* Expand to an integer constant of specified value and type intmax_t */ #define INTMAX_C( value ) _PDCLIB_INTMAX_C( value ) @@ -207,4 +207,3 @@ typedef _PDCLIB_uintmax_t uintmax_t; #endif #endif - diff --git a/includes/stdio.h b/includes/stdio.h index 954644b..5952ec7 100644 --- a/includes/stdio.h +++ b/includes/stdio.h @@ -1,4 +1,4 @@ -/* 7.19 Input/output +/* Input/output This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -7,7 +7,10 @@ #ifndef _PDCLIB_STDIO_H #define _PDCLIB_STDIO_H _PDCLIB_STDIO_H #include <_PDCLIB_int.h> -_PDCLIB_BEGIN_EXTERN_C + +#ifdef __cplusplus +extern "C" { +#endif #ifndef _PDCLIB_SIZE_T_DEFINED #define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED @@ -886,7 +889,6 @@ void rewind_unlocked( FILE * stream ) _PDCLIB_nothrow; int puts_unlocked( const char * s ) _PDCLIB_nothrow; int ungetc_unlocked( int c, FILE * stream ) _PDCLIB_nothrow; - int printf_unlocked( const char * _PDCLIB_restrict format, ... ) _PDCLIB_nothrow; int vprintf_unlocked( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) _PDCLIB_nothrow; int fprintf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ) _PDCLIB_nothrow; @@ -896,11 +898,13 @@ int vscanf_unlocked( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) int fscanf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ) _PDCLIB_nothrow; int vfscanf_unlocked( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) _PDCLIB_nothrow; - // Todo: remove prefix? _PDCLIB_uint_fast64_t _PDCLIB_ftell64( FILE * stream ) _PDCLIB_nothrow; _PDCLIB_uint_fast64_t _PDCLIB_ftell64_unlocked( FILE * stream ) _PDCLIB_nothrow; #endif -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} +#endif + #endif diff --git a/includes/stdlib.h b/includes/stdlib.h index 9ed464e..157ebee 100644 --- a/includes/stdlib.h +++ b/includes/stdlib.h @@ -1,4 +1,4 @@ -/* 7.20 General utilities +/* General utilities This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -7,7 +7,10 @@ #ifndef _PDCLIB_STDLIB_H #define _PDCLIB_STDLIB_H _PDCLIB_STDLIB_H #include <_PDCLIB_int.h> -_PDCLIB_BEGIN_EXTERN_C + +#ifdef __cplusplus +extern "C" { +#endif #ifndef _PDCLIB_SIZE_T_DEFINED #define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED @@ -148,7 +151,7 @@ _PDCLIB_noreturn void abort( void ) _PDCLIB_nothrow; reverse order of registration (last-in, first-out). Returns zero if registration is successfull, nonzero if it failed. */ -int atexit( void (*func)( void ) ) _PDCLIB_nothrow; +int atexit( void (*func)( void ) ) _PDCLIB_nothrow; /* Normal process termination. Functions registered by atexit() (see above) are called, streams flushed, files closed and temporary files removed before the @@ -248,5 +251,8 @@ size_t mbstowcs( wchar_t * _PDCLIB_restrict pwcs, const char * _PDCLIB_restrict size_t wcstombs( char * _PDCLIB_restrict s, const wchar_t * _PDCLIB_restrict pwcs, size_t n ); */ -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} +#endif + #endif diff --git a/includes/string.h b/includes/string.h index fcb1f3d..c0efcaf 100644 --- a/includes/string.h +++ b/includes/string.h @@ -1,4 +1,4 @@ -/* 7.21 String handling +/* String handling This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -7,7 +7,10 @@ #ifndef _PDCLIB_STRING_H #define _PDCLIB_STRING_H _PDCLIB_STRING_H #include <_PDCLIB_int.h> -_PDCLIB_BEGIN_EXTERN_C + +#ifdef __cplusplus +extern "C" { +#endif #ifndef _PDCLIB_SIZE_T_DEFINED #define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED @@ -206,5 +209,8 @@ size_t strlcat( size_t _DstSize) _PDCLIB_nothrow; #endif -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} +#endif + #endif diff --git a/includes/threads.h b/includes/threads.h index 77e39d4..1fd3d1c 100644 --- a/includes/threads.h +++ b/includes/threads.h @@ -1,102 +1,116 @@ -#ifndef _PDCLIB_THREADS_H -#define _PDCLIB_THREADS_H -#include <_PDCLIB_int.h> -#include <_PDCLIB_threadconfig.h> -#include -_PDCLIB_BEGIN_EXTERN_C - -#define thread_local _Thread_local - -typedef _PDCLIB_once_flag once_flag; - -enum { - mtx_plain = 0, - mtx_recursive = (1 << 0), - mtx_timed = (1 << 1), - - _PDCLIB_mtx_valid_mask = mtx_recursive | mtx_timed -}; - -enum { - thrd_success = 0, - thrd_timeout = 1, - thrd_busy = 2, - thrd_error = 3, - thrd_nomem = 4, -}; - -#define ONCE_FLAG_INIT _PDCLIB_ONCE_FLAG_INIT -#if defined(_PDCLIB_ONCE_FLAG_IS_DONE) -static inline void call_once(once_flag *flag, void (*func)(void)) -{ - if(!_PDCLIB_ONCE_FLAG_IS_DONE(flag)) { - _PDCLIB_call_once(flag, func); - } -} -#else -void call_once(once_flag *flag, void (*func)(void)); -#endif - -#if defined(_PDCLIB_MTX_T) -typedef _PDCLIB_MTX_T mtx_t; -void mtx_destroy(mtx_t *mtx) _PDCLIB_nothrow; -int mtx_init(mtx_t *mtx, int type) _PDCLIB_nothrow; -int mtx_lock(mtx_t *mtx) _PDCLIB_nothrow; -int mtx_timedlock(mtx_t *_PDCLIB_restrict mtx, const struct timespec *_PDCLIB_restrict ts) _PDCLIB_nothrow; -int mtx_trylock(mtx_t *mtx) _PDCLIB_nothrow; -int mtx_unlock(mtx_t *mtx) _PDCLIB_nothrow; -#endif - -#if defined(_PDCLIB_CND_T) -typedef _PDCLIB_CND_T cnd_t; -int cnd_broadcast(cnd_t *cond) _PDCLIB_nothrow; -void cnd_destroy(cnd_t *cond) _PDCLIB_nothrow; -int cnd_init(cnd_t *cond) _PDCLIB_nothrow; -int cnd_signal(cnd_t *cond) _PDCLIB_nothrow; -int cnd_timedwait(cnd_t *_PDCLIB_restrict cond, - mtx_t *_PDCLIB_restrict mtx, - const struct timespec *_PDCLIB_restrict ts) _PDCLIB_nothrow; -int cnd_wait(cnd_t *cond, mtx_t *mtx) _PDCLIB_nothrow; -#endif - -#if defined(_PDCLIB_THRD_T) -#define _PDCLIB_THRD_HAVE_MISC -typedef _PDCLIB_THRD_T thrd_t; -typedef int (*thrd_start_t)(void*); - -int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) _PDCLIB_nothrow; -thrd_t thrd_current(void) _PDCLIB_nothrow; -int thrd_detach(thrd_t thr) _PDCLIB_nothrow; -int thrd_equal(thrd_t thr0, thrd_t thr1) _PDCLIB_nothrow; - -/* Not nothrow: systems may use exceptions at thread exit */ -_PDCLIB_noreturn void thrd_exit(int res); -/* Not nothrow: systems may potentially propogate exceptions out of thrd_join?*/ -int thrd_join(thrd_t thr, int *res); -#endif - -#if defined(_PDCLIB_THRD_HAVE_MISC) -int thrd_sleep(const struct timespec *duration, struct timespec *remaining) _PDCLIB_nothrow; -void thrd_yield(void) _PDCLIB_nothrow; -#endif - -/* The behaviour of tss_t is woefully underspecified in the C11 standard. In - * particular, it never specifies where/when/if destructors are called. - * - * In lieu of any clarification, we assume the behaviour of POSIX pthread_key_t - */ - -#if defined(_PDCLIB_TSS_T) -#define TSS_DTOR_ITERATIONS _PDCLIB_TSS_DTOR_ITERATIONS - -typedef _PDCLIB_TSS_T tss_t; -typedef void (*tss_dtor_t)(void*); - -int tss_create(tss_t *key, tss_dtor_t dtor) _PDCLIB_nothrow; -void tss_delete(tss_t key) _PDCLIB_nothrow; -void *tss_get(tss_t key) _PDCLIB_nothrow; -int tss_set(tss_t key, void *val) _PDCLIB_nothrow; -#endif - -_PDCLIB_END_EXTERN_C -#endif +/* Threads + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_THREADS_H +#define _PDCLIB_THREADS_H _PDCLIB_THREADS_H +#include <_PDCLIB_int.h> +#include <_PDCLIB_threadconfig.h> + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define thread_local _Thread_local + +typedef _PDCLIB_once_flag once_flag; + +enum +{ + mtx_plain = 0, + mtx_recursive = (1 << 0), + mtx_timed = (1 << 1), + + _PDCLIB_mtx_valid_mask = mtx_recursive | mtx_timed +}; + +enum +{ + thrd_success = 0, + thrd_timeout = 1, + thrd_busy = 2, + thrd_error = 3, + thrd_nomem = 4, +}; + +#define ONCE_FLAG_INIT _PDCLIB_ONCE_FLAG_INIT +#ifdef _PDCLIB_ONCE_FLAG_IS_DONE +static inline void call_once( once_flag * flag, void (*func)( void ) ) +{ + if ( ! _PDCLIB_ONCE_FLAG_IS_DONE( flag ) ) + { + _PDCLIB_call_once( flag, func ); + } +} +#else +void call_once( once_flag * flag, void (*func)( void ) ); +#endif + +#ifdef _PDCLIB_MTX_T +typedef _PDCLIB_MTX_T mtx_t; +void mtx_destroy( mtx_t * mtx ) _PDCLIB_nothrow; +int mtx_init( mtx_t * mtx, int type ) _PDCLIB_nothrow; +int mtx_lock( mtx_t * mtx ) _PDCLIB_nothrow; +int mtx_timedlock( mtx_t * _PDCLIB_restrict mtx, const struct timespec * _PDCLIB_restrict ts ) _PDCLIB_nothrow; +int mtx_trylock( mtx_t * mtx ) _PDCLIB_nothrow; +int mtx_unlock( mtx_t * mtx ) _PDCLIB_nothrow; +#endif + +#ifdef _PDCLIB_CND_T +typedef _PDCLIB_CND_T cnd_t; +int cnd_broadcast( cnd_t * cond ) _PDCLIB_nothrow; +void cnd_destroy( cnd_t * cond ) _PDCLIB_nothrow; +int cnd_init( cnd_t * cond ) _PDCLIB_nothrow; +int cnd_signal( cnd_t * cond ) _PDCLIB_nothrow; +int cnd_timedwait( cnd_t *_PDCLIB_restrict cond, mtx_t * _PDCLIB_restrict mtx, const struct timespec * _PDCLIB_restrict ts ) _PDCLIB_nothrow; +int cnd_wait( cnd_t * cond, mtx_t * mtx ) _PDCLIB_nothrow; +#endif + +#ifdef _PDCLIB_THRD_T +#define _PDCLIB_THRD_HAVE_MISC +typedef _PDCLIB_THRD_T thrd_t; +typedef int (*thrd_start_t)( void * ); + +int thrd_create( thrd_t * thr, thrd_start_t func, void * arg ) _PDCLIB_nothrow; +thrd_t thrd_current( void ) _PDCLIB_nothrow; +int thrd_detach( thrd_t thr ) _PDCLIB_nothrow; +int thrd_equal( thrd_t thr0, thrd_t thr1 ) _PDCLIB_nothrow; + +/* Not nothrow: systems may use exceptions at thread exit */ +_PDCLIB_noreturn void thrd_exit( int res ); +/* Not nothrow: systems may potentially propogate exceptions out of thrd_join? */ +int thrd_join( thrd_t thr, int * res ); +#endif + +#ifdef _PDCLIB_THRD_HAVE_MISC +int thrd_sleep( const struct timespec * duration, struct timespec * remaining ) _PDCLIB_nothrow; +void thrd_yield( void ) _PDCLIB_nothrow; +#endif + +/* The behaviour of tss_t is woefully underspecified in the C11 standard. In + particular, it never specifies where/when/if destructors are called. + + In lieu of any clarification, we assume the behaviour of POSIX pthread_key_t +*/ + +#ifdef _PDCLIB_TSS_T +#define TSS_DTOR_ITERATIONS _PDCLIB_TSS_DTOR_ITERATIONS + +typedef _PDCLIB_TSS_T tss_t; +typedef void (*tss_dtor_t)( void * ); + +int tss_create( tss_t * key, tss_dtor_t dtor ) _PDCLIB_nothrow; +void tss_delete( tss_t key ) _PDCLIB_nothrow; +void * tss_get( tss_t key ) _PDCLIB_nothrow; +int tss_set( tss_t key, void * val ) _PDCLIB_nothrow; +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/includes/time.h b/includes/time.h index 41075db..5d07653 100644 --- a/includes/time.h +++ b/includes/time.h @@ -1,36 +1,81 @@ -#ifndef _PDCLIB_TIME_H -#define _PDCLIB_TIME_H -#include <_PDCLIB_aux.h> -#include <_PDCLIB_int.h> - -_PDCLIB_BEGIN_EXTERN_C -#ifndef _PDCLIB_SIZE_T_DEFINED -#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED -typedef _PDCLIB_size_t size_t; -#endif - -#ifndef _PDCLIB_NULL_DEFINED -#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED -#define NULL _PDCLIB_NULL -#endif - -typedef _PDCLIB_time_t time_t; -typedef _PDCLIB_clock_t clock_t; - -#define TIME_UTC _PDCLIB_TIME_UTC - -#ifndef _PDCLIB_STRUCT_TIMESPEC_DEFINED -#define _PDCLIB_STRUCT_TIMESPEC_DEFINED -_PDCLIB_DEFINE_STRUCT_TIMESPEC() -#endif - -#ifndef _PDCLIB_STRUCT_TM_DEFINED -#define _PDCLIB_STRUCT_TM_DEFINED -_PDCLIB_DEFINE_STRUCT_TM() -#endif - -time_t time( time_t* t ) _PDCLIB_nothrow; -int timespec_get( struct timespec *ts, int base ) _PDCLIB_nothrow; - -_PDCLIB_END_EXTERN_C -#endif +/* Date and time + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_TIME_H +#define _PDCLIB_TIME_H _PDCLIB_TIME_H +#include <_PDCLIB_aux.h> +#include <_PDCLIB_int.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _PDCLIB_SIZE_T_DEFINED +#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED +typedef _PDCLIB_size_t size_t; +#endif + +#ifndef _PDCLIB_NULL_DEFINED +#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED +#define NULL _PDCLIB_NULL +#endif + +typedef _PDCLIB_time_t time_t; +typedef _PDCLIB_clock_t clock_t; + +#define CLOCKS_PER_SEC _PDCLIB_CLOCKS_PER_SEC +#define TIME_UTC _PDCLIB_TIME_UTC + +struct timespec +{ + time_t tv_sec; + long tv_nsec; +}; + +struct tm +{ + int tm_sec; /* 0-60 */ + int tm_min; /* 0-59 */ + int tm_hour; /* 0-23 */ + int tm_mday; /* 1-31 */ + int tm_mon; /* 0-11 */ + int tm_year; /* years since 1900 */ + int tm_wday; /* 0-6 */ + int tm_yday; /* 0-365 */ + int tm_isdst; /* >0 DST, 0 no DST, <0 information unavailable */ +}; + +/* Returns the number of "clocks" in processor time since the invocation + of the program. Divide by CLOCKS_PER_SEC to get the value in seconds. + Returns -1 if the value cannot be represented in the return type or is + not available. +*/ +clock_t clock( void ) _PDCLIB_nothrow; + +/* Returns the difference between two calendar times in seconds. */ +double difftime( time_t time1, time_t time0 ) _PDCLIB_nothrow; + +time_t mktime( struct tm * timeptr ) _PDCLIB_nothrow; + +time_t time( time_t * timer ) _PDCLIB_nothrow; + +int timespec_get( struct timespec * ts, int base ) _PDCLIB_nothrow; + +char * asctime( const struct tm * timeptr ) _PDCLIB_nothrow; + +char * ctime( const time_t * timer ) _PDCLIB_nothrow; + +struct tm * gmtime( const time_t * timer ) _PDCLIB_nothrow; + +struct tm * localtime( const time_t * timer ) _PDCLIB_nothrow; + +size_t strftime( char * _PDCLIB_restrict s, size_t maxsize, const char * _PDCLIB_restrict format, const struct tm * _PDCLIB_restrict timeptr ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/includes/uchar.h b/includes/uchar.h index 97210ca..bcf1eac 100644 --- a/includes/uchar.h +++ b/includes/uchar.h @@ -1,19 +1,16 @@ -/* 7.28 +/* Unicode utilities - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. */ - #ifndef _PDCLIB_UCHAR_H -#define _PDCLIB_UCHAR_H +#define _PDCLIB_UCHAR_H _PDCLIB_UCHAR_H #include <_PDCLIB_int.h> -_PDCLIB_BEGIN_EXTERN_C -/* This is mostly a placeholder. for now. This header will be completed by the - * release of 0.6, but at present merely exposes types needed by the rest of the - * library - */ +#ifdef __cplusplus +extern "C" { +#endif #ifndef _PDCLIB_SIZE_T_DEFINED #define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED @@ -26,68 +23,46 @@ typedef _PDCLIB_mbstate_t mbstate_t; #endif #ifndef __cplusplus + +/* These are built-in types in C++ */ + #ifndef _PDCLIB_CHAR16_T_DEFINED #define _PDCLIB_CHAR16_T_DEFINED _PDCLIB_CHAR16_T_DEFINED -typedef _PDCLIB_char16_t char16_t; +typedef _PDCLIB_uint_least16_t char16_t; #endif #ifndef _PDCLIB_CHAR32_T_DEFINED #define _PDCLIB_CHAR32_T_DEFINED _PDCLIB_CHAR32_T_DEFINED -typedef _PDCLIB_char32_t char32_t; +typedef _PDCLIB_uint_least32_t char32_t; #endif + #endif -size_t mbrtoc16( - char16_t *_PDCLIB_restrict pc16, - const char *_PDCLIB_restrict s, - size_t n, - mbstate_t *_PDCLIB_restrict ps); +size_t mbrtoc16( char16_t * _PDCLIB_restrict pc16, const char * _PDCLIB_restrict s, size_t n, mbstate_t * _PDCLIB_restrict ps ); -size_t c16rtomb( - char *_PDCLIB_restrict s, - char16_t c16, - mbstate_t *_PDCLIB_restrict ps); +size_t c16rtomb( char * _PDCLIB_restrict s, char16_t c16, mbstate_t * _PDCLIB_restrict ps ); -size_t mbrtoc32( - char32_t *_PDCLIB_restrict pc32, - const char *_PDCLIB_restrict s, - size_t n, - mbstate_t *_PDCLIB_restrict ps); +size_t mbrtoc32( char32_t * _PDCLIB_restrict pc32, const char * _PDCLIB_restrict s, size_t n, mbstate_t * _PDCLIB_restrict ps); -size_t c32rtomb( - char *_PDCLIB_restrict s, - char32_t c32, - mbstate_t *_PDCLIB_restrict ps); +size_t c32rtomb( char * _PDCLIB_restrict s, char32_t c32, mbstate_t * _PDCLIB_restrict ps); #if defined(_PDCLIB_EXTENSIONS) -/* Analogous to strlen/wcslen */ -size_t _PDCLIB_c16slen(const char16_t * str); -size_t _PDCLIB_c32slen(const char32_t * str); + +/* Analogous to strlen() / wcslen() */ + +size_t _PDCLIB_c16slen( const char16_t * str ); + +size_t _PDCLIB_c32slen( const char32_t * str ); /* String generalizations of the above functions */ -size_t _PDCLIB_mbsrtoc16s( - char16_t *_PDCLIB_restrict dst, - const char **_PDCLIB_restrict src, - size_t len, - mbstate_t *_PDCLIB_restrict ps); - -size_t _PDCLIB_mbsrtoc32s( - char32_t *_PDCLIB_restrict dst, - const char **_PDCLIB_restrict src, - size_t len, - mbstate_t *_PDCLIB_restrict ps); - -size_t _PDCLIB_c16srtombs( - char *_PDCLIB_restrict dst, - const char16_t **_PDCLIB_restrict src, - size_t len, - mbstate_t *_PDCLIB_restrict ps); - -size_t _PDCLIB_c32srtombs( - char *_PDCLIB_restrict dst, - const char32_t **_PDCLIB_restrict src, - size_t len, - mbstate_t *_PDCLIB_restrict ps); + +size_t _PDCLIB_mbsrtoc16s( char16_t * _PDCLIB_restrict dst, const char * * _PDCLIB_restrict src, size_t len, mbstate_t * _PDCLIB_restrict ps ); + +size_t _PDCLIB_mbsrtoc32s( char32_t * _PDCLIB_restrict dst, const char * * _PDCLIB_restrict src, size_t len, mbstate_t * _PDCLIB_restrict ps ); + +size_t _PDCLIB_c16srtombs( char * _PDCLIB_restrict dst, const char16_t * * _PDCLIB_restrict src, size_t len, mbstate_t * _PDCLIB_restrict ps ); + +size_t _PDCLIB_c32srtombs( char * _PDCLIB_restrict dst, const char32_t * * _PDCLIB_restrict src, size_t len, mbstate_t * _PDCLIB_restrict ps ); #endif #endif diff --git a/includes/wchar.h b/includes/wchar.h index 83d880b..ceaf266 100644 --- a/includes/wchar.h +++ b/includes/wchar.h @@ -1,136 +1,146 @@ -/* 7. - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - - -#ifndef _PDCLIB_WCHAR_H -#define _PDCLIB_WCHAR_H -#include <_PDCLIB_int.h> -_PDCLIB_BEGIN_EXTERN_C - -#ifndef _PDCLIB_SIZE_T_DEFINED -#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED -typedef _PDCLIB_size_t size_t; -#endif - -#ifndef __cplusplus -#ifndef _PDCLIB_WCHAR_T_DEFINED -#define _PDCLIB_WCHAR_T_DEFINED _PDCLIB_WCHAR_T_DEFINED -typedef _PDCLIB_wchar_t wchar_t; -#endif -#endif - -#ifndef _PDCLIB_WINT_T_DEFINED -#define _PDCLIB_WINT_T_DEFINED _PDCLIB_WINT_T_DEFINED -typedef _PDCLIB_wint_t wint_t; -#endif - -#ifndef _PDCLIB_MBSTATE_T_DEFINED -#define _PDCLIB_MBSTATE_T_DEFINED _PDCLIB_MBSTATE_T_DEFINED -typedef _PDCLIB_mbstate_t mbstate_t; -#endif - -struct tm; - -#ifndef _PDCLIB_NULL_DEFINED -#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED -#define NULL _PDCLIB_NULL -#endif - -#ifndef _PDCLIB_WCHAR_MIN_MAX_DEFINED -#define _PDCLIB_WCHAR_MIN_MAX_DEFINED -#define WCHAR_MIN _PDCLIB_WCHAR_MIN -#define WCHAR_MAX _PDCLIB_WCHAR_MAX -#endif - -#ifndef _WEOF -#define WEOF ((wint_t) -1) -#endif - -/* Wide character string handling */ -wchar_t *wcscpy(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2); -wchar_t *wcsncpy(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2, size_t n); -wchar_t *wmemcpy(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2, size_t n); -wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2, size_t n); -wchar_t *wcscat(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2); -wchar_t *wcsncat(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2, size_t n); -int wcscmp(const wchar_t *s1, const wchar_t *s2); -int wcscoll(const wchar_t *s1, const wchar_t *s2); -int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n); -size_t wcsxfrm(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2, size_t n); -int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n); -wchar_t *wcschr(const wchar_t *s, wchar_t c); -size_t wcscspn(const wchar_t *s1, const wchar_t *s2); -wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2); -wchar_t *wcsrchr(const wchar_t *s, wchar_t c); -size_t wcsspn(const wchar_t *s1, const wchar_t *s2); -wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2); -wchar_t *wcstok(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2, wchar_t **_PDCLIB_restrict ptr); -wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n); -size_t wcslen(const wchar_t *s); -wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n); - -#if 0 -size_t wcsftime(wchar_t *_PDCLIB_restrict s, size_t maxsize, const wchar_t *_PDCLIB_restrict format, const struct tm *_PDCLIB_restrict timeptr); -#endif - -/* Wide character I/O */ -int fwprintf(_PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, ...); -int fwscanf(_PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, ...); -int swprintf(wchar_t *_PDCLIB_restrict s, size_t n, const wchar_t *_PDCLIB_restrict format, ...); -int swscanf(const wchar_t *_PDCLIB_restrict s, const wchar_t *_PDCLIB_restrict format, ...); -int vfwprintf(_PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); -int vfwscanf(_PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); -int vswprintf(wchar_t *_PDCLIB_restrict s, size_t n, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); -int vswscanf(const wchar_t *_PDCLIB_restrict s, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); -int vwprintf(const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); -int vwscanf(const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg); -int wprintf(const wchar_t *_PDCLIB_restrict format, ...); -int wscanf(const wchar_t *_PDCLIB_restrict format, ...); -wint_t fgetwc(_PDCLIB_file_t *stream); -wchar_t *fgetws(wchar_t *_PDCLIB_restrict s, int n, _PDCLIB_file_t *_PDCLIB_restrict stream); -wint_t fputwc(wchar_t c, _PDCLIB_file_t *stream); -int fputws(const wchar_t *_PDCLIB_restrict s, _PDCLIB_file_t *_PDCLIB_restrict stream); -int fwide(_PDCLIB_file_t *stream, int mode); -wint_t getwc(_PDCLIB_file_t *stream); -wint_t getwchar(void); -wint_t putwc(wchar_t c, _PDCLIB_file_t *stream); -wint_t putwchar(wchar_t c); -wint_t ungetwc(wint_t c, _PDCLIB_file_t *stream); - -#if _PDCLIB_GNU_SOURCE -wint_t getwc_unlocked(_PDCLIB_file_t *stream); -wint_t getwchar_unlocked(void); -wint_t fgetwc_unlocked(_PDCLIB_file_t *stream); -wint_t fputwc_unlocked(wchar_t wc, _PDCLIB_file_t *stream); -wint_t putwc_unlocked(wchar_t wc, _PDCLIB_file_t *stream); -wint_t putwchar_unlocked(wchar_t wc); -wchar_t *fgetws_unlocked(wchar_t *ws, int n, _PDCLIB_file_t *stream); -int fputws_unlocked(const wchar_t *ws, _PDCLIB_file_t *stream); -#endif - -/* Wide character <-> Numeric conversions */ -#if 0 -double wcstod(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr); -float wcstof(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr); -long double wcstold(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr); -#endif -long int wcstol(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr, int base); -long long int wcstoll(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr, int base); -unsigned long int wcstoul(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr, int base); -unsigned long long int wcstoull(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr, int base); - -/* Character set conversion */ -wint_t btowc(int c); -int wctob(wint_t c); -int mbsinit(const mbstate_t *ps); -size_t mbrlen(const char *_PDCLIB_restrict s, size_t n, mbstate_t *_PDCLIB_restrict ps); -size_t mbrtowc(wchar_t *_PDCLIB_restrict pwc, const char *_PDCLIB_restrict s, size_t n, mbstate_t *_PDCLIB_restrict ps); -size_t wcrtomb(char *_PDCLIB_restrict s, wchar_t wc, mbstate_t *_PDCLIB_restrict ps); -size_t mbsrtowcs(wchar_t *_PDCLIB_restrict dst, const char **_PDCLIB_restrict src, size_t len, mbstate_t *_PDCLIB_restrict ps); -size_t wcsrtombs(char *_PDCLIB_restrict dst, const wchar_t **_PDCLIB_restrict src, size_t len, mbstate_t *_PDCLIB_restrict ps); - -_PDCLIB_END_EXTERN_C -#endif +/* Extended multibyte and wide character utilities + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_WCHAR_H +#define _PDCLIB_WCHAR_H _PDCLIB_WCHAR_H +#include <_PDCLIB_int.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _PDCLIB_SIZE_T_DEFINED +#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED +typedef _PDCLIB_size_t size_t; +#endif + +#ifndef __cplusplus + +#ifndef _PDCLIB_WCHAR_T_DEFINED +#define _PDCLIB_WCHAR_T_DEFINED _PDCLIB_WCHAR_T_DEFINED +typedef _PDCLIB_wchar_t wchar_t; +#endif + +#endif + +#ifndef _PDCLIB_WINT_T_DEFINED +#define _PDCLIB_WINT_T_DEFINED _PDCLIB_WINT_T_DEFINED +typedef _PDCLIB_wint_t wint_t; +#endif + +#ifndef _PDCLIB_MBSTATE_T_DEFINED +#define _PDCLIB_MBSTATE_T_DEFINED _PDCLIB_MBSTATE_T_DEFINED +typedef _PDCLIB_mbstate_t mbstate_t; +#endif + +struct tm; + +#ifndef _PDCLIB_NULL_DEFINED +#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED +#define NULL _PDCLIB_NULL +#endif + +#ifndef _PDCLIB_WCHAR_MIN_MAX_DEFINED +#define _PDCLIB_WCHAR_MIN_MAX_DEFINED _PDCLIB_WCHAR_MIN_MAX_DEFINED +#define WCHAR_MIN _PDCLIB_WCHAR_MIN +#define WCHAR_MAX _PDCLIB_WCHAR_MAX +#endif + +#ifndef _PDCLIB_WEOF_DEFINED +#define _PDCLIB_WEOF_DEFINED _PDCLIB_WEOF_DEFINED +#define WEOF _PDCLIB_WEOF +#endif + +/* Wide character string handling */ +wchar_t * wcscpy( wchar_t * _PDCLIB_restrict s1, const wchar_t * _PDCLIB_restrict s2 ); +wchar_t * wcsncpy( wchar_t * _PDCLIB_restrict s1, const wchar_t * _PDCLIB_restrict s2, size_t n ); +wchar_t * wmemcpy( wchar_t * _PDCLIB_restrict s1, const wchar_t * _PDCLIB_restrict s2, size_t n ); +wchar_t * wmemmove( wchar_t * s1, const wchar_t * s2, size_t n ); +wchar_t * wcscat( wchar_t * _PDCLIB_restrict s1, const wchar_t * _PDCLIB_restrict s2 ); +wchar_t * wcsncat( wchar_t * _PDCLIB_restrict s1, const wchar_t * _PDCLIB_restrict s2, size_t n ); +int wcscmp( const wchar_t * s1, const wchar_t * s2 ); +int wcscoll( const wchar_t * s1, const wchar_t * s2 ); +int wcsncmp( const wchar_t * s1, const wchar_t * s2, size_t n ); +size_t wcsxfrm( wchar_t * _PDCLIB_restrict s1, const wchar_t * _PDCLIB_restrict s2, size_t n ); +int wmemcmp( const wchar_t * s1, const wchar_t * s2, size_t n ); +wchar_t * wcschr( const wchar_t * s, wchar_t c ); +size_t wcscspn( const wchar_t * s1, const wchar_t * s2 ); +wchar_t * wcspbrk( const wchar_t * s1, const wchar_t * s2 ); +wchar_t * wcsrchr( const wchar_t * s, wchar_t c ); +size_t wcsspn( const wchar_t * s1, const wchar_t * s2 ); +wchar_t * wcsstr( const wchar_t * s1, const wchar_t * s2 ); +wchar_t * wcstok( wchar_t * _PDCLIB_restrict s1, const wchar_t * _PDCLIB_restrict s2, wchar_t * * _PDCLIB_restrict ptr ); +wchar_t * wmemchr( const wchar_t * s, wchar_t c, size_t n ); +size_t wcslen( const wchar_t * s ); +wchar_t * wmemset( wchar_t * s, wchar_t c, size_t n ); + +#if 0 +size_t wcsftime( wchar_t * _PDCLIB_restrict s, size_t maxsize, const wchar_t * _PDCLIB_restrict format, const struct tm * _PDCLIB_restrict timeptr ); +#endif + +/* Wide character I/O */ +int fwprintf( _PDCLIB_file_t * _PDCLIB_restrict stream, const wchar_t * _PDCLIB_restrict format, ... ); +int fwscanf( _PDCLIB_file_t * _PDCLIB_restrict stream, const wchar_t * _PDCLIB_restrict format, ... ); +int swprintf( wchar_t * _PDCLIB_restrict s, size_t n, const wchar_t * _PDCLIB_restrict format, ... ); +int swscanf( const wchar_t * _PDCLIB_restrict s, const wchar_t * _PDCLIB_restrict format, ... ); +int vfwprintf( _PDCLIB_file_t * _PDCLIB_restrict stream, const wchar_t * _PDCLIB_restrict format, _PDCLIB_va_list arg ); +int vfwscanf( _PDCLIB_file_t * _PDCLIB_restrict stream, const wchar_t * _PDCLIB_restrict format, _PDCLIB_va_list arg ); +int vswprintf( wchar_t * _PDCLIB_restrict s, size_t n, const wchar_t * _PDCLIB_restrict format, _PDCLIB_va_list arg ); +int vswscanf( const wchar_t * _PDCLIB_restrict s, const wchar_t * _PDCLIB_restrict format, _PDCLIB_va_list arg ); +int vwprintf( const wchar_t * _PDCLIB_restrict format, _PDCLIB_va_list arg ); +int vwscanf( const wchar_t * _PDCLIB_restrict format, _PDCLIB_va_list arg ); +int wprintf( const wchar_t * _PDCLIB_restrict format, ... ); +int wscanf( const wchar_t * _PDCLIB_restrict format, ... ); +wint_t fgetwc( _PDCLIB_file_t * stream ); +wchar_t * fgetws( wchar_t * _PDCLIB_restrict s, int n, _PDCLIB_file_t * _PDCLIB_restrict stream ); +wint_t fputwc( wchar_t c, _PDCLIB_file_t * stream ); +int fputws( const wchar_t * _PDCLIB_restrict s, _PDCLIB_file_t * _PDCLIB_restrict stream ); +int fwide( _PDCLIB_file_t * stream, int mode ); +wint_t getwc( _PDCLIB_file_t * stream ); +wint_t getwchar( void ); +wint_t putwc( wchar_t c, _PDCLIB_file_t * stream ); +wint_t putwchar( wchar_t c ); +wint_t ungetwc( wint_t c, _PDCLIB_file_t * stream ); + +#if _PDCLIB_GNU_SOURCE +wint_t getwc_unlocked( _PDCLIB_file_t * stream ); +wint_t getwchar_unlocked( void ); +wint_t fgetwc_unlocked( _PDCLIB_file_t * stream ); +wint_t fputwc_unlocked( wchar_t wc, _PDCLIB_file_t * stream ); +wint_t putwc_unlocked( wchar_t wc, _PDCLIB_file_t * stream ); +wint_t putwchar_unlocked( wchar_t wc ); +wchar_t * fgetws_unlocked( wchar_t * ws, int n, _PDCLIB_file_t * stream ); +int fputws_unlocked( const wchar_t * ws, _PDCLIB_file_t * stream ); +#endif + +/* Wide character <-> Numeric conversions */ + +/* +double wcstod( const wchar_t * _PDCLIB_restrict nptr, wchar_t * * _PDCLIB_restrict endptr ); +float wcstof( const wchar_t * _PDCLIB_restrict nptr, wchar_t * * _PDCLIB_restrict endptr ); +long double wcstold( const wchar_t * _PDCLIB_restrict nptr, wchar_t * * _PDCLIB_restrict endptr ); +*/ + +long int wcstol( const wchar_t * _PDCLIB_restrict nptr, wchar_t * * _PDCLIB_restrict endptr, int base ); +long long int wcstoll( const wchar_t * _PDCLIB_restrict nptr, wchar_t * * _PDCLIB_restrict endptr, int base ); +unsigned long int wcstoul( const wchar_t * _PDCLIB_restrict nptr, wchar_t * * _PDCLIB_restrict endptr, int base ); +unsigned long long int wcstoull( const wchar_t * _PDCLIB_restrict nptr, wchar_t * * _PDCLIB_restrict endptr, int base ); + +/* Character set conversion */ +wint_t btowc( int c ); +int wctob( wint_t c ); +int mbsinit( const mbstate_t * ps ); +size_t mbrlen( const char * _PDCLIB_restrict s, size_t n, mbstate_t * _PDCLIB_restrict ps ); +size_t mbrtowc( wchar_t * _PDCLIB_restrict pwc, const char * _PDCLIB_restrict s, size_t n, mbstate_t * _PDCLIB_restrict ps ); +size_t wcrtomb( char * _PDCLIB_restrict s, wchar_t wc, mbstate_t * _PDCLIB_restrict ps ); +size_t mbsrtowcs( wchar_t * _PDCLIB_restrict dst, const char * * _PDCLIB_restrict src, size_t len, mbstate_t * _PDCLIB_restrict ps ); +size_t wcsrtombs( char * _PDCLIB_restrict dst, const wchar_t * * _PDCLIB_restrict src, size_t len, mbstate_t * _PDCLIB_restrict ps ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/includes/wctype.h b/includes/wctype.h index 4d6ed5e..1e49897 100644 --- a/includes/wctype.h +++ b/includes/wctype.h @@ -1,47 +1,65 @@ -/* 7.30 Wide Character Classification and Mapping Utilities - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_WCTYPE_H -#define _PDCLIB_WCTYPE_H _PDCLIB_WCTYPE_H -#include <_PDCLIB_int.h> -_PDCLIB_BEGIN_EXTERN_C - -#ifndef _PDCLIB_WINT_T_DEFINED -#define _PDCLIB_WINT_T_DEFINED _PDCLIB_WINT_T_DEFINED -typedef _PDCLIB_wint_t wint_t; -#endif - -typedef int wctrans_t; -typedef int wctype_t; - -/* 7.30.2.1 Character classification functions */ -int iswalnum( wint_t _Wc ); -int iswalpha( wint_t _Wc ); -int iswblank( wint_t _Wc ); -int iswcntrl( wint_t _Wc ); -int iswdigit( wint_t _Wc ); -int iswgraph( wint_t _Wc ); -int iswlower( wint_t _Wc ); -int iswprint( wint_t _Wc ); -int iswpunct( wint_t _Wc ); -int iswspace( wint_t _Wc ); -int iswupper( wint_t _Wc ); -int iswxdigit( wint_t _Wc ); - -/* 7.30.2.2 Extensible character classification functions */ -int iswctype( wint_t _Wc, wctype_t _Desc ); -wctype_t wctype( const char * _Property ); - -/* 7.30.3 Wide character case mapping utilities */ -wint_t towlower( wint_t _Wc ); -wint_t towupper( wint_t _Wc ); - -/* 7.30.3.2 Extensible wide character case mapping functions */ -wint_t towctrans( wint_t _Wc, wctrans_t _Desc ); -wctrans_t wctrans( const char * _Property ); - -_PDCLIB_END_EXTERN_C -#endif // _PDCLIB_WCTYPE_H +/* Wide character classification and mapping utilities + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_WCTYPE_H +#define _PDCLIB_WCTYPE_H _PDCLIB_WCTYPE_H +#include <_PDCLIB_int.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _PDCLIB_WINT_T_DEFINED +#define _PDCLIB_WINT_T_DEFINED _PDCLIB_WINT_T_DEFINED +typedef _PDCLIB_wint_t wint_t; +#endif + +#ifndef _PDCLIB_WEOF_DEFINED +#define _PDCLIB_WEOF_DEFINED _PDCLIB_WEOF_DEFINED +#define WEOF _PDCLIB_WEOF +#endif + +/* Scalar type representing locale-specific character mappings */ +typedef int wctrans_t; + +/* Scalar type representing locale-specific character classifications */ +typedef int wctype_t; + +/* Character classification functions */ + +int iswalnum( wint_t _Wc ); +int iswalpha( wint_t _Wc ); +int iswblank( wint_t _Wc ); +int iswcntrl( wint_t _Wc ); +int iswdigit( wint_t _Wc ); +int iswgraph( wint_t _Wc ); +int iswlower( wint_t _Wc ); +int iswprint( wint_t _Wc ); +int iswpunct( wint_t _Wc ); +int iswspace( wint_t _Wc ); +int iswupper( wint_t _Wc ); +int iswxdigit( wint_t _Wc ); + +/* Extensible character classification functions */ + +int iswctype( wint_t _Wc, wctype_t _Desc ); +wctype_t wctype( const char * _Property ); + +/* Wide character case mapping utilities */ + +wint_t towlower( wint_t _Wc ); +wint_t towupper( wint_t _Wc ); + +/* Extensible wide character case mapping functions */ + +wint_t towctrans( wint_t _Wc, wctrans_t _Desc ); +wctrans_t wctrans( const char * _Property ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/internals/_PDCLIB_aux.h b/internals/_PDCLIB_aux.h index 16e7ed8..8f1cb7f 100644 --- a/internals/_PDCLIB_aux.h +++ b/internals/_PDCLIB_aux.h @@ -1,12 +1,12 @@ -#ifndef __PDCLIB_AUX_H -#define __PDCLIB_AUX_H __PDCLIB_AUX_H - /* Auxiliary PDCLib code <_PDCLIB_aux.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_AUX_H +#define __PDCLIB_AUX_H __PDCLIB_AUX_H + /* -------------------------------------------------------------------------- */ /* You should not have to edit anything in this file; if you DO have to, it */ /* would be considered a bug / missing feature: notify the author(s). */ @@ -62,12 +62,8 @@ #endif #ifdef __cplusplus - #define _PDCLIB_BEGIN_EXTERN_C extern "C" { - #define _PDCLIB_END_EXTERN_C } typedef bool _PDCLIB_bool; #else - #define _PDCLIB_BEGIN_EXTERN_C - #define _PDCLIB_END_EXTERN_C typedef _Bool _PDCLIB_bool; #endif diff --git a/internals/_PDCLIB_encoding.h b/internals/_PDCLIB_encoding.h index 10f1140..7d893c2 100644 --- a/internals/_PDCLIB_encoding.h +++ b/internals/_PDCLIB_encoding.h @@ -6,6 +6,7 @@ #ifndef __PDCLIB_ENCODING_H #define __PDCLIB_ENCODING_H __PDCLIB_ENCODING_H + #include /* Must be cauued with bufsize >= 1, in != NULL, out != NULL, ps != NULL diff --git a/internals/_PDCLIB_float.h b/internals/_PDCLIB_float.h index ca34d65..b2944e7 100644 --- a/internals/_PDCLIB_float.h +++ b/internals/_PDCLIB_float.h @@ -1,12 +1,12 @@ -#ifndef __PDCLIB_PDCLIB_FLOAT_H -#define __PDCLIB_PDCLIB_FLOAT_H __PDCLIB_PDCLIB_FLOAT_H - /* PDCLib internal floating point logic <_PDCLIB_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_PDCLIB_FLOAT_H +#define __PDCLIB_PDCLIB_FLOAT_H __PDCLIB_PDCLIB_FLOAT_H + /* IEEE 754 single precision */ #define _PDCLIB_FP_SINGLE_MIN 1.17549435082228750797e-38 #define _PDCLIB_FP_SINGLE_EPSILON 1.19209289550781250000e-7 diff --git a/internals/_PDCLIB_glue.h b/internals/_PDCLIB_glue.h index 1d97863..ef224c7 100644 --- a/internals/_PDCLIB_glue.h +++ b/internals/_PDCLIB_glue.h @@ -1,16 +1,21 @@ -#ifndef __PDCLIB_GLUE_H -#define __PDCLIB_GLUE_H __PDCLIB_GLUE_H /* OS glue functions declaration <_PDCLIB_glue.h> This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. */ -#include <_PDCLIB_int.h> -#include <_PDCLIB_io.h> +#ifndef __PDCLIB_GLUE_H +#define __PDCLIB_GLUE_H __PDCLIB_GLUE_H + +#include "_PDCLIB_int.h" +#include "_PDCLIB_io.h" + #include #include -_PDCLIB_BEGIN_EXTERN_C + +#ifdef __cplusplus +extern "C" { +#endif /* -------------------------------------------------------------------------- */ /* OS "glue", part 2 */ @@ -69,5 +74,8 @@ int _PDCLIB_remove( const char * filename ); */ int _PDCLIB_rename( const char * old, const char * newn); -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} +#endif + #endif diff --git a/internals/_PDCLIB_int.h b/internals/_PDCLIB_int.h index ab1bc90..ecf8f66 100644 --- a/internals/_PDCLIB_int.h +++ b/internals/_PDCLIB_int.h @@ -1,12 +1,12 @@ -#ifndef __PDCLIB_INT_H -#define __PDCLIB_INT_H __PDCLIB_INT_H - /* PDCLib internal integer logic <_PDCLIB_int.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_INT_H +#define __PDCLIB_INT_H __PDCLIB_INT_H + /* -------------------------------------------------------------------------- */ /* You should not have to edit anything in this file; if you DO have to, it */ /* would be considered a bug / missing feature: notify the author(s). */ @@ -111,6 +111,8 @@ #if _PDCLIB_CHAR_BIT == 8 typedef signed char _PDCLIB_int8_t; typedef unsigned char _PDCLIB_uint8_t; +typedef signed char _PDCLIB_int_least8_t; +typedef unsigned char _PDCLIB_uint_least8_t; #define _PDCLIB_INT8_MAX _PDCLIB_CHAR_MAX #define _PDCLIB_INT8_MIN _PDCLIB_CHAR_MIN #define _PDCLIB_UINT8_MAX _PDCLIB_UCHAR_MAX @@ -123,6 +125,8 @@ typedef unsigned char _PDCLIB_uint8_t; #if _PDCLIB_INT_BYTES == 2 typedef signed int _PDCLIB_int16_t; typedef unsigned int _PDCLIB_uint16_t; +typedef signed int _PDCLIB_int_least16_t; +typedef unsigned int _PDCLIB_uint_least16_t; #define _PDCLIB_INT16_MAX _PDCLIB_INT_MAX #define _PDCLIB_INT16_MIN _PDCLIB_INT_MIN #define _PDCLIB_UINT16_MAX _PDCLIB_UINT_MAX @@ -130,6 +134,8 @@ typedef unsigned int _PDCLIB_uint16_t; #elif _PDCLIB_SHRT_BYTES == 2 typedef signed short _PDCLIB_int16_t; typedef unsigned short _PDCLIB_uint16_t; +typedef signed short _PDCLIB_int_least16_t; +typedef unsigned short _PDCLIB_uint_least16_t; #define _PDCLIB_INT16_MAX _PDCLIB_SHRT_MAX #define _PDCLIB_INT16_MIN _PDCLIB_SHRT_MIN #define _PDCLIB_UINT16_MAX _PDCLIB_USHRT_MAX @@ -142,6 +148,8 @@ typedef unsigned short _PDCLIB_uint16_t; #if _PDCLIB_INT_BYTES == 4 typedef signed int _PDCLIB_int32_t; typedef unsigned int _PDCLIB_uint32_t; +typedef signed int _PDCLIB_int_least32_t; +typedef unsigned int _PDCLIB_uint_least32_t; #define _PDCLIB_INT32_MAX _PDCLIB_INT_MAX #define _PDCLIB_INT32_MIN _PDCLIB_INT_MIN #define _PDCLIB_UINT32_MAX _PDCLIB_UINT_MAX @@ -151,6 +159,8 @@ typedef unsigned int _PDCLIB_uint32_t; #elif _PDCLIB_LONG_BYTES == 4 typedef signed long _PDCLIB_int32_t; typedef unsigned long _PDCLIB_uint32_t; +typedef signed long _PDCLIB_int_least32_t; +typedef unsigned long _PDCLIB_uint_least32_t; #define _PDCLIB_INT32_MAX _PDCLIB_LONG_MAX #define _PDCLIB_INT32_MIN _PDCLIB_LONG_MIN #define _PDCLIB_UINT32_MAX _PDCLIB_LONG_MAX @@ -165,6 +175,8 @@ typedef unsigned long _PDCLIB_uint32_t; #if _PDCLIB_LONG_BYTES == 8 && !defined(_PDCLIB_INT64_IS_LLONG) typedef signed long _PDCLIB_int64_t; typedef unsigned long _PDCLIB_uint64_t; +typedef signed long _PDCLIB_int_least64_t; +typedef unsigned long _PDCLIB_uint_least64_t; #define _PDCLIB_INT64_MAX _PDCLIB_LONG_MAX #define _PDCLIB_INT64_MIN _PDCLIB_LONG_MIN #define _PDCLIB_UINT64_MAX _PDCLIB_ULONG_MAX @@ -174,6 +186,8 @@ typedef unsigned long _PDCLIB_uint64_t; #elif _PDCLIB_LLONG_BYTES == 8 typedef signed long long _PDCLIB_int64_t; typedef unsigned long long _PDCLIB_uint64_t; +typedef signed long long _PDCLIB_int_least64_t; +typedef unsigned long long _PDCLIB_uint_least64_t; #define _PDCLIB_INT64_MAX _PDCLIB_LLONG_MAX #define _PDCLIB_INT64_MIN _PDCLIB_LLONG_MIN #define _PDCLIB_UINT64_MAX _PDCLIB_ULLONG_MAX @@ -224,13 +238,11 @@ typedef _PDCLIB_ptrdiff _PDCLIB_ptrdiff_t; #define _PDCLIB_PTRDIFF_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MIN ) #define _PDCLIB_PTRDIFF_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MAX ) -#define _PDCLIB_SIG_ATOMIC_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MIN ) -#define _PDCLIB_SIG_ATOMIC_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MAX ) - typedef _PDCLIB_size _PDCLIB_size_t; #define _PDCLIB_SIZE_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIZE ), _MAX ) typedef _PDCLIB_wint _PDCLIB_wint_t; + #ifndef __cplusplus typedef _PDCLIB_wchar _PDCLIB_wchar_t; #else @@ -239,6 +251,9 @@ typedef _PDCLIB_wint _PDCLIB_wint_t; #define _PDCLIB_WCHAR_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_WCHAR ), _MIN ) #define _PDCLIB_WCHAR_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_WCHAR ), _MAX ) +#define _PDCLIB_SIG_ATOMIC_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MIN ) +#define _PDCLIB_SIG_ATOMIC_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MAX ) + typedef _PDCLIB_intptr _PDCLIB_intptr_t; typedef unsigned _PDCLIB_intptr _PDCLIB_uintptr_t; #define _PDCLIB_INTPTR_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_INTPTR ), _MIN ) @@ -260,29 +275,6 @@ typedef unsigned _PDCLIB_intmax _PDCLIB_uintmax_t; typedef _PDCLIB_time _PDCLIB_time_t; typedef _PDCLIB_clock _PDCLIB_clock_t; -#if !defined(_PDCLIB_DEFINE_STRUCT_TIMESPEC) -#define _PDCLIB_DEFINE_STRUCT_TIMESPEC() \ - struct timespec { \ - time_t tv_sec; \ - long tv_nsec; \ - }; -#endif - -#if !defined(_PDCLIB_DEFINE_STRUCT_TM) -#define _PDCLIB_DEFINE_STRUCT_TM() \ - struct tm { \ - int tm_sec; \ - int tm_min; \ - int tm_hour; \ - int tm_mday; \ - int tm_mon; \ - int tm_year; \ - int tm_wday; \ - int tm_yday; \ - int tm_isdst; \ - }; -#endif - /* -------------------------------------------------------------------------- */ /* Internal data types */ /* -------------------------------------------------------------------------- */ @@ -372,6 +364,9 @@ typedef struct lconv _PDCLIB_lconv_t; _PDCLIB_size_t _PDCLIB_mb_cur_max( void ); +/* wide-character EOF */ +#define _PDCLIB_WEOF ((wint_t) -1 + /* -------------------------------------------------------------------------- */ /* stdio */ /* -------------------------------------------------------------------------- */ diff --git a/internals/_PDCLIB_io.h b/internals/_PDCLIB_io.h index 3561b21..27c33e7 100644 --- a/internals/_PDCLIB_io.h +++ b/internals/_PDCLIB_io.h @@ -1,14 +1,15 @@ -#ifndef __PDCLIB_IO_H -#define __PDCLIB_IO_H __PDCLIB_IO_H -#include "_PDCLIB_int.h" -#include "_PDCLIB_threadconfig.h" - -/* PDCLib internal I/O logic <_PDCLIB_io.h> +/* PDCLib I/O support <_PDCLIB_io.h> This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. */ +#ifndef __PDCLIB_IO_H +#define __PDCLIB_IO_H __PDCLIB_IO_H + +#include "_PDCLIB_int.h" +#include "_PDCLIB_threadconfig.h" + /* Flags for representing mode (see fopen()). Note these must fit the same status field as the _IO?BF flags in and the internal flags below. */ diff --git a/internals/_PDCLIB_locale.h b/internals/_PDCLIB_locale.h index 4595e9b..da9321e 100644 --- a/internals/_PDCLIB_locale.h +++ b/internals/_PDCLIB_locale.h @@ -1,6 +1,14 @@ +/* PDCLib locale support <_PDCLIB_locale.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_LOCALE_H #define __PDCLIB_LOCALE_H __PDCLIB_LOCALE_H -#include <_PDCLIB_int.h> + +#include "_PDCLIB_int.h" + #include #include #include diff --git a/opt/c_locale/_PDCLIB_clocale.h b/opt/c_locale/_PDCLIB_clocale.h index ee51d28..4d13ee5 100644 --- a/opt/c_locale/_PDCLIB_clocale.h +++ b/opt/c_locale/_PDCLIB_clocale.h @@ -7,9 +7,13 @@ #ifndef _PDCLIB_CLOCALE_H #define _PDCLIB_CLOCALE_H _PDCLIB_CLOCALE_H #include -_PDCLIB_BEGIN_EXTERN_C +#ifdef __cplusplus +extern "C" { +#endif void _PDCLIB_initclocale( locale_t l ); -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} +#endif #endif // _PDCLIB_CLOCALE_H diff --git a/opt/nothread/_PDCLIB_threadconfig.h b/opt/nothread/_PDCLIB_threadconfig.h index 3380b52..516cc36 100644 --- a/opt/nothread/_PDCLIB_threadconfig.h +++ b/opt/nothread/_PDCLIB_threadconfig.h @@ -3,7 +3,9 @@ #include <_PDCLIB_aux.h> #include <_PDCLIB_config.h> -_PDCLIB_BEGIN_EXTERN_C +#ifdef __cplusplus +extern "C" { +#endif #define _PDCLIB_ONCE_FLAG_INIT 0 #define _PDCLIB_ONCE_FLAG_IS_DONE(_f) (*(_f) == 1) typedef char _PDCLIB_once_flag; @@ -20,5 +22,7 @@ struct _PDCLIB_tss { void *value; }; -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} +#endif #endif diff --git a/opt/pthreads/_PDCLIB_threadconfig.h b/opt/pthreads/_PDCLIB_threadconfig.h index b855def..1ca4783 100644 --- a/opt/pthreads/_PDCLIB_threadconfig.h +++ b/opt/pthreads/_PDCLIB_threadconfig.h @@ -28,5 +28,7 @@ typedef pthread_once_t _PDCLIB_once_flag; #endif -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} +#endif #endif diff --git a/opt/tss_errno/errno.h b/opt/tss_errno/errno.h index 3b3feab..ef8f1f6 100644 --- a/opt/tss_errno/errno.h +++ b/opt/tss_errno/errno.h @@ -1,4 +1,4 @@ -/* 7.5 Errors +/* Errors This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. @@ -9,7 +9,9 @@ #include <_PDCLIB_int.h> -_PDCLIB_BEGIN_EXTERN_C +#ifdef __cplusplus +extern "C" { +#endif extern int * _PDCLIB_errno_func( void ); #define errno (*_PDCLIB_errno_func()) @@ -96,6 +98,8 @@ extern int * _PDCLIB_errno_func( void ); #define EWOULDBLOCK _PDCLIB_EWOULDBLOCK #define EXDEV _PDCLIB_EXDEV -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} +#endif #endif diff --git a/platform/example/functions/signal/signal.c b/platform/example/functions/signal/signal.c deleted file mode 100644 index 9d22275..0000000 --- a/platform/example/functions/signal/signal.c +++ /dev/null @@ -1,71 +0,0 @@ -/* signal( int sig, void (*func)( int ) ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include -#include - -void (*_PDCLIB_sigabrt)( int ) = SIG_DFL; -void (*_PDCLIB_sigfpe)( int ) = SIG_DFL; -void (*_PDCLIB_sigill)( int ) = SIG_DFL; -void (*_PDCLIB_sigint)( int ) = SIG_DFL; -void (*_PDCLIB_sigsegv)( int ) = SIG_DFL; -void (*_PDCLIB_sigterm)( int ) = SIG_DFL; - -void (*signal( int sig, void (*func)( int ) ) )( int ) -{ - void (*oldhandler)( int ); - if ( sig <= 0 || func == SIG_ERR ) - { - return SIG_ERR; - } - switch ( sig ) - { - case SIGABRT: - oldhandler = _PDCLIB_sigabrt; - _PDCLIB_sigabrt = func; - break; - case SIGFPE: - oldhandler = _PDCLIB_sigfpe; - _PDCLIB_sigfpe = func; - break; - case SIGILL: - oldhandler = _PDCLIB_sigill; - _PDCLIB_sigill = func; - break; - case SIGINT: - oldhandler = _PDCLIB_sigint; - _PDCLIB_sigint = func; - break; - case SIGSEGV: - oldhandler = _PDCLIB_sigsegv; - _PDCLIB_sigsegv = func; - break; - case SIGTERM: - oldhandler = _PDCLIB_sigterm; - _PDCLIB_sigterm = func; - break; - default: - errno = EINVAL; - 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/example/includes/signal.h b/platform/example/includes/signal.h index 2d52993..8b30a4f 100644 --- a/platform/example/includes/signal.h +++ b/platform/example/includes/signal.h @@ -1,4 +1,4 @@ -/* 7.14 Signal handling +/* Signal handling This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. diff --git a/platform/gandr/functions/signal/raise.c b/platform/gandr/functions/signal/raise.c deleted file mode 100644 index 51c787a..0000000 --- a/platform/gandr/functions/signal/raise.c +++ /dev/null @@ -1,112 +0,0 @@ -/* raise( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include -#include - -extern void (*_PDCLIB_sigabrt)( int ); -extern void (*_PDCLIB_sigfpe)( int ); -extern void (*_PDCLIB_sigill)( int ); -extern void (*_PDCLIB_sigint)( int ); -extern void (*_PDCLIB_sigsegv)( int ); -extern void (*_PDCLIB_sigterm)( int ); - -int raise( int sig ) -{ - void (*sighandler)( int ); - char const * message; - switch ( sig ) - { - case SIGABRT: - sighandler = _PDCLIB_sigabrt; - message = "Abnormal termination (SIGABRT)"; - break; - case SIGFPE: - sighandler = _PDCLIB_sigfpe; - message = "Arithmetic exception (SIGFPE)"; - break; - case SIGILL: - sighandler = _PDCLIB_sigill; - message = "Illegal instruction (SIGILL)"; - break; - case SIGINT: - sighandler = _PDCLIB_sigint; - message = "Interactive attention signal (SIGINT)"; - break; - case SIGSEGV: - sighandler = _PDCLIB_sigsegv; - message = "Invalid memory access (SIGSEGV)"; - break; - case SIGTERM: - sighandler = _PDCLIB_sigterm; - message = "Termination request (SIGTERM)"; - break; - default: - fprintf( stderr, "Unknown signal #%d\n", sig ); - _Exit( EXIT_FAILURE ); - } - if ( sighandler == SIG_DFL ) - { - fputs( message, stderr ); - _Exit( EXIT_FAILURE ); - } - else if ( sighandler != SIG_IGN ) - { - sighandler = signal( sig, SIG_DFL ); - sighandler( sig ); - } - return 0; -} - -#endif - -#ifdef TEST -#include <_PDCLIB_test.h> - -#include - -static volatile sig_atomic_t flag = 0; - -static int expected_signal = 0; - -static void test_handler( int sig ) -{ - TESTCASE( sig == expected_signal ); - flag = 1; -} - -int main( void ) -{ - /* Could be other than SIG_DFL if you changed the implementation. */ - TESTCASE( signal( SIGABRT, SIG_IGN ) == SIG_DFL ); - /* Should be ignored. */ - TESTCASE( raise( SIGABRT ) == 0 ); - /* Installing test handler, old handler should be returned */ - TESTCASE( signal( SIGABRT, test_handler ) == SIG_IGN ); - /* Raising and checking SIGABRT */ - expected_signal = SIGABRT; - TESTCASE( raise( SIGABRT ) == 0 ); - TESTCASE( flag == 1 ); - /* Re-installing test handler, should have been reset to default */ - /* Could be other than SIG_DFL if you changed the implementation. */ - TESTCASE( signal( SIGABRT, test_handler ) == SIG_DFL ); - /* Raising and checking SIGABRT */ - flag = 0; - TESTCASE( raise( SIGABRT ) == 0 ); - TESTCASE( flag == 1 ); - /* Installing test handler for different signal... */ - TESTCASE( signal( SIGTERM, test_handler ) == SIG_DFL ); - /* Raising and checking SIGTERM */ - expected_signal = SIGTERM; - TESTCASE( raise( SIGTERM ) == 0 ); - TESTCASE( flag == 1 ); - return TEST_RESULTS; -} -#endif diff --git a/platform/gandr/functions/signal/signal.c b/platform/gandr/functions/signal/signal.c deleted file mode 100644 index 9d22275..0000000 --- a/platform/gandr/functions/signal/signal.c +++ /dev/null @@ -1,71 +0,0 @@ -/* signal( int sig, void (*func)( int ) ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include -#include - -void (*_PDCLIB_sigabrt)( int ) = SIG_DFL; -void (*_PDCLIB_sigfpe)( int ) = SIG_DFL; -void (*_PDCLIB_sigill)( int ) = SIG_DFL; -void (*_PDCLIB_sigint)( int ) = SIG_DFL; -void (*_PDCLIB_sigsegv)( int ) = SIG_DFL; -void (*_PDCLIB_sigterm)( int ) = SIG_DFL; - -void (*signal( int sig, void (*func)( int ) ) )( int ) -{ - void (*oldhandler)( int ); - if ( sig <= 0 || func == SIG_ERR ) - { - return SIG_ERR; - } - switch ( sig ) - { - case SIGABRT: - oldhandler = _PDCLIB_sigabrt; - _PDCLIB_sigabrt = func; - break; - case SIGFPE: - oldhandler = _PDCLIB_sigfpe; - _PDCLIB_sigfpe = func; - break; - case SIGILL: - oldhandler = _PDCLIB_sigill; - _PDCLIB_sigill = func; - break; - case SIGINT: - oldhandler = _PDCLIB_sigint; - _PDCLIB_sigint = func; - break; - case SIGSEGV: - oldhandler = _PDCLIB_sigsegv; - _PDCLIB_sigsegv = func; - break; - case SIGTERM: - oldhandler = _PDCLIB_sigterm; - _PDCLIB_sigterm = func; - break; - default: - errno = EINVAL; - 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/gandr/includes/_PDCLIB_config.h b/platform/gandr/includes/_PDCLIB_config.h index bfd1788..2f0b6a2 100644 --- a/platform/gandr/includes/_PDCLIB_config.h +++ b/platform/gandr/includes/_PDCLIB_config.h @@ -1,5 +1,6 @@ #ifndef _PDCLIB_CONFIG_H #define _PDCLIB_CONFIG_H + /* Internal PDCLib configuration <_PDCLIB_config.h> (Gandr platform) @@ -7,23 +8,41 @@ Permission is granted to use, modify, and / or redistribute at will. */ +/* -------------------------------------------------------------------------- */ +/* Misc */ +/* -------------------------------------------------------------------------- */ - -/* end of line */ +/* The character (sequence) your platform uses as newline. */ #define _PDCLIB_endl "\n" -/* exit() */ +/* 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 -/* trivial memswp */ +/* qsort() in requires a function that swaps two memory areas. */ +/* Below is a naive implementation that can be improved significantly for */ +/* specific platforms, e.g. by swapping int instead of char. */ #define _PDCLIB_memswp( i, j, size ) char tmp; do { tmp = *i; *i++ = *j; *j++ = tmp; } while ( --size ); +/* -------------------------------------------------------------------------- */ +/* 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. */ +/* -------------------------------------------------------------------------- */ #if defined(__arm__) - #define _PDCLIB_CHAR_SIGNED 0 +#define _PDCLIB_CHAR_SIGNED 0 #else - #define _PDCLIB_CHAR_SIGNED 1 +#define _PDCLIB_CHAR_SIGNED 1 #endif /* Width of the integer types short, int, long, and long long, in bytes. */ @@ -32,18 +51,56 @@ #define _PDCLIB_SHRT_BYTES 2 #define _PDCLIB_INT_BYTES 4 #if defined(__LP64__) - #define _PDCLIB_LONG_BYTES 8 +#define _PDCLIB_LONG_BYTES 8 #else - #define _PDCLIB_LONG_BYTES 4 +#define _PDCLIB_LONG_BYTES 4 #endif #define _PDCLIB_LLONG_BYTES 8 -/* layout of div_t, ldiv_t, lldiv_t */ -struct _PDCLIB_div_t { int quot; int rem; }; -struct _PDCLIB_ldiv_t { long int quot; long int rem; }; -struct _PDCLIB_lldiv_t { long long int quot; long long int rem; }; +/* defines the div() function family that allows taking quotient */ +/* and remainder of an integer division in one operation. Many platforms */ +/* support this in hardware / opcode, and the standard permits ordering of */ +/* the return structure in any way to fit the hardware. That is why those */ +/* structs can be configured here. */ + +struct _PDCLIB_div_t +{ + int quot; + int rem; +}; + +struct _PDCLIB_ldiv_t +{ + long int quot; + long int rem; +}; + +struct _PDCLIB_lldiv_t +{ + long long int quot; + long long int rem; +}; + +/* -------------------------------------------------------------------------- */ +/* defines a set of integer types that are of a minimum width, and */ +/* "usually fastest" on the system. (If, for example, accessing a single char */ +/* requires the CPU to access a complete int and then mask out the char, the */ +/* "usually fastest" type of at least 8 bits would be int, not char.) */ +/* If you do not have information on the relative performance of the types, */ +/* the standard allows you to define any type that meets minimum width and */ +/* signedness requirements. */ +/* The defines below are just configuration for the real typedefs and limit */ +/* definitions done in <_PDCLIB_int.h>. The uppercase define shall be either */ +/* SHRT, INT, LONG, or LLONG (telling which values to use for the *_MIN and */ +/* *_MAX limits); the lowercase define either short, int, long, or long long */ +/* (telling the actual type to use). */ +/* The third define is the length modifier used for the type in printf() and */ +/* scanf() functions (used in ). */ +/* If you require a non-standard datatype to define the "usually fastest" */ +/* types, PDCLib as-is doesn't support that. Please contact the author with */ +/* details on your platform in that case, so support can be added. */ +/* -------------------------------------------------------------------------- */ -/* fast* datatypes. This is a bit of a blunt instrument. */ #define _PDCLIB_FAST8 CHAR #define _PDCLIB_fast8 char #define _PDCLIB_FAST8_CONV hh @@ -60,7 +117,18 @@ struct _PDCLIB_lldiv_t { long long int quot; long long int rem; }; #define _PDCLIB_fast64 long long #define _PDCLIB_FAST64_CONV ll -/* ptrdiff_t */ +/* -------------------------------------------------------------------------- */ +/* 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 types used for size_t and ptrdiff_t should not have an integer conversion + rank greater than that of signed long int unless the implementation supports + objects large enough to make this necessary. +*/ + +/* Result type of substracting two pointers (must be signed) */ #define _PDCLIB_ptrdiff long #define _PDCLIB_PTRDIFF LONG #define _PDCLIB_PTR_CONV l @@ -69,36 +137,100 @@ struct _PDCLIB_lldiv_t { long long int quot; long long int rem; }; #define _PDCLIB_size unsigned long #define _PDCLIB_SIZE ULONG -/* intptr_t */ -#define _PDCLIB_intptr long -#define _PDCLIB_INTPTR LONG - -/* sig_atomic_t */ +/* 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 char #define _PDCLIB_SIG_ATOMIC CHAR -/* wint_t, wchar_t */ -#define _PDCLIB_wint signed int +/* Object type whose alignment is as great as supported by implementation + in all contexts. +*/ +#define _PDCLIB_max_align long double + +/* Integer type whose range of values can represent distinct codes for + all members of the largest extended character set specified among the + supported locales. + Note that the definition of this type must agree with the type used + by the compiler for L"" string and L'' character literals. +*/ #define _PDCLIB_wchar unsigned int #define _PDCLIB_WCHAR UINT +/* Each member of the basic character set shall have a code value equal + to its value when used as the lone character in an integer character + constant. If that is not the case, uncomment the following line. +#define __STDC_MB_MIGHT_NEQ_WC__ +*/ + +/* Integer type unchanged by default argument promotions that can hold any + value corresponding to characters of the extended character set, as well + as at least one value that does not correspond to any member of the + extended character set (WEOF). +*/ +#define _PDCLIB_wint signed int + +#define _PDCLIB_intptr long +#define _PDCLIB_INTPTR LONG -/* Largest supported integer type */ +/* 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 -struct _PDCLIB_imaxdiv_t { _PDCLIB_intmax quot; _PDCLIB_intmax rem; }; +/* defines imaxdiv(), which is equivalent to the div() function */ +/* family (see further above) with intmax_t as basis. */ -/* time_t */ +struct _PDCLIB_imaxdiv_t +{ + _PDCLIB_intmax quot; + _PDCLIB_intmax rem; +}; + +/* : time_t + * The C standard doesn't define what representation of time is stored in + * time_t when returned by time() , but POSIX defines it to be seconds since the + * UNIX epoch and most appplications expect that. + * + * time_t is also used as the tv_sec member of struct timespec, which *is* + * defined as a linear count of seconds. + * + * time_t is defined as a "real type", so may be a floating point type, but with + * the presence of the nanosecond accurate struct timespec, and with the lack of + * any functions for manipulating more accurate values of time_t, this is + * probably not useful. + */ #define _PDCLIB_time unsigned long long -/* clock_t */ +/* : 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 unsigned #define _PDCLIB_CLOCKS_PER_SEC 1000000 -/* timespec_get */ +/* : TIME_UTC + * + * The TIME_UTC parameter is passed to the timespec_get function in order to get + * the system time in UTC since an implementation defined epoch (not necessarily + * the same as that used for time_t). That said, on POSIX the obvious + * implementation of timespec_get for TIME_UTC is to wrap + * clock_gettime(CLOCK_REALTIME, ...), which is defined as time in UTC since the + * same epoch. + * + * This may be any non-zero integer value. + */ #define _PDCLIB_TIME_UTC 1 /* -------------------------------------------------------------------------- */ @@ -139,29 +271,52 @@ struct _PDCLIB_imaxdiv_t { _PDCLIB_intmax quot; _PDCLIB_intmax rem; }; #define _PDCLIB_FLOAT_TYPE SINGLE #define _PDCLIB_DOUBLE_TYPE DOUBLE #if defined(__i386__) || defined(__amd64__) - #define _PDCLIB_LDOUBLE_TYPE EXTENDED +#define _PDCLIB_LDOUBLE_TYPE EXTENDED #else - #define _PDCLIB_LDOUBLE_TYPE DOUBLE +#define _PDCLIB_LDOUBLE_TYPE DOUBLE #endif /* -------------------------------------------------------------------------- */ /* Platform-dependent macros defined by the standard headers. */ /* -------------------------------------------------------------------------- */ -/* offsetof */ +/* 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. +*/ #define _PDCLIB_offsetof( type, member ) __builtin_offsetof( type, member ) -/* stdarg.h */ +/* Variable Length Parameter List Handling () + The macros defined by are highly dependent on the calling + conventions used, and you probably have to replace them with builtins of + your compiler. +*/ + typedef __builtin_va_list _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) )) -/* "OS glue" */ +/* -------------------------------------------------------------------------- */ +/* 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 4096 @@ -169,11 +324,13 @@ typedef __builtin_va_list _PDCLIB_va_list; #define _PDCLIB_MALLOC_MMAP_THRESHOLD 256*1024 #define _PDCLIB_MALLOC_RELEASE_CHECK_RATE 4095 +/* TODO: Better document these */ + /* Locale --------------------------------------------------------------------*/ /* Locale method. See _PDCLIB_locale.h. If undefined, POSIX per-thread locales - * will be disabled - */ + will be disabled +*/ /* #define _PDCLIB_LOCALE_METHOD _PDCLIB_LOCALE_METHOD_TSS */ /* wchar_t encoding */ @@ -201,17 +358,50 @@ typedef __builtin_va_list _PDCLIB_va_list; /* Number of distinct file names that can be generated by tmpnam(). */ #define _PDCLIB_TMP_MAX 50 -/* SEEK_SET, CUR, END */ +/* 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 -/* How much can you ungetc? Not much, thankfully */ +/* 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 -------------------------------------------------------------------- */ -/* errno values as per C++11 */ +/* These are the values that _PDCLIB_errno can be set to by the library. + + By keeping PDCLib's errno in the _PDCLIB_* namespace, the library is capable + to "translate" between errno values used by the hosting operating system and + those used and passed out by the library. + + Example: In the example platform, the remove() function uses the unlink() + system call as backend. Linux sets its errno to EISDIR if you try to unlink() + a directory, but POSIX demands EPERM. Within the remove() function, you can + catch the 'errno == EISDIR', and set '_PDCLIB_errno = _PDCLIB_EPERM'. Anyone + using PDCLib's will "see" EPERM instead of EISDIR (the _PDCLIB_* + prefix removed by mechanics). + + If you do not want that kind of translation, you might want to "match" the + values used by PDCLib with those used by the host OS, as to avoid confusion. + + The C standard only defines three distinct errno values: ERANGE, EDOM, and + EILSEQ. The standard leaves it up to "the implementation" whether there are + any more beyond those three. + + However, C++11 introduced the whole list of POSIX errno values into the + standard, so PDCLib might as well define those as well. + + 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. +*/ + #define _PDCLIB_ERANGE 1 #define _PDCLIB_EDOM 2 #define _PDCLIB_EILSEQ 3 diff --git a/platform/gandr/includes/signal.h b/platform/gandr/includes/signal.h index 8e6df09..68da214 100644 --- a/platform/gandr/includes/signal.h +++ b/platform/gandr/includes/signal.h @@ -1,4 +1,4 @@ -/* 7.14 Signal handling +/* Signal handling This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. diff --git a/platform/posix/functions/signal/raise.c b/platform/posix/functions/signal/raise.c deleted file mode 100644 index 51c787a..0000000 --- a/platform/posix/functions/signal/raise.c +++ /dev/null @@ -1,112 +0,0 @@ -/* raise( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include -#include - -extern void (*_PDCLIB_sigabrt)( int ); -extern void (*_PDCLIB_sigfpe)( int ); -extern void (*_PDCLIB_sigill)( int ); -extern void (*_PDCLIB_sigint)( int ); -extern void (*_PDCLIB_sigsegv)( int ); -extern void (*_PDCLIB_sigterm)( int ); - -int raise( int sig ) -{ - void (*sighandler)( int ); - char const * message; - switch ( sig ) - { - case SIGABRT: - sighandler = _PDCLIB_sigabrt; - message = "Abnormal termination (SIGABRT)"; - break; - case SIGFPE: - sighandler = _PDCLIB_sigfpe; - message = "Arithmetic exception (SIGFPE)"; - break; - case SIGILL: - sighandler = _PDCLIB_sigill; - message = "Illegal instruction (SIGILL)"; - break; - case SIGINT: - sighandler = _PDCLIB_sigint; - message = "Interactive attention signal (SIGINT)"; - break; - case SIGSEGV: - sighandler = _PDCLIB_sigsegv; - message = "Invalid memory access (SIGSEGV)"; - break; - case SIGTERM: - sighandler = _PDCLIB_sigterm; - message = "Termination request (SIGTERM)"; - break; - default: - fprintf( stderr, "Unknown signal #%d\n", sig ); - _Exit( EXIT_FAILURE ); - } - if ( sighandler == SIG_DFL ) - { - fputs( message, stderr ); - _Exit( EXIT_FAILURE ); - } - else if ( sighandler != SIG_IGN ) - { - sighandler = signal( sig, SIG_DFL ); - sighandler( sig ); - } - return 0; -} - -#endif - -#ifdef TEST -#include <_PDCLIB_test.h> - -#include - -static volatile sig_atomic_t flag = 0; - -static int expected_signal = 0; - -static void test_handler( int sig ) -{ - TESTCASE( sig == expected_signal ); - flag = 1; -} - -int main( void ) -{ - /* Could be other than SIG_DFL if you changed the implementation. */ - TESTCASE( signal( SIGABRT, SIG_IGN ) == SIG_DFL ); - /* Should be ignored. */ - TESTCASE( raise( SIGABRT ) == 0 ); - /* Installing test handler, old handler should be returned */ - TESTCASE( signal( SIGABRT, test_handler ) == SIG_IGN ); - /* Raising and checking SIGABRT */ - expected_signal = SIGABRT; - TESTCASE( raise( SIGABRT ) == 0 ); - TESTCASE( flag == 1 ); - /* Re-installing test handler, should have been reset to default */ - /* Could be other than SIG_DFL if you changed the implementation. */ - TESTCASE( signal( SIGABRT, test_handler ) == SIG_DFL ); - /* Raising and checking SIGABRT */ - flag = 0; - TESTCASE( raise( SIGABRT ) == 0 ); - TESTCASE( flag == 1 ); - /* Installing test handler for different signal... */ - TESTCASE( signal( SIGTERM, test_handler ) == SIG_DFL ); - /* Raising and checking SIGTERM */ - expected_signal = SIGTERM; - TESTCASE( raise( SIGTERM ) == 0 ); - TESTCASE( flag == 1 ); - return TEST_RESULTS; -} -#endif diff --git a/platform/posix/includes/signal.h b/platform/posix/includes/signal.h index 2d52993..8b30a4f 100644 --- a/platform/posix/includes/signal.h +++ b/platform/posix/includes/signal.h @@ -1,4 +1,4 @@ -/* 7.14 Signal handling +/* Signal handling This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. diff --git a/platform/posix/internals/_PDCLIB_config.h b/platform/posix/internals/_PDCLIB_config.h index 5b71195..a9dc26f 100644 --- a/platform/posix/internals/_PDCLIB_config.h +++ b/platform/posix/internals/_PDCLIB_config.h @@ -48,9 +48,9 @@ #define _PDCLIB_SHRT_BYTES 2 #define _PDCLIB_INT_BYTES 4 #if defined(_LP64) || defined(__ILP64__) - #define _PDCLIB_LONG_BYTES 8 +#define _PDCLIB_LONG_BYTES 8 #else - #define _PDCLIB_LONG_BYTES 4 +#define _PDCLIB_LONG_BYTES 4 #endif #define _PDCLIB_LLONG_BYTES 8 @@ -129,11 +129,20 @@ struct _PDCLIB_lldiv_t /* defines here are merely "configuration". See above for details. */ /* -------------------------------------------------------------------------- */ -/* The result type of substracting two pointers */ +/* The types used for size_t and ptrdiff_t should not have an integer conversion + rank greater than that of signed long int unless the implementation supports + objects large enough to make this necessary. +*/ + +/* Result type of substracting two pointers (must be signed) */ #define _PDCLIB_ptrdiff long #define _PDCLIB_PTRDIFF LONG #define _PDCLIB_PTR_CONV l +/* Result type of the 'sizeof' operator (must be unsigned) */ +#define _PDCLIB_size unsigned long +#define _PDCLIB_SIZE ULONG + /* 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.) @@ -141,16 +150,37 @@ struct _PDCLIB_lldiv_t #define _PDCLIB_sig_atomic int #define _PDCLIB_SIG_ATOMIC INT -/* Result type of the 'sizeof' operator (must be unsigned) */ -#define _PDCLIB_size unsigned long -#define _PDCLIB_SIZE ULONG +/* Object type whose alignment is as great as supported by implementation + in all contexts. +*/ +#define _PDCLIB_max_align long double -/* Large enough an integer to hold all character codes of the largest supported - locale. +/* Integer type whose range of values can represent distinct codes for + all members of the largest extended character set specified among the + supported locales. + Note that the definition of this type must agree with the type used + by the compiler for L"" string and L'' character literals. */ -#define _PDCLIB_wint int +#if defined(_LP64) || defined(__ILP64__) #define _PDCLIB_wchar int #define _PDCLIB_WCHAR INT +#else +#define _PDCLIB_wchar long +#define _PDCLIB_WCHAR LONG +#endif + +/* Each member of the basic character set shall have a code value equal + to its value when used as the lone character in an integer character + constant. If that is not the case, uncomment the following line. +#define __STDC_MB_MIGHT_NEQ_WC__ +*/ + +/* Integer type unchanged by default argument promotions that can hold any + value corresponding to characters of the extended character set, as well + as at least one value that does not correspond to any member of the + extended character set (WEOF). +*/ +#define _PDCLIB_wint int #define _PDCLIB_intptr long #define _PDCLIB_INTPTR LONG @@ -184,7 +214,7 @@ struct _PDCLIB_imaxdiv_t * any functions for manipulating more accurate values of time_t, this is * probably not useful. */ -#define _PDCLIB_time long +#define _PDCLIB_time long /* : clock_t * @@ -268,9 +298,9 @@ struct _PDCLIB_imaxdiv_t most compilers. */ #ifdef __GNUC__ - #define _PDCLIB_offsetof( type, member ) __builtin_offsetof( type, member ) +#define _PDCLIB_offsetof( type, member ) __builtin_offsetof( type, member ) #else - #define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) ) +#define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) ) #endif /* Variable Length Parameter List Handling () @@ -280,22 +310,21 @@ struct _PDCLIB_imaxdiv_t */ #ifdef __GNUC__ - typedef __builtin_va_list _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) )) +typedef __builtin_va_list _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) )) #elif (defined(__i386__) || defined(__i386) || defined(_M_IX86)) && !(defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64)) - /* Internal helper macro. va_round is not part of . */ - #define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) ) - - typedef char * _PDCLIB_va_list; - #define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) ) - #define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 ) - #define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 ) - #define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 ) +/* Internal helper macro. va_round is not part of . */ +#define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) ) +typedef char * _PDCLIB_va_list; +#define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) ) +#define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 ) +#define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 ) +#define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 ) #else - #error Compiler/Architecture support please +#error Compiler/Architecture support please #endif /* -------------------------------------------------------------------------- */ @@ -322,7 +351,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 */ @@ -379,7 +410,7 @@ struct _PDCLIB_imaxdiv_t prefix removed by mechanics). If you do not want that kind of translation, you might want to "match" the - values used by PDCLib with those used by the host OS, to avoid confusion. + 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 @@ -388,8 +419,8 @@ struct _PDCLIB_imaxdiv_t However, C++11 introduced the whole list of POSIX errno values into the standard, so PDCLib might as well define those as well. - 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 + 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. */ diff --git a/platform/win32/functions/signal/raise.c b/platform/win32/functions/signal/raise.c deleted file mode 100644 index 51c787a..0000000 --- a/platform/win32/functions/signal/raise.c +++ /dev/null @@ -1,112 +0,0 @@ -/* raise( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include -#include - -extern void (*_PDCLIB_sigabrt)( int ); -extern void (*_PDCLIB_sigfpe)( int ); -extern void (*_PDCLIB_sigill)( int ); -extern void (*_PDCLIB_sigint)( int ); -extern void (*_PDCLIB_sigsegv)( int ); -extern void (*_PDCLIB_sigterm)( int ); - -int raise( int sig ) -{ - void (*sighandler)( int ); - char const * message; - switch ( sig ) - { - case SIGABRT: - sighandler = _PDCLIB_sigabrt; - message = "Abnormal termination (SIGABRT)"; - break; - case SIGFPE: - sighandler = _PDCLIB_sigfpe; - message = "Arithmetic exception (SIGFPE)"; - break; - case SIGILL: - sighandler = _PDCLIB_sigill; - message = "Illegal instruction (SIGILL)"; - break; - case SIGINT: - sighandler = _PDCLIB_sigint; - message = "Interactive attention signal (SIGINT)"; - break; - case SIGSEGV: - sighandler = _PDCLIB_sigsegv; - message = "Invalid memory access (SIGSEGV)"; - break; - case SIGTERM: - sighandler = _PDCLIB_sigterm; - message = "Termination request (SIGTERM)"; - break; - default: - fprintf( stderr, "Unknown signal #%d\n", sig ); - _Exit( EXIT_FAILURE ); - } - if ( sighandler == SIG_DFL ) - { - fputs( message, stderr ); - _Exit( EXIT_FAILURE ); - } - else if ( sighandler != SIG_IGN ) - { - sighandler = signal( sig, SIG_DFL ); - sighandler( sig ); - } - return 0; -} - -#endif - -#ifdef TEST -#include <_PDCLIB_test.h> - -#include - -static volatile sig_atomic_t flag = 0; - -static int expected_signal = 0; - -static void test_handler( int sig ) -{ - TESTCASE( sig == expected_signal ); - flag = 1; -} - -int main( void ) -{ - /* Could be other than SIG_DFL if you changed the implementation. */ - TESTCASE( signal( SIGABRT, SIG_IGN ) == SIG_DFL ); - /* Should be ignored. */ - TESTCASE( raise( SIGABRT ) == 0 ); - /* Installing test handler, old handler should be returned */ - TESTCASE( signal( SIGABRT, test_handler ) == SIG_IGN ); - /* Raising and checking SIGABRT */ - expected_signal = SIGABRT; - TESTCASE( raise( SIGABRT ) == 0 ); - TESTCASE( flag == 1 ); - /* Re-installing test handler, should have been reset to default */ - /* Could be other than SIG_DFL if you changed the implementation. */ - TESTCASE( signal( SIGABRT, test_handler ) == SIG_DFL ); - /* Raising and checking SIGABRT */ - flag = 0; - TESTCASE( raise( SIGABRT ) == 0 ); - TESTCASE( flag == 1 ); - /* Installing test handler for different signal... */ - TESTCASE( signal( SIGTERM, test_handler ) == SIG_DFL ); - /* Raising and checking SIGTERM */ - expected_signal = SIGTERM; - TESTCASE( raise( SIGTERM ) == 0 ); - TESTCASE( flag == 1 ); - return TEST_RESULTS; -} -#endif diff --git a/platform/win32/functions/signal/signal.c b/platform/win32/functions/signal/signal.c deleted file mode 100644 index dc0b8ce..0000000 --- a/platform/win32/functions/signal/signal.c +++ /dev/null @@ -1,74 +0,0 @@ -/* 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 -#include - -#ifndef REGTEST - -#include - -void (*_PDCLIB_sigabrt)( int ) = SIG_DFL; -void (*_PDCLIB_sigfpe)( int ) = SIG_DFL; -void (*_PDCLIB_sigill)( int ) = SIG_DFL; -void (*_PDCLIB_sigint)( int ) = SIG_DFL; -void (*_PDCLIB_sigsegv)( int ) = SIG_DFL; -void (*_PDCLIB_sigterm)( int ) = SIG_DFL; - -void (*signal( int sig, void (*func)( int ) ) )( int ) -{ - void (*oldhandler)( int ); - if ( sig <= 0 || func == SIG_ERR ) - { - return SIG_ERR; - } - switch ( sig ) - { - case SIGABRT: - oldhandler = _PDCLIB_sigabrt; - _PDCLIB_sigabrt = func; - break; - case SIGFPE: - oldhandler = _PDCLIB_sigfpe; - _PDCLIB_sigfpe = func; - break; - case SIGILL: - oldhandler = _PDCLIB_sigill; - _PDCLIB_sigill = func; - break; - case SIGINT: - oldhandler = _PDCLIB_sigint; - _PDCLIB_sigint = func; - break; - case SIGSEGV: - oldhandler = _PDCLIB_sigsegv; - _PDCLIB_sigsegv = func; - break; - case SIGTERM: - oldhandler = _PDCLIB_sigterm; - _PDCLIB_sigterm = func; - break; - default: - /* The standard calls for an unspecified "positive value". You - will probably want to define a specific value for this. - */ - 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/includes/signal.h b/platform/win32/includes/signal.h index 2d52993..8b30a4f 100644 --- a/platform/win32/includes/signal.h +++ b/platform/win32/includes/signal.h @@ -1,4 +1,4 @@ -/* 7.14 Signal handling +/* Signal handling This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. diff --git a/platform/win32/internals/_PDCLIB_config.h b/platform/win32/internals/_PDCLIB_config.h index da83cba..1c4a363 100644 --- a/platform/win32/internals/_PDCLIB_config.h +++ b/platform/win32/internals/_PDCLIB_config.h @@ -116,15 +116,29 @@ struct _PDCLIB_lldiv_t /* defines here are merely "configuration". See above for details. */ /* -------------------------------------------------------------------------- */ -/* The result type of substracting two pointers */ +/* The types used for size_t and ptrdiff_t should not have an integer conversion + rank greater than that of signed long int unless the implementation supports + objects large enough to make this necessary. +*/ + +/* Result type of substracting two pointers (must be signed) */ +#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 + +/* Result type of the 'sizeof' operator (must be unsigned) */ #if defined(__amd64__) || defined(_M_AMD64) - #define _PDCLIB_ptrdiff long long - #define _PDCLIB_PTRDIFF LLONG - #define _PDCLIB_PTR_CONV ll +#define _PDCLIB_size unsigned long long +#define _PDCLIB_SIZE ULLONG #else - #define _PDCLIB_ptrdiff int - #define _PDCLIB_PTRDIFF INT - #define _PDCLIB_PTR_CONV +#define _PDCLIB_size unsigned int +#define _PDCLIB_SIZE UINT #endif /* An integer type that can be accessed as atomic entity (think asynchronous @@ -134,30 +148,39 @@ struct _PDCLIB_lldiv_t #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 +/* Object type whose alignment is as great as supported by implementation + in all contexts. +*/ +#define _PDCLIB_max_align long double -/* Large enough an integer to hold all character codes of the largest supported - locale. +/* Integer type whose range of values can represent distinct codes for + all members of the largest extended character set specified among the + supported locales. + Note that the definition of this type must agree with the type used + by the compiler for L"" string and L'' character literals. +*/ +#define _PDCLIB_wchar unsigned short +#define _PDCLIB_WCHAR USHRT - XX: Windows requires wchar_t be an unsigned short, but this is not compliant. +/* Each member of the basic character set shall have a code value equal + to its value when used as the lone character in an integer character + constant. If that is not the case, uncomment the following line. +#define __STDC_MB_MIGHT_NEQ_WC__ +*/ + +/* Integer type unchanged by default argument promotions that can hold any + value corresponding to characters of the extended character set, as well + as at least one value that does not correspond to any member of the + extended character set (WEOF). */ #define _PDCLIB_wint signed int -#define _PDCLIB_wchar unsigned short -#define _PDCLIB_WCHAR USHRT #if defined(__amd64__) || defined(_M_AMD64) - #define _PDCLIB_intptr long long - #define _PDCLIB_INTPTR LLONG +#define _PDCLIB_intptr long long +#define _PDCLIB_INTPTR LLONG #else - #define _PDCLIB_intptr int - #define _PDCLIB_INTPTR INT +#define _PDCLIB_intptr int +#define _PDCLIB_INTPTR INT #endif /* Largest supported integer type. Implementation note: see _PDCLIB_atomax(). */ @@ -176,30 +199,30 @@ struct _PDCLIB_imaxdiv_t _PDCLIB_intmax rem; }; -/* : time_t - * The C standard doesn't define what representation of time is stored in +/* : 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. + * UNIX epoch and most appplications expect that. * - * time_t is also used as the tv_sec member of struct timespec, which *is* + * 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 + * any functions for manipulating more accurate values of time_t, this is * probably not useful. */ -#define _PDCLIB_time unsigned long long +#define _PDCLIB_time unsigned long long /* : clock_t * * A count of "clock ticks", where the length of a clock tick is unspecified by - * the standard. The implementation is required to provide a macro, + * 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. + * various systems differs. * * On XSI systems, CLOCKS_PER_SEC must be defined to 1000000 */ @@ -210,8 +233,8 @@ struct _PDCLIB_imaxdiv_t * * The TIME_UTC parameter is passed to the timespec_get function in order to get * the system time in UTC since an implementation defined epoch (not necessarily - * the same as that used for time_t). That said, on POSIX the obvious - * implementation of timespec_get for TIME_UTC is to wrap + * the same as that used for time_t). That said, on POSIX the obvious + * implementation of timespec_get for TIME_UTC is to wrap * clock_gettime(CLOCK_REALTIME, ...), which is defined as time in UTC since the * same epoch. * @@ -273,9 +296,9 @@ struct _PDCLIB_imaxdiv_t most compilers. */ #ifdef __GNUC__ - #define _PDCLIB_offsetof( type, member ) __builtin_offsetof( type, member ) +#define _PDCLIB_offsetof( type, member ) __builtin_offsetof( type, member ) #else - #define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) ) +#define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) ) #endif /* Variable Length Parameter List Handling () @@ -285,22 +308,21 @@ struct _PDCLIB_imaxdiv_t */ #ifdef __GNUC__ - typedef __builtin_va_list _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) )) +typedef __builtin_va_list _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) )) #elif (defined(__i386__) || defined(__i386) || defined(_M_IX86)) && !(defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64)) - /* Internal helper macro. va_round is not part of . */ - #define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) ) - - typedef char * _PDCLIB_va_list; - #define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) ) - #define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 ) - #define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 ) - #define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 ) +/* Internal helper macro. va_round is not part of . */ +#define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) ) +typedef char * _PDCLIB_va_list; +#define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) ) +#define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 ) +#define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 ) +#define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 ) #else - #error Compiler/Architecture support please +#error Compiler/Architecture support please #endif /* -------------------------------------------------------------------------- */ @@ -328,8 +350,8 @@ struct _PDCLIB_imaxdiv_t /* Locale --------------------------------------------------------------------*/ /* Locale method. See _PDCLIB_locale.h. If undefined, POSIX per-thread locales - * will be disabled - */ + will be disabled. +*/ #define _PDCLIB_LOCALE_METHOD _PDCLIB_LOCALE_METHOD_TSS /* wchar_t encoding */ @@ -397,8 +419,8 @@ struct _PDCLIB_imaxdiv_t However, C++11 introduced the whole list of POSIX errno values into the standard, so PDCLib might as well define those as well. - 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 + 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. */ diff --git a/platform/win32/internals/_PDCLIB_threadconfig.h b/platform/win32/internals/_PDCLIB_threadconfig.h index 0f35d29..cca59e1 100644 --- a/platform/win32/internals/_PDCLIB_threadconfig.h +++ b/platform/win32/internals/_PDCLIB_threadconfig.h @@ -3,7 +3,9 @@ #include <_PDCLIB_aux.h> #include <_PDCLIB_int.h> -_PDCLIB_BEGIN_EXTERN_C +#ifdef __cplusplus +extern "C" { +#endif #define _PDCLIB_TSS_DTOR_ITERATIONS 3 #define _PDCLIB_ONCE_FLAG_INIT { -1, 0 } #define _PDCLIB_ONCE_FLAG_IS_DONE( _f ) ((_f)->_State == 0) @@ -32,5 +34,7 @@ struct _PDCLIB_tss { unsigned int _Key; }; -_PDCLIB_END_EXTERN_C +#ifdef __cplusplus +} +#endif #endif -- 2.40.0