*/
#include <signal.h>
+#include <errno.h>
#ifndef REGTEST
-#include <stdlib.h>
-#include <errno.h>
void (*_PDCLIB_sigabrt)( int ) = SIG_DFL;
void (*_PDCLIB_sigfpe)( int ) = SIG_DFL;
-/* 7.2 Diagnostics <assert.h>
+/* Diagnostics <assert.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
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
_PDCLIB_UNREACHABLE; \
} \
} while(0)
-
+
#else
#define assert(expression) \
do { if(!(expression)) { \
} \
} while(0)
#endif
-
-_PDCLIB_END_EXTERN_C
-/* 7.4 Character handling <ctype.h>
+/* Character handling <ctype.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_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 */
*/
int toupper( int c ) _PDCLIB_nothrow;
-_PDCLIB_END_EXTERN_C
+#ifdef __cplusplus
+}
+#endif
+
#endif
-/* 7.7 Characteristics of floating types <float.h>\r
+/* Characteristics of floating types <float.h>\r
\r
This file is part of the Public Domain C Library (PDCLib).\r
Permission is granted to use, modify, and / or redistribute at will.\r
#define FLT_EVAL_METHOD _PDCLIB_FLT_EVAL_METHOD\r
#define DECIMAL_DIG _PDCLIB_DECIMAL_DIG\r
\r
- /* Radix of exponent representation */\r
+/* Radix of exponent representation */\r
#define FLT_RADIX _PDCLIB_FLT_RADIX\r
- /* Number of base-FLT_RADIX digits in the significand of a float */\r
+\r
+/* Number of base-FLT_RADIX digits in the significand of a float */\r
#define FLT_MANT_DIG _PDCLIB_FLT_MANT_DIG\r
- /* Number of decimal digits of precision in a float */\r
+\r
+/* Number of decimal digits of precision in a float */\r
#define FLT_DIG _PDCLIB_FLT_DIG\r
- /* Difference between 1.0 and the minimum float greater than 1.0 */\r
+\r
+/* Difference between 1.0 and the minimum float greater than 1.0 */\r
#define FLT_EPSILON _PDCLIB_FLT_EPSILON\r
- /* Minimum int x such that FLT_RADIX**(x-1) is a normalised float */\r
+\r
+/* Minimum int x such that FLT_RADIX**(x-1) is a normalised float */\r
#define FLT_MIN_EXP _PDCLIB_FLT_MIN_EXP\r
- /* Minimum normalised float */\r
+\r
+/* Minimum normalised float */\r
#define FLT_MIN _PDCLIB_FLT_MIN\r
- /* Minimum int x such that 10**x is a normalised float */\r
+\r
+/* Minimum int x such that 10**x is a normalised float */\r
#define FLT_MIN_10_EXP _PDCLIB_FLT_MIN_10_EXP\r
- /* Maximum int x such that FLT_RADIX**(x-1) is a representable float */\r
+\r
+/* Maximum int x such that FLT_RADIX**(x-1) is a representable float */\r
#define FLT_MAX_EXP _PDCLIB_FLT_MAX_EXP\r
- /* Maximum float */\r
+\r
+/* Maximum float */\r
#define FLT_MAX _PDCLIB_FLT_MAX\r
- /* Maximum int x such that 10**x is a representable float */\r
+\r
+/* Maximum int x such that 10**x is a representable float */\r
#define FLT_MAX_10_EXP _PDCLIB_FLT_MAX_10_EXP\r
\r
- /* Number of base-FLT_RADIX digits in the significand of a double */\r
+\r
+/* Number of base-FLT_RADIX digits in the significand of a double */\r
#define DBL_MANT_DIG _PDCLIB_DBL_MANT_DIG\r
- /* Number of decimal digits of precision in a double */\r
+\r
+/* Number of decimal digits of precision in a double */\r
#define DBL_DIG _PDCLIB_DBL_DIG\r
- /* Difference between 1.0 and the minimum double greater than 1.0 */\r
+\r
+/* Difference between 1.0 and the minimum double greater than 1.0 */\r
#define DBL_EPSILON _PDCLIB_DBL_EPSILON\r
- /* Minimum int x such that FLT_RADIX**(x-1) is a normalised double */\r
+\r
+/* Minimum int x such that FLT_RADIX**(x-1) is a normalised double */\r
#define DBL_MIN_EXP _PDCLIB_DBL_MIN_EXP\r
- /* Minimum normalised double */\r
+\r
+/* Minimum normalised double */\r
#define DBL_MIN _PDCLIB_DBL_MIN\r
- /* Minimum int x such that 10**x is a normalised double */\r
+\r
+/* Minimum int x such that 10**x is a normalised double */\r
#define DBL_MIN_10_EXP _PDCLIB_DBL_MIN_10_EXP\r
- /* Maximum int x such that FLT_RADIX**(x-1) is a representable double */\r
+\r
+/* Maximum int x such that FLT_RADIX**(x-1) is a representable double */\r
#define DBL_MAX_EXP _PDCLIB_DBL_MAX_EXP\r
- /* Maximum double */\r
+\r
+/* Maximum double */\r
#define DBL_MAX _PDCLIB_DBL_MAX\r
- /* Maximum int x such that 10**x is a representable double */\r
+\r
+/* Maximum int x such that 10**x is a representable double */\r
#define DBL_MAX_10_EXP _PDCLIB_DBL_MAX_10_EXP\r
\r
- /* Number of base-FLT_RADIX digits in the significand of a long double */\r
+\r
+/* Number of base-FLT_RADIX digits in the significand of a long double */\r
#define LDBL_MANT_DIG _PDCLIB_LDBL_MANT_DIG\r
- /* Number of decimal digits of precision in a long double */\r
+\r
+/* Number of decimal digits of precision in a long double */\r
#define LDBL_DIG _PDCLIB_LDBL_DIG\r
- /* Difference between 1.0 and the minimum long double greater than 1.0 */\r
+\r
+/* Difference between 1.0 and the minimum long double greater than 1.0 */\r
#define LDBL_EPSILON _PDCLIB_LDBL_EPSILON\r
- /* Minimum int x such that FLT_RADIX**(x-1) is a normalised long double */\r
+\r
+/* Minimum int x such that FLT_RADIX**(x-1) is a normalised long double */\r
#define LDBL_MIN_EXP _PDCLIB_LDBL_MIN_EXP\r
- /* Minimum normalised long double */\r
+\r
+/* Minimum normalised long double */\r
#define LDBL_MIN _PDCLIB_LDBL_MIN\r
- /* Minimum int x such that 10**x is a normalised long double */\r
+\r
+/* Minimum int x such that 10**x is a normalised long double */\r
#define LDBL_MIN_10_EXP _PDCLIB_LDBL_MIN_10_EXP\r
- /* Maximum int x such that FLT_RADIX**(x-1) is a representable long double */\r
+\r
+/* Maximum int x such that FLT_RADIX**(x-1) is a representable long double */\r
#define LDBL_MAX_EXP _PDCLIB_LDBL_MAX_EXP\r
- /* Maximum long double */\r
+\r
+/* Maximum long double */\r
#define LDBL_MAX _PDCLIB_LDBL_MAX\r
- /* Maximum int x such that 10**x is a representable long double */\r
+\r
+/* Maximum int x such that 10**x is a representable long double */\r
#define LDBL_MAX_10_EXP _PDCLIB_LDBL_MAX_10_EXP\r
\r
#endif\r
-/* 7.8 Format conversion of integer types <inttypes.h>
+/* Format conversion of integer types <inttypes.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_INTTYPES_H
#define _PDCLIB_INTTYPES_H _PDCLIB_INTTYPES_H
#include <stdint.h>
-_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 ) )
#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;
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 <stdlib.h>, but on
+
+/* These functions are equivalent to strtol() / strtoul() in <stdlib.h>, 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 <wchar.h>, 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
-/* 7.9 Alternative spellings <iso646.h>
+/* Alternative spellings <iso646.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
#endif
#endif
-
-/* 7.10 Sizes of integer types <limits.h>
+/* Sizes of integer types <limits.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
#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
#define ULONG_MAX _PDCLIB_ULONG_MAX
#endif
-
-/* 7.11 Localization <locale.h>
+/* Localization <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>
-_PDCLIB_BEGIN_EXTERN_C
+
+#ifdef __cplusplus
+extern "C" {
+#endif
#ifndef _PDCLIB_NULL_DEFINED
#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED
#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)
#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
--- /dev/null
+/* Alignmend <stdalign.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_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
+
-/* 7.15 Variable arguments <stdarg.h>
+/* Variable arguments <stdarg.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
#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;
#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
-/* 7.16 Boolean type and values <stdbool.h>
+/* Boolean type and values <stdbool.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
#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
-
-/* 7.17 Common definitions <stddef.h>
+/* Common definitions <stddef.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
#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;
#define offsetof( type, member ) _PDCLIB_offsetof( type, member )
-_PDCLIB_END_EXTERN_C
+#ifdef __cplusplus
+}
#endif
+#endif
-/* 7.18 Integer types <stdint.h>
+/* Integer types <stdint.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
#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;
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. */
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
#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
#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.
#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
#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
#endif
-/* 7.18.4 Macros for integer constants */
+/* Macros for integer constants */
#ifdef __cplusplus
#ifndef __STDC_CONSTANT_MACROS
#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
#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 )
#endif
#endif
-
-/* 7.19 Input/output <stdio.h>
+/* Input/output <stdio.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_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
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;
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
-/* 7.20 General utilities <stdlib.h>
+/* General utilities <stdlib.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_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
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
size_t wcstombs( char * _PDCLIB_restrict s, const wchar_t * _PDCLIB_restrict pwcs, size_t n );
*/
-_PDCLIB_END_EXTERN_C
+#ifdef __cplusplus
+}
+#endif
+
#endif
-/* 7.21 String handling <string.h>
+/* String handling <string.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
#ifndef _PDCLIB_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
size_t _DstSize) _PDCLIB_nothrow;
#endif
-_PDCLIB_END_EXTERN_C
+#ifdef __cplusplus
+}
+#endif
+
#endif
-#ifndef _PDCLIB_THREADS_H\r
-#define _PDCLIB_THREADS_H\r
-#include <_PDCLIB_int.h>\r
-#include <_PDCLIB_threadconfig.h>\r
-#include <time.h>\r
-_PDCLIB_BEGIN_EXTERN_C\r
-\r
-#define thread_local _Thread_local\r
-\r
-typedef _PDCLIB_once_flag once_flag;\r
-\r
-enum {\r
- mtx_plain = 0,\r
- mtx_recursive = (1 << 0),\r
- mtx_timed = (1 << 1),\r
-\r
- _PDCLIB_mtx_valid_mask = mtx_recursive | mtx_timed\r
-};\r
-\r
-enum {\r
- thrd_success = 0,\r
- thrd_timeout = 1,\r
- thrd_busy = 2,\r
- thrd_error = 3,\r
- thrd_nomem = 4,\r
-};\r
-\r
-#define ONCE_FLAG_INIT _PDCLIB_ONCE_FLAG_INIT\r
-#if defined(_PDCLIB_ONCE_FLAG_IS_DONE)\r
-static inline void call_once(once_flag *flag, void (*func)(void))\r
-{\r
- if(!_PDCLIB_ONCE_FLAG_IS_DONE(flag)) {\r
- _PDCLIB_call_once(flag, func);\r
- }\r
-}\r
-#else\r
-void call_once(once_flag *flag, void (*func)(void));\r
-#endif\r
-\r
-#if defined(_PDCLIB_MTX_T)\r
-typedef _PDCLIB_MTX_T mtx_t;\r
-void mtx_destroy(mtx_t *mtx) _PDCLIB_nothrow;\r
-int mtx_init(mtx_t *mtx, int type) _PDCLIB_nothrow;\r
-int mtx_lock(mtx_t *mtx) _PDCLIB_nothrow;\r
-int mtx_timedlock(mtx_t *_PDCLIB_restrict mtx, const struct timespec *_PDCLIB_restrict ts) _PDCLIB_nothrow;\r
-int mtx_trylock(mtx_t *mtx) _PDCLIB_nothrow;\r
-int mtx_unlock(mtx_t *mtx) _PDCLIB_nothrow;\r
-#endif\r
-\r
-#if defined(_PDCLIB_CND_T)\r
-typedef _PDCLIB_CND_T cnd_t;\r
-int cnd_broadcast(cnd_t *cond) _PDCLIB_nothrow;\r
-void cnd_destroy(cnd_t *cond) _PDCLIB_nothrow;\r
-int cnd_init(cnd_t *cond) _PDCLIB_nothrow;\r
-int cnd_signal(cnd_t *cond) _PDCLIB_nothrow;\r
-int cnd_timedwait(cnd_t *_PDCLIB_restrict cond,\r
- mtx_t *_PDCLIB_restrict mtx,\r
- const struct timespec *_PDCLIB_restrict ts) _PDCLIB_nothrow;\r
-int cnd_wait(cnd_t *cond, mtx_t *mtx) _PDCLIB_nothrow;\r
-#endif\r
-\r
-#if defined(_PDCLIB_THRD_T)\r
-#define _PDCLIB_THRD_HAVE_MISC\r
-typedef _PDCLIB_THRD_T thrd_t;\r
-typedef int (*thrd_start_t)(void*);\r
-\r
-int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) _PDCLIB_nothrow;\r
-thrd_t thrd_current(void) _PDCLIB_nothrow;\r
-int thrd_detach(thrd_t thr) _PDCLIB_nothrow;\r
-int thrd_equal(thrd_t thr0, thrd_t thr1) _PDCLIB_nothrow;\r
-\r
-/* Not nothrow: systems may use exceptions at thread exit */\r
-_PDCLIB_noreturn void thrd_exit(int res);\r
-/* Not nothrow: systems may potentially propogate exceptions out of thrd_join?*/\r
-int thrd_join(thrd_t thr, int *res);\r
-#endif\r
-\r
-#if defined(_PDCLIB_THRD_HAVE_MISC)\r
-int thrd_sleep(const struct timespec *duration, struct timespec *remaining) _PDCLIB_nothrow;\r
-void thrd_yield(void) _PDCLIB_nothrow;\r
-#endif\r
-\r
-/* The behaviour of tss_t is woefully underspecified in the C11 standard. In \r
- * particular, it never specifies where/when/<b>if</b> destructors are called.\r
- *\r
- * In lieu of any clarification, we assume the behaviour of POSIX pthread_key_t\r
- */\r
-\r
-#if defined(_PDCLIB_TSS_T)\r
-#define TSS_DTOR_ITERATIONS _PDCLIB_TSS_DTOR_ITERATIONS\r
-\r
-typedef _PDCLIB_TSS_T tss_t;\r
-typedef void (*tss_dtor_t)(void*);\r
-\r
-int tss_create(tss_t *key, tss_dtor_t dtor) _PDCLIB_nothrow;\r
-void tss_delete(tss_t key) _PDCLIB_nothrow;\r
-void *tss_get(tss_t key) _PDCLIB_nothrow;\r
-int tss_set(tss_t key, void *val) _PDCLIB_nothrow;\r
-#endif\r
-\r
-_PDCLIB_END_EXTERN_C\r
-#endif\r
+/* Threads <threads.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_THREADS_H
+#define _PDCLIB_THREADS_H _PDCLIB_THREADS_H
+#include <_PDCLIB_int.h>
+#include <_PDCLIB_threadconfig.h>
+
+#include <time.h>
+
+#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/<b>if</b> 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
-#ifndef _PDCLIB_TIME_H\r
-#define _PDCLIB_TIME_H\r
-#include <_PDCLIB_aux.h>\r
-#include <_PDCLIB_int.h>\r
-\r
-_PDCLIB_BEGIN_EXTERN_C\r
-#ifndef _PDCLIB_SIZE_T_DEFINED\r
-#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED\r
-typedef _PDCLIB_size_t size_t;\r
-#endif\r
-\r
-#ifndef _PDCLIB_NULL_DEFINED\r
-#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED\r
-#define NULL _PDCLIB_NULL\r
-#endif\r
-\r
-typedef _PDCLIB_time_t time_t;\r
-typedef _PDCLIB_clock_t clock_t;\r
-\r
-#define TIME_UTC _PDCLIB_TIME_UTC\r
-\r
-#ifndef _PDCLIB_STRUCT_TIMESPEC_DEFINED\r
-#define _PDCLIB_STRUCT_TIMESPEC_DEFINED\r
-_PDCLIB_DEFINE_STRUCT_TIMESPEC()\r
-#endif\r
-\r
-#ifndef _PDCLIB_STRUCT_TM_DEFINED\r
-#define _PDCLIB_STRUCT_TM_DEFINED\r
-_PDCLIB_DEFINE_STRUCT_TM()\r
-#endif\r
-\r
-time_t time( time_t* t ) _PDCLIB_nothrow;\r
-int timespec_get( struct timespec *ts, int base ) _PDCLIB_nothrow;\r
-\r
-_PDCLIB_END_EXTERN_C\r
-#endif\r
+/* Date and time <time.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_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
-/* 7.28 <uchar.h>
+/* Unicode utilities <uchar.h>
- 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
#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
-/* 7. <wchar.h>\r
-\r
- This file is part of the Public Domain C Library (PDCLib).\r
- Permission is granted to use, modify, and / or redistribute at will.\r
-*/\r
-\r
-\r
-#ifndef _PDCLIB_WCHAR_H\r
-#define _PDCLIB_WCHAR_H\r
-#include <_PDCLIB_int.h>\r
-_PDCLIB_BEGIN_EXTERN_C\r
-\r
-#ifndef _PDCLIB_SIZE_T_DEFINED\r
-#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED\r
-typedef _PDCLIB_size_t size_t;\r
-#endif\r
-\r
-#ifndef __cplusplus\r
-#ifndef _PDCLIB_WCHAR_T_DEFINED\r
-#define _PDCLIB_WCHAR_T_DEFINED _PDCLIB_WCHAR_T_DEFINED\r
-typedef _PDCLIB_wchar_t wchar_t;\r
-#endif\r
-#endif\r
-\r
-#ifndef _PDCLIB_WINT_T_DEFINED\r
-#define _PDCLIB_WINT_T_DEFINED _PDCLIB_WINT_T_DEFINED\r
-typedef _PDCLIB_wint_t wint_t;\r
-#endif\r
-\r
-#ifndef _PDCLIB_MBSTATE_T_DEFINED\r
-#define _PDCLIB_MBSTATE_T_DEFINED _PDCLIB_MBSTATE_T_DEFINED\r
-typedef _PDCLIB_mbstate_t mbstate_t;\r
-#endif\r
-\r
-struct tm;\r
-\r
-#ifndef _PDCLIB_NULL_DEFINED\r
-#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED\r
-#define NULL _PDCLIB_NULL\r
-#endif\r
-\r
-#ifndef _PDCLIB_WCHAR_MIN_MAX_DEFINED\r
-#define _PDCLIB_WCHAR_MIN_MAX_DEFINED\r
-#define WCHAR_MIN _PDCLIB_WCHAR_MIN\r
-#define WCHAR_MAX _PDCLIB_WCHAR_MAX\r
-#endif\r
-\r
-#ifndef _WEOF\r
-#define WEOF ((wint_t) -1)\r
-#endif\r
-\r
-/* Wide character string handling */\r
-wchar_t *wcscpy(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2);\r
-wchar_t *wcsncpy(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2, size_t n);\r
-wchar_t *wmemcpy(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2, size_t n);\r
-wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2, size_t n);\r
-wchar_t *wcscat(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2);\r
-wchar_t *wcsncat(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2, size_t n);\r
-int wcscmp(const wchar_t *s1, const wchar_t *s2);\r
-int wcscoll(const wchar_t *s1, const wchar_t *s2);\r
-int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n);\r
-size_t wcsxfrm(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2, size_t n);\r
-int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n);\r
-wchar_t *wcschr(const wchar_t *s, wchar_t c);\r
-size_t wcscspn(const wchar_t *s1, const wchar_t *s2);\r
-wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2);\r
-wchar_t *wcsrchr(const wchar_t *s, wchar_t c);\r
-size_t wcsspn(const wchar_t *s1, const wchar_t *s2);\r
-wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2);\r
-wchar_t *wcstok(wchar_t *_PDCLIB_restrict s1, const wchar_t *_PDCLIB_restrict s2, wchar_t **_PDCLIB_restrict ptr);\r
-wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n); \r
-size_t wcslen(const wchar_t *s);\r
-wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n);\r
-\r
-#if 0\r
-size_t wcsftime(wchar_t *_PDCLIB_restrict s, size_t maxsize, const wchar_t *_PDCLIB_restrict format, const struct tm *_PDCLIB_restrict timeptr);\r
-#endif\r
-\r
-/* Wide character I/O */\r
-int fwprintf(_PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, ...);\r
-int fwscanf(_PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, ...);\r
-int swprintf(wchar_t *_PDCLIB_restrict s, size_t n, const wchar_t *_PDCLIB_restrict format, ...);\r
-int swscanf(const wchar_t *_PDCLIB_restrict s, const wchar_t *_PDCLIB_restrict format, ...);\r
-int vfwprintf(_PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg);\r
-int vfwscanf(_PDCLIB_file_t *_PDCLIB_restrict stream, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg);\r
-int vswprintf(wchar_t *_PDCLIB_restrict s, size_t n, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg);\r
-int vswscanf(const wchar_t *_PDCLIB_restrict s, const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg);\r
-int vwprintf(const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg);\r
-int vwscanf(const wchar_t *_PDCLIB_restrict format, _PDCLIB_va_list arg);\r
-int wprintf(const wchar_t *_PDCLIB_restrict format, ...);\r
-int wscanf(const wchar_t *_PDCLIB_restrict format, ...);\r
-wint_t fgetwc(_PDCLIB_file_t *stream);\r
-wchar_t *fgetws(wchar_t *_PDCLIB_restrict s, int n, _PDCLIB_file_t *_PDCLIB_restrict stream);\r
-wint_t fputwc(wchar_t c, _PDCLIB_file_t *stream);\r
-int fputws(const wchar_t *_PDCLIB_restrict s, _PDCLIB_file_t *_PDCLIB_restrict stream);\r
-int fwide(_PDCLIB_file_t *stream, int mode);\r
-wint_t getwc(_PDCLIB_file_t *stream);\r
-wint_t getwchar(void);\r
-wint_t putwc(wchar_t c, _PDCLIB_file_t *stream);\r
-wint_t putwchar(wchar_t c);\r
-wint_t ungetwc(wint_t c, _PDCLIB_file_t *stream);\r
-\r
-#if _PDCLIB_GNU_SOURCE\r
-wint_t getwc_unlocked(_PDCLIB_file_t *stream);\r
-wint_t getwchar_unlocked(void);\r
-wint_t fgetwc_unlocked(_PDCLIB_file_t *stream);\r
-wint_t fputwc_unlocked(wchar_t wc, _PDCLIB_file_t *stream);\r
-wint_t putwc_unlocked(wchar_t wc, _PDCLIB_file_t *stream);\r
-wint_t putwchar_unlocked(wchar_t wc);\r
-wchar_t *fgetws_unlocked(wchar_t *ws, int n, _PDCLIB_file_t *stream);\r
-int fputws_unlocked(const wchar_t *ws, _PDCLIB_file_t *stream);\r
-#endif\r
-\r
-/* Wide character <-> Numeric conversions */\r
-#if 0\r
-double wcstod(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr);\r
-float wcstof(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr);\r
-long double wcstold(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr);\r
-#endif\r
-long int wcstol(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr, int base);\r
-long long int wcstoll(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr, int base);\r
-unsigned long int wcstoul(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr, int base);\r
-unsigned long long int wcstoull(const wchar_t *_PDCLIB_restrict nptr, wchar_t **_PDCLIB_restrict endptr, int base);\r
-\r
-/* Character set conversion */\r
-wint_t btowc(int c);\r
-int wctob(wint_t c);\r
-int mbsinit(const mbstate_t *ps);\r
-size_t mbrlen(const char *_PDCLIB_restrict s, size_t n, mbstate_t *_PDCLIB_restrict ps);\r
-size_t mbrtowc(wchar_t *_PDCLIB_restrict pwc, const char *_PDCLIB_restrict s, size_t n, mbstate_t *_PDCLIB_restrict ps);\r
-size_t wcrtomb(char *_PDCLIB_restrict s, wchar_t wc, mbstate_t *_PDCLIB_restrict ps);\r
-size_t mbsrtowcs(wchar_t *_PDCLIB_restrict dst, const char **_PDCLIB_restrict src, size_t len, mbstate_t *_PDCLIB_restrict ps);\r
-size_t wcsrtombs(char *_PDCLIB_restrict dst, const wchar_t **_PDCLIB_restrict src, size_t len, mbstate_t *_PDCLIB_restrict ps);\r
-\r
-_PDCLIB_END_EXTERN_C\r
-#endif\r
+/* Extended multibyte and wide character utilities <wchar.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_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
-/* 7.30 Wide Character Classification and Mapping Utilities <wctype.h>\r
-\r
- This file is part of the Public Domain C Library (PDCLib).\r
- Permission is granted to use, modify, and / or redistribute at will.\r
-*/\r
-\r
-#ifndef _PDCLIB_WCTYPE_H\r
-#define _PDCLIB_WCTYPE_H _PDCLIB_WCTYPE_H\r
-#include <_PDCLIB_int.h>\r
-_PDCLIB_BEGIN_EXTERN_C\r
-\r
-#ifndef _PDCLIB_WINT_T_DEFINED\r
-#define _PDCLIB_WINT_T_DEFINED _PDCLIB_WINT_T_DEFINED\r
-typedef _PDCLIB_wint_t wint_t;\r
-#endif\r
-\r
-typedef int wctrans_t;\r
-typedef int wctype_t;\r
-\r
-/* 7.30.2.1 Character classification functions */\r
-int iswalnum( wint_t _Wc );\r
-int iswalpha( wint_t _Wc );\r
-int iswblank( wint_t _Wc );\r
-int iswcntrl( wint_t _Wc );\r
-int iswdigit( wint_t _Wc );\r
-int iswgraph( wint_t _Wc );\r
-int iswlower( wint_t _Wc );\r
-int iswprint( wint_t _Wc );\r
-int iswpunct( wint_t _Wc );\r
-int iswspace( wint_t _Wc );\r
-int iswupper( wint_t _Wc );\r
-int iswxdigit( wint_t _Wc );\r
-\r
-/* 7.30.2.2 Extensible character classification functions */\r
-int iswctype( wint_t _Wc, wctype_t _Desc );\r
-wctype_t wctype( const char * _Property );\r
-\r
-/* 7.30.3 Wide character case mapping utilities */\r
-wint_t towlower( wint_t _Wc );\r
-wint_t towupper( wint_t _Wc );\r
-\r
-/* 7.30.3.2 Extensible wide character case mapping functions */\r
-wint_t towctrans( wint_t _Wc, wctrans_t _Desc );\r
-wctrans_t wctrans( const char * _Property );\r
-\r
-_PDCLIB_END_EXTERN_C\r
-#endif // _PDCLIB_WCTYPE_H\r
+/* Wide character classification and mapping utilities <wctype.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_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
-#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). */
#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
#ifndef __PDCLIB_ENCODING_H
#define __PDCLIB_ENCODING_H __PDCLIB_ENCODING_H
+
#include <uchar.h>
/* Must be cauued with bufsize >= 1, in != NULL, out != NULL, ps != NULL
-#ifndef __PDCLIB_PDCLIB_FLOAT_H\r
-#define __PDCLIB_PDCLIB_FLOAT_H __PDCLIB_PDCLIB_FLOAT_H\r
-\r
/* PDCLib internal floating point logic <_PDCLIB_float.h>\r
\r
This file is part of the Public Domain C Library (PDCLib).\r
Permission is granted to use, modify, and / or redistribute at will.\r
*/\r
\r
+#ifndef __PDCLIB_PDCLIB_FLOAT_H\r
+#define __PDCLIB_PDCLIB_FLOAT_H __PDCLIB_PDCLIB_FLOAT_H\r
+\r
/* IEEE 754 single precision */\r
#define _PDCLIB_FP_SINGLE_MIN 1.17549435082228750797e-38\r
#define _PDCLIB_FP_SINGLE_EPSILON 1.19209289550781250000e-7\r
-#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 <stdbool.h>
#include <stddef.h>
-_PDCLIB_BEGIN_EXTERN_C
+
+#ifdef __cplusplus
+extern "C" {
+#endif
/* -------------------------------------------------------------------------- */
/* OS "glue", part 2 */
*/
int _PDCLIB_rename( const char * old, const char * newn);
-_PDCLIB_END_EXTERN_C
+#ifdef __cplusplus
+}
+#endif
+
#endif
-#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). */
#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
#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
#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
#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
#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
#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
#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
#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
#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 )
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 */
/* -------------------------------------------------------------------------- */
_PDCLIB_size_t _PDCLIB_mb_cur_max( void );
+/* wide-character EOF */
+#define _PDCLIB_WEOF ((wint_t) -1
+
/* -------------------------------------------------------------------------- */
/* stdio */
/* -------------------------------------------------------------------------- */
-#ifndef __PDCLIB_IO_H\r
-#define __PDCLIB_IO_H __PDCLIB_IO_H\r
-#include "_PDCLIB_int.h"\r
-#include "_PDCLIB_threadconfig.h"\r
-\r
-/* PDCLib internal I/O logic <_PDCLIB_io.h>\r
+/* PDCLib I/O support <_PDCLIB_io.h>\r
\r
This file is part of the Public Domain C Library (PDCLib).\r
Permission is granted to use, modify, and / or redistribute at will.\r
*/\r
\r
+#ifndef __PDCLIB_IO_H\r
+#define __PDCLIB_IO_H __PDCLIB_IO_H\r
+\r
+#include "_PDCLIB_int.h"\r
+#include "_PDCLIB_threadconfig.h"\r
+\r
/* Flags for representing mode (see fopen()). Note these must fit the same\r
status field as the _IO?BF flags in <stdio.h> and the internal flags below.\r
*/\r
+/* 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 <locale.h>
#include <wctype.h>
#include <threads.h>
#ifndef _PDCLIB_CLOCALE_H\r
#define _PDCLIB_CLOCALE_H _PDCLIB_CLOCALE_H\r
#include <locale.h>\r
-_PDCLIB_BEGIN_EXTERN_C\r
+#ifdef __cplusplus
+extern "C" {
+#endif\r
\r
void _PDCLIB_initclocale( locale_t l );\r
\r
-_PDCLIB_END_EXTERN_C\r
+#ifdef __cplusplus
+}
+#endif\r
#endif // _PDCLIB_CLOCALE_H\r
#include <_PDCLIB_aux.h>\r
#include <_PDCLIB_config.h>\r
\r
-_PDCLIB_BEGIN_EXTERN_C\r
+#ifdef __cplusplus
+extern "C" {
+#endif\r
#define _PDCLIB_ONCE_FLAG_INIT 0\r
#define _PDCLIB_ONCE_FLAG_IS_DONE(_f) (*(_f) == 1)\r
typedef char _PDCLIB_once_flag;\r
void *value;\r
};\r
\r
-_PDCLIB_END_EXTERN_C\r
+#ifdef __cplusplus
+}
+#endif\r
#endif\r
#endif
-_PDCLIB_END_EXTERN_C
+#ifdef __cplusplus
+}
+#endif
#endif
-/* 7.5 Errors <errno.h>
+/* Errors <errno.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>
-_PDCLIB_BEGIN_EXTERN_C
+#ifdef __cplusplus
+extern "C" {
+#endif
extern int * _PDCLIB_errno_func( void );
#define errno (*_PDCLIB_errno_func())
#define EWOULDBLOCK _PDCLIB_EWOULDBLOCK
#define EXDEV _PDCLIB_EXDEV
-_PDCLIB_END_EXTERN_C
+#ifdef __cplusplus
+}
+#endif
#endif
+++ /dev/null
-/* signal( int sig, void (*func)( int ) )
-
- This file is part of the Public Domain C Library (PDCLib).
- Permission is granted to use, modify, and / or redistribute at will.
-*/
-
-#include <signal.h>
-
-#ifndef REGTEST
-
-#include <stdlib.h>
-#include <errno.h>
-
-void (*_PDCLIB_sigabrt)( int ) = SIG_DFL;
-void (*_PDCLIB_sigfpe)( int ) = SIG_DFL;
-void (*_PDCLIB_sigill)( int ) = SIG_DFL;
-void (*_PDCLIB_sigint)( int ) = SIG_DFL;
-void (*_PDCLIB_sigsegv)( int ) = SIG_DFL;
-void (*_PDCLIB_sigterm)( int ) = SIG_DFL;
-
-void (*signal( int sig, void (*func)( int ) ) )( int )
-{
- void (*oldhandler)( int );
- if ( sig <= 0 || func == SIG_ERR )
- {
- return SIG_ERR;
- }
- switch ( sig )
- {
- case SIGABRT:
- oldhandler = _PDCLIB_sigabrt;
- _PDCLIB_sigabrt = func;
- break;
- case SIGFPE:
- oldhandler = _PDCLIB_sigfpe;
- _PDCLIB_sigfpe = func;
- break;
- case SIGILL:
- oldhandler = _PDCLIB_sigill;
- _PDCLIB_sigill = func;
- break;
- case SIGINT:
- oldhandler = _PDCLIB_sigint;
- _PDCLIB_sigint = func;
- break;
- case SIGSEGV:
- oldhandler = _PDCLIB_sigsegv;
- _PDCLIB_sigsegv = func;
- break;
- case SIGTERM:
- oldhandler = _PDCLIB_sigterm;
- _PDCLIB_sigterm = func;
- break;
- default:
- 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
-/* 7.14 Signal handling <string.h>
+/* Signal handling <string.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
+++ /dev/null
-/* raise( int )
-
- This file is part of the Public Domain C Library (PDCLib).
- Permission is granted to use, modify, and / or redistribute at will.
-*/
-
-#include <signal.h>
-
-#ifndef REGTEST
-
-#include <stdio.h>
-#include <stdlib.h>
-
-extern void (*_PDCLIB_sigabrt)( int );
-extern void (*_PDCLIB_sigfpe)( int );
-extern void (*_PDCLIB_sigill)( int );
-extern void (*_PDCLIB_sigint)( int );
-extern void (*_PDCLIB_sigsegv)( int );
-extern void (*_PDCLIB_sigterm)( int );
-
-int raise( int sig )
-{
- void (*sighandler)( int );
- char const * message;
- switch ( sig )
- {
- case SIGABRT:
- sighandler = _PDCLIB_sigabrt;
- message = "Abnormal termination (SIGABRT)";
- break;
- case SIGFPE:
- sighandler = _PDCLIB_sigfpe;
- message = "Arithmetic exception (SIGFPE)";
- break;
- case SIGILL:
- sighandler = _PDCLIB_sigill;
- message = "Illegal instruction (SIGILL)";
- break;
- case SIGINT:
- sighandler = _PDCLIB_sigint;
- message = "Interactive attention signal (SIGINT)";
- break;
- case SIGSEGV:
- sighandler = _PDCLIB_sigsegv;
- message = "Invalid memory access (SIGSEGV)";
- break;
- case SIGTERM:
- sighandler = _PDCLIB_sigterm;
- message = "Termination request (SIGTERM)";
- break;
- default:
- fprintf( stderr, "Unknown signal #%d\n", sig );
- _Exit( EXIT_FAILURE );
- }
- if ( sighandler == SIG_DFL )
- {
- fputs( message, stderr );
- _Exit( EXIT_FAILURE );
- }
- else if ( sighandler != SIG_IGN )
- {
- sighandler = signal( sig, SIG_DFL );
- sighandler( sig );
- }
- return 0;
-}
-
-#endif
-
-#ifdef TEST
-#include <_PDCLIB_test.h>
-
-#include <stdlib.h>
-
-static volatile sig_atomic_t flag = 0;
-
-static int expected_signal = 0;
-
-static void test_handler( int sig )
-{
- TESTCASE( sig == expected_signal );
- flag = 1;
-}
-
-int main( void )
-{
- /* Could be other than SIG_DFL if you changed the implementation. */
- TESTCASE( signal( SIGABRT, SIG_IGN ) == SIG_DFL );
- /* Should be ignored. */
- TESTCASE( raise( SIGABRT ) == 0 );
- /* Installing test handler, old handler should be returned */
- TESTCASE( signal( SIGABRT, test_handler ) == SIG_IGN );
- /* Raising and checking SIGABRT */
- expected_signal = SIGABRT;
- TESTCASE( raise( SIGABRT ) == 0 );
- TESTCASE( flag == 1 );
- /* Re-installing test handler, should have been reset to default */
- /* Could be other than SIG_DFL if you changed the implementation. */
- TESTCASE( signal( SIGABRT, test_handler ) == SIG_DFL );
- /* Raising and checking SIGABRT */
- flag = 0;
- TESTCASE( raise( SIGABRT ) == 0 );
- TESTCASE( flag == 1 );
- /* Installing test handler for different signal... */
- TESTCASE( signal( SIGTERM, test_handler ) == SIG_DFL );
- /* Raising and checking SIGTERM */
- expected_signal = SIGTERM;
- TESTCASE( raise( SIGTERM ) == 0 );
- TESTCASE( flag == 1 );
- return TEST_RESULTS;
-}
-#endif
+++ /dev/null
-/* signal( int sig, void (*func)( int ) )
-
- This file is part of the Public Domain C Library (PDCLib).
- Permission is granted to use, modify, and / or redistribute at will.
-*/
-
-#include <signal.h>
-
-#ifndef REGTEST
-
-#include <stdlib.h>
-#include <errno.h>
-
-void (*_PDCLIB_sigabrt)( int ) = SIG_DFL;
-void (*_PDCLIB_sigfpe)( int ) = SIG_DFL;
-void (*_PDCLIB_sigill)( int ) = SIG_DFL;
-void (*_PDCLIB_sigint)( int ) = SIG_DFL;
-void (*_PDCLIB_sigsegv)( int ) = SIG_DFL;
-void (*_PDCLIB_sigterm)( int ) = SIG_DFL;
-
-void (*signal( int sig, void (*func)( int ) ) )( int )
-{
- void (*oldhandler)( int );
- if ( sig <= 0 || func == SIG_ERR )
- {
- return SIG_ERR;
- }
- switch ( sig )
- {
- case SIGABRT:
- oldhandler = _PDCLIB_sigabrt;
- _PDCLIB_sigabrt = func;
- break;
- case SIGFPE:
- oldhandler = _PDCLIB_sigfpe;
- _PDCLIB_sigfpe = func;
- break;
- case SIGILL:
- oldhandler = _PDCLIB_sigill;
- _PDCLIB_sigill = func;
- break;
- case SIGINT:
- oldhandler = _PDCLIB_sigint;
- _PDCLIB_sigint = func;
- break;
- case SIGSEGV:
- oldhandler = _PDCLIB_sigsegv;
- _PDCLIB_sigsegv = func;
- break;
- case SIGTERM:
- oldhandler = _PDCLIB_sigterm;
- _PDCLIB_sigterm = func;
- break;
- default:
- 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
#ifndef _PDCLIB_CONFIG_H
#define _PDCLIB_CONFIG_H
+
/* Internal PDCLib configuration <_PDCLIB_config.h>
(Gandr platform)
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 <stdlib.h> requires a function that swaps two memory areas. */
+/* Below is a naive implementation that can be improved significantly for */
+/* specific platforms, e.g. by swapping int instead of char. */
#define _PDCLIB_memswp( i, j, size ) char tmp; do { tmp = *i; *i++ = *j; *j++ = tmp; } while ( --size );
+/* -------------------------------------------------------------------------- */
+/* 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. */
#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; };
+/* <stdlib.h> defines the div() function family that allows taking quotient */
+/* and remainder of an integer division in one operation. Many platforms */
+/* support this in hardware / opcode, and the standard permits ordering of */
+/* the return structure in any way to fit the hardware. That is why those */
+/* structs can be configured here. */
+
+struct _PDCLIB_div_t
+{
+ int quot;
+ int rem;
+};
+
+struct _PDCLIB_ldiv_t
+{
+ long int quot;
+ long int rem;
+};
+
+struct _PDCLIB_lldiv_t
+{
+ long long int quot;
+ long long int rem;
+};
+
+/* -------------------------------------------------------------------------- */
+/* <stdint.h> defines a set of integer types that are of a minimum width, and */
+/* "usually fastest" on the system. (If, for example, accessing a single char */
+/* requires the CPU to access a complete int and then mask out the char, the */
+/* "usually fastest" type of at least 8 bits would be int, not char.) */
+/* If you do not have information on the relative performance of the types, */
+/* the standard allows you to define any type that meets minimum width and */
+/* signedness requirements. */
+/* The defines below are just configuration for the real typedefs and limit */
+/* definitions done in <_PDCLIB_int.h>. The uppercase define shall be either */
+/* SHRT, INT, LONG, or LLONG (telling which values to use for the *_MIN and */
+/* *_MAX limits); the lowercase define either short, int, long, or long long */
+/* (telling the actual type to use). */
+/* The third define is the length modifier used for the type in printf() and */
+/* scanf() functions (used in <inttypes.h>). */
+/* If you require a non-standard datatype to define the "usually fastest" */
+/* types, PDCLib as-is doesn't support that. Please contact the author with */
+/* details on your platform in that case, so support can be added. */
+/* -------------------------------------------------------------------------- */
-/* fast* datatypes. This is a bit of a blunt instrument. */
#define _PDCLIB_FAST8 CHAR
#define _PDCLIB_fast8 char
#define _PDCLIB_FAST8_CONV hh
#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
#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; };
+/* <inttypes.h> 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.h>: time_t
+ * The C standard doesn't define what representation of time is stored in
+ * time_t when returned by time() , but POSIX defines it to be seconds since the
+ * UNIX epoch and most appplications expect that.
+ *
+ * time_t is also used as the tv_sec member of struct timespec, which *is*
+ * defined as a linear count of seconds.
+ *
+ * time_t is defined as a "real type", so may be a floating point type, but with
+ * the presence of the nanosecond accurate struct timespec, and with the lack of
+ * any functions for manipulating more accurate values of time_t, this is
+ * probably not useful.
+ */
#define _PDCLIB_time unsigned long long
-/* clock_t */
+/* <time.h>: clock_t
+ *
+ * A count of "clock ticks", where the length of a clock tick is unspecified by
+ * the standard. The implementation is required to provide a macro,
+ * CLOCKS_PER_SEC, which is the number of "clock ticks" which corresponds to one
+ * second.
+ *
+ * clock_t may be any real type (i.e. integral or floating), and its type on
+ * various systems differs.
+ *
+ * On XSI systems, CLOCKS_PER_SEC must be defined to 1000000
+ */
#define _PDCLIB_clock unsigned
#define _PDCLIB_CLOCKS_PER_SEC 1000000
-/* timespec_get */
+/* <time.h>: 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
/* -------------------------------------------------------------------------- */
#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 (<stdarg.h>)
+ The macros defined by <stdarg.h> are highly dependent on the calling
+ conventions used, and you probably have to replace them with builtins of
+ your compiler.
+*/
+
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
#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 */
/* 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 <errno.h> will "see" EPERM instead of EISDIR (the _PDCLIB_*
+ prefix removed by <errno.h> mechanics).
+
+ If you do not want that kind of translation, you might want to "match" the
+ values used by PDCLib with those used by the host OS, as to avoid confusion.
+
+ The C standard only defines three distinct errno values: ERANGE, EDOM, and
+ EILSEQ. The standard leaves it up to "the implementation" whether there are
+ any more beyond those three.
+
+ 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
-/* 7.14 Signal handling <string.h>
+/* Signal handling <string.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
+++ /dev/null
-/* raise( int )
-
- This file is part of the Public Domain C Library (PDCLib).
- Permission is granted to use, modify, and / or redistribute at will.
-*/
-
-#include <signal.h>
-
-#ifndef REGTEST
-
-#include <stdio.h>
-#include <stdlib.h>
-
-extern void (*_PDCLIB_sigabrt)( int );
-extern void (*_PDCLIB_sigfpe)( int );
-extern void (*_PDCLIB_sigill)( int );
-extern void (*_PDCLIB_sigint)( int );
-extern void (*_PDCLIB_sigsegv)( int );
-extern void (*_PDCLIB_sigterm)( int );
-
-int raise( int sig )
-{
- void (*sighandler)( int );
- char const * message;
- switch ( sig )
- {
- case SIGABRT:
- sighandler = _PDCLIB_sigabrt;
- message = "Abnormal termination (SIGABRT)";
- break;
- case SIGFPE:
- sighandler = _PDCLIB_sigfpe;
- message = "Arithmetic exception (SIGFPE)";
- break;
- case SIGILL:
- sighandler = _PDCLIB_sigill;
- message = "Illegal instruction (SIGILL)";
- break;
- case SIGINT:
- sighandler = _PDCLIB_sigint;
- message = "Interactive attention signal (SIGINT)";
- break;
- case SIGSEGV:
- sighandler = _PDCLIB_sigsegv;
- message = "Invalid memory access (SIGSEGV)";
- break;
- case SIGTERM:
- sighandler = _PDCLIB_sigterm;
- message = "Termination request (SIGTERM)";
- break;
- default:
- fprintf( stderr, "Unknown signal #%d\n", sig );
- _Exit( EXIT_FAILURE );
- }
- if ( sighandler == SIG_DFL )
- {
- fputs( message, stderr );
- _Exit( EXIT_FAILURE );
- }
- else if ( sighandler != SIG_IGN )
- {
- sighandler = signal( sig, SIG_DFL );
- sighandler( sig );
- }
- return 0;
-}
-
-#endif
-
-#ifdef TEST
-#include <_PDCLIB_test.h>
-
-#include <stdlib.h>
-
-static volatile sig_atomic_t flag = 0;
-
-static int expected_signal = 0;
-
-static void test_handler( int sig )
-{
- TESTCASE( sig == expected_signal );
- flag = 1;
-}
-
-int main( void )
-{
- /* Could be other than SIG_DFL if you changed the implementation. */
- TESTCASE( signal( SIGABRT, SIG_IGN ) == SIG_DFL );
- /* Should be ignored. */
- TESTCASE( raise( SIGABRT ) == 0 );
- /* Installing test handler, old handler should be returned */
- TESTCASE( signal( SIGABRT, test_handler ) == SIG_IGN );
- /* Raising and checking SIGABRT */
- expected_signal = SIGABRT;
- TESTCASE( raise( SIGABRT ) == 0 );
- TESTCASE( flag == 1 );
- /* Re-installing test handler, should have been reset to default */
- /* Could be other than SIG_DFL if you changed the implementation. */
- TESTCASE( signal( SIGABRT, test_handler ) == SIG_DFL );
- /* Raising and checking SIGABRT */
- flag = 0;
- TESTCASE( raise( SIGABRT ) == 0 );
- TESTCASE( flag == 1 );
- /* Installing test handler for different signal... */
- TESTCASE( signal( SIGTERM, test_handler ) == SIG_DFL );
- /* Raising and checking SIGTERM */
- expected_signal = SIGTERM;
- TESTCASE( raise( SIGTERM ) == 0 );
- TESTCASE( flag == 1 );
- return TEST_RESULTS;
-}
-#endif
-/* 7.14 Signal handling <string.h>
+/* Signal handling <string.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
#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
/* 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.)
#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
* any functions for manipulating more accurate values of time_t, this is
* probably not useful.
*/
-#define _PDCLIB_time long
+#define _PDCLIB_time long
/* <time.h>: clock_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 (<stdarg.h>)
*/
#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 <stdarg.h>. */
- #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 <stdarg.h>. */
+#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
/* -------------------------------------------------------------------------- */
/* 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 */
prefix removed by <errno.h> mechanics).
If you do not want that kind of translation, you might want to "match" the
- values used by PDCLib with those used by the host OS, 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
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.
*/
+++ /dev/null
-/* raise( int )
-
- This file is part of the Public Domain C Library (PDCLib).
- Permission is granted to use, modify, and / or redistribute at will.
-*/
-
-#include <signal.h>
-
-#ifndef REGTEST
-
-#include <stdio.h>
-#include <stdlib.h>
-
-extern void (*_PDCLIB_sigabrt)( int );
-extern void (*_PDCLIB_sigfpe)( int );
-extern void (*_PDCLIB_sigill)( int );
-extern void (*_PDCLIB_sigint)( int );
-extern void (*_PDCLIB_sigsegv)( int );
-extern void (*_PDCLIB_sigterm)( int );
-
-int raise( int sig )
-{
- void (*sighandler)( int );
- char const * message;
- switch ( sig )
- {
- case SIGABRT:
- sighandler = _PDCLIB_sigabrt;
- message = "Abnormal termination (SIGABRT)";
- break;
- case SIGFPE:
- sighandler = _PDCLIB_sigfpe;
- message = "Arithmetic exception (SIGFPE)";
- break;
- case SIGILL:
- sighandler = _PDCLIB_sigill;
- message = "Illegal instruction (SIGILL)";
- break;
- case SIGINT:
- sighandler = _PDCLIB_sigint;
- message = "Interactive attention signal (SIGINT)";
- break;
- case SIGSEGV:
- sighandler = _PDCLIB_sigsegv;
- message = "Invalid memory access (SIGSEGV)";
- break;
- case SIGTERM:
- sighandler = _PDCLIB_sigterm;
- message = "Termination request (SIGTERM)";
- break;
- default:
- fprintf( stderr, "Unknown signal #%d\n", sig );
- _Exit( EXIT_FAILURE );
- }
- if ( sighandler == SIG_DFL )
- {
- fputs( message, stderr );
- _Exit( EXIT_FAILURE );
- }
- else if ( sighandler != SIG_IGN )
- {
- sighandler = signal( sig, SIG_DFL );
- sighandler( sig );
- }
- return 0;
-}
-
-#endif
-
-#ifdef TEST
-#include <_PDCLIB_test.h>
-
-#include <stdlib.h>
-
-static volatile sig_atomic_t flag = 0;
-
-static int expected_signal = 0;
-
-static void test_handler( int sig )
-{
- TESTCASE( sig == expected_signal );
- flag = 1;
-}
-
-int main( void )
-{
- /* Could be other than SIG_DFL if you changed the implementation. */
- TESTCASE( signal( SIGABRT, SIG_IGN ) == SIG_DFL );
- /* Should be ignored. */
- TESTCASE( raise( SIGABRT ) == 0 );
- /* Installing test handler, old handler should be returned */
- TESTCASE( signal( SIGABRT, test_handler ) == SIG_IGN );
- /* Raising and checking SIGABRT */
- expected_signal = SIGABRT;
- TESTCASE( raise( SIGABRT ) == 0 );
- TESTCASE( flag == 1 );
- /* Re-installing test handler, should have been reset to default */
- /* Could be other than SIG_DFL if you changed the implementation. */
- TESTCASE( signal( SIGABRT, test_handler ) == SIG_DFL );
- /* Raising and checking SIGABRT */
- flag = 0;
- TESTCASE( raise( SIGABRT ) == 0 );
- TESTCASE( flag == 1 );
- /* Installing test handler for different signal... */
- TESTCASE( signal( SIGTERM, test_handler ) == SIG_DFL );
- /* Raising and checking SIGTERM */
- expected_signal = SIGTERM;
- TESTCASE( raise( SIGTERM ) == 0 );
- TESTCASE( flag == 1 );
- return TEST_RESULTS;
-}
-#endif
+++ /dev/null
-/* signal( int sig, void (*func)( int ) )
-
- This file is part of the Public Domain C Library (PDCLib).
- Permission is granted to use, modify, and / or redistribute at will.
-*/
-
-#include <signal.h>
-#include <errno.h>
-
-#ifndef REGTEST
-
-#include <stdlib.h>
-
-void (*_PDCLIB_sigabrt)( int ) = SIG_DFL;
-void (*_PDCLIB_sigfpe)( int ) = SIG_DFL;
-void (*_PDCLIB_sigill)( int ) = SIG_DFL;
-void (*_PDCLIB_sigint)( int ) = SIG_DFL;
-void (*_PDCLIB_sigsegv)( int ) = SIG_DFL;
-void (*_PDCLIB_sigterm)( int ) = SIG_DFL;
-
-void (*signal( int sig, void (*func)( int ) ) )( int )
-{
- void (*oldhandler)( int );
- if ( sig <= 0 || func == SIG_ERR )
- {
- return SIG_ERR;
- }
- switch ( sig )
- {
- case SIGABRT:
- oldhandler = _PDCLIB_sigabrt;
- _PDCLIB_sigabrt = func;
- break;
- case SIGFPE:
- oldhandler = _PDCLIB_sigfpe;
- _PDCLIB_sigfpe = func;
- break;
- case SIGILL:
- oldhandler = _PDCLIB_sigill;
- _PDCLIB_sigill = func;
- break;
- case SIGINT:
- oldhandler = _PDCLIB_sigint;
- _PDCLIB_sigint = func;
- break;
- case SIGSEGV:
- oldhandler = _PDCLIB_sigsegv;
- _PDCLIB_sigsegv = func;
- break;
- case SIGTERM:
- oldhandler = _PDCLIB_sigterm;
- _PDCLIB_sigterm = func;
- break;
- default:
- /* The standard calls for an unspecified "positive value". You
- will probably want to define a specific value for this.
- */
- 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
-/* 7.14 Signal handling <string.h>
+/* Signal handling <string.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
/* 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
#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(). */
_PDCLIB_intmax rem;
};
-/* <time.h>: time_t
- * The C standard doesn't define what representation of time is stored in
+/* <time.h>: time_t
+ * The C standard doesn't define what representation of time is stored in
* time_t when returned by time() , but POSIX defines it to be seconds since the
- * UNIX epoch and most appplications expect that.
+ * 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
/* <time.h>: clock_t
*
* A count of "clock ticks", where the length of a clock tick is unspecified by
- * the standard. The implementation is required to provide a macro,
+ * 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
*/
*
* 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.
*
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 (<stdarg.h>)
*/
#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 <stdarg.h>. */
- #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 <stdarg.h>. */
+#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
/* -------------------------------------------------------------------------- */
/* 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 */
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.
*/
#include <_PDCLIB_aux.h>\r
#include <_PDCLIB_int.h>\r
\r
-_PDCLIB_BEGIN_EXTERN_C\r
+#ifdef __cplusplus
+extern "C" {
+#endif\r
#define _PDCLIB_TSS_DTOR_ITERATIONS 3\r
#define _PDCLIB_ONCE_FLAG_INIT { -1, 0 }\r
#define _PDCLIB_ONCE_FLAG_IS_DONE( _f ) ((_f)->_State == 0)\r
unsigned int _Key;\r
};\r
\r
-_PDCLIB_END_EXTERN_C\r
+#ifdef __cplusplus
+}
+#endif\r
#endif\r