-#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
#define _PDCLIB_UCHAR_MAX 0xff
#define _PDCLIB_SCHAR_MIN (-0x7f - 1)
#define _PDCLIB_SCHAR_MAX 0x7f
-#ifdef _PDCLIB_CHAR_SIGNED
+#if _PDCLIB_CHAR_SIGNED == 1
#define _PDCLIB_CHAR_MIN _PDCLIB_SCHAR_MIN
#define _PDCLIB_CHAR_MAX _PDCLIB_SCHAR_MAX
#else
#if _PDCLIB_CHAR_BIT == 8
typedef signed char _PDCLIB_int8_t;
typedef unsigned char _PDCLIB_uint8_t;
+typedef signed char _PDCLIB_int_least8_t;
+typedef unsigned char _PDCLIB_uint_least8_t;
#define _PDCLIB_INT8_MAX _PDCLIB_CHAR_MAX
#define _PDCLIB_INT8_MIN _PDCLIB_CHAR_MIN
#define _PDCLIB_UINT8_MAX _PDCLIB_UCHAR_MAX
#if _PDCLIB_INT_BYTES == 2
typedef signed int _PDCLIB_int16_t;
typedef unsigned int _PDCLIB_uint16_t;
+typedef signed int _PDCLIB_int_least16_t;
+typedef unsigned int _PDCLIB_uint_least16_t;
#define _PDCLIB_INT16_MAX _PDCLIB_INT_MAX
#define _PDCLIB_INT16_MIN _PDCLIB_INT_MIN
#define _PDCLIB_UINT16_MAX _PDCLIB_UINT_MAX
#elif _PDCLIB_SHRT_BYTES == 2
typedef signed short _PDCLIB_int16_t;
typedef unsigned short _PDCLIB_uint16_t;
+typedef signed short _PDCLIB_int_least16_t;
+typedef unsigned short _PDCLIB_uint_least16_t;
#define _PDCLIB_INT16_MAX _PDCLIB_SHRT_MAX
#define _PDCLIB_INT16_MIN _PDCLIB_SHRT_MIN
#define _PDCLIB_UINT16_MAX _PDCLIB_USHRT_MAX
#if _PDCLIB_INT_BYTES == 4
typedef signed int _PDCLIB_int32_t;
typedef unsigned int _PDCLIB_uint32_t;
+typedef signed int _PDCLIB_int_least32_t;
+typedef unsigned int _PDCLIB_uint_least32_t;
#define _PDCLIB_INT32_MAX _PDCLIB_INT_MAX
#define _PDCLIB_INT32_MIN _PDCLIB_INT_MIN
#define _PDCLIB_UINT32_MAX _PDCLIB_UINT_MAX
#elif _PDCLIB_LONG_BYTES == 4
typedef signed long _PDCLIB_int32_t;
typedef unsigned long _PDCLIB_uint32_t;
+typedef signed long _PDCLIB_int_least32_t;
+typedef unsigned long _PDCLIB_uint_least32_t;
#define _PDCLIB_INT32_MAX _PDCLIB_LONG_MAX
#define _PDCLIB_INT32_MIN _PDCLIB_LONG_MIN
#define _PDCLIB_UINT32_MAX _PDCLIB_LONG_MAX
#if _PDCLIB_LONG_BYTES == 8 && !defined(_PDCLIB_INT64_IS_LLONG)
typedef signed long _PDCLIB_int64_t;
typedef unsigned long _PDCLIB_uint64_t;
+typedef signed long _PDCLIB_int_least64_t;
+typedef unsigned long _PDCLIB_uint_least64_t;
#define _PDCLIB_INT64_MAX _PDCLIB_LONG_MAX
#define _PDCLIB_INT64_MIN _PDCLIB_LONG_MIN
#define _PDCLIB_UINT64_MAX _PDCLIB_ULONG_MAX
#elif _PDCLIB_LLONG_BYTES == 8
typedef signed long long _PDCLIB_int64_t;
typedef unsigned long long _PDCLIB_uint64_t;
+typedef signed long long _PDCLIB_int_least64_t;
+typedef unsigned long long _PDCLIB_uint_least64_t;
#define _PDCLIB_INT64_MAX _PDCLIB_LLONG_MAX
#define _PDCLIB_INT64_MIN _PDCLIB_LLONG_MIN
#define _PDCLIB_UINT64_MAX _PDCLIB_ULLONG_MAX
#define _PDCLIB_PTRDIFF_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MIN )
#define _PDCLIB_PTRDIFF_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MAX )
-#define _PDCLIB_SIG_ATOMIC_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MIN )
-#define _PDCLIB_SIG_ATOMIC_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MAX )
-
typedef _PDCLIB_size _PDCLIB_size_t;
#define _PDCLIB_SIZE_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIZE ), _MAX )
typedef _PDCLIB_wint _PDCLIB_wint_t;
+
#ifndef __cplusplus
typedef _PDCLIB_wchar _PDCLIB_wchar_t;
#else
#define _PDCLIB_WCHAR_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_WCHAR ), _MIN )
#define _PDCLIB_WCHAR_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_WCHAR ), _MAX )
+#define _PDCLIB_SIG_ATOMIC_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MIN )
+#define _PDCLIB_SIG_ATOMIC_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MAX )
+
typedef _PDCLIB_intptr _PDCLIB_intptr_t;
typedef unsigned _PDCLIB_intptr _PDCLIB_uintptr_t;
#define _PDCLIB_INTPTR_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_INTPTR ), _MIN )
typedef _PDCLIB_time _PDCLIB_time_t;
typedef _PDCLIB_clock _PDCLIB_clock_t;
-#if !defined(_PDCLIB_DEFINE_STRUCT_TIMESPEC)
-#define _PDCLIB_DEFINE_STRUCT_TIMESPEC() \
- struct timespec { \
- time_t tv_sec; \
- long tv_nsec; \
- };
-#endif
-
-#if !defined(_PDCLIB_DEFINE_STRUCT_TM)
-#define _PDCLIB_DEFINE_STRUCT_TM() \
- struct tm { \
- int tm_sec; \
- int tm_min; \
- int tm_hour; \
- int tm_mday; \
- int tm_mon; \
- int tm_year; \
- int tm_wday; \
- int tm_yday; \
- int tm_isdst; \
- };
-#endif
-
/* -------------------------------------------------------------------------- */
/* Internal data types */
/* -------------------------------------------------------------------------- */
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 <errno.h>.
-*/
-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;
*/
_PDCLIB_uint16_t _Surrogate;
- /* In cases where the underlying codec is capable of regurgitating a
+ /* 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
+ * 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
+ * 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 */
/* -------------------------------------------------------------------------- */
/* 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 */
};