version 0.0.1
[fms.git] / include / pstdint.h
1 /*  A portable stdint.h\r
2  *\r
3  *  Copyright (c) 2005-2007 Paul Hsieh\r
4  *\r
5  *  Redistribution and use in source and binary forms, with or without\r
6  *  modification, are permitted provided that the following conditions\r
7  *  are met:\r
8  *\r
9  *      Redistributions of source code must retain the above copyright\r
10  *      notice, this list of conditions and the following disclaimer.\r
11  *\r
12  *      Redistributions in binary form must not misrepresent the orignal\r
13  *      source in the documentation and/or other materials provided\r
14  *      with the distribution.\r
15  *\r
16  *      The names of the authors nor its contributors may be used to\r
17  *      endorse or promote products derived from this software without\r
18  *      specific prior written permission.\r
19  *\r
20  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
21  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
22  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
23  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
24  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
25  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
26  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
27  *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
28  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
29  *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
30  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\r
31  *  OF THE POSSIBILITY OF SUCH DAMAGE.\r
32  *\r
33  ****************************************************************************\r
34  *\r
35  *  Version 0.1.8\r
36  *\r
37  *  The ANSI C standard committee, for the C99 standard, specified the\r
38  *  inclusion of a new standard include file called stdint.h.  This is\r
39  *  a very useful and long desired include file which contains several\r
40  *  very precise definitions for integer scalar types that is\r
41  *  critically important for making portable several classes of\r
42  *  applications including cryptography, hashing, variable length\r
43  *  integer libraries and so on.  But for most developers its likely\r
44  *  useful just for programming sanity.\r
45  *\r
46  *  The problem is that most compiler vendors have decided not to\r
47  *  implement the C99 standard, and the next C++ language standard\r
48  *  (which has a lot more mindshare these days) will be a long time in\r
49  *  coming and its unknown whether or not it will include stdint.h or\r
50  *  how much adoption it will have.  Either way, it will be a long time\r
51  *  before all compilers come with a stdint.h and it also does nothing\r
52  *  for the extremely large number of compilers available today which\r
53  *  do not include this file, or anything comparable to it.\r
54  *\r
55  *  So that's what this file is all about.  Its an attempt to build a\r
56  *  single universal include file that works on as many platforms as\r
57  *  possible to deliver what stdint.h is supposed to.  A few things\r
58  *  that should be noted about this file:\r
59  *\r
60  *    1) It is not guaranteed to be portable and/or present an identical\r
61  *       interface on all platforms.  The extreme variability of the\r
62  *       ANSI C standard makes this an impossibility right from the\r
63  *       very get go. Its really only meant to be useful for the vast\r
64  *       majority of platforms that possess the capability of\r
65  *       implementing usefully and precisely defined, standard sized\r
66  *       integer scalars.  Systems which are not intrinsically 2s\r
67  *       complement may produce invalid constants.\r
68  *\r
69  *    2) There is an unavoidable use of non-reserved symbols.\r
70  *\r
71  *    3) Other standard include files are invoked.\r
72  *\r
73  *    4) This file may come in conflict with future platforms that do\r
74  *       include stdint.h.  The hope is that one or the other can be\r
75  *       used with no real difference.\r
76  *\r
77  *    5) In the current verison, if your platform can't represent\r
78  *       int32_t, int16_t and int8_t, it just dumps out with a compiler\r
79  *       error.\r
80  *\r
81  *    6) 64 bit integers may or may not be defined.  Test for their\r
82  *       presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.\r
83  *       Note that this is different from the C99 specification which\r
84  *       requires the existence of 64 bit support in the compiler.  If\r
85  *       this is not defined for your platform, yet it is capable of\r
86  *       dealing with 64 bits then it is because this file has not yet\r
87  *       been extended to cover all of your system's capabilities.\r
88  *\r
89  *    7) (u)intptr_t may or may not be defined.  Test for its presence\r
90  *       with the test: #ifdef PTRDIFF_MAX.  If this is not defined\r
91  *       for your platform, then it is because this file has not yet\r
92  *       been extended to cover all of your system's capabilities, not\r
93  *       because its optional.\r
94  *\r
95  *    8) The following might not been defined even if your platform is\r
96  *       capable of defining it:\r
97  *\r
98  *       WCHAR_MIN\r
99  *       WCHAR_MAX\r
100  *       (u)int64_t\r
101  *       PTRDIFF_MIN\r
102  *       PTRDIFF_MAX\r
103  *       (u)intptr_t\r
104  *\r
105  *    9) The following have not been defined:\r
106  *\r
107  *       WINT_MIN\r
108  *       WINT_MAX\r
109  *\r
110  *   10) The criteria for defining (u)int_least(*)_t isn't clear,\r
111  *       except for systems which don't have a type that precisely\r
112  *       defined 8, 16, or 32 bit types (which this include file does\r
113  *       not support anyways). Default definitions have been given.\r
114  *\r
115  *   11) The criteria for defining (u)int_fast(*)_t isn't something I\r
116  *       would trust to any particular compiler vendor or the ANSI C\r
117  *       committee.  It is well known that "compatible systems" are\r
118  *       commonly created that have very different performance\r
119  *       characteristics from the systems they are compatible with,\r
120  *       especially those whose vendors make both the compiler and the\r
121  *       system.  Default definitions have been given, but its strongly\r
122  *       recommended that users never use these definitions for any\r
123  *       reason (they do *NOT* deliver any serious guarantee of\r
124  *       improved performance -- not in this file, nor any vendor's\r
125  *       stdint.h).\r
126  *\r
127  *   12) The following macros:\r
128  *\r
129  *       PRINTF_INTMAX_MODIFIER\r
130  *       PRINTF_INT64_MODIFIER\r
131  *       PRINTF_INT32_MODIFIER\r
132  *       PRINTF_INT16_MODIFIER\r
133  *       PRINTF_LEAST64_MODIFIER\r
134  *       PRINTF_LEAST32_MODIFIER\r
135  *       PRINTF_LEAST16_MODIFIER\r
136  *       PRINTF_INTPTR_MODIFIER\r
137  *\r
138  *       are strings which have been defined as the modifiers required\r
139  *       for the "d", "u" and "x" printf formats to correctly output\r
140  *       (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,\r
141  *       (u)least32_t, (u)least16_t and (u)intptr_t types respectively.\r
142  *       PRINTF_INTPTR_MODIFIER is not defined for some systems which\r
143  *       provide their own stdint.h.  PRINTF_INT64_MODIFIER is not\r
144  *       defined if INT64_MAX is not defined.  These are an extension\r
145  *       beyond what C99 specifies must be in stdint.h.\r
146  *\r
147  *       In addition, the following macros are defined:\r
148  *\r
149  *       PRINTF_INTMAX_HEX_WIDTH\r
150  *       PRINTF_INT64_HEX_WIDTH\r
151  *       PRINTF_INT32_HEX_WIDTH\r
152  *       PRINTF_INT16_HEX_WIDTH\r
153  *       PRINTF_INT8_HEX_WIDTH\r
154  *       PRINTF_INTMAX_DEC_WIDTH\r
155  *       PRINTF_INT64_DEC_WIDTH\r
156  *       PRINTF_INT32_DEC_WIDTH\r
157  *       PRINTF_INT16_DEC_WIDTH\r
158  *       PRINTF_INT8_DEC_WIDTH\r
159  *\r
160  *       Which specifies the maximum number of characters required to\r
161  *       print the number of that type in either hexadecimal or decimal.\r
162  *       These are an extension beyond what C99 specifies must be in\r
163  *       stdint.h.\r
164  *\r
165  *  Compilers tested (all with 0 warnings at their highest respective\r
166  *  settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32\r
167  *  bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio\r
168  *  .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3\r
169  *\r
170  *  This file should be considered a work in progress.  Suggestions for\r
171  *  improvements, especially those which increase coverage are strongly\r
172  *  encouraged.\r
173  *\r
174  *  Acknowledgements\r
175  *\r
176  *  The following people have made significant contributions to the\r
177  *  development and testing of this file:\r
178  *\r
179  *  Chris Howie\r
180  *  John Steele Scott\r
181  *  Dave Thorup\r
182  *\r
183  */\r
184 \r
185 #include <stddef.h>\r
186 #include <limits.h>\r
187 #include <signal.h>\r
188 \r
189 /*\r
190  *  For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and\r
191  *  do nothing else.  On the Mac OS X version of gcc this is _STDINT_H_.\r
192  */\r
193 \r
194 #if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) )) && !defined (_PSTDINT_H_INCLUDED)\r
195 #include <stdint.h>\r
196 #define _PSTDINT_H_INCLUDED\r
197 # ifndef PRINTF_INT64_MODIFIER\r
198 #  define PRINTF_INT64_MODIFIER "ll"\r
199 # endif\r
200 # ifndef PRINTF_INT32_MODIFIER\r
201 #  define PRINTF_INT32_MODIFIER "l"\r
202 # endif\r
203 # ifndef PRINTF_INT16_MODIFIER\r
204 #  define PRINTF_INT16_MODIFIER "h"\r
205 # endif\r
206 # ifndef PRINTF_INTMAX_MODIFIER\r
207 #  define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER\r
208 # endif\r
209 # ifndef PRINTF_INT64_HEX_WIDTH\r
210 #  define PRINTF_INT64_HEX_WIDTH "16"\r
211 # endif\r
212 # ifndef PRINTF_INT32_HEX_WIDTH\r
213 #  define PRINTF_INT32_HEX_WIDTH "8"\r
214 # endif\r
215 # ifndef PRINTF_INT16_HEX_WIDTH\r
216 #  define PRINTF_INT16_HEX_WIDTH "4"\r
217 # endif\r
218 # ifndef PRINTF_INT8_HEX_WIDTH\r
219 #  define PRINTF_INT8_HEX_WIDTH "2"\r
220 # endif\r
221 # ifndef PRINTF_INT64_DEC_WIDTH\r
222 #  define PRINTF_INT64_DEC_WIDTH "20"\r
223 # endif\r
224 # ifndef PRINTF_INT32_DEC_WIDTH\r
225 #  define PRINTF_INT32_DEC_WIDTH "10"\r
226 # endif\r
227 # ifndef PRINTF_INT16_DEC_WIDTH\r
228 #  define PRINTF_INT16_DEC_WIDTH "5"\r
229 # endif\r
230 # ifndef PRINTF_INT8_DEC_WIDTH\r
231 #  define PRINTF_INT8_DEC_WIDTH "3"\r
232 # endif\r
233 # ifndef PRINTF_INTMAX_HEX_WIDTH\r
234 #  define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH\r
235 # endif\r
236 # ifndef PRINTF_INTMAX_DEC_WIDTH\r
237 #  define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH\r
238 # endif\r
239 #endif\r
240 \r
241 #ifndef _PSTDINT_H_INCLUDED\r
242 #define _PSTDINT_H_INCLUDED\r
243 \r
244 #ifndef SIZE_MAX\r
245 # define SIZE_MAX (~(size_t)0)\r
246 #endif\r
247 \r
248 /*\r
249  *  Deduce the type assignments from limits.h under the assumption that\r
250  *  integer sizes in bits are powers of 2, and follow the ANSI\r
251  *  definitions.\r
252  */\r
253 \r
254 #ifndef UINT8_MAX\r
255 # define UINT8_MAX 0xff\r
256 #endif\r
257 #ifndef uint8_t\r
258 # if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)\r
259     typedef unsigned char uint8_t;\r
260 #   define UINT8_C(v) ((uint8_t) v)\r
261 # else\r
262 #   error "Platform not supported"\r
263 # endif\r
264 #endif\r
265 \r
266 #ifndef INT8_MAX\r
267 # define INT8_MAX 0x7f\r
268 #endif\r
269 #ifndef INT8_MIN\r
270 # define INT8_MIN INT8_C(0x80)\r
271 #endif\r
272 #ifndef int8_t\r
273 # if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)\r
274     typedef signed char int8_t;\r
275 #   define INT8_C(v) ((int8_t) v)\r
276 # else\r
277 #   error "Platform not supported"\r
278 # endif\r
279 #endif\r
280 \r
281 #ifndef UINT16_MAX\r
282 # define UINT16_MAX 0xffff\r
283 #endif\r
284 #ifndef uint16_t\r
285 #if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)\r
286   typedef unsigned int uint16_t;\r
287 # ifndef PRINTF_INT16_MODIFIER\r
288 #  define PRINTF_INT16_MODIFIER ""\r
289 # endif\r
290 # define UINT16_C(v) ((uint16_t) (v))\r
291 #elif (USHRT_MAX == UINT16_MAX)\r
292   typedef unsigned short uint16_t;\r
293 # define UINT16_C(v) ((uint16_t) (v))\r
294 # ifndef PRINTF_INT16_MODIFIER\r
295 #  define PRINTF_INT16_MODIFIER "h"\r
296 # endif\r
297 #else\r
298 #error "Platform not supported"\r
299 #endif\r
300 #endif\r
301 \r
302 #ifndef INT16_MAX\r
303 # define INT16_MAX 0x7fff\r
304 #endif\r
305 #ifndef INT16_MIN\r
306 # define INT16_MIN INT16_C(0x8000)\r
307 #endif\r
308 #ifndef int16_t\r
309 #if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)\r
310   typedef signed int int16_t;\r
311 # define INT16_C(v) ((int16_t) (v))\r
312 # ifndef PRINTF_INT16_MODIFIER\r
313 #  define PRINTF_INT16_MODIFIER ""\r
314 # endif\r
315 #elif (SHRT_MAX == INT16_MAX)\r
316   typedef signed short int16_t;\r
317 # define INT16_C(v) ((int16_t) (v))\r
318 # ifndef PRINTF_INT16_MODIFIER\r
319 #  define PRINTF_INT16_MODIFIER "h"\r
320 # endif\r
321 #else\r
322 #error "Platform not supported"\r
323 #endif\r
324 #endif\r
325 \r
326 #ifndef UINT32_MAX\r
327 # define UINT32_MAX (0xffffffffUL)\r
328 #endif\r
329 #ifndef uint32_t\r
330 #if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)\r
331   typedef unsigned long uint32_t;\r
332 # define UINT32_C(v) v ## UL\r
333 # ifndef PRINTF_INT32_MODIFIER\r
334 #  define PRINTF_INT32_MODIFIER "l"\r
335 # endif\r
336 #elif (UINT_MAX == UINT32_MAX)\r
337   typedef unsigned int uint32_t;\r
338 # ifndef PRINTF_INT32_MODIFIER\r
339 #  define PRINTF_INT32_MODIFIER ""\r
340 # endif\r
341 # define UINT32_C(v) v ## U\r
342 #elif (USHRT_MAX == UINT32_MAX)\r
343   typedef unsigned short uint32_t;\r
344 # define UINT32_C(v) ((unsigned short) (v))\r
345 # ifndef PRINTF_INT32_MODIFIER\r
346 #  define PRINTF_INT32_MODIFIER ""\r
347 # endif\r
348 #else\r
349 #error "Platform not supported"\r
350 #endif\r
351 #endif\r
352 \r
353 #ifndef INT32_MAX\r
354 # define INT32_MAX (0x7fffffffL)\r
355 #endif\r
356 #ifndef INT32_MIN\r
357 # define INT32_MIN INT32_C(0x80000000)\r
358 #endif\r
359 #ifndef int32_t\r
360 #if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)\r
361   typedef signed long int32_t;\r
362 # define INT32_C(v) v ## L\r
363 # ifndef PRINTF_INT32_MODIFIER\r
364 #  define PRINTF_INT32_MODIFIER "l"\r
365 # endif\r
366 #elif (INT_MAX == INT32_MAX)\r
367   typedef signed int int32_t;\r
368 # define INT32_C(v) v\r
369 # ifndef PRINTF_INT32_MODIFIER\r
370 #  define PRINTF_INT32_MODIFIER ""\r
371 # endif\r
372 #elif (SHRT_MAX == INT32_MAX)\r
373   typedef signed short int32_t;\r
374 # define INT32_C(v) ((short) (v))\r
375 # ifndef PRINTF_INT32_MODIFIER\r
376 #  define PRINTF_INT32_MODIFIER ""\r
377 # endif\r
378 #else\r
379 #error "Platform not supported"\r
380 #endif\r
381 #endif\r
382 \r
383 /*\r
384  *  The macro stdint_int64_defined is temporarily used to record\r
385  *  whether or not 64 integer support is available.  It must be\r
386  *  defined for any 64 integer extensions for new platforms that are\r
387  *  added.\r
388  */\r
389 \r
390 #undef stdint_int64_defined\r
391 #if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)\r
392 # if (__STDC__ && __STDC_VERSION >= 199901L) || defined (S_SPLINT_S)\r
393 #  define stdint_int64_defined\r
394    typedef long long int64_t;\r
395    typedef unsigned long long uint64_t;\r
396 #  define UINT64_C(v) v ## ULL\r
397 #  define  INT64_C(v) v ## LL\r
398 #  ifndef PRINTF_INT64_MODIFIER\r
399 #   define PRINTF_INT64_MODIFIER "ll"\r
400 #  endif\r
401 # endif\r
402 #endif\r
403 \r
404 #if !defined (stdint_int64_defined)\r
405 # if defined(__GNUC__)\r
406 #  define stdint_int64_defined\r
407    __extension__ typedef long long int64_t;\r
408    __extension__ typedef unsigned long long uint64_t;\r
409 #  define UINT64_C(v) v ## ULL\r
410 #  define  INT64_C(v) v ## LL\r
411 #  ifndef PRINTF_INT64_MODIFIER\r
412 #   define PRINTF_INT64_MODIFIER "ll"\r
413 #  endif\r
414 # elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)\r
415 #  define stdint_int64_defined\r
416    typedef long long int64_t;\r
417    typedef unsigned long long uint64_t;\r
418 #  define UINT64_C(v) v ## ULL\r
419 #  define  INT64_C(v) v ## LL\r
420 #  ifndef PRINTF_INT64_MODIFIER\r
421 #   define PRINTF_INT64_MODIFIER "ll"\r
422 #  endif\r
423 # elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)\r
424 #  define stdint_int64_defined\r
425    typedef __int64 int64_t;\r
426    typedef unsigned __int64 uint64_t;\r
427 #  define UINT64_C(v) v ## UI64\r
428 #  define  INT64_C(v) v ## I64\r
429 #  ifndef PRINTF_INT64_MODIFIER\r
430 #   define PRINTF_INT64_MODIFIER "I64"\r
431 #  endif\r
432 # endif\r
433 #endif\r
434 \r
435 #if !defined (LONG_LONG_MAX) && defined (INT64_C)\r
436 # define LONG_LONG_MAX INT64_C (9223372036854775807)\r
437 #endif\r
438 #ifndef ULONG_LONG_MAX\r
439 # define ULONG_LONG_MAX UINT64_C (18446744073709551615)\r
440 #endif\r
441 \r
442 #if !defined (INT64_MAX) && defined (INT64_C)\r
443 # define INT64_MAX INT64_C (9223372036854775807)\r
444 #endif\r
445 #if !defined (INT64_MIN) && defined (INT64_C)\r
446 # define INT64_MIN INT64_C (-9223372036854775808)\r
447 #endif\r
448 #if !defined (UINT64_MAX) && defined (INT64_C)\r
449 # define UINT64_MAX UINT64_C (18446744073709551615)\r
450 #endif\r
451 \r
452 /*\r
453  *  Width of hexadecimal for number field.\r
454  */\r
455 \r
456 #ifndef PRINTF_INT64_HEX_WIDTH\r
457 # define PRINTF_INT64_HEX_WIDTH "16"\r
458 #endif\r
459 #ifndef PRINTF_INT32_HEX_WIDTH\r
460 # define PRINTF_INT32_HEX_WIDTH "8"\r
461 #endif\r
462 #ifndef PRINTF_INT16_HEX_WIDTH\r
463 # define PRINTF_INT16_HEX_WIDTH "4"\r
464 #endif\r
465 #ifndef PRINTF_INT8_HEX_WIDTH\r
466 # define PRINTF_INT8_HEX_WIDTH "2"\r
467 #endif\r
468 \r
469 #ifndef PRINTF_INT64_DEC_WIDTH\r
470 # define PRINTF_INT64_DEC_WIDTH "20"\r
471 #endif\r
472 #ifndef PRINTF_INT32_DEC_WIDTH\r
473 # define PRINTF_INT32_DEC_WIDTH "10"\r
474 #endif\r
475 #ifndef PRINTF_INT16_DEC_WIDTH\r
476 # define PRINTF_INT16_DEC_WIDTH "5"\r
477 #endif\r
478 #ifndef PRINTF_INT8_DEC_WIDTH\r
479 # define PRINTF_INT8_DEC_WIDTH "3"\r
480 #endif\r
481 \r
482 /*\r
483  *  Ok, lets not worry about 128 bit integers for now.  Moore's law says\r
484  *  we don't need to worry about that until about 2040 at which point\r
485  *  we'll have bigger things to worry about.\r
486  */\r
487 \r
488 #ifdef stdint_int64_defined\r
489   typedef int64_t intmax_t;\r
490   typedef uint64_t uintmax_t;\r
491 # define  INTMAX_MAX   INT64_MAX\r
492 # define  INTMAX_MIN   INT64_MIN\r
493 # define UINTMAX_MAX  UINT64_MAX\r
494 # define UINTMAX_C(v) UINT64_C(v)\r
495 # define  INTMAX_C(v)  INT64_C(v)\r
496 # ifndef PRINTF_INTMAX_MODIFIER\r
497 #   define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER\r
498 # endif\r
499 # ifndef PRINTF_INTMAX_HEX_WIDTH\r
500 #  define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH\r
501 # endif\r
502 # ifndef PRINTF_INTMAX_DEC_WIDTH\r
503 #  define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH\r
504 # endif\r
505 #else\r
506   typedef int32_t intmax_t;\r
507   typedef uint32_t uintmax_t;\r
508 # define  INTMAX_MAX   INT32_MAX\r
509 # define UINTMAX_MAX  UINT32_MAX\r
510 # define UINTMAX_C(v) UINT32_C(v)\r
511 # define  INTMAX_C(v)  INT32_C(v)\r
512 # ifndef PRINTF_INTMAX_MODIFIER\r
513 #   define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER\r
514 # endif\r
515 # ifndef PRINTF_INTMAX_HEX_WIDTH\r
516 #  define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH\r
517 # endif\r
518 # ifndef PRINTF_INTMAX_DEC_WIDTH\r
519 #  define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH\r
520 # endif\r
521 #endif\r
522 \r
523 /*\r
524  *  Because this file currently only supports platforms which have\r
525  *  precise powers of 2 as bit sizes for the default integers, the\r
526  *  least definitions are all trivial.  Its possible that a future\r
527  *  version of this file could have different definitions.\r
528  */\r
529 \r
530 #ifndef stdint_least_defined\r
531   typedef   int8_t   int_least8_t;\r
532   typedef  uint8_t  uint_least8_t;\r
533   typedef  int16_t  int_least16_t;\r
534   typedef uint16_t uint_least16_t;\r
535   typedef  int32_t  int_least32_t;\r
536   typedef uint32_t uint_least32_t;\r
537 # define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER\r
538 # define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER\r
539 # define  UINT_LEAST8_MAX  UINT8_MAX\r
540 # define   INT_LEAST8_MAX   INT8_MAX\r
541 # define UINT_LEAST16_MAX UINT16_MAX\r
542 # define  INT_LEAST16_MAX  INT16_MAX\r
543 # define UINT_LEAST32_MAX UINT32_MAX\r
544 # define  INT_LEAST32_MAX  INT32_MAX\r
545 # define   INT_LEAST8_MIN   INT8_MIN\r
546 # define  INT_LEAST16_MIN  INT16_MIN\r
547 # define  INT_LEAST32_MIN  INT32_MIN\r
548 # ifdef stdint_int64_defined\r
549     typedef  int64_t  int_least64_t;\r
550     typedef uint64_t uint_least64_t;\r
551 #   define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER\r
552 #   define UINT_LEAST64_MAX UINT64_MAX\r
553 #   define  INT_LEAST64_MAX  INT64_MAX\r
554 #   define  INT_LEAST64_MIN  INT64_MIN\r
555 # endif\r
556 #endif\r
557 #undef stdint_least_defined\r
558 \r
559 /*\r
560  *  The ANSI C committee pretending to know or specify anything about\r
561  *  performance is the epitome of misguided arrogance.  The mandate of\r
562  *  this file is to *ONLY* ever support that absolute minimum\r
563  *  definition of the fast integer types, for compatibility purposes.\r
564  *  No extensions, and no attempt to suggest what may or may not be a\r
565  *  faster integer type will ever be made in this file.  Developers are\r
566  *  warned to stay away from these types when using this or any other\r
567  *  stdint.h.\r
568  */\r
569 \r
570 typedef   int_least8_t   int_fast8_t;\r
571 typedef  uint_least8_t  uint_fast8_t;\r
572 typedef  int_least16_t  int_fast16_t;\r
573 typedef uint_least16_t uint_fast16_t;\r
574 typedef  int_least32_t  int_fast32_t;\r
575 typedef uint_least32_t uint_fast32_t;\r
576 #define  UINT_FAST8_MAX  UINT_LEAST8_MAX\r
577 #define   INT_FAST8_MAX   INT_LEAST8_MAX\r
578 #define UINT_FAST16_MAX UINT_LEAST16_MAX\r
579 #define  INT_FAST16_MAX  INT_LEAST16_MAX\r
580 #define UINT_FAST32_MAX UINT_LEAST32_MAX\r
581 #define  INT_FAST32_MAX  INT_LEAST32_MAX\r
582 #define   INT_FAST8_MIN   IN_LEASTT8_MIN\r
583 #define  INT_FAST16_MIN  INT_LEAST16_MIN\r
584 #define  INT_FAST32_MIN  INT_LEAST32_MIN\r
585 #ifdef stdint_int64_defined\r
586   typedef  int_least64_t  int_fast64_t;\r
587   typedef uint_least64_t uint_fast64_t;\r
588 # define UINT_FAST64_MAX UINT_LEAST64_MAX\r
589 # define  INT_FAST64_MAX  INT_LEAST64_MAX\r
590 # define  INT_FAST64_MIN  INT_LEAST64_MIN\r
591 #endif\r
592 \r
593 #undef stdint_int64_defined\r
594 \r
595 /*\r
596  *  Whatever piecemeal, per compiler thing we can do about the wchar_t\r
597  *  type limits.\r
598  */\r
599 \r
600 #if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)\r
601 # include <wchar.h>\r
602 # ifndef WCHAR_MIN\r
603 #  define WCHAR_MIN 0\r
604 # endif\r
605 # ifndef WCHAR_MAX\r
606 #  define WCHAR_MAX ((wchar_t)-1)\r
607 # endif\r
608 #endif\r
609 \r
610 /*\r
611  *  Whatever piecemeal, per compiler/platform thing we can do about the\r
612  *  (u)intptr_t types and limits.\r
613  */\r
614 \r
615 #if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)\r
616 # define STDINT_H_UINTPTR_T_DEFINED\r
617 #endif\r
618 \r
619 #ifndef STDINT_H_UINTPTR_T_DEFINED\r
620 # if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)\r
621 #  define stdint_intptr_bits 64\r
622 # elif defined (__WATCOMC__) || defined (__TURBOC__)\r
623 #  if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)\r
624 #    define stdint_intptr_bits 16\r
625 #  else\r
626 #    define stdint_intptr_bits 32\r
627 #  endif\r
628 # elif defined (__i386__) || defined (_WIN32) || defined (WIN32)\r
629 #  define stdint_intptr_bits 32\r
630 # elif defined (__INTEL_COMPILER)\r
631 /* TODO -- what will Intel do about x86-64? */\r
632 # endif\r
633 \r
634 # ifdef stdint_intptr_bits\r
635 #  define stdint_intptr_glue3_i(a,b,c)  a##b##c\r
636 #  define stdint_intptr_glue3(a,b,c)    stdint_intptr_glue3_i(a,b,c)\r
637 #  ifndef PRINTF_INTPTR_MODIFIER\r
638 #    define PRINTF_INTPTR_MODIFIER      stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)\r
639 #  endif\r
640 #  ifndef PTRDIFF_MAX\r
641 #    define PTRDIFF_MAX                 stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)\r
642 #  endif\r
643 #  ifndef PTRDIFF_MIN\r
644 #    define PTRDIFF_MIN                 stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)\r
645 #  endif\r
646 #  ifndef UINTPTR_MAX\r
647 #    define UINTPTR_MAX                 stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)\r
648 #  endif\r
649 #  ifndef INTPTR_MAX\r
650 #    define INTPTR_MAX                  stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)\r
651 #  endif\r
652 #  ifndef INTPTR_MIN\r
653 #    define INTPTR_MIN                  stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)\r
654 #  endif\r
655 #  ifndef INTPTR_C\r
656 #    define INTPTR_C(x)                 stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)\r
657 #  endif\r
658 #  ifndef UINTPTR_C\r
659 #    define UINTPTR_C(x)                stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)\r
660 #  endif\r
661   typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;\r
662   typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t)  intptr_t;\r
663 # else\r
664 /* TODO -- This following is likely wrong for some platforms, and does\r
665    nothing for the definition of uintptr_t. */\r
666   typedef ptrdiff_t intptr_t;\r
667 # endif\r
668 # define STDINT_H_UINTPTR_T_DEFINED\r
669 #endif\r
670 \r
671 /*\r
672  *  Assumes sig_atomic_t is signed and we have a 2s complement machine.\r
673  */\r
674 \r
675 #ifndef SIG_ATOMIC_MAX\r
676 # define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)\r
677 #endif\r
678 \r
679 #endif\r