2005-03-07 04:51:38 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004, 2005 by
|
|
|
|
* Ralf Corsepius, Ulm/Germany. All rights reserved.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software
|
|
|
|
* is freely granted, provided that this notice is preserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @todo - Add fast<N>_t types.
|
|
|
|
* @todo - Add support for wint_t types.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _STDINT_H
|
|
|
|
#define _STDINT_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2005-09-28 04:49:53 +08:00
|
|
|
#if defined(__GNUC__) && \
|
|
|
|
( (__GNUC__ >= 4) || \
|
|
|
|
( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 2) ) )
|
|
|
|
/* gcc > 3.2 implicitly defines the values we are interested */
|
2005-09-21 05:21:51 +08:00
|
|
|
#define __STDINT_EXP(x) __##x##__
|
2005-03-07 04:51:38 +08:00
|
|
|
#else
|
2005-09-21 05:21:51 +08:00
|
|
|
#define __STDINT_EXP(x) x
|
2005-03-07 04:51:38 +08:00
|
|
|
#include <limits.h>
|
|
|
|
#endif
|
|
|
|
|
2005-10-05 05:02:59 +08:00
|
|
|
/* Check if "long long" is 64bit wide */
|
|
|
|
/* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */
|
|
|
|
#if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \
|
|
|
|
|| ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) )
|
|
|
|
#define __have_longlong64 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Check if "long" is 64bit or 32bit wide */
|
|
|
|
#if __STDINT_EXP(LONG_MAX) > 0x7fffffff
|
|
|
|
#define __have_long64 1
|
|
|
|
#elif __STDINT_EXP(LONG_MAX) == 0x7fffffff
|
|
|
|
#define __have_long32 1
|
|
|
|
#endif
|
|
|
|
|
2005-09-21 05:21:51 +08:00
|
|
|
#if __STDINT_EXP(SCHAR_MAX) == 0x7f
|
2005-03-07 04:51:38 +08:00
|
|
|
typedef signed char int8_t ;
|
|
|
|
typedef unsigned char uint8_t ;
|
|
|
|
#define __int8_t_defined 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __int8_t_defined
|
|
|
|
typedef signed char int_least8_t;
|
|
|
|
typedef unsigned char uint_least8_t;
|
|
|
|
#define __int_least8_t_defined 1
|
|
|
|
#endif
|
|
|
|
|
2005-09-21 05:21:51 +08:00
|
|
|
#if __STDINT_EXP(SHRT_MAX) == 0x7fff
|
2005-03-07 04:51:38 +08:00
|
|
|
typedef signed short int16_t;
|
|
|
|
typedef unsigned short uint16_t;
|
|
|
|
#define __int16_t_defined 1
|
2005-09-21 05:21:51 +08:00
|
|
|
#elif __STDINT_EXP(INT_MAX) == 0x7fff
|
2005-03-07 04:51:38 +08:00
|
|
|
typedef signed int int16_t;
|
|
|
|
typedef unsigned int uint16_t;
|
|
|
|
#define __int16_t_defined 1
|
2005-09-21 05:21:51 +08:00
|
|
|
#elif __STDINT_EXP(SCHAR_MAX) == 0x7fff
|
2005-03-07 04:51:38 +08:00
|
|
|
typedef signed char int16_t;
|
|
|
|
typedef unsigned char uint16_t;
|
|
|
|
#define __int16_t_defined 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __int16_t_defined
|
|
|
|
typedef int16_t int_least16_t;
|
|
|
|
typedef uint16_t uint_least16_t;
|
|
|
|
#define __int_least16_t_defined 1
|
|
|
|
|
|
|
|
#ifndef __int_least8_t_defined
|
|
|
|
typedef int16_t int_least8_t;
|
|
|
|
typedef uint16_t uint_least8_t;
|
|
|
|
#define __int_least8_t_defined 1
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2005-09-21 05:21:51 +08:00
|
|
|
#if __STDINT_EXP(INT_MAX) == 0x7fffffffL
|
2005-03-07 04:51:38 +08:00
|
|
|
typedef signed int int32_t;
|
|
|
|
typedef unsigned int uint32_t;
|
|
|
|
#define __int32_t_defined 1
|
2005-09-21 05:21:51 +08:00
|
|
|
#elif __STDINT_EXP(LONG_MAX) == 0x7fffffffL
|
2005-03-07 04:51:38 +08:00
|
|
|
typedef signed long int32_t;
|
|
|
|
typedef unsigned long uint32_t;
|
|
|
|
#define __int32_t_defined 1
|
2005-09-21 05:21:51 +08:00
|
|
|
#elif __STDINT_EXP(SHRT_MAX) == 0x7fffffffL
|
2005-03-07 04:51:38 +08:00
|
|
|
typedef signed short int32_t;
|
|
|
|
typedef unsigned short uint32_t;
|
|
|
|
#define __int32_t_defined 1
|
2005-09-21 05:21:51 +08:00
|
|
|
#elif __STDINT_EXP(SCHAR_MAX) == 0x7fffffffL
|
2005-03-07 04:51:38 +08:00
|
|
|
typedef signed char int32_t;
|
|
|
|
typedef unsigned char uint32_t;
|
|
|
|
#define __int32_t_defined 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __int32_t_defined
|
|
|
|
typedef int32_t int_least32_t;
|
|
|
|
typedef uint32_t uint_least32_t;
|
|
|
|
#define __int_least32_t_defined 1
|
|
|
|
|
|
|
|
#ifndef __int_least8_t_defined
|
|
|
|
typedef int32_t int_least8_t;
|
|
|
|
typedef uint32_t uint_least8_t;
|
|
|
|
#define __int_least8_t_defined 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __int_least16_t_defined
|
|
|
|
typedef int32_t int_least16_t;
|
|
|
|
typedef uint32_t uint_least16_t;
|
|
|
|
#define __int_least16_t_defined 1
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2005-10-05 05:02:59 +08:00
|
|
|
#if __have_long64
|
2005-03-07 04:51:38 +08:00
|
|
|
typedef signed long int64_t;
|
|
|
|
typedef unsigned long uint64_t;
|
|
|
|
#define __int64_t_defined 1
|
2005-10-05 05:02:59 +08:00
|
|
|
#elif __have_longlong64
|
2005-03-07 04:51:38 +08:00
|
|
|
typedef signed long long int64_t;
|
|
|
|
typedef unsigned long long uint64_t;
|
|
|
|
#define __int64_t_defined 1
|
2005-09-21 05:21:51 +08:00
|
|
|
#elif __STDINT_EXP(INT_MAX) > 0x7fffffff
|
2005-03-07 04:51:38 +08:00
|
|
|
typedef signed int int64_t;
|
|
|
|
typedef unsigned int uint64_t;
|
|
|
|
#define __int64_t_defined 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __int64_t_defined
|
|
|
|
typedef int64_t int_least64_t;
|
|
|
|
typedef uint64_t uint_least64_t;
|
|
|
|
#define __int_least64_t_defined 1
|
|
|
|
|
|
|
|
#ifndef __int_least8_t_defined
|
|
|
|
typedef int64_t int_least8_t;
|
|
|
|
typedef uint64_t uint_least8_t;
|
|
|
|
#define __int_least8_t_defined 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __int_least16_t_defined
|
|
|
|
typedef int64_t int_least16_t;
|
|
|
|
typedef uint64_t uint_least16_t;
|
|
|
|
#define __int_least16_t_defined 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __int_least32_t_defined
|
|
|
|
typedef int64_t int_least32_t;
|
|
|
|
typedef uint64_t uint_least32_t;
|
|
|
|
#define __int_least32_t_defined 1
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2005-10-04 01:02:48 +08:00
|
|
|
/* Greatest-width integer types */
|
|
|
|
/* Modern GCCs provide __INTMAX_TYPE__ */
|
|
|
|
#if defined(__INTMAX_TYPE__)
|
|
|
|
typedef __INTMAX_TYPE__ intmax_t;
|
|
|
|
#elif __have_longlong64
|
|
|
|
typedef signed long long intmax_t;
|
2005-03-07 04:51:38 +08:00
|
|
|
#else
|
2005-10-04 01:02:48 +08:00
|
|
|
typedef signed long intmax_t;
|
2005-03-07 04:51:38 +08:00
|
|
|
#endif
|
|
|
|
|
2005-10-04 01:02:48 +08:00
|
|
|
/* Modern GCCs provide __UINTMAX_TYPE__ */
|
|
|
|
#if defined(__UINTMAX_TYPE__)
|
|
|
|
typedef __UINTMAX_TYPE__ uintmax_t;
|
|
|
|
#elif __have_longlong64
|
|
|
|
typedef unsigned long long uintmax_t;
|
2005-10-05 05:02:59 +08:00
|
|
|
#else
|
2005-10-04 01:02:48 +08:00
|
|
|
typedef unsigned long uintmax_t;
|
2005-10-05 05:02:59 +08:00
|
|
|
#endif
|
2005-10-04 01:02:48 +08:00
|
|
|
|
2005-03-07 04:51:38 +08:00
|
|
|
/*
|
2005-10-04 01:02:48 +08:00
|
|
|
* GCC doesn't provide an appropriate macro for [u]intptr_t
|
2005-03-07 04:51:38 +08:00
|
|
|
* For now, use __PTRDIFF_TYPE__
|
|
|
|
*/
|
|
|
|
#if defined(__PTRDIFF_TYPE__)
|
|
|
|
typedef signed __PTRDIFF_TYPE__ intptr_t;
|
|
|
|
typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Fallback to hardcoded values,
|
|
|
|
* should be valid on cpu's with 32bit int/32bit void*
|
|
|
|
*/
|
|
|
|
typedef signed long intptr_t;
|
|
|
|
typedef unsigned long uintptr_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Limits of Specified-Width Integer Types */
|
|
|
|
|
|
|
|
#if __int8_t_defined
|
|
|
|
#define INT8_MIN -128
|
|
|
|
#define INT8_MAX 127
|
|
|
|
#define UINT8_MAX 255
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __int_least8_t_defined
|
2005-09-21 03:33:58 +08:00
|
|
|
#define INT_LEAST8_MIN -128
|
|
|
|
#define INT_LEAST8_MAX 127
|
|
|
|
#define UINT_LEAST8_MAX 255
|
2005-03-07 04:51:38 +08:00
|
|
|
#else
|
|
|
|
#error required type int_least8_t missing
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __int16_t_defined
|
|
|
|
#define INT16_MIN -32768
|
|
|
|
#define INT16_MAX 32767
|
|
|
|
#define UINT16_MAX 65535
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __int_least16_t_defined
|
2005-09-21 03:33:58 +08:00
|
|
|
#define INT_LEAST16_MIN -32768
|
|
|
|
#define INT_LEAST16_MAX 32767
|
|
|
|
#define UINT_LEAST16_MAX 65535
|
2005-03-07 04:51:38 +08:00
|
|
|
#else
|
|
|
|
#error required type int_least16_t missing
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __int32_t_defined
|
2005-09-21 05:21:51 +08:00
|
|
|
#define INT32_MIN (-2147483647-1)
|
2005-03-07 04:51:38 +08:00
|
|
|
#define INT32_MAX 2147483647
|
2005-09-21 05:21:51 +08:00
|
|
|
#define UINT32_MAX 4294967295U
|
2005-03-07 04:51:38 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __int_least32_t_defined
|
2005-09-21 05:21:51 +08:00
|
|
|
#define INT_LEAST32_MIN (-2147483647-1)
|
2005-09-21 03:33:58 +08:00
|
|
|
#define INT_LEAST32_MAX 2147483647
|
2005-09-21 05:21:51 +08:00
|
|
|
#define UINT_LEAST32_MAX 4294967295U
|
2005-03-07 04:51:38 +08:00
|
|
|
#else
|
|
|
|
#error required type int_least32_t missing
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __int64_t_defined
|
2005-09-21 05:21:51 +08:00
|
|
|
#ifdef __have_long64
|
|
|
|
#define INT64_MIN (-9223372036854775807L-1L)
|
|
|
|
#define INT64_MAX 9223372036854775807L
|
|
|
|
#define UINT64_MAX 18446744073709551615U
|
2005-10-05 05:02:59 +08:00
|
|
|
#elif __have_longlong64
|
2005-09-21 05:21:51 +08:00
|
|
|
#define INT64_MIN (-9223372036854775807LL-1LL)
|
|
|
|
#define INT64_MAX 9223372036854775807LL
|
|
|
|
#define UINT64_MAX 18446744073709551615ULL
|
|
|
|
#endif
|
2005-03-07 04:51:38 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __int_least64_t_defined
|
2005-09-21 05:21:51 +08:00
|
|
|
#ifdef __have_long64
|
|
|
|
#define INT_LEAST64_MIN (-9223372036854775807L-1L)
|
|
|
|
#define INT_LEAST64_MAX 9223372036854775807L
|
|
|
|
#define UINT_LEAST64_MAX 18446744073709551615U
|
2005-10-05 05:02:59 +08:00
|
|
|
#elif __have_longlong64
|
2005-09-21 05:21:51 +08:00
|
|
|
#define INT_LEAST64_MIN (-9223372036854775807LL-1LL)
|
|
|
|
#define INT_LEAST64_MAX 9223372036854775807LL
|
|
|
|
#define UINT_LEAST64_MAX 18446744073709551615ULL
|
|
|
|
#endif
|
2005-03-07 04:51:38 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* This must match size_t in stddef.h, currently long unsigned int */
|
2005-09-21 05:21:51 +08:00
|
|
|
#define SIZE_MIN (-__STDINT_EXP(LONG_MAX) - 1L)
|
|
|
|
#define SIZE_MAX __STDINT_EXP(LONG_MAX)
|
2005-03-07 04:51:38 +08:00
|
|
|
|
|
|
|
/* This must match sig_atomic_t in <signal.h> (currently int) */
|
2005-09-21 05:21:51 +08:00
|
|
|
#define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1)
|
|
|
|
#define SIG_ATOMIC_MAX __STDINT_EXP(INT_MAX)
|
2005-03-07 04:51:38 +08:00
|
|
|
|
|
|
|
/* This must match ptrdiff_t in <stddef.h> (currently long int) */
|
2005-09-21 05:21:51 +08:00
|
|
|
#define PTRDIFF_MIN (-__STDINT_EXP(LONG_MAX) - 1L)
|
|
|
|
#define PTRDIFF_MAX __STDINT_EXP(LONG_MAX)
|
2005-03-07 04:51:38 +08:00
|
|
|
|
|
|
|
/** Macros for minimum-width integer constant expressions */
|
|
|
|
#define INT8_C(x) x
|
|
|
|
#define UINT8_C(x) x##U
|
|
|
|
|
|
|
|
#define INT16_C(x) x
|
|
|
|
#define UINT16_C(x) x##U
|
|
|
|
|
|
|
|
#if __have_long32
|
|
|
|
#define INT32_C(x) x##L
|
|
|
|
#define UINT32_C(x) x##UL
|
|
|
|
#else
|
|
|
|
#define INT32_C(x) x
|
|
|
|
#define UINT32_C(x) x##U
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __int64_t_defined
|
|
|
|
#if __have_longlong64
|
|
|
|
#define INT64_C(x) x##LL
|
|
|
|
#define UINT64_C(x) x##ULL
|
|
|
|
#else
|
|
|
|
#define INT64_C(x) x##L
|
|
|
|
#define UINT64_C(x) x##UL
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Macros for greatest-width integer constant expression */
|
|
|
|
#if __have_longlong64
|
|
|
|
#define INTMAX_C(x) x##LL
|
|
|
|
#define UINTMAX_C(x) x##ULL
|
|
|
|
#else
|
|
|
|
#define INTMAX_C(x) x##L
|
|
|
|
#define UINTMAX_C(x) x##UL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _STDINT_H */
|