66 lines
1.5 KiB
C
66 lines
1.5 KiB
C
/*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
* Small fixed-width integer compatibility layer for SJ3.
|
|
*
|
|
* In C99 or newer translation units, use <stdint.h>. In C89 translation
|
|
* units, provide the fixed-width names that SJ3 needs when the host integer
|
|
* model has matching types.
|
|
*/
|
|
|
|
#ifndef SJ_STDINT_H_
|
|
#define SJ_STDINT_H_
|
|
|
|
#if defined(HAVE_C99_STDINT) && HAVE_C99_STDINT && \
|
|
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
|
#include <stdint.h>
|
|
#else
|
|
|
|
#include <limits.h>
|
|
|
|
#if !defined(UINT8_MAX)
|
|
#if UCHAR_MAX == 255
|
|
typedef signed char int8_t;
|
|
typedef unsigned char uint8_t;
|
|
#define UINT8_MAX UCHAR_MAX
|
|
#else
|
|
#error "SJ3 requires an 8-bit unsigned char"
|
|
#endif
|
|
#endif
|
|
|
|
#if !defined(UINT16_MAX)
|
|
#if USHRT_MAX == 65535
|
|
typedef short int16_t;
|
|
typedef unsigned short uint16_t;
|
|
#define UINT16_MAX USHRT_MAX
|
|
#else
|
|
#error "SJ3 requires a 16-bit unsigned short"
|
|
#endif
|
|
#endif
|
|
|
|
#if !defined(UINT32_MAX)
|
|
#if UINT_MAX == 4294967295U
|
|
typedef int int32_t;
|
|
typedef unsigned int uint32_t;
|
|
#define UINT32_MAX UINT_MAX
|
|
#elif ULONG_MAX == 4294967295UL
|
|
typedef long int32_t;
|
|
typedef unsigned long uint32_t;
|
|
#define UINT32_MAX ULONG_MAX
|
|
#else
|
|
#error "SJ3 requires a 32-bit integer type"
|
|
#endif
|
|
#endif
|
|
|
|
#if !defined(UINT64_MAX) && (ULONG_MAX > 4294967295UL)
|
|
typedef long int64_t;
|
|
typedef unsigned long uint64_t;
|
|
#define UINT64_MAX ULONG_MAX
|
|
#elif !defined(UINT64_MAX) && (defined(_MSC_VER) || defined(_WIN32))
|
|
typedef __int64 int64_t;
|
|
typedef unsigned __int64 uint64_t;
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif /* SJ_STDINT_H_ */
|