X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=internals%2F_PDCLIB_int.h;h=bd656958d5df7f319ccc7c46831d1ad898947dcd;hp=c9988a9d7c2d67e045b2b705702f82a1ac696ee2;hb=197791f4a590c4db2d7b667698dbe3f732537b2f;hpb=d77b84be585e9ceaed1501579df5a4aec6a24a63 diff --git a/internals/_PDCLIB_int.h b/internals/_PDCLIB_int.h index c9988a9..bd65695 100644 --- a/internals/_PDCLIB_int.h +++ b/internals/_PDCLIB_int.h @@ -1,19 +1,19 @@ -#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). */ /* -------------------------------------------------------------------------- */ -#include <_PDCLIB_config.h> -#include <_PDCLIB_aux.h> +#include "_PDCLIB_config.h" +#include "_PDCLIB_aux.h" /* null pointer constant */ #define _PDCLIB_NULL 0 @@ -111,6 +111,8 @@ #if _PDCLIB_CHAR_BIT == 8 typedef signed char _PDCLIB_int8_t; typedef unsigned char _PDCLIB_uint8_t; +typedef signed char _PDCLIB_int_least8_t; +typedef unsigned char _PDCLIB_uint_least8_t; #define _PDCLIB_INT8_MAX _PDCLIB_CHAR_MAX #define _PDCLIB_INT8_MIN _PDCLIB_CHAR_MIN #define _PDCLIB_UINT8_MAX _PDCLIB_UCHAR_MAX @@ -123,6 +125,8 @@ typedef unsigned char _PDCLIB_uint8_t; #if _PDCLIB_INT_BYTES == 2 typedef signed int _PDCLIB_int16_t; typedef unsigned int _PDCLIB_uint16_t; +typedef signed int _PDCLIB_int_least16_t; +typedef unsigned int _PDCLIB_uint_least16_t; #define _PDCLIB_INT16_MAX _PDCLIB_INT_MAX #define _PDCLIB_INT16_MIN _PDCLIB_INT_MIN #define _PDCLIB_UINT16_MAX _PDCLIB_UINT_MAX @@ -130,6 +134,8 @@ typedef unsigned int _PDCLIB_uint16_t; #elif _PDCLIB_SHRT_BYTES == 2 typedef signed short _PDCLIB_int16_t; typedef unsigned short _PDCLIB_uint16_t; +typedef signed short _PDCLIB_int_least16_t; +typedef unsigned short _PDCLIB_uint_least16_t; #define _PDCLIB_INT16_MAX _PDCLIB_SHRT_MAX #define _PDCLIB_INT16_MIN _PDCLIB_SHRT_MIN #define _PDCLIB_UINT16_MAX _PDCLIB_USHRT_MAX @@ -142,6 +148,8 @@ typedef unsigned short _PDCLIB_uint16_t; #if _PDCLIB_INT_BYTES == 4 typedef signed int _PDCLIB_int32_t; typedef unsigned int _PDCLIB_uint32_t; +typedef signed int _PDCLIB_int_least32_t; +typedef unsigned int _PDCLIB_uint_least32_t; #define _PDCLIB_INT32_MAX _PDCLIB_INT_MAX #define _PDCLIB_INT32_MIN _PDCLIB_INT_MIN #define _PDCLIB_UINT32_MAX _PDCLIB_UINT_MAX @@ -151,6 +159,8 @@ typedef unsigned int _PDCLIB_uint32_t; #elif _PDCLIB_LONG_BYTES == 4 typedef signed long _PDCLIB_int32_t; typedef unsigned long _PDCLIB_uint32_t; +typedef signed long _PDCLIB_int_least32_t; +typedef unsigned long _PDCLIB_uint_least32_t; #define _PDCLIB_INT32_MAX _PDCLIB_LONG_MAX #define _PDCLIB_INT32_MIN _PDCLIB_LONG_MIN #define _PDCLIB_UINT32_MAX _PDCLIB_LONG_MAX @@ -165,6 +175,8 @@ typedef unsigned long _PDCLIB_uint32_t; #if _PDCLIB_LONG_BYTES == 8 && !defined(_PDCLIB_INT64_IS_LLONG) typedef signed long _PDCLIB_int64_t; typedef unsigned long _PDCLIB_uint64_t; +typedef signed long _PDCLIB_int_least64_t; +typedef unsigned long _PDCLIB_uint_least64_t; #define _PDCLIB_INT64_MAX _PDCLIB_LONG_MAX #define _PDCLIB_INT64_MIN _PDCLIB_LONG_MIN #define _PDCLIB_UINT64_MAX _PDCLIB_ULONG_MAX @@ -174,6 +186,8 @@ typedef unsigned long _PDCLIB_uint64_t; #elif _PDCLIB_LLONG_BYTES == 8 typedef signed long long _PDCLIB_int64_t; typedef unsigned long long _PDCLIB_uint64_t; +typedef signed long long _PDCLIB_int_least64_t; +typedef unsigned long long _PDCLIB_uint_least64_t; #define _PDCLIB_INT64_MAX _PDCLIB_LLONG_MAX #define _PDCLIB_INT64_MIN _PDCLIB_LLONG_MIN #define _PDCLIB_UINT64_MAX _PDCLIB_ULLONG_MAX @@ -224,13 +238,11 @@ typedef _PDCLIB_ptrdiff _PDCLIB_ptrdiff_t; #define _PDCLIB_PTRDIFF_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MIN ) #define _PDCLIB_PTRDIFF_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MAX ) -#define _PDCLIB_SIG_ATOMIC_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MIN ) -#define _PDCLIB_SIG_ATOMIC_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MAX ) - typedef _PDCLIB_size _PDCLIB_size_t; #define _PDCLIB_SIZE_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIZE ), _MAX ) typedef _PDCLIB_wint _PDCLIB_wint_t; + #ifndef __cplusplus typedef _PDCLIB_wchar _PDCLIB_wchar_t; #else @@ -239,6 +251,9 @@ typedef _PDCLIB_wint _PDCLIB_wint_t; #define _PDCLIB_WCHAR_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_WCHAR ), _MIN ) #define _PDCLIB_WCHAR_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_WCHAR ), _MAX ) +#define _PDCLIB_SIG_ATOMIC_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MIN ) +#define _PDCLIB_SIG_ATOMIC_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MAX ) + typedef _PDCLIB_intptr _PDCLIB_intptr_t; typedef unsigned _PDCLIB_intptr _PDCLIB_uintptr_t; #define _PDCLIB_INTPTR_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_INTPTR ), _MIN ) @@ -260,29 +275,6 @@ typedef unsigned _PDCLIB_intmax _PDCLIB_uintmax_t; typedef _PDCLIB_time _PDCLIB_time_t; typedef _PDCLIB_clock _PDCLIB_clock_t; -#if !defined(_PDCLIB_DEFINE_STRUCT_TIMESPEC) -#define _PDCLIB_DEFINE_STRUCT_TIMESPEC() \ - struct timespec { \ - time_t tv_sec; \ - long tv_nsec; \ - }; -#endif - -#if !defined(_PDCLIB_DEFINE_STRUCT_TM) -#define _PDCLIB_DEFINE_STRUCT_TM() \ - struct tm { \ - int tm_sec; \ - int tm_min; \ - int tm_hour; \ - int tm_mday; \ - int tm_mon; \ - int tm_year; \ - int tm_wday; \ - int tm_yday; \ - int tm_isdst; \ - }; -#endif - /* -------------------------------------------------------------------------- */ /* Internal data types */ /* -------------------------------------------------------------------------- */ @@ -310,28 +302,32 @@ extern char _PDCLIB_digits[]; extern char _PDCLIB_Xdigits[]; /* -------------------------------------------------------------------------- */ -/* errno */ +/* Sanity checks */ /* -------------------------------------------------------------------------- */ -/* If PDCLib would call its error number "errno" directly, there would be no way - to catch its value from underlying system calls that also use it (i.e., POSIX - operating systems). That is why we use an internal name, providing a means to - access it through . -*/ -extern int _PDCLIB_errno; +#if _PDCLIB_C_VERSION >= 2011 +_Static_assert( sizeof( short ) == _PDCLIB_SHRT_BYTES, "Compiler disagrees on _PDCLIB_SHRT_BYTES." ); +_Static_assert( sizeof( int ) == _PDCLIB_INT_BYTES, "Compiler disagrees on _PDCLIB_INT_BYTES." ); +_Static_assert( sizeof( long ) == _PDCLIB_LONG_BYTES, "Compiler disagrees on _PDCLIB_LONG_BYTES." ); +_Static_assert( sizeof( long long ) == _PDCLIB_LLONG_BYTES, "Compiler disagrees on _PDCLIB_LLONG_BYTES." ); -/* A mechanism for delayed evaluation. (Not sure if this is really necessary, so - no detailed documentation on the "why".) -*/ -int * _PDCLIB_errno_func( void ) _PDCLIB_nothrow; +_Static_assert( ( (char)-1 < 0 ) == _PDCLIB_CHAR_SIGNED, "Compiler disagrees on _PDCLIB_CHAR_SIGNED." ); +_Static_assert( sizeof( sizeof( int ) ) == sizeof( _PDCLIB_size ), "Compiler disagrees on _PDCLIB_size." ); + +_Static_assert( sizeof( _PDCLIB_wchar ) == sizeof( L'x' ), "Compiler disagrees on _PDCLIB_wchar." ); + +_Static_assert( sizeof( void * ) == sizeof( _PDCLIB_intptr ), "Compiler disagrees on _PDCLIB_intptr." ); + +_Static_assert( sizeof( &_PDCLIB_digits[1] - &_PDCLIB_digits[0] ) == sizeof( _PDCLIB_ptrdiff ), "Compiler disagrees on _PDCLIB_ptrdiff." ); +#endif /* -------------------------------------------------------------------------- */ /* locale / wchar / uchar */ /* -------------------------------------------------------------------------- */ #ifndef __cplusplus -typedef _PDCLIB_int16_t _PDCLIB_char16_t; -typedef _PDCLIB_int32_t _PDCLIB_char32_t; +typedef _PDCLIB_uint16_t _PDCLIB_char16_t; +typedef _PDCLIB_uint32_t _PDCLIB_char32_t; #else typedef char16_t _PDCLIB_char16_t; typedef char32_t _PDCLIB_char32_t; @@ -348,22 +344,33 @@ typedef struct _PDCLIB_mbstate { char _StC [124]; }; - union { - /* c16/related functions: Surrogate storage - * - * If zero, no surrogate pending. If nonzero, surrogate. - */ - _PDCLIB_uint16_t _Surrogate; - - /* Reserved for potential mbtoutf8/etc functions */ - unsigned char _U8[4]; - }; + /* c16/related functions: Surrogate storage + * + * If zero, no surrogate pending. If nonzero, surrogate. + */ + _PDCLIB_uint16_t _Surrogate; + + /* In cases where the underlying codec is capable of regurgitating a + * character without consuming any extra input (e.g. a surrogate pair in a + * UCS-4 to UTF-16 conversion) then these fields are used to track that + * state. In particular, they are used to buffer/fake the input for mbrtowc + * and similar functions. + * + * See _PDCLIB_encoding.h for values of _PendState and the resultant value + * in _PendChar. + */ + unsigned char _PendState; + char _PendChar; } _PDCLIB_mbstate_t; -typedef struct _PDCLIB_charcodec *_PDCLIB_charcodec_t; typedef struct _PDCLIB_locale *_PDCLIB_locale_t; typedef struct lconv _PDCLIB_lconv_t; +_PDCLIB_size_t _PDCLIB_mb_cur_max( void ); + +/* wide-character EOF */ +#define _PDCLIB_WEOF ((wint_t) -1 + /* -------------------------------------------------------------------------- */ /* stdio */ /* -------------------------------------------------------------------------- */ @@ -382,17 +389,26 @@ typedef struct _PDCLIB_file _PDCLIB_file_t; // Rename to _PDCLIB_FILE? /* Status structure required by _PDCLIB_print(). */ struct _PDCLIB_status_t { + /* XXX This structure is horrible now. scanf needs its own */ + int base; /* base to which the value shall be converted */ _PDCLIB_int_fast32_t flags; /* flags and length modifiers */ - unsigned n; /* print: maximum characters to be written */ + unsigned n; /* print: maximum characters to be written (snprintf) */ /* scan: number matched conversion specifiers */ unsigned i; /* number of characters read/written */ unsigned current;/* chars read/written in the CURRENT conversion */ - char * s; /* *sprintf(): target buffer */ - /* *sscanf(): source string */ unsigned width; /* specified field width */ int prec; /* specified field precision */ - _PDCLIB_file_t * stream; /* *fprintf() / *fscanf() stream */ + + union { + void * ctx; /* context for callback */ + const char * s; /* input string for scanf */ + }; + + union { + _PDCLIB_size_t ( *write ) ( void *p, const char *buf, _PDCLIB_size_t size ); + _PDCLIB_file_t *stream; /* for scanf */ + }; _PDCLIB_va_list arg; /* argument stack */ };