From: solar Date: Sun, 20 Nov 2005 10:04:48 +0000 (+0000) Subject: Moved the includes into subdirectory (again). Teaches you to decide on a proper layou... X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=585a29d7e130d8f9f7388a17cf0ea02d5cc8b655;p=fw%2Fpdclib Moved the includes into subdirectory (again). Teaches you to decide on a proper layout FIRST. git-svn-id: https://srv7.svn-repos.de/dev34/pdclib/trunk@62 546481bc-9713-0410-bf18-d3337bbf4a3e --- diff --git a/_PDCLIB_aux.h b/_PDCLIB_aux.h deleted file mode 100755 index 4ef019e..0000000 --- a/_PDCLIB_aux.h +++ /dev/null @@ -1,61 +0,0 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* 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. -*/ - -/* -------------------------------------------------------------------------- */ -/* Standard Version */ -/* -------------------------------------------------------------------------- */ - -/* Many a compiler gets this wrong, so you might have to hardcode it instead. */ - -#if __STDC__ != 1 -#error Compiler does not define _ _STDC_ _ to 1 (not standard-compliant)! -#endif - -#ifndef __STDC_VERSION__ -#define _PDCLIB_C_VERSION 90 -#define _PDCLIB_restrict -#elif __STDC_VERSION__ == 199409L -#define _PDCLIB_C_VERSION 95 -#define _PDCLIB_restrict -#elif __STDC_VERSION__ == 199901L -#define _PDCLIB_C_VERSION 99 -#define _PDCLIB_restrict restrict -#else -#error Unsupported _ _STDC_VERSION_ _ (__STDC_VERSION__) (supported: ISO/IEC 9899:1990, 9899/AMD1:1995, and 9899:1999). -#endif - -#ifndef __STDC_HOSTED__ -#warning Compiler does not define _ _STDC_HOSTED_ _ (not standard-compliant)! -#elif __STDC_HOSTED__ == 0 -#define _PDCLIB_HOSTED 0 -#elif __STDC_HOSTED__ == 1 -#define _PDCLIB_HOSTED 1 -#else -#error Compiler does not define _ _STDC_HOSTED_ _ to 0 or 1 (not standard-compliant)! -#endif - -#if _PDCLIB_C_VERSION != 99 -#warning Up to and including v1.x, PDCLib is only aiming at ISO/IEC 9899:1999 (C99). -#warning PDCLib might not be fully conforming to either C89 or C95 prior to v2.x. -#endif - -/* -------------------------------------------------------------------------- */ -/* Helper macros: */ -/* _PDCLIB_cc( x, y ) concatenates two preprocessor tokens without extending */ -/* _PDCLIB_concat( x, y ) concatenates two preprocessor tokens with extending */ -/* -------------------------------------------------------------------------- */ - -#define _PDCLIB_cc( x, y ) x ## y -#define _PDCLIB_concat( x, y ) _PDCLIB_cc( x, y ) - -#define _PDCLIB_symbol2value( x ) #x -#define _PDCLIB_symbol2string( x ) _PDCLIB_symbol2value( x ) -#define _PDCLIB_symbol2identity( x ) x - diff --git a/_PDCLIB_config.h b/_PDCLIB_config.h deleted file mode 100644 index 74eb290..0000000 --- a/_PDCLIB_config.h +++ /dev/null @@ -1,164 +0,0 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* Internal PDCLib configuration <_PDCLIB_config.h> - (Generic Template) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* -------------------------------------------------------------------------- */ -/* Misc */ -/* -------------------------------------------------------------------------- */ - -/* The character (sequence) your platform uses as newline. */ -#define _PDCLIB_endl "\n" - -/* -------------------------------------------------------------------------- */ -/* Integers */ -/* -------------------------------------------------------------------------- */ -/* Assuming 8-bit char, two's-complement architecture here. 'short' being */ -/* 16 bit, 'int' being either 16, 32 or 64 bit, 'long' being either 32 or 64 */ -/* bit (but 64 bit only if 'int' is 32 bit), and 'long long' being 64 bit if */ -/* 'long' is not, 64 or 128 bit otherwise. */ -/* Author is quite willing to support other systems but would like to hear of */ -/* interest in such support and details on the to-be-supported architecture */ -/* first, before going to lengths about it. */ -/* -------------------------------------------------------------------------- */ - -/* Comment out (or delete) the line below if your 'char' type is unsigned. */ -#define _PDCLIB_CHAR_SIGNED 1 - -/* Width of the integer types short, int, long, and long long, in bytes. */ -/* SHRT == 2, INT >= SHRT, LONG >= INT >= 4, LLONG >= LONG - check your */ -/* compiler manuals. */ -#define _PDCLIB_SHRT_BYTES 2 -#define _PDCLIB_INT_BYTES 4 -#define _PDCLIB_LONG_BYTES 4 -#define _PDCLIB_LLONG_BYTES 8 - -/* -------------------------------------------------------------------------- */ -/* 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). */ -/* If you require a non-standard datatype to define the "usually fastest" */ -/* types, PDCLib as-is doesn't support that. Please contact the author with */ -/* details on your platform in that case, so support can be added. */ -/* -------------------------------------------------------------------------- */ - -#define _PDCLIB_FAST8 INT -#define _PDCLIB_fast8 int - -#define _PDCLIB_FAST16 INT -#define _PDCLIB_fast16 int - -#define _PDCLIB_FAST32 INT -#define _PDCLIB_fast32 int - -#define _PDCLIB_FAST64 LLONG -#define _PDCLIB_fast64 long long - -/* -------------------------------------------------------------------------- */ -/* What follows are a couple of "special" typedefs and their limits. Again, */ -/* the actual definition of the limits is done in <_PDCLIB_int.h>, and the */ -/* defines here are merely "configuration". See above for details. */ -/* -------------------------------------------------------------------------- */ - -/* The result type of substracting two pointers */ -#define _PDCLIB_ptrdiff int -#define _PDCLIB_PTRDIFF INT - -/* 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 - -/* Result type of the 'sizeof' operator */ -#define _PDCLIB_size unsigned int -#define _PDCLIB_SIZE UINT - -/* Large enough an integer to hold all character codes of the largest supported - locale. -*/ -#define _PDCLIB_wchar unsigned short -#define _PDCLIB_WCHAR USHRT - -#define _PDCLIB_intptr int -#define _PDCLIB_INTPTR INT - -#define _PDCLIB_intmax long long int -#define _PDCLIB_INTMAX LLINT -/* You are also required to state the literal suffix for the intmax type */ -#define _PDCLIB_INTMAX_LITERAL ll - -/* -------------------------------------------------------------------------- */ -/* Floating Point */ -/* -------------------------------------------------------------------------- */ - -/* Whether the implementation rounds toward zero (0), to nearest (1), toward - positive infinity (2), or toward negative infinity (3). (-1) signifies - indeterminable rounding, any other value implementation-specific rounding. -*/ -#define _PDCLIB_FLT_ROUNDS -1 - -/* Whether the implementation uses exact-width precision (0), promotes float - to double (1), or promotes float and double to long double (2). (-1) - signifies indeterminable behaviour, any other value implementation-specific - behaviour. -*/ -#define _PDCLIB_FLT_EVAL_METHOD -1 - -/* "Number of the decimal digits (n), such that any floating-point number in the - widest supported floating type with p(max) radix (b) digits can be rounded to - a floating-point number with (n) decimal digits and back again without change - to the value p(max) log(10)b if (b) is a power of 10, [1 + p(max) log(10)b] - otherwise." - 64bit IEC 60559 double format (53bit mantissa) is DECIMAL_DIG 17. - 80bit IEC 60559 double-extended format (64bit mantissa) is DECIMAL_DIG 21. -*/ -#define _PDCLIB_DECIMAL_DIG 17 - -/* -------------------------------------------------------------------------- */ -/* Platform-dependent macros defined by the standard headers. */ -/* -------------------------------------------------------------------------- */ - -/* The offsetof macro - Contract: Expand to an integer constant expression of type size_t, which - represents the offset in bytes to the structure member from the beginning - of the structure. If the specified member is a bitfield, behaviour is - undefined. - There is no standard-compliant way to do this. - This implementation casts an integer zero to 'pointer to type', and then - takes the address of member. This is undefined behaviour but should work on - most compilers. -*/ -#define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) ) - -/* Variable Length Parameter List Handling () - The macros defined by are highly dependent on the calling - conventions used, and you probably have to replace them with builtins of - your compiler. The following generic implementation works only for pure - stack-based architectures, and only if arguments are aligned to pointer - type. Credits to Michael Moody, who contributed this to the Public Domain. -*/ - -/* Internal helper macro. va_round is not part of . */ -#define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) ) - -typedef char * _PDCLIB_va_list; -#define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) ) -#define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 ) -#define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 ) -#define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 ) diff --git a/_PDCLIB_int.h b/_PDCLIB_int.h deleted file mode 100644 index 24accb0..0000000 --- a/_PDCLIB_int.h +++ /dev/null @@ -1,253 +0,0 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* 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. -*/ - -/* -------------------------------------------------------------------------- */ -/* 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). */ -/* -------------------------------------------------------------------------- */ - -#ifndef _PDCLIB_CONFIG_H -#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H -#include <_PDCLIB_config.h> -#endif - -#ifndef _PDCLIB_AUX_H -#define _PDCLIB_AUX_H _PDCLIB_AUX_H -#include <_PDCLIB_aux.h> -#endif - -/* null pointer constant */ -#define _PDCLIB_NULL 0 - -/* -------------------------------------------------------------------------- */ -/* Limits of native datatypes */ -/* -------------------------------------------------------------------------- */ -/* The definition of minimum limits for unsigned datatypes is done because */ -/* later on we will "construct" limits for other abstract types: */ -/* USHRT -> _PDCLIB_ + USHRT + _MIN -> _PDCLIB_USHRT_MIN -> 0 */ -/* INT -> _PDCLIB_ + INT + _MIN -> _PDCLIB_INT_MIN -> ... you get the idea. */ -/* -------------------------------------------------------------------------- */ - -/* Setting 'char' limits */ -#define _PDCLIB_CHAR_BIT 8 -#define _PDCLIB_UCHAR_MIN 0 -#define _PDCLIB_UCHAR_MAX 0xff -#define _PDCLIB_SCHAR_MIN (-0x7f - 1) -#define _PDCLIB_SCHAR_MAX 0x7f -#ifdef _PDCLIB_CHAR_SIGNED -#define _PDCLIB_CHAR_MIN _PDCLIB_SCHAR_MIN -#define _PDCLIB_CHAR_MAX _PDCLIB_SCHAR_MAX -#else -#define _PDCLIB_CHAR_MIN 0 -#define _PDCLIB_CHAR_MAX _PDCLIB_UCHAR_MAX -#endif - -/* Setting 'short' limits */ -#if _PDCLIB_SHRT_BYTES == 2 -#define _PDCLIB_SHRT_MAX 0x7fff -#define _PDCLIB_SHRT_MIN (-0x7fff - 1) -#define _PDCLIB_USHRT_MAX 0xffff -#else -#error Unsupported width of 'short' (not 16 bit). -#endif -#define _PDCLIB_USHRT_MIN 0 - -#if _PDCLIB_INT_BYTES < _PDCLIB_SHRT_BYTES -#error Bogus setting: short > int? Check _PDCLIB_config.h. -#endif - -/* Setting 'int' limits */ -#if _PDCLIB_INT_BYTES == 2 -#define _PDCLIB_INT_MAX 0x7fff -#define _PDCLIB_INT_MIN (-0x7fff - 1) -#define _PDCLIB_UINT_MAX 0xffffU -#elif _PDCLIB_INT_BYTES == 4 -#define _PDCLIB_INT_MAX 0x7fffffff -#define _PDCLIB_INT_MIN (-0x7fffffff - 1) -#define _PDCLIB_UINT_MAX 0xffffffffU -#elif _PDCLIB_INT_BYTES == 8 -#define _PDCLIB_INT_MAX 0x7fffffffffffffff -#define _PDCLIB_INT_MIN (-0x7fffffffffffffff - 1) -#define _PDCLIB_UINT_MAX 0xffffffffffffffff -#else -#error Unsupported width of 'int' (neither 16, 32, nor 64 bit). -#endif -#define _PDCLIB_UINT_MIN 0 - -/* Setting 'long' limits */ -#if _PDCLIB_LONG_BYTES == 4 -#define _PDCLIB_LONG_MAX 0x7fffffffL -#define _PDCLIB_LONG_MIN (-0x7fffffffL - 1L) -#define _PDCLIB_ULONG_MAX 0xffffffffUL -#elif _PDCLIB_LONG_BYTES == 8 -#define _PDCLIB_LONG_MAX 0x7fffffffffffffffL -#define _PDCLIB_LONG_MIN (-0x7fffffffffffffffL - 1L) -#define _PDCLIB_ULONG_MAX 0xffffffffffffffffUL -#else -#error Unsupported width of 'long' (neither 32 nor 64 bit). -#endif -#define _PDCLIB_ULONG_MIN 0 - -/* Setting 'long long' limits */ -#if _PDCLIB_LLONG_BYTES == 8 -#define _PDCLIB_LLONG_MAX 0x7fffffffffffffffLL -#define _PDCLIB_LLONG_MIN (-0x7fffffffffffffffLL - 1LL) -#define _PDCLIB_ULLONG_MAX 0xffffffffffffffffULL -#elif _PDCLIB_LLONG_BYTES == 16 -#define _PDCLIB_LLONG_MAX 0x7fffffffffffffffffffffffffffffffLL -#define _PDCLIB_LLONG_MIN (-0x7fffffffffffffffffffffffffffffffLL - 1LL) -#define _PDCLIB_ULLONG_MAX 0xffffffffffffffffffffffffffffffffLL -#else -#error Unsupported width of 'long long' (neither 64 nor 128 bit). -#endif -#define _PDCLIB_ULLONG_MIN 0 - -/* -------------------------------------------------------------------------- */ -/* exact-width types and their limits */ -/* -------------------------------------------------------------------------- */ - -/* Setting 'int8_t', its limits, and its literal. */ -#if _PDCLIB_CHAR_BIT == 8 -typedef signed char _PDCLIB_int8_t; -typedef unsigned char _PDCLIB_uint8_t; -#define _PDCLIB_INT8_MAX _PDCLIB_CHAR_MAX -#define _PDCLIB_INT8_MIN _PDCLIB_CHAR_MIN -#define _PDCLIB_UINT8_MAX _PDCLIB_UCHAR_MAX -#define _PDCLIB_INT8_LITERAL -#define _PDCLIB_UINT8_LITERAL -#else -#error Unsupported width of char (not 8 bits). -#endif - -/* Setting 'int16_t', its limits, and its literal */ -#if _PDCLIB_INT_BYTES == 2 -typedef signed int _PDCLIB_int16_t; -typedef unsigned int _PDCLIB_uint16_t; -#define _PDCLIB_INT16_MAX _PDCLIB_INT_MAX -#define _PDCLIB_INT16_MIN _PDCLIB_INT_MIN -#define _PDCLIB_UINT16_MAX _PDCLIB_UINT_MAX -#define _PDCLIB_INT16_LITERAL -#define _PDCLIB_UINT16_LITERAL -#elif _PDCLIB_SHRT_BYTES == 2 -typedef signed short _PDCLIB_int16_t; -typedef unsigned short _PDCLIB_uint16_t; -#define _PDCLIB_INT16_MAX _PDCLIB_SHRT_MAX -#define _PDCLIB_INT16_MIN _PDCLIB_SHRT_MIN -#define _PDCLIB_UINT16_MAX _PDCLIB_USHRT_MAX -#define _PDCLIB_INT16_LITERAL s -#define _PDCLIB_UINT16_LITERAL us -#else -#error Neither 'short' nor 'int' are 16-bit. -#endif - -/* Setting 'int32_t', its limits, and its literal */ -#if _PDCLIB_INT_BYTES == 4 -typedef signed int _PDCLIB_int32_t; -typedef unsigned int _PDCLIB_uint32_t; -#define _PDCLIB_INT32_MAX _PDCLIB_INT_MAX -#define _PDCLIB_INT32_MIN _PDCLIB_INT_MIN -#define _PDCLIB_UINT32_MAX _PDCLIB_UINT_MAX -#define _PDCLIB_INT32_LITERAL -#define _PDCLIB_UINT32_LITERAL -#elif _PDCLIB_LONG_BYTES == 4 -typedef signed long _PDCLIB_int32_t; -typedef unsigned long _PDCLIB_uint32_t; -#define _PDCLIB_INT32_MAX _PDCLIB_LONG_MAX -#define _PDCLIB_INT32_MIN _PDCLIB_LONG_MIN -#define _PDCLIB_UINT32_MAX _PDCLIB_LONG_MAX -#define _PDCLIB_INT32_LITERAL l -#define _PDCLIB_UINT32_LITERAL ul -#else -#error Neither 'int' nor 'long' are 32-bit. -#endif - -#if _PDCLIB_LONG_BYTES == 8 -typedef signed long _PDCLIB_int64_t; -typedef unsigned long _PDCLIB_uint64_t; -#define _PDCLIB_INT64_MAX _PDCLIB_LONG_MAX -#define _PDCLIB_INT64_MIN _PDCLIB_LONG_MIN -#define _PDCLIB_UINT64_MAX _PDCLIB_ULONG_MAX -#define _PDCLIB_INT64_LITERAL l -#define _PDCLIB_UINT64_LITERAL ul -#elif _PDCLIB_LLONG_BYTES == 8 -typedef signed long long _PDCLIB_int64_t; -typedef unsigned long long _PDCLIB_uint64_t; -#define _PDCLIB_INT64_MAX _PDCLIB_LLONG_MAX -#define _PDCLIB_INT64_MIN _PDCLIB_LLONG_MIN -#define _PDCLIB_UINT64_MAX _PDCLIB_ULLONG_MAX -#define _PDCLIB_INT64_LITERAL ll -#define _PDCLIB_UINT64_LITERAL ull -#else -#error Neither 'long' nor 'long long' are 64-bit. -#endif - -/* -------------------------------------------------------------------------- */ -/* "fastest" types and their limits */ -/* -------------------------------------------------------------------------- */ -/* This is, admittedly, butt-ugly. But at least it's ugly where the average */ -/* user of PDCLib will never see it, and makes <_PDCLIB_config.h> much */ -/* cleaner. */ -/* -------------------------------------------------------------------------- */ - -typedef _PDCLIB_fast8 _PDCLIB_int_fast8_t; -typedef unsigned _PDCLIB_fast8 _PDCLIB_uint_fast8_t; -#define _PDCLIB_INT_FAST8_MIN concat( concat( _PDCLIB_, _PDCLIB_FAST8 ), _MIN ) -#define _PDCLIB_INT_FAST8_MAX concat( concat( _PDCLIB_, _PDCLIB_FAST8 ), _MAX ) -#define _PDCLIB_UINT_FAST8_MAX concat( concat( _PDCLIB_U, _PDCLIB_FAST8 ), _MAX ) - -typedef _PDCLIB_fast16 _PDCLIB_int_fast16_t; -typedef unsigned _PDCLIB_fast16 _PDCLIB_uint_fast16_t; -#define _PDCLIB_INT_FAST16_MIN concat( concat( _PDCLIB_, _PDCLIB_FAST16 ), _MIN ) -#define _PDCLIB_INT_FAST16_MAX concat( concat( _PDCLIB_, _PDCLIB_FAST16 ), _MAX ) -#define _PDCLIB_UINT_FAST16_MAX concat( concat( _PDCLIB_U, _PDCLIB_FAST16 ), _MAX ) - -typedef _PDCLIB_fast32 _PDCLIB_int_fast32_t; -typedef unsigned _PDCLIB_fast32 _PDCLIB_uint_fast32_t; -#define _PDCLIB_INT_FAST32_MIN concat( concat( _PDCLIB_, _PDCLIB_FAST32 ), _MIN ) -#define _PDCLIB_INT_FAST32_MAX concat( concat( _PDCLIB_, _PDCLIB_FAST32 ), _MAX ) -#define _PDCLIB_UINT_FAST32_MAX concat( concat( _PDCLIB_U, _PDCLIB_FAST32 ), _MAX ) - -typedef _PDCLIB_fast64 _PDCLIB_int_fast64_t; -typedef unsigned _PDCLIB_fast64 _PDCLIB_uint_fast64_t; -#define _PDCLIB_INT_FAST64_MIN concat( concat( _PDCLIB_, _PDCLIB_FAST64 ), _MIN ) -#define _PDCLIB_INT_FAST64_MAX concat( concat( _PDCLIB_, _PDCLIB_FAST64 ), _MAX ) -#define _PDCLIB_UINT_FAST64_MAX concat( concat( _PDCLIB_U, _PDCLIB_FAST64 ), _MAX ) - -/* -------------------------------------------------------------------------- */ -/* Various typedefs and limits */ -/* -------------------------------------------------------------------------- */ - -typedef _PDCLIB_ptrdiff _PDCLIB_ptrdiff_t; -#define _PDCLIB_PTRDIFF_MIN concat( concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MIN ) -#define _PDCLIB_PTRDIFF_MAX concat( concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MAX ) - -#define _PDCLIB_SIG_ATOMIC_MIN concat( concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MIN ) -#define _PDCLIB_SIG_ATOMIC_MAX concat( concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MAX ) - -typedef _PDCLIB_size _PDCLIB_size_t; -#define _PDCLIB_SIZE_MAX concat( concat( _PDCLIB_, _PDCLIB_SIZE ), _MAX ) - -typedef _PDCLIB_wchar _PDCLIB_wchar_t; -#define _PDCLIB_WCHAR_MIN concat( concat( _PDCLIB_, _PDCLIB_WCHAR ), _MIN ) -#define _PDCLIB_WCHAR_MAX concat( concat( _PDCLIB_, _PDCLIB_WCHAR ), _MAX ) - -typedef _PDCLIB_intptr _PDCLIB_intptr_t; -typedef unsigned _PDCLIB_intptr _PDCLIB_uintptr_t; -#define _PDCLIB_INTPTR_MIN concat( concat( _PDCLIB_, _PDCLIB_INTPTR ), _MIN ) -#define _PDCLIB_INTPTR_MAX concat( concat( _PDCLIB_, _PDCLIB_INTPTR ), _MAX ) -#define _PDCLIB_UINTPTR_MAX concat( concat( _PDCLIB_U, _PDCLIB_INTPTR ), _MAX ) - -typedef _PDCLIB_intmax _PDCLIB_intmax_t; -typedef unsigned _PDCLIB_intmax _PDCLIB_uintmax_t; -#define _PDCLIB_INTMAX_MIN concat( concat( _PDCLIB_, _PDCLIB_INTMAX ), _MIN ) -#define _PDCLIB_INTMAX_MAX concat( concat( _PDCLIB_, _PDCLIB_INTMAX ), _MAX ) -#define _PDCLIB_UINTMAX_MAX concat( concat( _PDCLIB_U, _PDCLIB_INTMAX ), _MAX ) -#define _PDCLIB_INTMAX_C( value ) concat( value, _PDCLIB_INTMAX_LITERAL ) -#define _PDCLIB_UINTMAX_C( value ) concat( value, concat( u, _PDCLIB_INTMAX_LITERAL ) ) diff --git a/assert.h b/assert.h deleted file mode 100755 index d5d61ec..0000000 --- a/assert.h +++ /dev/null @@ -1,51 +0,0 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* 7.2 Diagnostics - - 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 -#include <_PDCLIB_aux.h> -#endif - -#ifndef _PDCLIB_CONFIG_H -#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H -#include <_PDCLIB_config.h> -#endif - -#ifndef _PDCLIB_ASSERT_H -#define _PDCLIB_ASSERT_H _PDCLIB_ASSERT_H -#if _PDCLIB_C_VERSION == 99 -void _PDCLIB_assert( char const * const, char const * const, char const * const ); -#else -void _PDCLIB_assert( char const * const ); -#endif -#endif - -/* If NDEBUG is set, assert() is a null operation. */ -#undef assert - -#ifdef NDEBUG -#define assert( ignore ) ( (void) 0 ) -#else -#if _PDCLIB_C_VERSION == 99 -#define assert( expression ) ( ( expression ) ? (void) 0 \ - : _PDCLIB_assert( "Assertion failed: " #expression \ - ", function ", __func__, \ - ", file " __FILE__ \ - ", line " _PDCLIB_symbol2string( __LINE__ ) \ - "." _PDCLIB_endl ) ) -#else -#define assert( expression ) ( ( expression ) ? (void) 0 \ - : _PDCLIB_assert( "Assertion failed: " #expression \ - ", file " __FILE__ \ - ", line " _PDCLIB_symbol2string( __LINE__ ) \ - "." _PDCLIB_endl ) ) -#endif -#endif - diff --git a/float.h b/float.h deleted file mode 100644 index 7c0136a..0000000 --- a/float.h +++ /dev/null @@ -1,86 +0,0 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* 7.7 Characteristics of floating types - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_FLOAT_H -#define _PDCLIB_FLOAT_H _PDCLIB_FLOAT_H - -#ifndef _PDCLIB_CONFIG_H -#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H -#include <_PDCLIB_config.h> -#endif - -#define FLT_ROUNDS _PDCLIB_FLT_ROUNDS -#define FLT_EVAL_METHOD _PDCLIB_FLT_EVAL_METHOD -#define DECIMAL_DIG _PDCLIB_DECIMAL_DIG - -/* Produced by enquire version 5.1a, CWI, Amsterdam - http://www.cwi.nl/~steven/enquire.html */ - - /* Radix of exponent representation */ -#define FLT_RADIX 2 - /* Number of base-FLT_RADIX digits in the significand of a float */ -#define FLT_MANT_DIG 24 - /* Number of decimal digits of precision in a float */ -#define FLT_DIG 6 - /* Difference between 1.0 and the minimum float greater than 1.0 */ -#define FLT_EPSILON 1.19209290e-07F - /* Minimum int x such that FLT_RADIX**(x-1) is a normalised float */ -#define FLT_MIN_EXP (-125) - /* Minimum normalised float */ -#define FLT_MIN 1.17549435e-38F - /* Minimum int x such that 10**x is a normalised float */ -#define FLT_MIN_10_EXP (-37) - /* Maximum int x such that FLT_RADIX**(x-1) is a representable float */ -#define FLT_MAX_EXP 128 - /* Maximum float */ -#define FLT_MAX 3.40282347e+38F - /* Maximum int x such that 10**x is a representable float */ -#define FLT_MAX_10_EXP 38 - - /* Number of base-FLT_RADIX digits in the significand of a double */ -#define DBL_MANT_DIG 53 - /* Number of decimal digits of precision in a double */ -#define DBL_DIG 15 - /* Difference between 1.0 and the minimum double greater than 1.0 */ -#define DBL_EPSILON 2.2204460492503131e-16 - /* Minimum int x such that FLT_RADIX**(x-1) is a normalised double */ -#define DBL_MIN_EXP (-1021) - /* Minimum normalised double */ -#define DBL_MIN 2.2250738585072014e-308 - /* Minimum int x such that 10**x is a normalised double */ -#define DBL_MIN_10_EXP (-307) - /* Maximum int x such that FLT_RADIX**(x-1) is a representable double */ -#define DBL_MAX_EXP 1024 - /* Maximum double */ -#define DBL_MAX 1.7976931348623157e+308 - /* Maximum int x such that 10**x is a representable double */ -#define DBL_MAX_10_EXP 308 - - /* Number of base-FLT_RADIX digits in the significand of a long double */ -#define LDBL_MANT_DIG 113 - /* Number of decimal digits of precision in a long double */ -#define LDBL_DIG 33 - /* Difference between 1.0 and the minimum long double greater than 1.0 */ -#define LDBL_EPSILON 1.92592994438723585305597794258492732e-34L - /* Minimum int x such that FLT_RADIX**(x-1) is a normalised long double */ -#define LDBL_MIN_EXP (-16381) - /* Minimum normalised long double */ -#define LDBL_MIN 3.36210314311209350626267781732175260e-4932L - /* Minimum int x such that 10**x is a normalised long double */ -#define LDBL_MIN_10_EXP (-4931) - /* Maximum int x such that FLT_RADIX**(x-1) is a representable long double */ -#define LDBL_MAX_EXP 16384 - /* Maximum long double */ -#define LDBL_MAX 1.18973149535723176508575932662800702e+4932L - /* Maximum int x such that 10**x is a representable long double */ -#define LDBL_MAX_10_EXP 4932 - -#endif - diff --git a/includes/_PDCLIB_aux.h b/includes/_PDCLIB_aux.h new file mode 100644 index 0000000..4ef019e --- /dev/null +++ b/includes/_PDCLIB_aux.h @@ -0,0 +1,61 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* 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. +*/ + +/* -------------------------------------------------------------------------- */ +/* Standard Version */ +/* -------------------------------------------------------------------------- */ + +/* Many a compiler gets this wrong, so you might have to hardcode it instead. */ + +#if __STDC__ != 1 +#error Compiler does not define _ _STDC_ _ to 1 (not standard-compliant)! +#endif + +#ifndef __STDC_VERSION__ +#define _PDCLIB_C_VERSION 90 +#define _PDCLIB_restrict +#elif __STDC_VERSION__ == 199409L +#define _PDCLIB_C_VERSION 95 +#define _PDCLIB_restrict +#elif __STDC_VERSION__ == 199901L +#define _PDCLIB_C_VERSION 99 +#define _PDCLIB_restrict restrict +#else +#error Unsupported _ _STDC_VERSION_ _ (__STDC_VERSION__) (supported: ISO/IEC 9899:1990, 9899/AMD1:1995, and 9899:1999). +#endif + +#ifndef __STDC_HOSTED__ +#warning Compiler does not define _ _STDC_HOSTED_ _ (not standard-compliant)! +#elif __STDC_HOSTED__ == 0 +#define _PDCLIB_HOSTED 0 +#elif __STDC_HOSTED__ == 1 +#define _PDCLIB_HOSTED 1 +#else +#error Compiler does not define _ _STDC_HOSTED_ _ to 0 or 1 (not standard-compliant)! +#endif + +#if _PDCLIB_C_VERSION != 99 +#warning Up to and including v1.x, PDCLib is only aiming at ISO/IEC 9899:1999 (C99). +#warning PDCLib might not be fully conforming to either C89 or C95 prior to v2.x. +#endif + +/* -------------------------------------------------------------------------- */ +/* Helper macros: */ +/* _PDCLIB_cc( x, y ) concatenates two preprocessor tokens without extending */ +/* _PDCLIB_concat( x, y ) concatenates two preprocessor tokens with extending */ +/* -------------------------------------------------------------------------- */ + +#define _PDCLIB_cc( x, y ) x ## y +#define _PDCLIB_concat( x, y ) _PDCLIB_cc( x, y ) + +#define _PDCLIB_symbol2value( x ) #x +#define _PDCLIB_symbol2string( x ) _PDCLIB_symbol2value( x ) +#define _PDCLIB_symbol2identity( x ) x + diff --git a/includes/_PDCLIB_config.h b/includes/_PDCLIB_config.h new file mode 100644 index 0000000..74eb290 --- /dev/null +++ b/includes/_PDCLIB_config.h @@ -0,0 +1,164 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* Internal PDCLib configuration <_PDCLIB_config.h> + (Generic Template) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* -------------------------------------------------------------------------- */ +/* Misc */ +/* -------------------------------------------------------------------------- */ + +/* The character (sequence) your platform uses as newline. */ +#define _PDCLIB_endl "\n" + +/* -------------------------------------------------------------------------- */ +/* Integers */ +/* -------------------------------------------------------------------------- */ +/* Assuming 8-bit char, two's-complement architecture here. 'short' being */ +/* 16 bit, 'int' being either 16, 32 or 64 bit, 'long' being either 32 or 64 */ +/* bit (but 64 bit only if 'int' is 32 bit), and 'long long' being 64 bit if */ +/* 'long' is not, 64 or 128 bit otherwise. */ +/* Author is quite willing to support other systems but would like to hear of */ +/* interest in such support and details on the to-be-supported architecture */ +/* first, before going to lengths about it. */ +/* -------------------------------------------------------------------------- */ + +/* Comment out (or delete) the line below if your 'char' type is unsigned. */ +#define _PDCLIB_CHAR_SIGNED 1 + +/* Width of the integer types short, int, long, and long long, in bytes. */ +/* SHRT == 2, INT >= SHRT, LONG >= INT >= 4, LLONG >= LONG - check your */ +/* compiler manuals. */ +#define _PDCLIB_SHRT_BYTES 2 +#define _PDCLIB_INT_BYTES 4 +#define _PDCLIB_LONG_BYTES 4 +#define _PDCLIB_LLONG_BYTES 8 + +/* -------------------------------------------------------------------------- */ +/* 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). */ +/* If you require a non-standard datatype to define the "usually fastest" */ +/* types, PDCLib as-is doesn't support that. Please contact the author with */ +/* details on your platform in that case, so support can be added. */ +/* -------------------------------------------------------------------------- */ + +#define _PDCLIB_FAST8 INT +#define _PDCLIB_fast8 int + +#define _PDCLIB_FAST16 INT +#define _PDCLIB_fast16 int + +#define _PDCLIB_FAST32 INT +#define _PDCLIB_fast32 int + +#define _PDCLIB_FAST64 LLONG +#define _PDCLIB_fast64 long long + +/* -------------------------------------------------------------------------- */ +/* What follows are a couple of "special" typedefs and their limits. Again, */ +/* the actual definition of the limits is done in <_PDCLIB_int.h>, and the */ +/* defines here are merely "configuration". See above for details. */ +/* -------------------------------------------------------------------------- */ + +/* The result type of substracting two pointers */ +#define _PDCLIB_ptrdiff int +#define _PDCLIB_PTRDIFF INT + +/* 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 + +/* Result type of the 'sizeof' operator */ +#define _PDCLIB_size unsigned int +#define _PDCLIB_SIZE UINT + +/* Large enough an integer to hold all character codes of the largest supported + locale. +*/ +#define _PDCLIB_wchar unsigned short +#define _PDCLIB_WCHAR USHRT + +#define _PDCLIB_intptr int +#define _PDCLIB_INTPTR INT + +#define _PDCLIB_intmax long long int +#define _PDCLIB_INTMAX LLINT +/* You are also required to state the literal suffix for the intmax type */ +#define _PDCLIB_INTMAX_LITERAL ll + +/* -------------------------------------------------------------------------- */ +/* Floating Point */ +/* -------------------------------------------------------------------------- */ + +/* Whether the implementation rounds toward zero (0), to nearest (1), toward + positive infinity (2), or toward negative infinity (3). (-1) signifies + indeterminable rounding, any other value implementation-specific rounding. +*/ +#define _PDCLIB_FLT_ROUNDS -1 + +/* Whether the implementation uses exact-width precision (0), promotes float + to double (1), or promotes float and double to long double (2). (-1) + signifies indeterminable behaviour, any other value implementation-specific + behaviour. +*/ +#define _PDCLIB_FLT_EVAL_METHOD -1 + +/* "Number of the decimal digits (n), such that any floating-point number in the + widest supported floating type with p(max) radix (b) digits can be rounded to + a floating-point number with (n) decimal digits and back again without change + to the value p(max) log(10)b if (b) is a power of 10, [1 + p(max) log(10)b] + otherwise." + 64bit IEC 60559 double format (53bit mantissa) is DECIMAL_DIG 17. + 80bit IEC 60559 double-extended format (64bit mantissa) is DECIMAL_DIG 21. +*/ +#define _PDCLIB_DECIMAL_DIG 17 + +/* -------------------------------------------------------------------------- */ +/* Platform-dependent macros defined by the standard headers. */ +/* -------------------------------------------------------------------------- */ + +/* The offsetof macro + Contract: Expand to an integer constant expression of type size_t, which + represents the offset in bytes to the structure member from the beginning + of the structure. If the specified member is a bitfield, behaviour is + undefined. + There is no standard-compliant way to do this. + This implementation casts an integer zero to 'pointer to type', and then + takes the address of member. This is undefined behaviour but should work on + most compilers. +*/ +#define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) ) + +/* Variable Length Parameter List Handling () + The macros defined by are highly dependent on the calling + conventions used, and you probably have to replace them with builtins of + your compiler. The following generic implementation works only for pure + stack-based architectures, and only if arguments are aligned to pointer + type. Credits to Michael Moody, who contributed this to the Public Domain. +*/ + +/* Internal helper macro. va_round is not part of . */ +#define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) ) + +typedef char * _PDCLIB_va_list; +#define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) ) +#define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 ) +#define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 ) +#define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 ) diff --git a/includes/_PDCLIB_int.h b/includes/_PDCLIB_int.h new file mode 100644 index 0000000..24accb0 --- /dev/null +++ b/includes/_PDCLIB_int.h @@ -0,0 +1,253 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* 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. +*/ + +/* -------------------------------------------------------------------------- */ +/* 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). */ +/* -------------------------------------------------------------------------- */ + +#ifndef _PDCLIB_CONFIG_H +#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H +#include <_PDCLIB_config.h> +#endif + +#ifndef _PDCLIB_AUX_H +#define _PDCLIB_AUX_H _PDCLIB_AUX_H +#include <_PDCLIB_aux.h> +#endif + +/* null pointer constant */ +#define _PDCLIB_NULL 0 + +/* -------------------------------------------------------------------------- */ +/* Limits of native datatypes */ +/* -------------------------------------------------------------------------- */ +/* The definition of minimum limits for unsigned datatypes is done because */ +/* later on we will "construct" limits for other abstract types: */ +/* USHRT -> _PDCLIB_ + USHRT + _MIN -> _PDCLIB_USHRT_MIN -> 0 */ +/* INT -> _PDCLIB_ + INT + _MIN -> _PDCLIB_INT_MIN -> ... you get the idea. */ +/* -------------------------------------------------------------------------- */ + +/* Setting 'char' limits */ +#define _PDCLIB_CHAR_BIT 8 +#define _PDCLIB_UCHAR_MIN 0 +#define _PDCLIB_UCHAR_MAX 0xff +#define _PDCLIB_SCHAR_MIN (-0x7f - 1) +#define _PDCLIB_SCHAR_MAX 0x7f +#ifdef _PDCLIB_CHAR_SIGNED +#define _PDCLIB_CHAR_MIN _PDCLIB_SCHAR_MIN +#define _PDCLIB_CHAR_MAX _PDCLIB_SCHAR_MAX +#else +#define _PDCLIB_CHAR_MIN 0 +#define _PDCLIB_CHAR_MAX _PDCLIB_UCHAR_MAX +#endif + +/* Setting 'short' limits */ +#if _PDCLIB_SHRT_BYTES == 2 +#define _PDCLIB_SHRT_MAX 0x7fff +#define _PDCLIB_SHRT_MIN (-0x7fff - 1) +#define _PDCLIB_USHRT_MAX 0xffff +#else +#error Unsupported width of 'short' (not 16 bit). +#endif +#define _PDCLIB_USHRT_MIN 0 + +#if _PDCLIB_INT_BYTES < _PDCLIB_SHRT_BYTES +#error Bogus setting: short > int? Check _PDCLIB_config.h. +#endif + +/* Setting 'int' limits */ +#if _PDCLIB_INT_BYTES == 2 +#define _PDCLIB_INT_MAX 0x7fff +#define _PDCLIB_INT_MIN (-0x7fff - 1) +#define _PDCLIB_UINT_MAX 0xffffU +#elif _PDCLIB_INT_BYTES == 4 +#define _PDCLIB_INT_MAX 0x7fffffff +#define _PDCLIB_INT_MIN (-0x7fffffff - 1) +#define _PDCLIB_UINT_MAX 0xffffffffU +#elif _PDCLIB_INT_BYTES == 8 +#define _PDCLIB_INT_MAX 0x7fffffffffffffff +#define _PDCLIB_INT_MIN (-0x7fffffffffffffff - 1) +#define _PDCLIB_UINT_MAX 0xffffffffffffffff +#else +#error Unsupported width of 'int' (neither 16, 32, nor 64 bit). +#endif +#define _PDCLIB_UINT_MIN 0 + +/* Setting 'long' limits */ +#if _PDCLIB_LONG_BYTES == 4 +#define _PDCLIB_LONG_MAX 0x7fffffffL +#define _PDCLIB_LONG_MIN (-0x7fffffffL - 1L) +#define _PDCLIB_ULONG_MAX 0xffffffffUL +#elif _PDCLIB_LONG_BYTES == 8 +#define _PDCLIB_LONG_MAX 0x7fffffffffffffffL +#define _PDCLIB_LONG_MIN (-0x7fffffffffffffffL - 1L) +#define _PDCLIB_ULONG_MAX 0xffffffffffffffffUL +#else +#error Unsupported width of 'long' (neither 32 nor 64 bit). +#endif +#define _PDCLIB_ULONG_MIN 0 + +/* Setting 'long long' limits */ +#if _PDCLIB_LLONG_BYTES == 8 +#define _PDCLIB_LLONG_MAX 0x7fffffffffffffffLL +#define _PDCLIB_LLONG_MIN (-0x7fffffffffffffffLL - 1LL) +#define _PDCLIB_ULLONG_MAX 0xffffffffffffffffULL +#elif _PDCLIB_LLONG_BYTES == 16 +#define _PDCLIB_LLONG_MAX 0x7fffffffffffffffffffffffffffffffLL +#define _PDCLIB_LLONG_MIN (-0x7fffffffffffffffffffffffffffffffLL - 1LL) +#define _PDCLIB_ULLONG_MAX 0xffffffffffffffffffffffffffffffffLL +#else +#error Unsupported width of 'long long' (neither 64 nor 128 bit). +#endif +#define _PDCLIB_ULLONG_MIN 0 + +/* -------------------------------------------------------------------------- */ +/* exact-width types and their limits */ +/* -------------------------------------------------------------------------- */ + +/* Setting 'int8_t', its limits, and its literal. */ +#if _PDCLIB_CHAR_BIT == 8 +typedef signed char _PDCLIB_int8_t; +typedef unsigned char _PDCLIB_uint8_t; +#define _PDCLIB_INT8_MAX _PDCLIB_CHAR_MAX +#define _PDCLIB_INT8_MIN _PDCLIB_CHAR_MIN +#define _PDCLIB_UINT8_MAX _PDCLIB_UCHAR_MAX +#define _PDCLIB_INT8_LITERAL +#define _PDCLIB_UINT8_LITERAL +#else +#error Unsupported width of char (not 8 bits). +#endif + +/* Setting 'int16_t', its limits, and its literal */ +#if _PDCLIB_INT_BYTES == 2 +typedef signed int _PDCLIB_int16_t; +typedef unsigned int _PDCLIB_uint16_t; +#define _PDCLIB_INT16_MAX _PDCLIB_INT_MAX +#define _PDCLIB_INT16_MIN _PDCLIB_INT_MIN +#define _PDCLIB_UINT16_MAX _PDCLIB_UINT_MAX +#define _PDCLIB_INT16_LITERAL +#define _PDCLIB_UINT16_LITERAL +#elif _PDCLIB_SHRT_BYTES == 2 +typedef signed short _PDCLIB_int16_t; +typedef unsigned short _PDCLIB_uint16_t; +#define _PDCLIB_INT16_MAX _PDCLIB_SHRT_MAX +#define _PDCLIB_INT16_MIN _PDCLIB_SHRT_MIN +#define _PDCLIB_UINT16_MAX _PDCLIB_USHRT_MAX +#define _PDCLIB_INT16_LITERAL s +#define _PDCLIB_UINT16_LITERAL us +#else +#error Neither 'short' nor 'int' are 16-bit. +#endif + +/* Setting 'int32_t', its limits, and its literal */ +#if _PDCLIB_INT_BYTES == 4 +typedef signed int _PDCLIB_int32_t; +typedef unsigned int _PDCLIB_uint32_t; +#define _PDCLIB_INT32_MAX _PDCLIB_INT_MAX +#define _PDCLIB_INT32_MIN _PDCLIB_INT_MIN +#define _PDCLIB_UINT32_MAX _PDCLIB_UINT_MAX +#define _PDCLIB_INT32_LITERAL +#define _PDCLIB_UINT32_LITERAL +#elif _PDCLIB_LONG_BYTES == 4 +typedef signed long _PDCLIB_int32_t; +typedef unsigned long _PDCLIB_uint32_t; +#define _PDCLIB_INT32_MAX _PDCLIB_LONG_MAX +#define _PDCLIB_INT32_MIN _PDCLIB_LONG_MIN +#define _PDCLIB_UINT32_MAX _PDCLIB_LONG_MAX +#define _PDCLIB_INT32_LITERAL l +#define _PDCLIB_UINT32_LITERAL ul +#else +#error Neither 'int' nor 'long' are 32-bit. +#endif + +#if _PDCLIB_LONG_BYTES == 8 +typedef signed long _PDCLIB_int64_t; +typedef unsigned long _PDCLIB_uint64_t; +#define _PDCLIB_INT64_MAX _PDCLIB_LONG_MAX +#define _PDCLIB_INT64_MIN _PDCLIB_LONG_MIN +#define _PDCLIB_UINT64_MAX _PDCLIB_ULONG_MAX +#define _PDCLIB_INT64_LITERAL l +#define _PDCLIB_UINT64_LITERAL ul +#elif _PDCLIB_LLONG_BYTES == 8 +typedef signed long long _PDCLIB_int64_t; +typedef unsigned long long _PDCLIB_uint64_t; +#define _PDCLIB_INT64_MAX _PDCLIB_LLONG_MAX +#define _PDCLIB_INT64_MIN _PDCLIB_LLONG_MIN +#define _PDCLIB_UINT64_MAX _PDCLIB_ULLONG_MAX +#define _PDCLIB_INT64_LITERAL ll +#define _PDCLIB_UINT64_LITERAL ull +#else +#error Neither 'long' nor 'long long' are 64-bit. +#endif + +/* -------------------------------------------------------------------------- */ +/* "fastest" types and their limits */ +/* -------------------------------------------------------------------------- */ +/* This is, admittedly, butt-ugly. But at least it's ugly where the average */ +/* user of PDCLib will never see it, and makes <_PDCLIB_config.h> much */ +/* cleaner. */ +/* -------------------------------------------------------------------------- */ + +typedef _PDCLIB_fast8 _PDCLIB_int_fast8_t; +typedef unsigned _PDCLIB_fast8 _PDCLIB_uint_fast8_t; +#define _PDCLIB_INT_FAST8_MIN concat( concat( _PDCLIB_, _PDCLIB_FAST8 ), _MIN ) +#define _PDCLIB_INT_FAST8_MAX concat( concat( _PDCLIB_, _PDCLIB_FAST8 ), _MAX ) +#define _PDCLIB_UINT_FAST8_MAX concat( concat( _PDCLIB_U, _PDCLIB_FAST8 ), _MAX ) + +typedef _PDCLIB_fast16 _PDCLIB_int_fast16_t; +typedef unsigned _PDCLIB_fast16 _PDCLIB_uint_fast16_t; +#define _PDCLIB_INT_FAST16_MIN concat( concat( _PDCLIB_, _PDCLIB_FAST16 ), _MIN ) +#define _PDCLIB_INT_FAST16_MAX concat( concat( _PDCLIB_, _PDCLIB_FAST16 ), _MAX ) +#define _PDCLIB_UINT_FAST16_MAX concat( concat( _PDCLIB_U, _PDCLIB_FAST16 ), _MAX ) + +typedef _PDCLIB_fast32 _PDCLIB_int_fast32_t; +typedef unsigned _PDCLIB_fast32 _PDCLIB_uint_fast32_t; +#define _PDCLIB_INT_FAST32_MIN concat( concat( _PDCLIB_, _PDCLIB_FAST32 ), _MIN ) +#define _PDCLIB_INT_FAST32_MAX concat( concat( _PDCLIB_, _PDCLIB_FAST32 ), _MAX ) +#define _PDCLIB_UINT_FAST32_MAX concat( concat( _PDCLIB_U, _PDCLIB_FAST32 ), _MAX ) + +typedef _PDCLIB_fast64 _PDCLIB_int_fast64_t; +typedef unsigned _PDCLIB_fast64 _PDCLIB_uint_fast64_t; +#define _PDCLIB_INT_FAST64_MIN concat( concat( _PDCLIB_, _PDCLIB_FAST64 ), _MIN ) +#define _PDCLIB_INT_FAST64_MAX concat( concat( _PDCLIB_, _PDCLIB_FAST64 ), _MAX ) +#define _PDCLIB_UINT_FAST64_MAX concat( concat( _PDCLIB_U, _PDCLIB_FAST64 ), _MAX ) + +/* -------------------------------------------------------------------------- */ +/* Various typedefs and limits */ +/* -------------------------------------------------------------------------- */ + +typedef _PDCLIB_ptrdiff _PDCLIB_ptrdiff_t; +#define _PDCLIB_PTRDIFF_MIN concat( concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MIN ) +#define _PDCLIB_PTRDIFF_MAX concat( concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MAX ) + +#define _PDCLIB_SIG_ATOMIC_MIN concat( concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MIN ) +#define _PDCLIB_SIG_ATOMIC_MAX concat( concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MAX ) + +typedef _PDCLIB_size _PDCLIB_size_t; +#define _PDCLIB_SIZE_MAX concat( concat( _PDCLIB_, _PDCLIB_SIZE ), _MAX ) + +typedef _PDCLIB_wchar _PDCLIB_wchar_t; +#define _PDCLIB_WCHAR_MIN concat( concat( _PDCLIB_, _PDCLIB_WCHAR ), _MIN ) +#define _PDCLIB_WCHAR_MAX concat( concat( _PDCLIB_, _PDCLIB_WCHAR ), _MAX ) + +typedef _PDCLIB_intptr _PDCLIB_intptr_t; +typedef unsigned _PDCLIB_intptr _PDCLIB_uintptr_t; +#define _PDCLIB_INTPTR_MIN concat( concat( _PDCLIB_, _PDCLIB_INTPTR ), _MIN ) +#define _PDCLIB_INTPTR_MAX concat( concat( _PDCLIB_, _PDCLIB_INTPTR ), _MAX ) +#define _PDCLIB_UINTPTR_MAX concat( concat( _PDCLIB_U, _PDCLIB_INTPTR ), _MAX ) + +typedef _PDCLIB_intmax _PDCLIB_intmax_t; +typedef unsigned _PDCLIB_intmax _PDCLIB_uintmax_t; +#define _PDCLIB_INTMAX_MIN concat( concat( _PDCLIB_, _PDCLIB_INTMAX ), _MIN ) +#define _PDCLIB_INTMAX_MAX concat( concat( _PDCLIB_, _PDCLIB_INTMAX ), _MAX ) +#define _PDCLIB_UINTMAX_MAX concat( concat( _PDCLIB_U, _PDCLIB_INTMAX ), _MAX ) +#define _PDCLIB_INTMAX_C( value ) concat( value, _PDCLIB_INTMAX_LITERAL ) +#define _PDCLIB_UINTMAX_C( value ) concat( value, concat( u, _PDCLIB_INTMAX_LITERAL ) ) diff --git a/includes/assert.h b/includes/assert.h new file mode 100644 index 0000000..d5d61ec --- /dev/null +++ b/includes/assert.h @@ -0,0 +1,51 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* 7.2 Diagnostics + + 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 +#include <_PDCLIB_aux.h> +#endif + +#ifndef _PDCLIB_CONFIG_H +#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H +#include <_PDCLIB_config.h> +#endif + +#ifndef _PDCLIB_ASSERT_H +#define _PDCLIB_ASSERT_H _PDCLIB_ASSERT_H +#if _PDCLIB_C_VERSION == 99 +void _PDCLIB_assert( char const * const, char const * const, char const * const ); +#else +void _PDCLIB_assert( char const * const ); +#endif +#endif + +/* If NDEBUG is set, assert() is a null operation. */ +#undef assert + +#ifdef NDEBUG +#define assert( ignore ) ( (void) 0 ) +#else +#if _PDCLIB_C_VERSION == 99 +#define assert( expression ) ( ( expression ) ? (void) 0 \ + : _PDCLIB_assert( "Assertion failed: " #expression \ + ", function ", __func__, \ + ", file " __FILE__ \ + ", line " _PDCLIB_symbol2string( __LINE__ ) \ + "." _PDCLIB_endl ) ) +#else +#define assert( expression ) ( ( expression ) ? (void) 0 \ + : _PDCLIB_assert( "Assertion failed: " #expression \ + ", file " __FILE__ \ + ", line " _PDCLIB_symbol2string( __LINE__ ) \ + "." _PDCLIB_endl ) ) +#endif +#endif + diff --git a/includes/float.h b/includes/float.h new file mode 100644 index 0000000..7c0136a --- /dev/null +++ b/includes/float.h @@ -0,0 +1,86 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* 7.7 Characteristics of floating types + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_FLOAT_H +#define _PDCLIB_FLOAT_H _PDCLIB_FLOAT_H + +#ifndef _PDCLIB_CONFIG_H +#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H +#include <_PDCLIB_config.h> +#endif + +#define FLT_ROUNDS _PDCLIB_FLT_ROUNDS +#define FLT_EVAL_METHOD _PDCLIB_FLT_EVAL_METHOD +#define DECIMAL_DIG _PDCLIB_DECIMAL_DIG + +/* Produced by enquire version 5.1a, CWI, Amsterdam + http://www.cwi.nl/~steven/enquire.html */ + + /* Radix of exponent representation */ +#define FLT_RADIX 2 + /* Number of base-FLT_RADIX digits in the significand of a float */ +#define FLT_MANT_DIG 24 + /* Number of decimal digits of precision in a float */ +#define FLT_DIG 6 + /* Difference between 1.0 and the minimum float greater than 1.0 */ +#define FLT_EPSILON 1.19209290e-07F + /* Minimum int x such that FLT_RADIX**(x-1) is a normalised float */ +#define FLT_MIN_EXP (-125) + /* Minimum normalised float */ +#define FLT_MIN 1.17549435e-38F + /* Minimum int x such that 10**x is a normalised float */ +#define FLT_MIN_10_EXP (-37) + /* Maximum int x such that FLT_RADIX**(x-1) is a representable float */ +#define FLT_MAX_EXP 128 + /* Maximum float */ +#define FLT_MAX 3.40282347e+38F + /* Maximum int x such that 10**x is a representable float */ +#define FLT_MAX_10_EXP 38 + + /* Number of base-FLT_RADIX digits in the significand of a double */ +#define DBL_MANT_DIG 53 + /* Number of decimal digits of precision in a double */ +#define DBL_DIG 15 + /* Difference between 1.0 and the minimum double greater than 1.0 */ +#define DBL_EPSILON 2.2204460492503131e-16 + /* Minimum int x such that FLT_RADIX**(x-1) is a normalised double */ +#define DBL_MIN_EXP (-1021) + /* Minimum normalised double */ +#define DBL_MIN 2.2250738585072014e-308 + /* Minimum int x such that 10**x is a normalised double */ +#define DBL_MIN_10_EXP (-307) + /* Maximum int x such that FLT_RADIX**(x-1) is a representable double */ +#define DBL_MAX_EXP 1024 + /* Maximum double */ +#define DBL_MAX 1.7976931348623157e+308 + /* Maximum int x such that 10**x is a representable double */ +#define DBL_MAX_10_EXP 308 + + /* Number of base-FLT_RADIX digits in the significand of a long double */ +#define LDBL_MANT_DIG 113 + /* Number of decimal digits of precision in a long double */ +#define LDBL_DIG 33 + /* Difference between 1.0 and the minimum long double greater than 1.0 */ +#define LDBL_EPSILON 1.92592994438723585305597794258492732e-34L + /* Minimum int x such that FLT_RADIX**(x-1) is a normalised long double */ +#define LDBL_MIN_EXP (-16381) + /* Minimum normalised long double */ +#define LDBL_MIN 3.36210314311209350626267781732175260e-4932L + /* Minimum int x such that 10**x is a normalised long double */ +#define LDBL_MIN_10_EXP (-4931) + /* Maximum int x such that FLT_RADIX**(x-1) is a representable long double */ +#define LDBL_MAX_EXP 16384 + /* Maximum long double */ +#define LDBL_MAX 1.18973149535723176508575932662800702e+4932L + /* Maximum int x such that 10**x is a representable long double */ +#define LDBL_MAX_10_EXP 4932 + +#endif + diff --git a/includes/iso646.h b/includes/iso646.h new file mode 100644 index 0000000..48ca809 --- /dev/null +++ b/includes/iso646.h @@ -0,0 +1,27 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* 7.9 Alternative spellings + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_ISO646_H +#define _PDCLIB_ISO646_H _PDCLIB_ISO646_H + +#define and && +#define and_eq &= +#define bitand & +#define bitor | +#define compl ˜ +#define not ! +#define not_eq != +#define or || +#define or_eq |= +#define xor ˆ +#define xor_eq ˆ= + +#endif + diff --git a/includes/limits.h b/includes/limits.h new file mode 100644 index 0000000..0631bf0 --- /dev/null +++ b/includes/limits.h @@ -0,0 +1,43 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* 7.10 Sizes of integer types + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_LIMITS_H +#define _PDCLIB_LIMITS_H _PDCLIB_LIMITS_H + +#ifndef _PDCLIB_INT_H +#define _PDCLIB_INT_H _PDCLIB_INT_H +#include <_PDCLIB_int.h> +#endif + +/* TODO: Defined to 1 as multibyte characters are not supported yet. */ +#define MB_LEN_MAX 1 + +#define LLONG_MIN _PDCLIB_LLONG_MIN +#define LLONG_MAX _PDCLIB_LLONG_MAX +#define ULLONG_MAX _PDCLIB_ULLONG_MAX + +#define CHAR_BIT _PDCLIB_CHAR_BIT +#define CHAR_MAX _PDCLIB_CHAR_MAX +#define CHAR_MIN _PDCLIB_CHAR_MIN +#define SCHAR_MAX _PDCLIB_SCHAR_MAX +#define SCHAR_MIN _PDCLIB_SCHAR_MIN +#define UCHAR_MAX _PDCLIB_UCHAR_MAX +#define SHRT_MAX _PDCLIB_SHRT_MAX +#define SHRT_MIN _PDCLIB_SHRT_MIN +#define INT_MAX _PDCLIB_INT_MAX +#define INT_MIN _PDCLIB_INT_MIN +#define LONG_MAX _PDCLIB_LONG_MAX +#define LONG_MIN _PDCLIB_LONG_MIN +#define USHRT_MAX _PDCLIB_USHRT_MAX +#define UINT_MAX _PDCLIB_UINT_MAX +#define ULONG_MAX _PDCLIB_ULONG_MAX + +#endif + diff --git a/includes/stdarg.h b/includes/stdarg.h new file mode 100644 index 0000000..7558131 --- /dev/null +++ b/includes/stdarg.h @@ -0,0 +1,27 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* 7.15 Variable arguments + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_STDARG_H +#define _PDCLIB_STDARG_H _PDCLIB_STDARG_H + +#ifndef _PDCLIB_CONFIG_H +#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H +#include <_PDCLIB_config.h> +#endif + +typedef _PDCLIB_va_list va_list; + +#define va_arg( ap, type ) _PDCLIB_va_arg( ap, type ) +#define va_copy( dest, src ) _PDCLIB_va_copy( dest, src ) +#define va_end( ap ) _PDCLIB_va_end( ap ) +#define va_start( ap, parmN ) _PDCLIB_va_start( ap, parmN ) + +#endif + diff --git a/includes/stdbool.h b/includes/stdbool.h new file mode 100644 index 0000000..f067e97 --- /dev/null +++ b/includes/stdbool.h @@ -0,0 +1,20 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* 7.16 Boolean type and values + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_STDBOOL_H +#define _PDCLIB_STDBOOL_H _PDCLIB_STDBOOL_H + +#define bool _Bool +#define true 1 +#define false 0 +#define __bool_true_false_are_defined 1 + +#endif + diff --git a/includes/stddef.h b/includes/stddef.h new file mode 100644 index 0000000..d0577d0 --- /dev/null +++ b/includes/stddef.h @@ -0,0 +1,28 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* 7.17 Common definitions + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_STDDEF_H +#define _PDCLIB_STDDEF_H _PDCLIB_STDDEF_H + +#ifndef _PDCLIB_CONFIG_H +#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H +#include <_PDCLIB_config.h> +#endif + +typedef _PDCLIB_ptrdiff_t ptrdiff_t; +typedef _PDCLIB_size_t size_t; +typedef _PDCLIB_wchar_t wchar_t; + +#define NULL _PDCLIB_NULL + +#define offsetof( type, member ) _PDCLIB_offsetof( type, member ) + +#endif + diff --git a/includes/stdint.h b/includes/stdint.h new file mode 100644 index 0000000..50d3a6e --- /dev/null +++ b/includes/stdint.h @@ -0,0 +1,215 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* 7.18 Integer types + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _PDCLIB_STDINT_H +#define _PDCLIB_STDINT_H _PDCLIB_STDINT_H + +#ifndef _PDCLIB_INT_H +#define _PDCLIB_INT_H _PDCLIB_INT_H +#include <_PDCLIB_int.h> +#endif + +/* 7.18.1.1 Exact-width integer types. */ + +typedef _PDCLIB_int8_t int8_t; +typedef _PDCLIB_int16_t int16_t; +typedef _PDCLIB_int32_t int32_t; +typedef _PDCLIB_int64_t int64_t; + +typedef _PDCLIB_uint8_t uint8_t; +typedef _PDCLIB_uint16_t uint16_t; +typedef _PDCLIB_uint32_t uint32_t; +typedef _PDCLIB_uint64_t uint64_t; + +/* 7.18.1.2 Minimum-width integer types */ + +/* 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 uint8_t uint_least8_t; +typedef uint16_t uint_least16_t; +typedef uint32_t uint_least32_t; +typedef uint64_t uint_least64_t; + +/* 7.18.1.3 Fastest minimum-width integer types */ + +/* You are allowed to add more types here, e.g. int_fast24_t. */ + +typedef _PDCLIB_int_fast8_t int_fast8_t; +typedef _PDCLIB_int_fast16_t int_fast16_t; +typedef _PDCLIB_int_fast32_t int_fast32_t; +typedef _PDCLIB_int_fast64_t int_fast64_t; + +typedef _PDCLIB_uint_fast8_t uint_fast8_t; +typedef _PDCLIB_uint_fast16_t uint_fast16_t; +typedef _PDCLIB_uint_fast32_t uint_fast32_t; +typedef _PDCLIB_uint_fast64_t uint_fast64_t; + +/* 7.18.1.4 Integer types capable of holding object pointers */ + +typedef _PDCLIB_intptr_t intptr_t; +typedef _PDCLIB_uintptr_t uintptr_t; + +/* 7.18.1.5 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 */ + +#ifdef __cplusplus +#ifndef __STDC_LIMIT_MACROS +#define _PDCLIB_NO_LIMIT_MACROS +#endif +#endif + +#ifndef _PDCLIB_NO_LIMIT_MACROS + +/* 7.18.2.1 Limits of exact-width integer types */ + +#define INT8_MIN _PDCLIB_INT8_MIN +#define INT8_MAX _PDCLIB_INT8_MAX +#define UINT8_MAX _PDCLIB_UINT8_MAX + +#define INT16_MIN _PDCLIB_INT16_MIN +#define INT16_MAX _PDCLIB_INT16_MAX +#define UINT16_MAX _PDCLIB_UINT16_MAX + +#define INT32_MIN _PDCLIB_INT32_MIN +#define INT32_MAX _PDCLIB_INT32_MAX +#define UINT32_MAX _PDCLIB_UINT32_MAX + +#define INT64_MIN _PDCLIB_INT64_MIN +#define INT64_MAX _PDCLIB_INT64_MAX +#define UINT64_MAX _PDCLIB_UINT64_MAX + +/* 7.18.2.2 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_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define UINT_LEAST8_MAX UINT8_MAX + +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST16_MAX INT16_MAX +#define UINT_LEAST16_MAX UINT16_MAX + +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define UINT_LEAST32_MAX UINT32_MAX + +#define INT_LEAST64_MIN INT64_MIN +#define INT_LEAST64_MAX INT64_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +/* 7.18.2.3 Limits of fastest minimum-width integer types */ + +#define INT_FAST8_MIN _PDCLIB_INT_FAST8_MIN +#define INT_FAST8_MAX _PDCLIB_INT_FAST8_MAX +#define UINT_FAST8_MAX _PDCLIB_UINT_FAST8_MAX + +#define INT_FAST16_MIN _PDCLIB_INT_FAST16_MIN +#define INT_FAST16_MAX _PDCLIB_INT_FAST16_MAX +#define UINT_FAST16_MAX _PDCLIB_UINT_FAST16_MAX + +#define INT_FAST32_MIN _PDCLIB_INT_FAST32_MIN +#define INT_FAST32_MAX _PDCLIB_INT_FAST32_MAX +#define UINT_FAST32_MAX _PDCLIB_UINT_FAST32_MAX + +#define INT_FAST64_MIN _PDCLIB_INT_FAST64_MIN +#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 */ + +#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 */ + +#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 */ + +#define PTRDIFF_MIN _PDCLIB_PTRDIFF_MIN +#define PTRDIFF_MAX _PDCLIB_PTRDIFF_MAX + +#define SIG_ATOMIC_MIN _PDCLIB_SIG_ATOMIC_MIN +#define SIG_ATOMIC_MAX _PDCLIB_SIG_ATOMIC_MAX + +#define SIZE_MAX _PDCLIB_SIZE_MAX + +#define WCHAR_MIN _PDCLIB_WCHAR_MIN +#define WCHAR_MAX _PDCLIB_WCHAR_MAX + +#define WINT_MIN _PDCLIB_WINT_MIN +#define WINT_MAX _PDCLIB_WINT_MAX + +#endif + +/* 7.18.4 Macros for integer constants */ + +#ifdef __cplusplus +#ifndef __STDC_CONSTANT_MACROS +#define _PDCLIB_NO_CONSTANT_MACROS +#endif +#endif + +#ifndef _PDCLIB_NO_CONSTANT_MACROS + +/* 7.18.4.1 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 + these macros is to append the literal of that exact-width type to the macro + parameter. + This is considered a hack, as the author is not sure his understanding of + the requirements of this macro is correct. Any input appreciated. +*/ + +/* Expand to an integer constant of specified value and type int_leastN_t */ + +#define INT8_C( value ) concat( value, _PDCLIB_INT8_LITERAL ) +#define INT16_C( value ) concat( value, _PDCLIB_INT16_LITERAL ) +#define INT32_C( value ) concat( value, _PDCLIB_INT32_LITERAL ) +#define INT64_C( value ) concat( value, _PDCLIB_INT64_LITERAL ) + +/* Expand to an integer constant of specified value and type uint_leastN_t */ + +#define UINT8_C( value ) concat( value, _PDCLIB_UINT8_LITERAL ) +#define UINT16_C( value ) concat( value, _PDCLIB_UINT16_LITERAL ) +#define UINT32_C( value ) concat( value, _PDCLIB_UINT32_LITERAL ) +#define UINT64_C( value ) concat( value, _PDCLIB_UINT64_LITERAL ) + +/* 7.18.4.2 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 ) + +/* Expand to an integer constant of specified value and type uintmax_t */ +#define UINTMAX_C( value ) _PDCLIB_UINTMAX_C( value ) + +#endif + +#endif + diff --git a/includes/string.h b/includes/string.h new file mode 100644 index 0000000..c63bab8 --- /dev/null +++ b/includes/string.h @@ -0,0 +1,197 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* String handling + + 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 + +#ifndef _PDCLIB_AUX_H +#define _PDCLIB_AUX_H _PDCLIB_AUX_H +#include <_PDCLIB_aux.h> +#endif + +#ifndef _PDCLIB_INT_H +#define _PDCLIB_INT_H _PDCLIB_INT_H +#include <_PDCLIB_int.h> +#endif + +#if _PDCLIB_HOSTED == 1 +#warning As of the current release, PDCLib is not a conforming hosted environment. +#warning is not standard-compliant (yet) - strerror is missing. +#endif + +typedef _PDCLIB_size_t size_t; + +#define NULL _PDCLIB_NULL + +/* String function conventions */ + +/* + In any of the following functions taking a size_t n to specify the length of + an array or size of a memory region, n may be 0, but the pointer arguments to + the call shall still be valid unless otherwise stated. +*/ + +/* Copying functions */ + +/* Copy a number of n characters from the memory area pointed to by s2 to the + area pointed to by s1. If the two areas overlap, behaviour is undefined. + Returns the value of s1. +*/ +void * memcpy( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n ); + +/* Copy a number of n characters from the memory area pointed to by s2 to the + area pointed to by s1. The two areas may overlap. + Returns the value of s1. +*/ +void * memmove( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n ); + +/* Copy the character array s2 (including terminating '\0' byte) into the + character array s1. + Returns the value of s1. +*/ +char * strcpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ); + +/* Copy a maximum of n characters from the character array s2 into the character + array s1. If s2 is shorter than n characters, '\0' bytes will be appended to + the copy in s1 until n characters have been written. If s2 is longer than n + characters, NO terminating '\0' will be written to s1. If the arrays overlap, + behaviour is undefined. + Returns the value of s1. +*/ +char * strncpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ); + +/* Concatenation functions */ + +/* Append the contents of the character array s2 (including terminating '\0') to + the character array s1 (first character of s2 overwriting the '\0' of s1). If + the arrays overlap, behaviour is undefined. + Returns the value of s1. +*/ +char * strcat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ); + +/* Append a maximum of n characters from the character array s1 to the character + array s1 (first character of s2 overwriting the '\0' of s1). A terminating + '\0' is ALWAYS appended, even if the full n characters have already been + written. If the arrays overlap, behaviour is undefined. + Returns the value of s1. +*/ +char * strncat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ); + +/* Comparison functions */ + +/* Compare the first n characters of the memory areas pointed to by s1 and s2. + Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if + s1 > s2. +*/ +int memcmp( const void * s1, const void * s2, size_t n ); + +/* Compare the character arrays s1 and s2. + Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if + s1 > s2. +*/ +int strcmp( const char * s1, const char * s2 ); + +/* Compare the character arrays s1 and s2, interpreted as specified by the + LC_COLLATE category of the current locale. + Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if + s1 > s2. + TODO: Currently a dummy wrapper for strcmp() as PDCLib does not yet support + locales. +*/ +int strcoll( const char * s1, const char * s2 ); + +/* Compare no more than the first n characters of the character arrays s1 and + s2. + Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if + s1 > s2. +*/ +int strncmp( const char * s1, const char * s2, size_t n ); + +/* Transform the character array s2 as appropriate for the LC_COLLATE setting of + the current locale. If length of resulting string is less than n, store it in + the character array pointed to by s1. Return the length of the resulting + string. +*/ +size_t strxfrm( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ); + +/* Search functions */ + +/* Search the first n characters in the memory area pointed to by s for the + character c (interpreted as unsigned char). + Returns a pointer to the first instance found, or NULL. +*/ +void * memchr( const void * s, int c, size_t n ); + +/* Search the character array s (including terminating '\0') for the character c + (interpreted as char). + Returns a pointer to the first instance found, or NULL. +*/ +char * strchr( const char * s, int c ); + +/* Determine the length of the initial substring of character array s1 which + consists only of characters not from the character array s2. + Returns the length of that substring. +*/ +size_t strcspn( const char * s1, const char * s2 ); + +/* Search the character array s1 for any character from the character array s2. + Returns a pointer to the first occurrence, or NULL. +*/ +char * strpbrk( const char * s1, const char * s2 ); + +/* Search the character array s (including terminating '\0') for the character c + (interpreted as char). + Returns a pointer to the last instance found, or NULL. +*/ +char * strrchr( const char * s, int c ); + +/* Determine the length of the initial substring of character array s1 which + consists only of characters from the character array s2. + Returns the length of that substring. +*/ +size_t strspn( const char * s1, const char * s2 ); + +/* Search the character array s1 for the substring in character array s2. + Returns a pointer to that sbstring, or NULL. If s2 is of length zero, + returns s1. +*/ +char * strstr( const char * s1, const char * s2 ); + +/* In a series of subsequent calls, parse a C string into tokens. + On the first call to strtok(), the first argument is a pointer to the to-be- + parsed C string. On subsequent calls, the first argument is NULL unless you + want to start parsing a new string. s2 holds an array of seperator characters + which can differ from call to call. Leading seperators are skipped, the first + trailing seperator overwritten with '\0'. + Returns a pointer to the next token. + WARNING: This function uses static storage, and as such is not reentrant. +*/ +char * strtok( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ); + +/* Miscellaneous functions */ + +/* Write the character c (interpreted as unsigned char) to the first n + characters of the memory area pointed to by s. + Returns s. +*/ +void * memset( void * s, int c, size_t n ); + +/* Map an error number to a (locale-specific) error message string. Error + numbers are typically errno values, but any number is mapped to a message. + TODO: PDCLib does not yet support locales. + TODO: strerror() not yet implemented. +char * strerror( int errnum ); +*/ + +/* Returns the length of the string s (excluding terminating '\0'). +*/ +size_t strlen( const char * s ); + +#endif diff --git a/iso646.h b/iso646.h deleted file mode 100644 index 48ca809..0000000 --- a/iso646.h +++ /dev/null @@ -1,27 +0,0 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* 7.9 Alternative spellings - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_ISO646_H -#define _PDCLIB_ISO646_H _PDCLIB_ISO646_H - -#define and && -#define and_eq &= -#define bitand & -#define bitor | -#define compl ˜ -#define not ! -#define not_eq != -#define or || -#define or_eq |= -#define xor ˆ -#define xor_eq ˆ= - -#endif - diff --git a/limits.h b/limits.h deleted file mode 100644 index 0631bf0..0000000 --- a/limits.h +++ /dev/null @@ -1,43 +0,0 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* 7.10 Sizes of integer types - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_LIMITS_H -#define _PDCLIB_LIMITS_H _PDCLIB_LIMITS_H - -#ifndef _PDCLIB_INT_H -#define _PDCLIB_INT_H _PDCLIB_INT_H -#include <_PDCLIB_int.h> -#endif - -/* TODO: Defined to 1 as multibyte characters are not supported yet. */ -#define MB_LEN_MAX 1 - -#define LLONG_MIN _PDCLIB_LLONG_MIN -#define LLONG_MAX _PDCLIB_LLONG_MAX -#define ULLONG_MAX _PDCLIB_ULLONG_MAX - -#define CHAR_BIT _PDCLIB_CHAR_BIT -#define CHAR_MAX _PDCLIB_CHAR_MAX -#define CHAR_MIN _PDCLIB_CHAR_MIN -#define SCHAR_MAX _PDCLIB_SCHAR_MAX -#define SCHAR_MIN _PDCLIB_SCHAR_MIN -#define UCHAR_MAX _PDCLIB_UCHAR_MAX -#define SHRT_MAX _PDCLIB_SHRT_MAX -#define SHRT_MIN _PDCLIB_SHRT_MIN -#define INT_MAX _PDCLIB_INT_MAX -#define INT_MIN _PDCLIB_INT_MIN -#define LONG_MAX _PDCLIB_LONG_MAX -#define LONG_MIN _PDCLIB_LONG_MIN -#define USHRT_MAX _PDCLIB_USHRT_MAX -#define UINT_MAX _PDCLIB_UINT_MAX -#define ULONG_MAX _PDCLIB_ULONG_MAX - -#endif - diff --git a/stdarg.h b/stdarg.h deleted file mode 100644 index 7558131..0000000 --- a/stdarg.h +++ /dev/null @@ -1,27 +0,0 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* 7.15 Variable arguments - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_STDARG_H -#define _PDCLIB_STDARG_H _PDCLIB_STDARG_H - -#ifndef _PDCLIB_CONFIG_H -#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H -#include <_PDCLIB_config.h> -#endif - -typedef _PDCLIB_va_list va_list; - -#define va_arg( ap, type ) _PDCLIB_va_arg( ap, type ) -#define va_copy( dest, src ) _PDCLIB_va_copy( dest, src ) -#define va_end( ap ) _PDCLIB_va_end( ap ) -#define va_start( ap, parmN ) _PDCLIB_va_start( ap, parmN ) - -#endif - diff --git a/stdbool.h b/stdbool.h deleted file mode 100644 index f067e97..0000000 --- a/stdbool.h +++ /dev/null @@ -1,20 +0,0 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* 7.16 Boolean type and values - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_STDBOOL_H -#define _PDCLIB_STDBOOL_H _PDCLIB_STDBOOL_H - -#define bool _Bool -#define true 1 -#define false 0 -#define __bool_true_false_are_defined 1 - -#endif - diff --git a/stddef.h b/stddef.h deleted file mode 100644 index d0577d0..0000000 --- a/stddef.h +++ /dev/null @@ -1,28 +0,0 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* 7.17 Common definitions - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_STDDEF_H -#define _PDCLIB_STDDEF_H _PDCLIB_STDDEF_H - -#ifndef _PDCLIB_CONFIG_H -#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H -#include <_PDCLIB_config.h> -#endif - -typedef _PDCLIB_ptrdiff_t ptrdiff_t; -typedef _PDCLIB_size_t size_t; -typedef _PDCLIB_wchar_t wchar_t; - -#define NULL _PDCLIB_NULL - -#define offsetof( type, member ) _PDCLIB_offsetof( type, member ) - -#endif - diff --git a/stdint.h b/stdint.h deleted file mode 100644 index 50d3a6e..0000000 --- a/stdint.h +++ /dev/null @@ -1,215 +0,0 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* 7.18 Integer types - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_STDINT_H -#define _PDCLIB_STDINT_H _PDCLIB_STDINT_H - -#ifndef _PDCLIB_INT_H -#define _PDCLIB_INT_H _PDCLIB_INT_H -#include <_PDCLIB_int.h> -#endif - -/* 7.18.1.1 Exact-width integer types. */ - -typedef _PDCLIB_int8_t int8_t; -typedef _PDCLIB_int16_t int16_t; -typedef _PDCLIB_int32_t int32_t; -typedef _PDCLIB_int64_t int64_t; - -typedef _PDCLIB_uint8_t uint8_t; -typedef _PDCLIB_uint16_t uint16_t; -typedef _PDCLIB_uint32_t uint32_t; -typedef _PDCLIB_uint64_t uint64_t; - -/* 7.18.1.2 Minimum-width integer types */ - -/* 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 uint8_t uint_least8_t; -typedef uint16_t uint_least16_t; -typedef uint32_t uint_least32_t; -typedef uint64_t uint_least64_t; - -/* 7.18.1.3 Fastest minimum-width integer types */ - -/* You are allowed to add more types here, e.g. int_fast24_t. */ - -typedef _PDCLIB_int_fast8_t int_fast8_t; -typedef _PDCLIB_int_fast16_t int_fast16_t; -typedef _PDCLIB_int_fast32_t int_fast32_t; -typedef _PDCLIB_int_fast64_t int_fast64_t; - -typedef _PDCLIB_uint_fast8_t uint_fast8_t; -typedef _PDCLIB_uint_fast16_t uint_fast16_t; -typedef _PDCLIB_uint_fast32_t uint_fast32_t; -typedef _PDCLIB_uint_fast64_t uint_fast64_t; - -/* 7.18.1.4 Integer types capable of holding object pointers */ - -typedef _PDCLIB_intptr_t intptr_t; -typedef _PDCLIB_uintptr_t uintptr_t; - -/* 7.18.1.5 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 */ - -#ifdef __cplusplus -#ifndef __STDC_LIMIT_MACROS -#define _PDCLIB_NO_LIMIT_MACROS -#endif -#endif - -#ifndef _PDCLIB_NO_LIMIT_MACROS - -/* 7.18.2.1 Limits of exact-width integer types */ - -#define INT8_MIN _PDCLIB_INT8_MIN -#define INT8_MAX _PDCLIB_INT8_MAX -#define UINT8_MAX _PDCLIB_UINT8_MAX - -#define INT16_MIN _PDCLIB_INT16_MIN -#define INT16_MAX _PDCLIB_INT16_MAX -#define UINT16_MAX _PDCLIB_UINT16_MAX - -#define INT32_MIN _PDCLIB_INT32_MIN -#define INT32_MAX _PDCLIB_INT32_MAX -#define UINT32_MAX _PDCLIB_UINT32_MAX - -#define INT64_MIN _PDCLIB_INT64_MIN -#define INT64_MAX _PDCLIB_INT64_MAX -#define UINT64_MAX _PDCLIB_UINT64_MAX - -/* 7.18.2.2 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_LEAST8_MIN INT8_MIN -#define INT_LEAST8_MAX INT8_MAX -#define UINT_LEAST8_MAX UINT8_MAX - -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST16_MAX INT16_MAX -#define UINT_LEAST16_MAX UINT16_MAX - -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST32_MAX INT32_MAX -#define UINT_LEAST32_MAX UINT32_MAX - -#define INT_LEAST64_MIN INT64_MIN -#define INT_LEAST64_MAX INT64_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -/* 7.18.2.3 Limits of fastest minimum-width integer types */ - -#define INT_FAST8_MIN _PDCLIB_INT_FAST8_MIN -#define INT_FAST8_MAX _PDCLIB_INT_FAST8_MAX -#define UINT_FAST8_MAX _PDCLIB_UINT_FAST8_MAX - -#define INT_FAST16_MIN _PDCLIB_INT_FAST16_MIN -#define INT_FAST16_MAX _PDCLIB_INT_FAST16_MAX -#define UINT_FAST16_MAX _PDCLIB_UINT_FAST16_MAX - -#define INT_FAST32_MIN _PDCLIB_INT_FAST32_MIN -#define INT_FAST32_MAX _PDCLIB_INT_FAST32_MAX -#define UINT_FAST32_MAX _PDCLIB_UINT_FAST32_MAX - -#define INT_FAST64_MIN _PDCLIB_INT_FAST64_MIN -#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 */ - -#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 */ - -#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 */ - -#define PTRDIFF_MIN _PDCLIB_PTRDIFF_MIN -#define PTRDIFF_MAX _PDCLIB_PTRDIFF_MAX - -#define SIG_ATOMIC_MIN _PDCLIB_SIG_ATOMIC_MIN -#define SIG_ATOMIC_MAX _PDCLIB_SIG_ATOMIC_MAX - -#define SIZE_MAX _PDCLIB_SIZE_MAX - -#define WCHAR_MIN _PDCLIB_WCHAR_MIN -#define WCHAR_MAX _PDCLIB_WCHAR_MAX - -#define WINT_MIN _PDCLIB_WINT_MIN -#define WINT_MAX _PDCLIB_WINT_MAX - -#endif - -/* 7.18.4 Macros for integer constants */ - -#ifdef __cplusplus -#ifndef __STDC_CONSTANT_MACROS -#define _PDCLIB_NO_CONSTANT_MACROS -#endif -#endif - -#ifndef _PDCLIB_NO_CONSTANT_MACROS - -/* 7.18.4.1 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 - these macros is to append the literal of that exact-width type to the macro - parameter. - This is considered a hack, as the author is not sure his understanding of - the requirements of this macro is correct. Any input appreciated. -*/ - -/* Expand to an integer constant of specified value and type int_leastN_t */ - -#define INT8_C( value ) concat( value, _PDCLIB_INT8_LITERAL ) -#define INT16_C( value ) concat( value, _PDCLIB_INT16_LITERAL ) -#define INT32_C( value ) concat( value, _PDCLIB_INT32_LITERAL ) -#define INT64_C( value ) concat( value, _PDCLIB_INT64_LITERAL ) - -/* Expand to an integer constant of specified value and type uint_leastN_t */ - -#define UINT8_C( value ) concat( value, _PDCLIB_UINT8_LITERAL ) -#define UINT16_C( value ) concat( value, _PDCLIB_UINT16_LITERAL ) -#define UINT32_C( value ) concat( value, _PDCLIB_UINT32_LITERAL ) -#define UINT64_C( value ) concat( value, _PDCLIB_UINT64_LITERAL ) - -/* 7.18.4.2 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 ) - -/* Expand to an integer constant of specified value and type uintmax_t */ -#define UINTMAX_C( value ) _PDCLIB_UINTMAX_C( value ) - -#endif - -#endif - diff --git a/string.h b/string.h deleted file mode 100755 index c63bab8..0000000 --- a/string.h +++ /dev/null @@ -1,197 +0,0 @@ -/* $Id$ */ - -/* Release $Name$ */ - -/* String handling - - 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 - -#ifndef _PDCLIB_AUX_H -#define _PDCLIB_AUX_H _PDCLIB_AUX_H -#include <_PDCLIB_aux.h> -#endif - -#ifndef _PDCLIB_INT_H -#define _PDCLIB_INT_H _PDCLIB_INT_H -#include <_PDCLIB_int.h> -#endif - -#if _PDCLIB_HOSTED == 1 -#warning As of the current release, PDCLib is not a conforming hosted environment. -#warning is not standard-compliant (yet) - strerror is missing. -#endif - -typedef _PDCLIB_size_t size_t; - -#define NULL _PDCLIB_NULL - -/* String function conventions */ - -/* - In any of the following functions taking a size_t n to specify the length of - an array or size of a memory region, n may be 0, but the pointer arguments to - the call shall still be valid unless otherwise stated. -*/ - -/* Copying functions */ - -/* Copy a number of n characters from the memory area pointed to by s2 to the - area pointed to by s1. If the two areas overlap, behaviour is undefined. - Returns the value of s1. -*/ -void * memcpy( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n ); - -/* Copy a number of n characters from the memory area pointed to by s2 to the - area pointed to by s1. The two areas may overlap. - Returns the value of s1. -*/ -void * memmove( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n ); - -/* Copy the character array s2 (including terminating '\0' byte) into the - character array s1. - Returns the value of s1. -*/ -char * strcpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ); - -/* Copy a maximum of n characters from the character array s2 into the character - array s1. If s2 is shorter than n characters, '\0' bytes will be appended to - the copy in s1 until n characters have been written. If s2 is longer than n - characters, NO terminating '\0' will be written to s1. If the arrays overlap, - behaviour is undefined. - Returns the value of s1. -*/ -char * strncpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ); - -/* Concatenation functions */ - -/* Append the contents of the character array s2 (including terminating '\0') to - the character array s1 (first character of s2 overwriting the '\0' of s1). If - the arrays overlap, behaviour is undefined. - Returns the value of s1. -*/ -char * strcat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ); - -/* Append a maximum of n characters from the character array s1 to the character - array s1 (first character of s2 overwriting the '\0' of s1). A terminating - '\0' is ALWAYS appended, even if the full n characters have already been - written. If the arrays overlap, behaviour is undefined. - Returns the value of s1. -*/ -char * strncat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ); - -/* Comparison functions */ - -/* Compare the first n characters of the memory areas pointed to by s1 and s2. - Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if - s1 > s2. -*/ -int memcmp( const void * s1, const void * s2, size_t n ); - -/* Compare the character arrays s1 and s2. - Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if - s1 > s2. -*/ -int strcmp( const char * s1, const char * s2 ); - -/* Compare the character arrays s1 and s2, interpreted as specified by the - LC_COLLATE category of the current locale. - Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if - s1 > s2. - TODO: Currently a dummy wrapper for strcmp() as PDCLib does not yet support - locales. -*/ -int strcoll( const char * s1, const char * s2 ); - -/* Compare no more than the first n characters of the character arrays s1 and - s2. - Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if - s1 > s2. -*/ -int strncmp( const char * s1, const char * s2, size_t n ); - -/* Transform the character array s2 as appropriate for the LC_COLLATE setting of - the current locale. If length of resulting string is less than n, store it in - the character array pointed to by s1. Return the length of the resulting - string. -*/ -size_t strxfrm( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ); - -/* Search functions */ - -/* Search the first n characters in the memory area pointed to by s for the - character c (interpreted as unsigned char). - Returns a pointer to the first instance found, or NULL. -*/ -void * memchr( const void * s, int c, size_t n ); - -/* Search the character array s (including terminating '\0') for the character c - (interpreted as char). - Returns a pointer to the first instance found, or NULL. -*/ -char * strchr( const char * s, int c ); - -/* Determine the length of the initial substring of character array s1 which - consists only of characters not from the character array s2. - Returns the length of that substring. -*/ -size_t strcspn( const char * s1, const char * s2 ); - -/* Search the character array s1 for any character from the character array s2. - Returns a pointer to the first occurrence, or NULL. -*/ -char * strpbrk( const char * s1, const char * s2 ); - -/* Search the character array s (including terminating '\0') for the character c - (interpreted as char). - Returns a pointer to the last instance found, or NULL. -*/ -char * strrchr( const char * s, int c ); - -/* Determine the length of the initial substring of character array s1 which - consists only of characters from the character array s2. - Returns the length of that substring. -*/ -size_t strspn( const char * s1, const char * s2 ); - -/* Search the character array s1 for the substring in character array s2. - Returns a pointer to that sbstring, or NULL. If s2 is of length zero, - returns s1. -*/ -char * strstr( const char * s1, const char * s2 ); - -/* In a series of subsequent calls, parse a C string into tokens. - On the first call to strtok(), the first argument is a pointer to the to-be- - parsed C string. On subsequent calls, the first argument is NULL unless you - want to start parsing a new string. s2 holds an array of seperator characters - which can differ from call to call. Leading seperators are skipped, the first - trailing seperator overwritten with '\0'. - Returns a pointer to the next token. - WARNING: This function uses static storage, and as such is not reentrant. -*/ -char * strtok( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ); - -/* Miscellaneous functions */ - -/* Write the character c (interpreted as unsigned char) to the first n - characters of the memory area pointed to by s. - Returns s. -*/ -void * memset( void * s, int c, size_t n ); - -/* Map an error number to a (locale-specific) error message string. Error - numbers are typically errno values, but any number is mapped to a message. - TODO: PDCLib does not yet support locales. - TODO: strerror() not yet implemented. -char * strerror( int errnum ); -*/ - -/* Returns the length of the string s (excluding terminating '\0'). -*/ -size_t strlen( const char * s ); - -#endif