libkombilo  0.8
/home/ug/devel/kombilo-py-dev/kombilo/libkombilo/pstdint.h
1 /* A portable stdint.h
2  ****************************************************************************
3  * BSD License:
4  ****************************************************************************
5  *
6  * Copyright (c) 2005-2016 Paul Hsieh
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************
33  *
34  * Version 0.1.15.4
35  *
36  * The ANSI C standard committee, for the C99 standard, specified the
37  * inclusion of a new standard include file called stdint.h. This is
38  * a very useful and long desired include file which contains several
39  * very precise definitions for integer scalar types that is
40  * critically important for making portable several classes of
41  * applications including cryptography, hashing, variable length
42  * integer libraries and so on. But for most developers its likely
43  * useful just for programming sanity.
44  *
45  * The problem is that some compiler vendors chose to ignore the C99
46  * standard and some older compilers have no opportunity to be updated.
47  * Because of this situation, simply including stdint.h in your code
48  * makes it unportable.
49  *
50  * So that's what this file is all about. Its an attempt to build a
51  * single universal include file that works on as many platforms as
52  * possible to deliver what stdint.h is supposed to. Even compilers
53  * that already come with stdint.h can use this file instead without
54  * any loss of functionality. A few things that should be noted about
55  * this file:
56  *
57  * 1) It is not guaranteed to be portable and/or present an identical
58  * interface on all platforms. The extreme variability of the
59  * ANSI C standard makes this an impossibility right from the
60  * very get go. Its really only meant to be useful for the vast
61  * majority of platforms that possess the capability of
62  * implementing usefully and precisely defined, standard sized
63  * integer scalars. Systems which are not intrinsically 2s
64  * complement may produce invalid constants.
65  *
66  * 2) There is an unavoidable use of non-reserved symbols.
67  *
68  * 3) Other standard include files are invoked.
69  *
70  * 4) This file may come in conflict with future platforms that do
71  * include stdint.h. The hope is that one or the other can be
72  * used with no real difference.
73  *
74  * 5) In the current version, if your platform can't represent
75  * int32_t, int16_t and int8_t, it just dumps out with a compiler
76  * error.
77  *
78  * 6) 64 bit integers may or may not be defined. Test for their
79  * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
80  * Note that this is different from the C99 specification which
81  * requires the existence of 64 bit support in the compiler. If
82  * this is not defined for your platform, yet it is capable of
83  * dealing with 64 bits then it is because this file has not yet
84  * been extended to cover all of your system's capabilities.
85  *
86  * 7) (u)intptr_t may or may not be defined. Test for its presence
87  * with the test: #ifdef PTRDIFF_MAX. If this is not defined
88  * for your platform, then it is because this file has not yet
89  * been extended to cover all of your system's capabilities, not
90  * because its optional.
91  *
92  * 8) The following might not been defined even if your platform is
93  * capable of defining it:
94  *
95  * WCHAR_MIN
96  * WCHAR_MAX
97  * (u)int64_t
98  * PTRDIFF_MIN
99  * PTRDIFF_MAX
100  * (u)intptr_t
101  *
102  * 9) The following have not been defined:
103  *
104  * WINT_MIN
105  * WINT_MAX
106  *
107  * 10) The criteria for defining (u)int_least(*)_t isn't clear,
108  * except for systems which don't have a type that precisely
109  * defined 8, 16, or 32 bit types (which this include file does
110  * not support anyways). Default definitions have been given.
111  *
112  * 11) The criteria for defining (u)int_fast(*)_t isn't something I
113  * would trust to any particular compiler vendor or the ANSI C
114  * committee. It is well known that "compatible systems" are
115  * commonly created that have very different performance
116  * characteristics from the systems they are compatible with,
117  * especially those whose vendors make both the compiler and the
118  * system. Default definitions have been given, but its strongly
119  * recommended that users never use these definitions for any
120  * reason (they do *NOT* deliver any serious guarantee of
121  * improved performance -- not in this file, nor any vendor's
122  * stdint.h).
123  *
124  * 12) The following macros:
125  *
126  * PRINTF_INTMAX_MODIFIER
127  * PRINTF_INT64_MODIFIER
128  * PRINTF_INT32_MODIFIER
129  * PRINTF_INT16_MODIFIER
130  * PRINTF_LEAST64_MODIFIER
131  * PRINTF_LEAST32_MODIFIER
132  * PRINTF_LEAST16_MODIFIER
133  * PRINTF_INTPTR_MODIFIER
134  *
135  * are strings which have been defined as the modifiers required
136  * for the "d", "u" and "x" printf formats to correctly output
137  * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
138  * (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
139  * PRINTF_INTPTR_MODIFIER is not defined for some systems which
140  * provide their own stdint.h. PRINTF_INT64_MODIFIER is not
141  * defined if INT64_MAX is not defined. These are an extension
142  * beyond what C99 specifies must be in stdint.h.
143  *
144  * In addition, the following macros are defined:
145  *
146  * PRINTF_INTMAX_HEX_WIDTH
147  * PRINTF_INT64_HEX_WIDTH
148  * PRINTF_INT32_HEX_WIDTH
149  * PRINTF_INT16_HEX_WIDTH
150  * PRINTF_INT8_HEX_WIDTH
151  * PRINTF_INTMAX_DEC_WIDTH
152  * PRINTF_INT64_DEC_WIDTH
153  * PRINTF_INT32_DEC_WIDTH
154  * PRINTF_INT16_DEC_WIDTH
155  * PRINTF_UINT8_DEC_WIDTH
156  * PRINTF_UINTMAX_DEC_WIDTH
157  * PRINTF_UINT64_DEC_WIDTH
158  * PRINTF_UINT32_DEC_WIDTH
159  * PRINTF_UINT16_DEC_WIDTH
160  * PRINTF_UINT8_DEC_WIDTH
161  *
162  * Which specifies the maximum number of characters required to
163  * print the number of that type in either hexadecimal or decimal.
164  * These are an extension beyond what C99 specifies must be in
165  * stdint.h.
166  *
167  * Compilers tested (all with 0 warnings at their highest respective
168  * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
169  * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
170  * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
171  *
172  * This file should be considered a work in progress. Suggestions for
173  * improvements, especially those which increase coverage are strongly
174  * encouraged.
175  *
176  * Acknowledgements
177  *
178  * The following people have made significant contributions to the
179  * development and testing of this file:
180  *
181  * Chris Howie
182  * John Steele Scott
183  * Dave Thorup
184  * John Dill
185  * Florian Wobbe
186  * Christopher Sean Morrison
187  * Mikkel Fahnoe Jorgensen
188  *
189  */
190 
191 #include <stddef.h>
192 #include <limits.h>
193 #include <signal.h>
194 
195 /*
196  * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
197  * do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
198  */
199 
200 #if ((defined(__SUNPRO_C) && __SUNPRO_C >= 0x570) || (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (__GNUC__ > 3 || defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)) )) && !defined (_PSTDINT_H_INCLUDED)
201 #include <stdint.h>
202 #define _PSTDINT_H_INCLUDED
203 # if defined(__GNUC__) && (defined(__x86_64__) || defined(__ppc64__)) && !(defined(__APPLE__) && defined(__MACH__))
204 # ifndef PRINTF_INT64_MODIFIER
205 # define PRINTF_INT64_MODIFIER "l"
206 # endif
207 # ifndef PRINTF_INT32_MODIFIER
208 # define PRINTF_INT32_MODIFIER ""
209 # endif
210 # else
211 # ifndef PRINTF_INT64_MODIFIER
212 # define PRINTF_INT64_MODIFIER "ll"
213 # endif
214 # ifndef PRINTF_INT32_MODIFIER
215 # if (UINT_MAX == UINT32_MAX)
216 # define PRINTF_INT32_MODIFIER ""
217 # else
218 # define PRINTF_INT32_MODIFIER "l"
219 # endif
220 # endif
221 # endif
222 # ifndef PRINTF_INT16_MODIFIER
223 # define PRINTF_INT16_MODIFIER "h"
224 # endif
225 # ifndef PRINTF_INTMAX_MODIFIER
226 # define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
227 # endif
228 # ifndef PRINTF_INT64_HEX_WIDTH
229 # define PRINTF_INT64_HEX_WIDTH "16"
230 # endif
231 # ifndef PRINTF_UINT64_HEX_WIDTH
232 # define PRINTF_UINT64_HEX_WIDTH "16"
233 # endif
234 # ifndef PRINTF_INT32_HEX_WIDTH
235 # define PRINTF_INT32_HEX_WIDTH "8"
236 # endif
237 # ifndef PRINTF_UINT32_HEX_WIDTH
238 # define PRINTF_UINT32_HEX_WIDTH "8"
239 # endif
240 # ifndef PRINTF_INT16_HEX_WIDTH
241 # define PRINTF_INT16_HEX_WIDTH "4"
242 # endif
243 # ifndef PRINTF_UINT16_HEX_WIDTH
244 # define PRINTF_UINT16_HEX_WIDTH "4"
245 # endif
246 # ifndef PRINTF_INT8_HEX_WIDTH
247 # define PRINTF_INT8_HEX_WIDTH "2"
248 # endif
249 # ifndef PRINTF_UINT8_HEX_WIDTH
250 # define PRINTF_UINT8_HEX_WIDTH "2"
251 # endif
252 # ifndef PRINTF_INT64_DEC_WIDTH
253 # define PRINTF_INT64_DEC_WIDTH "19"
254 # endif
255 # ifndef PRINTF_UINT64_DEC_WIDTH
256 # define PRINTF_UINT64_DEC_WIDTH "20"
257 # endif
258 # ifndef PRINTF_INT32_DEC_WIDTH
259 # define PRINTF_INT32_DEC_WIDTH "10"
260 # endif
261 # ifndef PRINTF_UINT32_DEC_WIDTH
262 # define PRINTF_UINT32_DEC_WIDTH "10"
263 # endif
264 # ifndef PRINTF_INT16_DEC_WIDTH
265 # define PRINTF_INT16_DEC_WIDTH "5"
266 # endif
267 # ifndef PRINTF_UINT16_DEC_WIDTH
268 # define PRINTF_UINT16_DEC_WIDTH "5"
269 # endif
270 # ifndef PRINTF_INT8_DEC_WIDTH
271 # define PRINTF_INT8_DEC_WIDTH "3"
272 # endif
273 # ifndef PRINTF_UINT8_DEC_WIDTH
274 # define PRINTF_UINT8_DEC_WIDTH "3"
275 # endif
276 # ifndef PRINTF_INTMAX_HEX_WIDTH
277 # define PRINTF_INTMAX_HEX_WIDTH PRINTF_UINT64_HEX_WIDTH
278 # endif
279 # ifndef PRINTF_UINTMAX_HEX_WIDTH
280 # define PRINTF_UINTMAX_HEX_WIDTH PRINTF_UINT64_HEX_WIDTH
281 # endif
282 # ifndef PRINTF_INTMAX_DEC_WIDTH
283 # define PRINTF_INTMAX_DEC_WIDTH PRINTF_UINT64_DEC_WIDTH
284 # endif
285 # ifndef PRINTF_UINTMAX_DEC_WIDTH
286 # define PRINTF_UINTMAX_DEC_WIDTH PRINTF_UINT64_DEC_WIDTH
287 # endif
288 
289 /*
290  * Something really weird is going on with Open Watcom. Just pull some of
291  * these duplicated definitions from Open Watcom's stdint.h file for now.
292  */
293 
294 # if defined (__WATCOMC__) && __WATCOMC__ >= 1250
295 # if !defined (INT64_C)
296 # define INT64_C(x) (x + (INT64_MAX - INT64_MAX))
297 # endif
298 # if !defined (UINT64_C)
299 # define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
300 # endif
301 # if !defined (INT32_C)
302 # define INT32_C(x) (x + (INT32_MAX - INT32_MAX))
303 # endif
304 # if !defined (UINT32_C)
305 # define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))
306 # endif
307 # if !defined (INT16_C)
308 # define INT16_C(x) (x)
309 # endif
310 # if !defined (UINT16_C)
311 # define UINT16_C(x) (x)
312 # endif
313 # if !defined (INT8_C)
314 # define INT8_C(x) (x)
315 # endif
316 # if !defined (UINT8_C)
317 # define UINT8_C(x) (x)
318 # endif
319 # if !defined (UINT64_MAX)
320 # define UINT64_MAX 18446744073709551615ULL
321 # endif
322 # if !defined (INT64_MAX)
323 # define INT64_MAX 9223372036854775807LL
324 # endif
325 # if !defined (UINT32_MAX)
326 # define UINT32_MAX 4294967295UL
327 # endif
328 # if !defined (INT32_MAX)
329 # define INT32_MAX 2147483647L
330 # endif
331 # if !defined (INTMAX_MAX)
332 # define INTMAX_MAX INT64_MAX
333 # endif
334 # if !defined (INTMAX_MIN)
335 # define INTMAX_MIN INT64_MIN
336 # endif
337 # endif
338 #endif
339 
340 /*
341  * I have no idea what is the truly correct thing to do on older Solaris.
342  * From some online discussions, this seems to be what is being
343  * recommended. For people who actually are developing on older Solaris,
344  * what I would like to know is, does this define all of the relevant
345  * macros of a complete stdint.h? Remember, in pstdint.h 64 bit is
346  * considered optional.
347  */
348 
349 #if (defined(__SUNPRO_C) && __SUNPRO_C >= 0x420) && !defined(_PSTDINT_H_INCLUDED)
350 #include <sys/inttypes.h>
351 #define _PSTDINT_H_INCLUDED
352 #endif
353 
354 #ifndef _PSTDINT_H_INCLUDED
355 #define _PSTDINT_H_INCLUDED
356 
357 #ifndef SIZE_MAX
358 # define SIZE_MAX (~(size_t)0)
359 #endif
360 
361 /*
362  * Deduce the type assignments from limits.h under the assumption that
363  * integer sizes in bits are powers of 2, and follow the ANSI
364  * definitions.
365  */
366 
367 #ifndef UINT8_MAX
368 # define UINT8_MAX 0xff
369 #endif
370 #if !defined(uint8_t) && !defined(_UINT8_T) && !defined(vxWorks)
371 # if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
372  typedef unsigned char uint8_t;
373 # define UINT8_C(v) ((uint8_t) v)
374 # else
375 # error "Platform not supported"
376 # endif
377 #endif
378 
379 #ifndef INT8_MAX
380 # define INT8_MAX 0x7f
381 #endif
382 #ifndef INT8_MIN
383 # define INT8_MIN INT8_C(0x80)
384 #endif
385 #if !defined(int8_t) && !defined(_INT8_T) && !defined(vxWorks)
386 # if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
387  typedef signed char int8_t;
388 # define INT8_C(v) ((int8_t) v)
389 # else
390 # error "Platform not supported"
391 # endif
392 #endif
393 
394 #ifndef UINT16_MAX
395 # define UINT16_MAX 0xffff
396 #endif
397 #if !defined(uint16_t) && !defined(_UINT16_T) && !defined(vxWorks)
398 #if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
399  typedef unsigned int uint16_t;
400 # ifndef PRINTF_INT16_MODIFIER
401 # define PRINTF_INT16_MODIFIER ""
402 # endif
403 # define UINT16_C(v) ((uint16_t) (v))
404 #elif (USHRT_MAX == UINT16_MAX)
405  typedef unsigned short uint16_t;
406 # define UINT16_C(v) ((uint16_t) (v))
407 # ifndef PRINTF_INT16_MODIFIER
408 # define PRINTF_INT16_MODIFIER "h"
409 # endif
410 #else
411 #error "Platform not supported"
412 #endif
413 #endif
414 
415 #ifndef INT16_MAX
416 # define INT16_MAX 0x7fff
417 #endif
418 #ifndef INT16_MIN
419 # define INT16_MIN INT16_C(0x8000)
420 #endif
421 #if !defined(int16_t) && !defined(_INT16_T) && !defined(vxWorks)
422 #if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
423  typedef signed int int16_t;
424 # define INT16_C(v) ((int16_t) (v))
425 # ifndef PRINTF_INT16_MODIFIER
426 # define PRINTF_INT16_MODIFIER ""
427 # endif
428 #elif (SHRT_MAX == INT16_MAX)
429  typedef signed short int16_t;
430 # define INT16_C(v) ((int16_t) (v))
431 # ifndef PRINTF_INT16_MODIFIER
432 # define PRINTF_INT16_MODIFIER "h"
433 # endif
434 #else
435 #error "Platform not supported"
436 #endif
437 #endif
438 
439 #ifndef UINT32_MAX
440 # define UINT32_MAX (0xffffffffUL)
441 #endif
442 #if !defined(uint32_t) && !defined(_UINT32_T) && !defined(vxWorks)
443 #if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
444  typedef unsigned long uint32_t;
445 # define UINT32_C(v) v ## UL
446 # ifndef PRINTF_INT32_MODIFIER
447 # define PRINTF_INT32_MODIFIER "l"
448 # endif
449 #elif (UINT_MAX == UINT32_MAX)
450  typedef unsigned int uint32_t;
451 # ifndef PRINTF_INT32_MODIFIER
452 # define PRINTF_INT32_MODIFIER ""
453 # endif
454 # define UINT32_C(v) v ## U
455 #elif (USHRT_MAX == UINT32_MAX)
456  typedef unsigned short uint32_t;
457 # define UINT32_C(v) ((unsigned short) (v))
458 # ifndef PRINTF_INT32_MODIFIER
459 # define PRINTF_INT32_MODIFIER ""
460 # endif
461 #else
462 #error "Platform not supported"
463 #endif
464 #endif
465 
466 #ifndef INT32_MAX
467 # define INT32_MAX (0x7fffffffL)
468 #endif
469 #ifndef INT32_MIN
470 # define INT32_MIN INT32_C(0x80000000)
471 #endif
472 #if !defined(int32_t) && !defined(_INT32_T) && !defined(vxWorks)
473 #if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
474  typedef signed long int32_t;
475 # define INT32_C(v) v ## L
476 # ifndef PRINTF_INT32_MODIFIER
477 # define PRINTF_INT32_MODIFIER "l"
478 # endif
479 #elif (INT_MAX == INT32_MAX)
480  typedef signed int int32_t;
481 # define INT32_C(v) v
482 # ifndef PRINTF_INT32_MODIFIER
483 # define PRINTF_INT32_MODIFIER ""
484 # endif
485 #elif (SHRT_MAX == INT32_MAX)
486  typedef signed short int32_t;
487 # define INT32_C(v) ((short) (v))
488 # ifndef PRINTF_INT32_MODIFIER
489 # define PRINTF_INT32_MODIFIER ""
490 # endif
491 #else
492 #error "Platform not supported"
493 #endif
494 #endif
495 
496 /*
497  * The macro stdint_int64_defined is temporarily used to record
498  * whether or not 64 integer support is available. It must be
499  * defined for any 64 integer extensions for new platforms that are
500  * added.
501  */
502 
503 #undef stdint_int64_defined
504 #if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
505 # if (__STDC__ && __STDC_VERSION__ >= 199901L) || defined (S_SPLINT_S)
506 # define stdint_int64_defined
507  typedef long long int64_t;
508  typedef unsigned long long uint64_t;
509 # define UINT64_C(v) v ## ULL
510 # define INT64_C(v) v ## LL
511 # ifndef PRINTF_INT64_MODIFIER
512 # define PRINTF_INT64_MODIFIER "ll"
513 # endif
514 # endif
515 #endif
516 
517 #if !defined (stdint_int64_defined)
518 # if defined(__GNUC__) && !defined(vxWorks)
519 # define stdint_int64_defined
520  __extension__ typedef long long int64_t;
521  __extension__ typedef unsigned long long uint64_t;
522 # define UINT64_C(v) v ## ULL
523 # define INT64_C(v) v ## LL
524 # ifndef PRINTF_INT64_MODIFIER
525 # define PRINTF_INT64_MODIFIER "ll"
526 # endif
527 # elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
528 # define stdint_int64_defined
529  typedef long long int64_t;
530  typedef unsigned long long uint64_t;
531 # define UINT64_C(v) v ## ULL
532 # define INT64_C(v) v ## LL
533 # ifndef PRINTF_INT64_MODIFIER
534 # define PRINTF_INT64_MODIFIER "ll"
535 # endif
536 # elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
537 # define stdint_int64_defined
538  typedef __int64 int64_t;
539  typedef unsigned __int64 uint64_t;
540 # define UINT64_C(v) v ## UI64
541 # define INT64_C(v) v ## I64
542 # ifndef PRINTF_INT64_MODIFIER
543 # define PRINTF_INT64_MODIFIER "I64"
544 # endif
545 # endif
546 #endif
547 
548 #if !defined (LONG_LONG_MAX) && defined (INT64_C)
549 # define LONG_LONG_MAX INT64_C (9223372036854775807)
550 #endif
551 #ifndef ULONG_LONG_MAX
552 # define ULONG_LONG_MAX UINT64_C (18446744073709551615)
553 #endif
554 
555 #if !defined (INT64_MAX) && defined (INT64_C)
556 # define INT64_MAX INT64_C (9223372036854775807)
557 #endif
558 #if !defined (INT64_MIN) && defined (INT64_C)
559 # define INT64_MIN INT64_C (-9223372036854775808)
560 #endif
561 #if !defined (UINT64_MAX) && defined (INT64_C)
562 # define UINT64_MAX UINT64_C (18446744073709551615)
563 #endif
564 
565 /*
566  * Width of hexadecimal for number field.
567  */
568 
569 #ifndef PRINTF_INT64_HEX_WIDTH
570 # define PRINTF_INT64_HEX_WIDTH "16"
571 #endif
572 #ifndef PRINTF_INT32_HEX_WIDTH
573 # define PRINTF_INT32_HEX_WIDTH "8"
574 #endif
575 #ifndef PRINTF_INT16_HEX_WIDTH
576 # define PRINTF_INT16_HEX_WIDTH "4"
577 #endif
578 #ifndef PRINTF_INT8_HEX_WIDTH
579 # define PRINTF_INT8_HEX_WIDTH "2"
580 #endif
581 #ifndef PRINTF_INT64_DEC_WIDTH
582 # define PRINTF_INT64_DEC_WIDTH "19"
583 #endif
584 #ifndef PRINTF_INT32_DEC_WIDTH
585 # define PRINTF_INT32_DEC_WIDTH "10"
586 #endif
587 #ifndef PRINTF_INT16_DEC_WIDTH
588 # define PRINTF_INT16_DEC_WIDTH "5"
589 #endif
590 #ifndef PRINTF_INT8_DEC_WIDTH
591 # define PRINTF_INT8_DEC_WIDTH "3"
592 #endif
593 #ifndef PRINTF_UINT64_DEC_WIDTH
594 # define PRINTF_UINT64_DEC_WIDTH "20"
595 #endif
596 #ifndef PRINTF_UINT32_DEC_WIDTH
597 # define PRINTF_UINT32_DEC_WIDTH "10"
598 #endif
599 #ifndef PRINTF_UINT16_DEC_WIDTH
600 # define PRINTF_UINT16_DEC_WIDTH "5"
601 #endif
602 #ifndef PRINTF_UINT8_DEC_WIDTH
603 # define PRINTF_UINT8_DEC_WIDTH "3"
604 #endif
605 
606 /*
607  * Ok, lets not worry about 128 bit integers for now. Moore's law says
608  * we don't need to worry about that until about 2040 at which point
609  * we'll have bigger things to worry about.
610  */
611 
612 #ifdef stdint_int64_defined
613  typedef int64_t intmax_t;
614  typedef uint64_t uintmax_t;
615 # define INTMAX_MAX INT64_MAX
616 # define INTMAX_MIN INT64_MIN
617 # define UINTMAX_MAX UINT64_MAX
618 # define UINTMAX_C(v) UINT64_C(v)
619 # define INTMAX_C(v) INT64_C(v)
620 # ifndef PRINTF_INTMAX_MODIFIER
621 # define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
622 # endif
623 # ifndef PRINTF_INTMAX_HEX_WIDTH
624 # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
625 # endif
626 # ifndef PRINTF_INTMAX_DEC_WIDTH
627 # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
628 # endif
629 #else
630  typedef int32_t intmax_t;
631  typedef uint32_t uintmax_t;
632 # define INTMAX_MAX INT32_MAX
633 # define UINTMAX_MAX UINT32_MAX
634 # define UINTMAX_C(v) UINT32_C(v)
635 # define INTMAX_C(v) INT32_C(v)
636 # ifndef PRINTF_INTMAX_MODIFIER
637 # define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
638 # endif
639 # ifndef PRINTF_INTMAX_HEX_WIDTH
640 # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
641 # endif
642 # ifndef PRINTF_INTMAX_DEC_WIDTH
643 # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
644 # endif
645 #endif
646 
647 /*
648  * Because this file currently only supports platforms which have
649  * precise powers of 2 as bit sizes for the default integers, the
650  * least definitions are all trivial. Its possible that a future
651  * version of this file could have different definitions.
652  */
653 
654 #ifndef stdint_least_defined
655  typedef int8_t int_least8_t;
656  typedef uint8_t uint_least8_t;
657  typedef int16_t int_least16_t;
658  typedef uint16_t uint_least16_t;
659  typedef int32_t int_least32_t;
660  typedef uint32_t uint_least32_t;
661 # define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
662 # define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
663 # define UINT_LEAST8_MAX UINT8_MAX
664 # define INT_LEAST8_MAX INT8_MAX
665 # define UINT_LEAST16_MAX UINT16_MAX
666 # define INT_LEAST16_MAX INT16_MAX
667 # define UINT_LEAST32_MAX UINT32_MAX
668 # define INT_LEAST32_MAX INT32_MAX
669 # define INT_LEAST8_MIN INT8_MIN
670 # define INT_LEAST16_MIN INT16_MIN
671 # define INT_LEAST32_MIN INT32_MIN
672 # ifdef stdint_int64_defined
673  typedef int64_t int_least64_t;
674  typedef uint64_t uint_least64_t;
675 # define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
676 # define UINT_LEAST64_MAX UINT64_MAX
677 # define INT_LEAST64_MAX INT64_MAX
678 # define INT_LEAST64_MIN INT64_MIN
679 # endif
680 #endif
681 #undef stdint_least_defined
682 
683 /*
684  * The ANSI C committee pretending to know or specify anything about
685  * performance is the epitome of misguided arrogance. The mandate of
686  * this file is to *ONLY* ever support that absolute minimum
687  * definition of the fast integer types, for compatibility purposes.
688  * No extensions, and no attempt to suggest what may or may not be a
689  * faster integer type will ever be made in this file. Developers are
690  * warned to stay away from these types when using this or any other
691  * stdint.h.
692  */
693 
694 typedef int_least8_t int_fast8_t;
695 typedef uint_least8_t uint_fast8_t;
696 typedef int_least16_t int_fast16_t;
697 typedef uint_least16_t uint_fast16_t;
698 typedef int_least32_t int_fast32_t;
699 typedef uint_least32_t uint_fast32_t;
700 #define UINT_FAST8_MAX UINT_LEAST8_MAX
701 #define INT_FAST8_MAX INT_LEAST8_MAX
702 #define UINT_FAST16_MAX UINT_LEAST16_MAX
703 #define INT_FAST16_MAX INT_LEAST16_MAX
704 #define UINT_FAST32_MAX UINT_LEAST32_MAX
705 #define INT_FAST32_MAX INT_LEAST32_MAX
706 #define INT_FAST8_MIN INT_LEAST8_MIN
707 #define INT_FAST16_MIN INT_LEAST16_MIN
708 #define INT_FAST32_MIN INT_LEAST32_MIN
709 #ifdef stdint_int64_defined
710  typedef int_least64_t int_fast64_t;
711  typedef uint_least64_t uint_fast64_t;
712 # define UINT_FAST64_MAX UINT_LEAST64_MAX
713 # define INT_FAST64_MAX INT_LEAST64_MAX
714 # define INT_FAST64_MIN INT_LEAST64_MIN
715 #endif
716 
717 #undef stdint_int64_defined
718 
719 /*
720  * Whatever piecemeal, per compiler thing we can do about the wchar_t
721  * type limits.
722  */
723 
724 #if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__) && !defined(vxWorks)
725 # include <wchar.h>
726 # ifndef WCHAR_MIN
727 # define WCHAR_MIN 0
728 # endif
729 # ifndef WCHAR_MAX
730 # define WCHAR_MAX ((wchar_t)-1)
731 # endif
732 #endif
733 
734 /*
735  * Whatever piecemeal, per compiler/platform thing we can do about the
736  * (u)intptr_t types and limits.
737  */
738 
739 #if (defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)) || defined (_UINTPTR_T)
740 # define STDINT_H_UINTPTR_T_DEFINED
741 #endif
742 
743 #ifndef STDINT_H_UINTPTR_T_DEFINED
744 # if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64) || defined (__ppc64__)
745 # define stdint_intptr_bits 64
746 # elif defined (__WATCOMC__) || defined (__TURBOC__)
747 # if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
748 # define stdint_intptr_bits 16
749 # else
750 # define stdint_intptr_bits 32
751 # endif
752 # elif defined (__i386__) || defined (_WIN32) || defined (WIN32) || defined (__ppc64__)
753 # define stdint_intptr_bits 32
754 # elif defined (__INTEL_COMPILER)
755 /* TODO -- what did Intel do about x86-64? */
756 # else
757 /* #error "This platform might not be supported yet" */
758 # endif
759 
760 # ifdef stdint_intptr_bits
761 # define stdint_intptr_glue3_i(a,b,c) a##b##c
762 # define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
763 # ifndef PRINTF_INTPTR_MODIFIER
764 # define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
765 # endif
766 # ifndef PTRDIFF_MAX
767 # define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
768 # endif
769 # ifndef PTRDIFF_MIN
770 # define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
771 # endif
772 # ifndef UINTPTR_MAX
773 # define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
774 # endif
775 # ifndef INTPTR_MAX
776 # define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
777 # endif
778 # ifndef INTPTR_MIN
779 # define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
780 # endif
781 # ifndef INTPTR_C
782 # define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
783 # endif
784 # ifndef UINTPTR_C
785 # define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
786 # endif
787  typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
788  typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
789 # else
790 /* TODO -- This following is likely wrong for some platforms, and does
791  nothing for the definition of uintptr_t. */
792  typedef ptrdiff_t intptr_t;
793 # endif
794 # define STDINT_H_UINTPTR_T_DEFINED
795 #endif
796 
797 /*
798  * Assumes sig_atomic_t is signed and we have a 2s complement machine.
799  */
800 
801 #ifndef SIG_ATOMIC_MAX
802 # define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
803 #endif
804 
805 #endif
806 
807 #if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
808 
809 /*
810  * Please compile with the maximum warning settings to make sure macros are
811  * not defined more than once.
812  */
813 
814 #include <stdlib.h>
815 #include <stdio.h>
816 #include <string.h>
817 
818 #define glue3_aux(x,y,z) x ## y ## z
819 #define glue3(x,y,z) glue3_aux(x,y,z)
820 
821 #define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,) = glue3(UINT,bits,_C) (0);
822 #define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,) = glue3(INT,bits,_C) (0);
823 
824 #define DECL(us,bits) glue3(DECL,us,) (bits)
825 
826 #define TESTUMAX(bits) glue3(u,bits,) = ~glue3(u,bits,); if (glue3(UINT,bits,_MAX) != glue3(u,bits,)) printf ("Something wrong with UINT%d_MAX\n", bits)
827 
828 #define REPORTERROR(msg) { err_n++; if (err_first <= 0) err_first = __LINE__; printf msg; }
829 
830 int main () {
831  int err_n = 0;
832  int err_first = 0;
833  DECL(I,8)
834  DECL(U,8)
835  DECL(I,16)
836  DECL(U,16)
837  DECL(I,32)
838  DECL(U,32)
839 #ifdef INT64_MAX
840  DECL(I,64)
841  DECL(U,64)
842 #endif
843  intmax_t imax = INTMAX_C(0);
844  uintmax_t umax = UINTMAX_C(0);
845  char str0[256], str1[256];
846 
847  sprintf (str0, "%" PRINTF_INT32_MODIFIER "d", INT32_C(2147483647));
848  if (0 != strcmp (str0, "2147483647")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str0));
849  if (atoi(PRINTF_INT32_DEC_WIDTH) != (int) strlen(str0)) REPORTERROR (("Something wrong with PRINTF_INT32_DEC_WIDTH : %s\n", PRINTF_INT32_DEC_WIDTH));
850  sprintf (str0, "%" PRINTF_INT32_MODIFIER "u", UINT32_C(4294967295));
851  if (0 != strcmp (str0, "4294967295")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str0));
852  if (atoi(PRINTF_UINT32_DEC_WIDTH) != (int) strlen(str0)) REPORTERROR (("Something wrong with PRINTF_UINT32_DEC_WIDTH : %s\n", PRINTF_UINT32_DEC_WIDTH));
853 #ifdef INT64_MAX
854  sprintf (str1, "%" PRINTF_INT64_MODIFIER "d", INT64_C(9223372036854775807));
855  if (0 != strcmp (str1, "9223372036854775807")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str1));
856  if (atoi(PRINTF_INT64_DEC_WIDTH) != (int) strlen(str1)) REPORTERROR (("Something wrong with PRINTF_INT64_DEC_WIDTH : %s, %d\n", PRINTF_INT64_DEC_WIDTH, (int) strlen(str1)));
857  sprintf (str1, "%" PRINTF_INT64_MODIFIER "u", UINT64_C(18446744073709550591));
858  if (0 != strcmp (str1, "18446744073709550591")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str1));
859  if (atoi(PRINTF_UINT64_DEC_WIDTH) != (int) strlen(str1)) REPORTERROR (("Something wrong with PRINTF_UINT64_DEC_WIDTH : %s, %d\n", PRINTF_UINT64_DEC_WIDTH, (int) strlen(str1)));
860 #endif
861 
862  sprintf (str0, "%d %x\n", 0, ~0);
863 
864  sprintf (str1, "%d %x\n", i8, ~0);
865  if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i8 : %s\n", str1));
866  sprintf (str1, "%u %x\n", u8, ~0);
867  if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u8 : %s\n", str1));
868  sprintf (str1, "%d %x\n", i16, ~0);
869  if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i16 : %s\n", str1));
870  sprintf (str1, "%u %x\n", u16, ~0);
871  if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u16 : %s\n", str1));
872  sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
873  if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i32 : %s\n", str1));
874  sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
875  if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u32 : %s\n", str1));
876 #ifdef INT64_MAX
877  sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
878  if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i64 : %s\n", str1));
879 #endif
880  sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
881  if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with imax : %s\n", str1));
882  sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
883  if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with umax : %s\n", str1));
884 
885  TESTUMAX(8);
886  TESTUMAX(16);
887  TESTUMAX(32);
888 #ifdef INT64_MAX
889  TESTUMAX(64);
890 #endif
891 
892 #define STR(v) #v
893 #define Q(v) printf ("sizeof " STR(v) " = %u\n", (unsigned) sizeof (v));
894  if (err_n) {
895  printf ("pstdint.h is not correct. Please use sizes below to correct it:\n");
896  }
897 
898  Q(int)
899  Q(unsigned)
900  Q(long int)
901  Q(short int)
902  Q(int8_t)
903  Q(int16_t)
904  Q(int32_t)
905 #ifdef INT64_MAX
906  Q(int64_t)
907 #endif
908 
909  return EXIT_SUCCESS;
910 }
911 
912 #endif