nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

pstdint.h (30303B)


      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.2
     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 verison, 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(_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 #ifndef _PSTDINT_H_INCLUDED
    341 #define _PSTDINT_H_INCLUDED
    342 
    343 #ifndef SIZE_MAX
    344 # define SIZE_MAX (~(size_t)0)
    345 #endif
    346 
    347 /*
    348  *  Deduce the type assignments from limits.h under the assumption that
    349  *  integer sizes in bits are powers of 2, and follow the ANSI
    350  *  definitions.
    351  */
    352 
    353 #ifndef UINT8_MAX
    354 # define UINT8_MAX 0xff
    355 #endif
    356 #if !defined(uint8_t) && !defined(_UINT8_T)
    357 # if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
    358     typedef unsigned char uint8_t;
    359 #   define UINT8_C(v) ((uint8_t) v)
    360 # else
    361 #   error "Platform not supported"
    362 # endif
    363 #endif
    364 
    365 #ifndef INT8_MAX
    366 # define INT8_MAX 0x7f
    367 #endif
    368 #ifndef INT8_MIN
    369 # define INT8_MIN INT8_C(0x80)
    370 #endif
    371 #if !defined(int8_t) && !defined(_INT8_T)
    372 # if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
    373     typedef signed char int8_t;
    374 #   define INT8_C(v) ((int8_t) v)
    375 # else
    376 #   error "Platform not supported"
    377 # endif
    378 #endif
    379 
    380 #ifndef UINT16_MAX
    381 # define UINT16_MAX 0xffff
    382 #endif
    383 #if !defined(uint16_t) && !defined(_UINT16_T)
    384 #if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
    385   typedef unsigned int uint16_t;
    386 # ifndef PRINTF_INT16_MODIFIER
    387 #  define PRINTF_INT16_MODIFIER ""
    388 # endif
    389 # define UINT16_C(v) ((uint16_t) (v))
    390 #elif (USHRT_MAX == UINT16_MAX)
    391   typedef unsigned short uint16_t;
    392 # define UINT16_C(v) ((uint16_t) (v))
    393 # ifndef PRINTF_INT16_MODIFIER
    394 #  define PRINTF_INT16_MODIFIER "h"
    395 # endif
    396 #else
    397 #error "Platform not supported"
    398 #endif
    399 #endif
    400 
    401 #ifndef INT16_MAX
    402 # define INT16_MAX 0x7fff
    403 #endif
    404 #ifndef INT16_MIN
    405 # define INT16_MIN INT16_C(0x8000)
    406 #endif
    407 #if !defined(int16_t) && !defined(_INT16_T)
    408 #if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
    409   typedef signed int int16_t;
    410 # define INT16_C(v) ((int16_t) (v))
    411 # ifndef PRINTF_INT16_MODIFIER
    412 #  define PRINTF_INT16_MODIFIER ""
    413 # endif
    414 #elif (SHRT_MAX == INT16_MAX)
    415   typedef signed short int16_t;
    416 # define INT16_C(v) ((int16_t) (v))
    417 # ifndef PRINTF_INT16_MODIFIER
    418 #  define PRINTF_INT16_MODIFIER "h"
    419 # endif
    420 #else
    421 #error "Platform not supported"
    422 #endif
    423 #endif
    424 
    425 #ifndef UINT32_MAX
    426 # define UINT32_MAX (0xffffffffUL)
    427 #endif
    428 #if !defined(uint32_t) && !defined(_UINT32_T)
    429 #if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
    430   typedef unsigned long uint32_t;
    431 # define UINT32_C(v) v ## UL
    432 # ifndef PRINTF_INT32_MODIFIER
    433 #  define PRINTF_INT32_MODIFIER "l"
    434 # endif
    435 #elif (UINT_MAX == UINT32_MAX)
    436   typedef unsigned int uint32_t;
    437 # ifndef PRINTF_INT32_MODIFIER
    438 #  define PRINTF_INT32_MODIFIER ""
    439 # endif
    440 # define UINT32_C(v) v ## U
    441 #elif (USHRT_MAX == UINT32_MAX)
    442   typedef unsigned short uint32_t;
    443 # define UINT32_C(v) ((unsigned short) (v))
    444 # ifndef PRINTF_INT32_MODIFIER
    445 #  define PRINTF_INT32_MODIFIER ""
    446 # endif
    447 #else
    448 #error "Platform not supported"
    449 #endif
    450 #endif
    451 
    452 #ifndef INT32_MAX
    453 # define INT32_MAX (0x7fffffffL)
    454 #endif
    455 #ifndef INT32_MIN
    456 # define INT32_MIN INT32_C(0x80000000)
    457 #endif
    458 #if !defined(int32_t) && !defined(_INT32_T)
    459 #if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
    460   typedef signed long int32_t;
    461 # define INT32_C(v) v ## L
    462 # ifndef PRINTF_INT32_MODIFIER
    463 #  define PRINTF_INT32_MODIFIER "l"
    464 # endif
    465 #elif (INT_MAX == INT32_MAX)
    466   typedef signed int int32_t;
    467 # define INT32_C(v) v
    468 # ifndef PRINTF_INT32_MODIFIER
    469 #  define PRINTF_INT32_MODIFIER ""
    470 # endif
    471 #elif (SHRT_MAX == INT32_MAX)
    472   typedef signed short int32_t;
    473 # define INT32_C(v) ((short) (v))
    474 # ifndef PRINTF_INT32_MODIFIER
    475 #  define PRINTF_INT32_MODIFIER ""
    476 # endif
    477 #else
    478 #error "Platform not supported"
    479 #endif
    480 #endif
    481 
    482 /*
    483  *  The macro stdint_int64_defined is temporarily used to record
    484  *  whether or not 64 integer support is available.  It must be
    485  *  defined for any 64 integer extensions for new platforms that are
    486  *  added.
    487  */
    488 
    489 #undef stdint_int64_defined
    490 #if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
    491 # if (__STDC__ && __STDC_VERSION__ >= 199901L) || defined (S_SPLINT_S)
    492 #  define stdint_int64_defined
    493    typedef long long int64_t;
    494    typedef unsigned long long uint64_t;
    495 #  define UINT64_C(v) v ## ULL
    496 #  define  INT64_C(v) v ## LL
    497 #  ifndef PRINTF_INT64_MODIFIER
    498 #   define PRINTF_INT64_MODIFIER "ll"
    499 #  endif
    500 # endif
    501 #endif
    502 
    503 #if !defined (stdint_int64_defined)
    504 # if defined(__GNUC__)
    505 #  define stdint_int64_defined
    506    __extension__ typedef long long int64_t;
    507    __extension__ typedef unsigned long long uint64_t;
    508 #  define UINT64_C(v) v ## ULL
    509 #  define  INT64_C(v) v ## LL
    510 #  ifndef PRINTF_INT64_MODIFIER
    511 #   define PRINTF_INT64_MODIFIER "ll"
    512 #  endif
    513 # elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
    514 #  define stdint_int64_defined
    515    typedef long long int64_t;
    516    typedef unsigned long long uint64_t;
    517 #  define UINT64_C(v) v ## ULL
    518 #  define  INT64_C(v) v ## LL
    519 #  ifndef PRINTF_INT64_MODIFIER
    520 #   define PRINTF_INT64_MODIFIER "ll"
    521 #  endif
    522 # elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
    523 #  define stdint_int64_defined
    524    typedef __int64 int64_t;
    525    typedef unsigned __int64 uint64_t;
    526 #  define UINT64_C(v) v ## UI64
    527 #  define  INT64_C(v) v ## I64
    528 #  ifndef PRINTF_INT64_MODIFIER
    529 #   define PRINTF_INT64_MODIFIER "I64"
    530 #  endif
    531 # endif
    532 #endif
    533 
    534 #if !defined (LONG_LONG_MAX) && defined (INT64_C)
    535 # define LONG_LONG_MAX INT64_C (9223372036854775807)
    536 #endif
    537 #ifndef ULONG_LONG_MAX
    538 # define ULONG_LONG_MAX UINT64_C (18446744073709551615)
    539 #endif
    540 
    541 #if !defined (INT64_MAX) && defined (INT64_C)
    542 # define INT64_MAX INT64_C (9223372036854775807)
    543 #endif
    544 #if !defined (INT64_MIN) && defined (INT64_C)
    545 # define INT64_MIN INT64_C (-9223372036854775808)
    546 #endif
    547 #if !defined (UINT64_MAX) && defined (INT64_C)
    548 # define UINT64_MAX UINT64_C (18446744073709551615)
    549 #endif
    550 
    551 /*
    552  *  Width of hexadecimal for number field.
    553  */
    554 
    555 #ifndef PRINTF_INT64_HEX_WIDTH
    556 # define PRINTF_INT64_HEX_WIDTH "16"
    557 #endif
    558 #ifndef PRINTF_INT32_HEX_WIDTH
    559 # define PRINTF_INT32_HEX_WIDTH "8"
    560 #endif
    561 #ifndef PRINTF_INT16_HEX_WIDTH
    562 # define PRINTF_INT16_HEX_WIDTH "4"
    563 #endif
    564 #ifndef PRINTF_INT8_HEX_WIDTH
    565 # define PRINTF_INT8_HEX_WIDTH "2"
    566 #endif
    567 #ifndef PRINTF_INT64_DEC_WIDTH
    568 # define PRINTF_INT64_DEC_WIDTH "19"
    569 #endif
    570 #ifndef PRINTF_INT32_DEC_WIDTH
    571 # define PRINTF_INT32_DEC_WIDTH "10"
    572 #endif
    573 #ifndef PRINTF_INT16_DEC_WIDTH
    574 # define PRINTF_INT16_DEC_WIDTH "5"
    575 #endif
    576 #ifndef PRINTF_INT8_DEC_WIDTH
    577 # define PRINTF_INT8_DEC_WIDTH "3"
    578 #endif
    579 #ifndef PRINTF_UINT64_DEC_WIDTH
    580 # define PRINTF_UINT64_DEC_WIDTH "20"
    581 #endif
    582 #ifndef PRINTF_UINT32_DEC_WIDTH
    583 # define PRINTF_UINT32_DEC_WIDTH "10"
    584 #endif
    585 #ifndef PRINTF_UINT16_DEC_WIDTH
    586 # define PRINTF_UINT16_DEC_WIDTH "5"
    587 #endif
    588 #ifndef PRINTF_UINT8_DEC_WIDTH
    589 # define PRINTF_UINT8_DEC_WIDTH "3"
    590 #endif
    591 
    592 /*
    593  *  Ok, lets not worry about 128 bit integers for now.  Moore's law says
    594  *  we don't need to worry about that until about 2040 at which point
    595  *  we'll have bigger things to worry about.
    596  */
    597 
    598 #ifdef stdint_int64_defined
    599   typedef int64_t intmax_t;
    600   typedef uint64_t uintmax_t;
    601 # define  INTMAX_MAX   INT64_MAX
    602 # define  INTMAX_MIN   INT64_MIN
    603 # define UINTMAX_MAX  UINT64_MAX
    604 # define UINTMAX_C(v) UINT64_C(v)
    605 # define  INTMAX_C(v)  INT64_C(v)
    606 # ifndef PRINTF_INTMAX_MODIFIER
    607 #   define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
    608 # endif
    609 # ifndef PRINTF_INTMAX_HEX_WIDTH
    610 #  define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
    611 # endif
    612 # ifndef PRINTF_INTMAX_DEC_WIDTH
    613 #  define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
    614 # endif
    615 #else
    616   typedef int32_t intmax_t;
    617   typedef uint32_t uintmax_t;
    618 # define  INTMAX_MAX   INT32_MAX
    619 # define UINTMAX_MAX  UINT32_MAX
    620 # define UINTMAX_C(v) UINT32_C(v)
    621 # define  INTMAX_C(v)  INT32_C(v)
    622 # ifndef PRINTF_INTMAX_MODIFIER
    623 #   define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
    624 # endif
    625 # ifndef PRINTF_INTMAX_HEX_WIDTH
    626 #  define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
    627 # endif
    628 # ifndef PRINTF_INTMAX_DEC_WIDTH
    629 #  define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
    630 # endif
    631 #endif
    632 
    633 /*
    634  *  Because this file currently only supports platforms which have
    635  *  precise powers of 2 as bit sizes for the default integers, the
    636  *  least definitions are all trivial.  Its possible that a future
    637  *  version of this file could have different definitions.
    638  */
    639 
    640 #ifndef stdint_least_defined
    641   typedef   int8_t   int_least8_t;
    642   typedef  uint8_t  uint_least8_t;
    643   typedef  int16_t  int_least16_t;
    644   typedef uint16_t uint_least16_t;
    645   typedef  int32_t  int_least32_t;
    646   typedef uint32_t uint_least32_t;
    647 # define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
    648 # define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
    649 # define  UINT_LEAST8_MAX  UINT8_MAX
    650 # define   INT_LEAST8_MAX   INT8_MAX
    651 # define UINT_LEAST16_MAX UINT16_MAX
    652 # define  INT_LEAST16_MAX  INT16_MAX
    653 # define UINT_LEAST32_MAX UINT32_MAX
    654 # define  INT_LEAST32_MAX  INT32_MAX
    655 # define   INT_LEAST8_MIN   INT8_MIN
    656 # define  INT_LEAST16_MIN  INT16_MIN
    657 # define  INT_LEAST32_MIN  INT32_MIN
    658 # ifdef stdint_int64_defined
    659     typedef  int64_t  int_least64_t;
    660     typedef uint64_t uint_least64_t;
    661 #   define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
    662 #   define UINT_LEAST64_MAX UINT64_MAX
    663 #   define  INT_LEAST64_MAX  INT64_MAX
    664 #   define  INT_LEAST64_MIN  INT64_MIN
    665 # endif
    666 #endif
    667 #undef stdint_least_defined
    668 
    669 /*
    670  *  The ANSI C committee pretending to know or specify anything about
    671  *  performance is the epitome of misguided arrogance.  The mandate of
    672  *  this file is to *ONLY* ever support that absolute minimum
    673  *  definition of the fast integer types, for compatibility purposes.
    674  *  No extensions, and no attempt to suggest what may or may not be a
    675  *  faster integer type will ever be made in this file.  Developers are
    676  *  warned to stay away from these types when using this or any other
    677  *  stdint.h.
    678  */
    679 
    680 typedef   int_least8_t   int_fast8_t;
    681 typedef  uint_least8_t  uint_fast8_t;
    682 typedef  int_least16_t  int_fast16_t;
    683 typedef uint_least16_t uint_fast16_t;
    684 typedef  int_least32_t  int_fast32_t;
    685 typedef uint_least32_t uint_fast32_t;
    686 #define  UINT_FAST8_MAX  UINT_LEAST8_MAX
    687 #define   INT_FAST8_MAX   INT_LEAST8_MAX
    688 #define UINT_FAST16_MAX UINT_LEAST16_MAX
    689 #define  INT_FAST16_MAX  INT_LEAST16_MAX
    690 #define UINT_FAST32_MAX UINT_LEAST32_MAX
    691 #define  INT_FAST32_MAX  INT_LEAST32_MAX
    692 #define   INT_FAST8_MIN   INT_LEAST8_MIN
    693 #define  INT_FAST16_MIN  INT_LEAST16_MIN
    694 #define  INT_FAST32_MIN  INT_LEAST32_MIN
    695 #ifdef stdint_int64_defined
    696   typedef  int_least64_t  int_fast64_t;
    697   typedef uint_least64_t uint_fast64_t;
    698 # define UINT_FAST64_MAX UINT_LEAST64_MAX
    699 # define  INT_FAST64_MAX  INT_LEAST64_MAX
    700 # define  INT_FAST64_MIN  INT_LEAST64_MIN
    701 #endif
    702 
    703 #undef stdint_int64_defined
    704 
    705 /*
    706  *  Whatever piecemeal, per compiler thing we can do about the wchar_t
    707  *  type limits.
    708  */
    709 
    710 #if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
    711 # include <wchar.h>
    712 # ifndef WCHAR_MIN
    713 #  define WCHAR_MIN 0
    714 # endif
    715 # ifndef WCHAR_MAX
    716 #  define WCHAR_MAX ((wchar_t)-1)
    717 # endif
    718 #endif
    719 
    720 /*
    721  *  Whatever piecemeal, per compiler/platform thing we can do about the
    722  *  (u)intptr_t types and limits.
    723  */
    724 
    725 #if (defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)) || defined (_UINTPTR_T)
    726 # define STDINT_H_UINTPTR_T_DEFINED
    727 #endif
    728 
    729 #ifndef STDINT_H_UINTPTR_T_DEFINED
    730 # if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64) || defined (__ppc64__)
    731 #  define stdint_intptr_bits 64
    732 # elif defined (__WATCOMC__) || defined (__TURBOC__)
    733 #  if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
    734 #    define stdint_intptr_bits 16
    735 #  else
    736 #    define stdint_intptr_bits 32
    737 #  endif
    738 # elif defined (__i386__) || defined (_WIN32) || defined (WIN32) || defined (__ppc64__)
    739 #  define stdint_intptr_bits 32
    740 # elif defined (__INTEL_COMPILER)
    741 /* TODO -- what did Intel do about x86-64? */
    742 # else
    743 /* #error "This platform might not be supported yet" */
    744 # endif
    745 
    746 # ifdef stdint_intptr_bits
    747 #  define stdint_intptr_glue3_i(a,b,c)  a##b##c
    748 #  define stdint_intptr_glue3(a,b,c)    stdint_intptr_glue3_i(a,b,c)
    749 #  ifndef PRINTF_INTPTR_MODIFIER
    750 #    define PRINTF_INTPTR_MODIFIER      stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
    751 #  endif
    752 #  ifndef PTRDIFF_MAX
    753 #    define PTRDIFF_MAX                 stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
    754 #  endif
    755 #  ifndef PTRDIFF_MIN
    756 #    define PTRDIFF_MIN                 stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
    757 #  endif
    758 #  ifndef UINTPTR_MAX
    759 #    define UINTPTR_MAX                 stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
    760 #  endif
    761 #  ifndef INTPTR_MAX
    762 #    define INTPTR_MAX                  stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
    763 #  endif
    764 #  ifndef INTPTR_MIN
    765 #    define INTPTR_MIN                  stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
    766 #  endif
    767 #  ifndef INTPTR_C
    768 #    define INTPTR_C(x)                 stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
    769 #  endif
    770 #  ifndef UINTPTR_C
    771 #    define UINTPTR_C(x)                stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
    772 #  endif
    773   typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
    774   typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t)  intptr_t;
    775 # else
    776 /* TODO -- This following is likely wrong for some platforms, and does
    777    nothing for the definition of uintptr_t. */
    778   typedef ptrdiff_t intptr_t;
    779 # endif
    780 # define STDINT_H_UINTPTR_T_DEFINED
    781 #endif
    782 
    783 /*
    784  *  Assumes sig_atomic_t is signed and we have a 2s complement machine.
    785  */
    786 
    787 #ifndef SIG_ATOMIC_MAX
    788 # define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
    789 #endif
    790 
    791 #endif
    792 
    793 #if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
    794 
    795 /*
    796  *  Please compile with the maximum warning settings to make sure macros are
    797  *  not defined more than once.
    798  */
    799 
    800 #include <stdlib.h>
    801 #include <stdio.h>
    802 #include <string.h>
    803 
    804 #define glue3_aux(x,y,z) x ## y ## z
    805 #define glue3(x,y,z) glue3_aux(x,y,z)
    806 
    807 #define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,) = glue3(UINT,bits,_C) (0);
    808 #define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,) = glue3(INT,bits,_C) (0);
    809 
    810 #define DECL(us,bits) glue3(DECL,us,) (bits)
    811 
    812 #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)
    813 
    814 #define REPORTERROR(msg) { err_n++; if (err_first <= 0) err_first = __LINE__; printf msg; }
    815 
    816 int main () {
    817 	int err_n = 0;
    818 	int err_first = 0;
    819 	DECL(I,8)
    820 	DECL(U,8)
    821 	DECL(I,16)
    822 	DECL(U,16)
    823 	DECL(I,32)
    824 	DECL(U,32)
    825 #ifdef INT64_MAX
    826 	DECL(I,64)
    827 	DECL(U,64)
    828 #endif
    829 	intmax_t imax = INTMAX_C(0);
    830 	uintmax_t umax = UINTMAX_C(0);
    831 	char str0[256], str1[256];
    832 
    833 	sprintf (str0, "%" PRINTF_INT32_MODIFIER "d", INT32_C(2147483647));
    834 	if (0 != strcmp (str0, "2147483647")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str0));
    835 	if (atoi(PRINTF_INT32_DEC_WIDTH) != (int) strlen(str0)) REPORTERROR (("Something wrong with PRINTF_INT32_DEC_WIDTH : %s\n", PRINTF_INT32_DEC_WIDTH));
    836 	sprintf (str0, "%" PRINTF_INT32_MODIFIER "u", UINT32_C(4294967295));
    837 	if (0 != strcmp (str0, "4294967295")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str0));
    838 	if (atoi(PRINTF_UINT32_DEC_WIDTH) != (int) strlen(str0)) REPORTERROR (("Something wrong with PRINTF_UINT32_DEC_WIDTH : %s\n", PRINTF_UINT32_DEC_WIDTH));
    839 #ifdef INT64_MAX
    840 	sprintf (str1, "%" PRINTF_INT64_MODIFIER "d", INT64_C(9223372036854775807));
    841 	if (0 != strcmp (str1, "9223372036854775807")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str1));
    842 	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)));
    843 	sprintf (str1, "%" PRINTF_INT64_MODIFIER "u", UINT64_C(18446744073709550591));
    844 	if (0 != strcmp (str1, "18446744073709550591")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str1));
    845 	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)));
    846 #endif
    847 
    848 	sprintf (str0, "%d %x\n", 0, ~0);
    849 
    850 	sprintf (str1, "%d %x\n",  i8, ~0);
    851 	if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i8 : %s\n", str1));
    852 	sprintf (str1, "%u %x\n",  u8, ~0);
    853 	if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u8 : %s\n", str1));
    854 	sprintf (str1, "%d %x\n",  i16, ~0);
    855 	if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i16 : %s\n", str1));
    856 	sprintf (str1, "%u %x\n",  u16, ~0);
    857 	if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u16 : %s\n", str1));
    858 	sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n",  i32, ~0);
    859 	if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i32 : %s\n", str1));
    860 	sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n",  u32, ~0);
    861 	if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u32 : %s\n", str1));
    862 #ifdef INT64_MAX
    863 	sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n",  i64, ~0);
    864 	if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i64 : %s\n", str1));
    865 #endif
    866 	sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n",  imax, ~0);
    867 	if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with imax : %s\n", str1));
    868 	sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n",  umax, ~0);
    869 	if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with umax : %s\n", str1));
    870 
    871 	TESTUMAX(8);
    872 	TESTUMAX(16);
    873 	TESTUMAX(32);
    874 #ifdef INT64_MAX
    875 	TESTUMAX(64);
    876 #endif
    877 
    878 #define STR(v) #v
    879 #define Q(v) printf ("sizeof " STR(v) " = %u\n", (unsigned) sizeof (v));
    880 	if (err_n) {
    881 		printf ("pstdint.h is not correct.  Please use sizes below to correct it:\n");
    882 	}
    883 
    884 	Q(int)
    885 	Q(unsigned)
    886 	Q(long int)
    887 	Q(short int)
    888 	Q(int8_t)
    889 	Q(int16_t)
    890 	Q(int32_t)
    891 #ifdef INT64_MAX
    892 	Q(int64_t)
    893 #endif
    894 
    895 	return EXIT_SUCCESS;
    896 }
    897 
    898 #endif