]> pd.if.org Git - pdclib/blob - internals/_PDCLIB_int.h
Started implementation of <time.h>
[pdclib] / internals / _PDCLIB_int.h
1 /* PDCLib internal integer logic <_PDCLIB_int.h>
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #ifndef _PDCLIB_INT_H
8 #define _PDCLIB_INT_H _PDCLIB_INT_H
9
10 /* -------------------------------------------------------------------------- */
11 /* You should not have to edit anything in this file; if you DO have to, it   */
12 /* would be considered a bug / missing feature: notify the author(s).         */
13 /* -------------------------------------------------------------------------- */
14
15 #include "_PDCLIB_config.h"
16 #include "_PDCLIB_aux.h"
17
18 /* null pointer constant */
19 #define _PDCLIB_NULL 0
20
21 /* -------------------------------------------------------------------------- */
22 /* Limits of native datatypes                                                 */
23 /* -------------------------------------------------------------------------- */
24 /* The definition of minimum limits for unsigned datatypes is done because    */
25 /* later on we will "construct" limits for other abstract types:              */
26 /* USHRT -> _PDCLIB_ + USHRT + _MIN -> _PDCLIB_USHRT_MIN -> 0                 */
27 /* INT -> _PDCLIB_ + INT + _MIN -> _PDCLIB_INT_MIN -> ... you get the idea.   */
28 /* -------------------------------------------------------------------------- */
29
30 /* Setting 'char' limits                                                      */
31 #define _PDCLIB_CHAR_BIT    8
32 #define _PDCLIB_UCHAR_MIN   0
33 #define _PDCLIB_UCHAR_MAX   0xff
34 #define _PDCLIB_SCHAR_MIN   (-0x7f - 1)
35 #define _PDCLIB_SCHAR_MAX   0x7f
36 #ifdef  _PDCLIB_CHAR_SIGNED
37 #define _PDCLIB_CHAR_MIN    _PDCLIB_SCHAR_MIN
38 #define _PDCLIB_CHAR_MAX    _PDCLIB_SCHAR_MAX
39 #else
40 #define _PDCLIB_CHAR_MIN    0
41 #define _PDCLIB_CHAR_MAX    _PDCLIB_UCHAR_MAX
42 #endif
43
44 /* Setting 'short' limits                                                     */
45 #if     _PDCLIB_SHRT_BYTES == 2
46 #define _PDCLIB_SHRT_MAX      0x7fff
47 #define _PDCLIB_SHRT_MIN      (-0x7fff - 1)
48 #define _PDCLIB_USHRT_MAX     0xffff
49 #else
50 #error Unsupported width of 'short' (not 16 bit).
51 #endif
52 #define _PDCLIB_USHRT_MIN 0
53
54 #if _PDCLIB_INT_BYTES < _PDCLIB_SHRT_BYTES
55 #error Bogus setting: short > int? Check _PDCLIB_config.h.
56 #endif
57
58 /* Setting 'int' limits                                                       */
59 #if     _PDCLIB_INT_BYTES == 2
60 #define _PDCLIB_INT_MAX   0x7fff
61 #define _PDCLIB_INT_MIN   (-0x7fff - 1)
62 #define _PDCLIB_UINT_MAX  0xffffU
63 #elif   _PDCLIB_INT_BYTES == 4
64 #define _PDCLIB_INT_MAX   0x7fffffff
65 #define _PDCLIB_INT_MIN   (-0x7fffffff - 1)
66 #define _PDCLIB_UINT_MAX  0xffffffffU
67 #elif _PDCLIB_INT_BYTES   == 8
68 #define _PDCLIB_INT_MAX   0x7fffffffffffffff
69 #define _PDCLIB_INT_MIN   (-0x7fffffffffffffff - 1)
70 #define _PDCLIB_UINT_MAX  0xffffffffffffffff
71 #else
72 #error Unsupported width of 'int' (neither 16, 32, nor 64 bit).
73 #endif
74 #define _PDCLIB_UINT_MIN 0
75
76 /* Setting 'long' limits                                                      */
77 #if   _PDCLIB_LONG_BYTES   == 4
78 #define _PDCLIB_LONG_MAX   0x7fffffffL
79 #define _PDCLIB_LONG_MIN   (-0x7fffffffL - 1L)
80 #define _PDCLIB_ULONG_MAX  0xffffffffUL
81 #elif   _PDCLIB_LONG_BYTES == 8
82 #define _PDCLIB_LONG_MAX   0x7fffffffffffffffL
83 #define _PDCLIB_LONG_MIN   (-0x7fffffffffffffffL - 1L)
84 #define _PDCLIB_ULONG_MAX  0xffffffffffffffffUL
85 #else
86 #error Unsupported width of 'long' (neither 32 nor 64 bit).
87 #endif
88 #define _PDCLIB_ULONG_MIN 0
89
90 /* Setting 'long long' limits                                                 */
91 #if _PDCLIB_LLONG_BYTES    == 8
92 #define _PDCLIB_LLONG_MAX  0x7fffffffffffffffLL
93 #define _PDCLIB_LLONG_MIN  (-0x7fffffffffffffffLL - 1LL)
94 #define _PDCLIB_ULLONG_MAX 0xffffffffffffffffULL
95 #elif _PDCLIB_LLONG_BYTES  == 16
96 #define _PDCLIB_LLONG_MAX  0x7fffffffffffffffffffffffffffffffLL
97 #define _PDCLIB_LLONG_MIN  (-0x7fffffffffffffffffffffffffffffffLL - 1LL)
98 #define _PDCLIB_ULLONG_MAX 0xffffffffffffffffffffffffffffffffULL
99 #else
100 #error Unsupported width of 'long long' (neither 64 nor 128 bit).
101 #endif
102 #define _PDCLIB_ULLONG_MIN 0
103
104 /* -------------------------------------------------------------------------- */
105 /* <stdint.h> exact-width types and their limits                              */
106 /* -------------------------------------------------------------------------- */
107 /* Note that, for the "standard" widths of 8, 16, 32 and 64 bit, the "LEAST"  */
108 /* types are identical to the "exact-width" types, by definition.             */
109
110 /* Setting 'int8_t', its limits, its literal, and conversion macros.          */
111 #if     _PDCLIB_CHAR_BIT == 8
112 typedef signed char        _PDCLIB_int8_t;
113 typedef unsigned char      _PDCLIB_uint8_t;
114 #define _PDCLIB_INT8_MAX   _PDCLIB_CHAR_MAX
115 #define _PDCLIB_INT8_MIN   _PDCLIB_CHAR_MIN
116 #define _PDCLIB_UINT8_MAX  _PDCLIB_UCHAR_MAX
117 #define _PDCLIB_8_CONV     hh
118 #else
119 #error Unsupported width of char (not 8 bits).
120 #endif
121
122 /* Setting 'int16_t', its limits, its literal, and conversion macros.         */
123 #if     _PDCLIB_INT_BYTES  == 2
124 typedef signed int         _PDCLIB_int16_t;
125 typedef unsigned int       _PDCLIB_uint16_t;
126 #define _PDCLIB_INT16_MAX  _PDCLIB_INT_MAX
127 #define _PDCLIB_INT16_MIN  _PDCLIB_INT_MIN
128 #define _PDCLIB_UINT16_MAX _PDCLIB_UINT_MAX
129 #define _PDCLIB_16_CONV
130 #elif   _PDCLIB_SHRT_BYTES == 2
131 typedef signed short       _PDCLIB_int16_t;
132 typedef unsigned short     _PDCLIB_uint16_t;
133 #define _PDCLIB_INT16_MAX  _PDCLIB_SHRT_MAX
134 #define _PDCLIB_INT16_MIN  _PDCLIB_SHRT_MIN
135 #define _PDCLIB_UINT16_MAX _PDCLIB_USHRT_MAX
136 #define _PDCLIB_16_CONV    h
137 #else
138 #error Neither 'short' nor 'int' are 16-bit.
139 #endif
140
141 /* Setting 'int32_t', its limits, its literal, and conversion macros.         */
142 #if     _PDCLIB_INT_BYTES  == 4
143 typedef signed int         _PDCLIB_int32_t;
144 typedef unsigned int       _PDCLIB_uint32_t;
145 #define _PDCLIB_INT32_MAX  _PDCLIB_INT_MAX
146 #define _PDCLIB_INT32_MIN  _PDCLIB_INT_MIN
147 #define _PDCLIB_UINT32_MAX _PDCLIB_UINT_MAX
148 #define _PDCLIB_INT32_LITERAL
149 #define _PDCLIB_UINT32_LITERAL
150 #define _PDCLIB_32_CONV
151 #elif   _PDCLIB_LONG_BYTES == 4
152 typedef signed long        _PDCLIB_int32_t;
153 typedef unsigned long      _PDCLIB_uint32_t;
154 #define _PDCLIB_INT32_MAX  _PDCLIB_LONG_MAX
155 #define _PDCLIB_INT32_MIN  _PDCLIB_LONG_MIN
156 #define _PDCLIB_UINT32_MAX _PDCLIB_LONG_MAX
157 #define _PDCLIB_INT32_LITERAL  l
158 #define _PDCLIB_UINT32_LITERAL ul
159 #define _PDCLIB_32_CONV        l
160 #else
161 #error Neither 'int' nor 'long' are 32-bit.
162 #endif
163
164 /* Setting 'int64_t', its limits, its literal, and conversion macros.         */
165 #if     _PDCLIB_LONG_BYTES == 8
166 typedef signed long        _PDCLIB_int64_t;
167 typedef unsigned long      _PDCLIB_uint64_t;
168 #define _PDCLIB_INT64_MAX  _PDCLIB_LONG_MAX
169 #define _PDCLIB_INT64_MIN  _PDCLIB_LONG_MIN
170 #define _PDCLIB_UINT64_MAX  _PDCLIB_ULONG_MAX
171 #define _PDCLIB_INT64_LITERAL  l
172 #define _PDCLIB_UINT64_LITERAL ul
173 #define _PDCLIB_64_CONV        l
174 #elif _PDCLIB_LLONG_BYTES  == 8
175 typedef signed long long   _PDCLIB_int64_t;
176 typedef unsigned long long _PDCLIB_uint64_t;
177 #define _PDCLIB_INT64_MAX  _PDCLIB_LLONG_MAX
178 #define _PDCLIB_INT64_MIN  _PDCLIB_LLONG_MIN
179 #define _PDCLIB_UINT64_MAX  _PDCLIB_ULLONG_MAX
180 #define _PDCLIB_INT64_LITERAL  ll
181 #define _PDCLIB_UINT64_LITERAL ull
182 #define _PDCLIB_64_CONV        ll
183 #else
184 #error Neither 'long' nor 'long long' are 64-bit.
185 #endif
186
187 /* -------------------------------------------------------------------------- */
188 /* <stdint.h> "fastest" types and their limits                                */
189 /* -------------------------------------------------------------------------- */
190 /* This is, admittedly, butt-ugly. But at least it's ugly where the average   */
191 /* user of PDCLib will never see it, and makes <_PDCLIB_config.h> much        */
192 /* cleaner.                                                                   */
193 /* -------------------------------------------------------------------------- */
194
195 typedef _PDCLIB_fast8          _PDCLIB_int_fast8_t;
196 typedef unsigned _PDCLIB_fast8 _PDCLIB_uint_fast8_t;
197 #define _PDCLIB_INT_FAST8_MIN  _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_FAST8 ), _MIN )
198 #define _PDCLIB_INT_FAST8_MAX  _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_FAST8 ), _MAX )
199 #define _PDCLIB_UINT_FAST8_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_U, _PDCLIB_FAST8 ), _MAX )
200
201 typedef _PDCLIB_fast16          _PDCLIB_int_fast16_t;
202 typedef unsigned _PDCLIB_fast16 _PDCLIB_uint_fast16_t;
203 #define _PDCLIB_INT_FAST16_MIN  _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_FAST16 ), _MIN )
204 #define _PDCLIB_INT_FAST16_MAX  _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_FAST16 ), _MAX )
205 #define _PDCLIB_UINT_FAST16_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_U, _PDCLIB_FAST16 ), _MAX )
206
207 typedef _PDCLIB_fast32          _PDCLIB_int_fast32_t;
208 typedef unsigned _PDCLIB_fast32 _PDCLIB_uint_fast32_t;
209 #define _PDCLIB_INT_FAST32_MIN  _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_FAST32 ), _MIN )
210 #define _PDCLIB_INT_FAST32_MAX  _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_FAST32 ), _MAX )
211 #define _PDCLIB_UINT_FAST32_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_U, _PDCLIB_FAST32 ), _MAX )
212
213 typedef _PDCLIB_fast64          _PDCLIB_int_fast64_t;
214 typedef unsigned _PDCLIB_fast64 _PDCLIB_uint_fast64_t;
215 #define _PDCLIB_INT_FAST64_MIN  _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_FAST64 ), _MIN )
216 #define _PDCLIB_INT_FAST64_MAX  _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_FAST64 ), _MAX )
217 #define _PDCLIB_UINT_FAST64_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_U, _PDCLIB_FAST64 ), _MAX )
218
219 /* -------------------------------------------------------------------------- */
220 /* Various <stddef.h> typedefs and limits                                     */
221 /* -------------------------------------------------------------------------- */
222
223 typedef _PDCLIB_ptrdiff     _PDCLIB_ptrdiff_t;
224 #define _PDCLIB_PTRDIFF_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MIN )
225 #define _PDCLIB_PTRDIFF_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MAX )
226
227 #define _PDCLIB_SIG_ATOMIC_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MIN )
228 #define _PDCLIB_SIG_ATOMIC_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MAX )
229
230 typedef _PDCLIB_size     _PDCLIB_size_t;
231 #define _PDCLIB_SIZE_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_SIZE ), _MAX )
232
233 typedef _PDCLIB_wchar     _PDCLIB_wchar_t;
234 #define _PDCLIB_WCHAR_MIN _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_WCHAR ), _MIN )
235 #define _PDCLIB_WCHAR_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_WCHAR ), _MAX )
236
237 typedef _PDCLIB_intptr          _PDCLIB_intptr_t;
238 typedef unsigned _PDCLIB_intptr _PDCLIB_uintptr_t;
239 #define _PDCLIB_INTPTR_MIN  _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_INTPTR ), _MIN )
240 #define _PDCLIB_INTPTR_MAX  _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_INTPTR ), _MAX )
241 #define _PDCLIB_UINTPTR_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_U, _PDCLIB_INTPTR ), _MAX )
242
243 typedef _PDCLIB_intmax          _PDCLIB_intmax_t;
244 typedef unsigned _PDCLIB_intmax _PDCLIB_uintmax_t;
245 #define _PDCLIB_INTMAX_MIN  _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_INTMAX ), _MIN )
246 #define _PDCLIB_INTMAX_MAX  _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_, _PDCLIB_INTMAX ), _MAX )
247 #define _PDCLIB_UINTMAX_MAX _PDCLIB_concat( _PDCLIB_concat( _PDCLIB_U, _PDCLIB_INTMAX ), _MAX )
248 #define _PDCLIB_INTMAX_C( value )  _PDCLIB_concat( value, _PDCLIB_INTMAX_LITERAL )
249 #define _PDCLIB_UINTMAX_C( value ) _PDCLIB_concat( value, _PDCLIB_concat( u, _PDCLIB_INTMAX_LITERAL ) )
250
251 /* -------------------------------------------------------------------------- */
252 /* Various <stdio.h> internals                                                */
253 /* -------------------------------------------------------------------------- */
254
255 /* Flags for representing mode (see fopen()). Note these must fit the same
256    status field as the _IO?BF flags in <stdio.h> and the internal flags below.
257 */
258 #define _PDCLIB_FREAD     8u
259 #define _PDCLIB_FWRITE   16u
260 #define _PDCLIB_FAPPEND  32u
261 #define _PDCLIB_FRW      64u
262 #define _PDCLIB_FBIN    128u
263
264 /* Internal flags, made to fit the same status field as the flags above. */
265 /* -------------------------------------------------------------------------- */
266 /* free() the buffer memory on closing (false for user-supplied buffer) */
267 #define _PDCLIB_FREEBUFFER   512u
268 /* stream has encountered error / EOF */
269 #define _PDCLIB_ERRORFLAG   1024u
270 #define _PDCLIB_EOFFLAG     2048u
271 /* stream is wide-oriented */
272 #define _PDCLIB_WIDESTREAM  4096u
273 /* stream is byte-oriented */
274 #define _PDCLIB_BYTESTREAM  8192u
275 /* file associated with stream should be remove()d on closing (tmpfile()) */
276 #define _PDCLIB_DELONCLOSE 16384u
277 /* stream handle should not be free()d on close (stdin, stdout, stderr) */
278 #define _PDCLIB_STATIC     32768u
279
280 /* Position / status structure for getpos() / fsetpos(). */
281 struct _PDCLIB_fpos_t
282 {
283     _PDCLIB_uint64_t offset; /* File position offset */
284     int              status; /* Multibyte parsing state (unused, reserved) */
285 };
286
287 /* FILE structure */
288 struct _PDCLIB_file_t
289 {
290     _PDCLIB_fd_t            handle;   /* OS file handle */
291     char *                  buffer;   /* Pointer to buffer memory */
292     _PDCLIB_size_t          bufsize;  /* Size of buffer */
293     _PDCLIB_size_t          bufidx;   /* Index of current position in buffer */
294     _PDCLIB_size_t          bufend;   /* Index of last pre-read character in buffer */
295     struct _PDCLIB_fpos_t   pos;      /* Offset and multibyte parsing state */
296     _PDCLIB_size_t          ungetidx; /* Number of ungetc()'ed characters */
297     unsigned char *         ungetbuf; /* ungetc() buffer */
298     unsigned int            status;   /* Status flags; see above */
299     /* multibyte parsing status to be added later */
300     char *                  filename; /* Name the current stream has been opened with */
301     struct _PDCLIB_file_t * next;     /* Pointer to next struct (internal) */
302 };
303
304 /* -------------------------------------------------------------------------- */
305 /* Various <time.h> internals                                                 */
306 /* -------------------------------------------------------------------------- */
307
308 typedef _PDCLIB_time            _PDCLIB_time_t;
309 typedef _PDCLIB_clock           _PDCLIB_clock_t;
310
311 /* -------------------------------------------------------------------------- */
312 /* Internal data types                                                        */
313 /* -------------------------------------------------------------------------- */
314
315 /* Structure required by both atexit() and exit() for handling atexit functions */
316 struct _PDCLIB_exitfunc_t
317 {
318     struct _PDCLIB_exitfunc_t * next;
319     void (*func)( void );
320 };
321
322 /* Structures required by malloc(), realloc(), and free(). */
323 struct _PDCLIB_headnode_t
324 {
325     struct _PDCLIB_memnode_t * first;
326     struct _PDCLIB_memnode_t * last;
327 };
328
329 struct _PDCLIB_memnode_t
330 {
331     _PDCLIB_size_t size;
332     struct _PDCLIB_memnode_t * next;
333 };
334
335 /* Status structure required by _PDCLIB_print(). */
336 struct _PDCLIB_status_t
337 {
338     int              base;   /* base to which the value shall be converted   */
339     _PDCLIB_int_fast32_t flags; /* flags and length modifiers                */
340     _PDCLIB_size_t   n;      /* print: maximum characters to be written      */
341                              /* scan:  number matched conversion specifiers  */
342     _PDCLIB_size_t   i;      /* number of characters read/written            */
343     _PDCLIB_size_t   current;/* chars read/written in the CURRENT conversion */
344     char *           s;      /* *sprintf(): target buffer                    */
345                              /* *sscanf():  source string                    */
346     _PDCLIB_size_t   width;  /* specified field width                        */
347     _PDCLIB_size_t   prec;   /* specified field precision                    */
348     struct _PDCLIB_file_t * stream; /* *fprintf() / *fscanf() stream         */
349     _PDCLIB_va_list  arg;    /* argument stack                               */
350 };
351
352 /* -------------------------------------------------------------------------- */
353 /* Declaration of helper functions (implemented in functions/_PDCLIB).        */
354 /* -------------------------------------------------------------------------- */
355
356 /* This is the main function called by atoi(), atol() and atoll().            */
357 _PDCLIB_intmax_t _PDCLIB_atomax( const char * s );
358
359 /* Two helper functions used by strtol(), strtoul() and long long variants.   */
360 const char * _PDCLIB_strtox_prelim( const char * p, char * sign, int * base );
361 _PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, _PDCLIB_uintmax_t error, _PDCLIB_uintmax_t limval, int limdigit, char * sign );
362
363 /* Digits arrays used by various integer conversion functions */
364 extern const char _PDCLIB_digits[];
365 extern const char _PDCLIB_Xdigits[];
366
367 /* The worker for all printf() type of functions. The pointer spec should point
368    to the introducing '%' of a conversion specifier. The status structure is to
369    be that of the current printf() function, of which the members n, s, stream
370    and arg will be preserved; i will be updated; and all others will be trashed
371    by the function.
372    Returns a pointer to the first character not parsed as conversion specifier.
373 */
374 const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status );
375
376 /* The worker for all scanf() type of functions. The pointer spec should point
377    to the introducing '%' of a conversion specifier. The status structure is to
378    be that of the current scanf() function, of which the member stream will be
379    preserved; n, i, and s will be updated; and all others will be trashed by
380    the function.
381    Returns a pointer to the first character not parsed as conversion specifier,
382    or NULL in case of error.
383    FIXME: Should distinguish between matching and input error
384 */
385 const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status );
386
387 /* Parsing any fopen() style filemode string into a number of flags. */
388 unsigned int _PDCLIB_filemode( const char * mode );
389
390 /* Sanity checking and preparing of read buffer, should be called first thing
391    by any stdio read-data function.
392    Returns 0 on success, EOF on error.
393    On error, EOF / error flags and errno are set appropriately.
394 */
395 int _PDCLIB_prepread( struct _PDCLIB_file_t * stream );
396
397 /* Sanity checking, should be called first thing by any stdio write-data
398    function.
399    Returns 0 on success, EOF on error.
400    On error, error flags and errno are set appropriately.
401 */
402 int _PDCLIB_prepwrite( struct _PDCLIB_file_t * stream );
403
404 /* Closing all streams on program exit */
405 void _PDCLIB_closeall( void );
406
407 /* -------------------------------------------------------------------------- */
408 /* errno                                                                      */
409 /* -------------------------------------------------------------------------- */
410
411 /* If PDCLib would call its error number "errno" directly, there would be no way
412    to catch its value from underlying system calls that also use it (i.e., POSIX
413    operating systems). That is why we use an internal name, providing a means to
414    access it through <errno.h>.
415 */
416 extern int _PDCLIB_errno;
417
418 /* A mechanism for delayed evaluation. (Not sure if this is really necessary, so
419    no detailed documentation on the "why".)
420 */
421 int * _PDCLIB_errno_func( void );
422
423 /* -------------------------------------------------------------------------- */
424 /* <ctype.h> lookup tables                                                    */
425 /* -------------------------------------------------------------------------- */
426
427 #define _PDCLIB_CTYPE_ALPHA   1
428 #define _PDCLIB_CTYPE_BLANK   2
429 #define _PDCLIB_CTYPE_CNTRL   4
430 #define _PDCLIB_CTYPE_GRAPH   8
431 #define _PDCLIB_CTYPE_PUNCT  16
432 #define _PDCLIB_CTYPE_SPACE  32
433 #define _PDCLIB_CTYPE_LOWER  64
434 #define _PDCLIB_CTYPE_UPPER 128
435 #define _PDCLIB_CTYPE_DIGIT 256
436 #define _PDCLIB_CTYPE_XDIGT 512
437
438 struct _PDCLIB_ctype_t
439 {
440     _PDCLIB_uint16_t flags;
441     unsigned char upper;
442     unsigned char lower;
443     unsigned char collation;
444 };
445
446 /* -------------------------------------------------------------------------- */
447 /* Sanity checks                                                              */
448 /* -------------------------------------------------------------------------- */
449
450 _PDCLIB_static_assert( sizeof( short ) == _PDCLIB_SHRT_BYTES, "Compiler disagrees on _PDCLIB_SHRT_BYTES." );
451 _PDCLIB_static_assert( sizeof( int ) == _PDCLIB_INT_BYTES, "Compiler disagrees on _PDCLIB_INT_BYTES." );
452 _PDCLIB_static_assert( sizeof( long ) == _PDCLIB_LONG_BYTES, "Compiler disagrees on _PDCLIB_LONG_BYTES." );
453 _PDCLIB_static_assert( sizeof( long long ) == _PDCLIB_LLONG_BYTES, "Compiler disagrees on _PDCLIB_LLONG_BYTES." );
454
455 _PDCLIB_static_assert( ( (char)-1 < 0 ) == _PDCLIB_CHAR_SIGNED, "Compiler disagrees on _PDCLIB_CHAR_SIGNED." );
456 _PDCLIB_static_assert( sizeof( sizeof( int ) ) == sizeof( _PDCLIB_size ), "Compiler disagrees on _PDCLIB_size." );
457
458 _PDCLIB_static_assert( sizeof( _PDCLIB_wchar ) == sizeof( L'x' ), "Compiler disagrees on _PDCLIB_wchar." );
459
460 _PDCLIB_static_assert( sizeof( void * ) == sizeof( _PDCLIB_intptr ), "Compiler disagrees on _PDCLIB_intptr." );
461
462 _PDCLIB_static_assert( sizeof( &_PDCLIB_digits[1] - &_PDCLIB_digits[0] ) == sizeof( _PDCLIB_ptrdiff ), "Compiler disagrees on _PDCLIB_ptrdiff." );
463
464 #endif