115ab0bcfSAxel Dörfler/*
236576214SAdrien Destugues * Copyright 2003-2017 Haiku, Inc. All Rights Reserved.
315ab0bcfSAxel Dörfler * Distributed under the terms of the MIT License.
415ab0bcfSAxel Dörfler */
5c6544683SAxel Dörfler#ifndef _STDINT_H_
6c6544683SAxel Dörfler#define _STDINT_H_
7c6544683SAxel Dörfler
8c6544683SAxel Dörfler
92222d055SIngo Weinhold#include <config/types.h>
102222d055SIngo Weinhold
11c6544683SAxel Dörfler
12c6544683SAxel Dörfler/* Exact-width integer types */
132222d055SIngo Weinholdtypedef __haiku_std_int8	int8_t;
142222d055SIngo Weinholdtypedef __haiku_std_uint8	uint8_t;
1522611e78SIngo Weinhold
162222d055SIngo Weinholdtypedef __haiku_std_int16	int16_t;
172222d055SIngo Weinholdtypedef __haiku_std_uint16	uint16_t;
1822611e78SIngo Weinhold
192222d055SIngo Weinholdtypedef __haiku_std_int32	int32_t;
202222d055SIngo Weinholdtypedef __haiku_std_uint32	uint32_t;
2122611e78SIngo Weinhold
222222d055SIngo Weinholdtypedef __haiku_std_int64	int64_t;
232222d055SIngo Weinholdtypedef __haiku_std_uint64	uint64_t;
2422611e78SIngo Weinhold
2522611e78SIngo Weinhold/* Minimum-width integer types */
2622611e78SIngo Weinholdtypedef int8_t int_least8_t;
2722611e78SIngo Weinholdtypedef uint8_t uint_least8_t;
2822611e78SIngo Weinhold
2922611e78SIngo Weinholdtypedef int16_t int_least16_t;
3022611e78SIngo Weinholdtypedef uint16_t uint_least16_t;
3122611e78SIngo Weinhold
3222611e78SIngo Weinholdtypedef int32_t int_least32_t;
3322611e78SIngo Weinholdtypedef uint32_t uint_least32_t;
3422611e78SIngo Weinhold
3522611e78SIngo Weinholdtypedef int64_t int_least64_t;
3622611e78SIngo Weinholdtypedef uint64_t uint_least64_t;
3722611e78SIngo Weinhold
3822611e78SIngo Weinhold/* Fastest minimum-width integer types */
3922611e78SIngo Weinholdtypedef int32_t int_fast8_t;
4022611e78SIngo Weinholdtypedef uint32_t uint_fast8_t;
4122611e78SIngo Weinhold
4222611e78SIngo Weinholdtypedef int32_t int_fast16_t;
4322611e78SIngo Weinholdtypedef uint32_t uint_fast16_t;
4422611e78SIngo Weinhold
4522611e78SIngo Weinholdtypedef int32_t int_fast32_t;
4622611e78SIngo Weinholdtypedef uint32_t uint_fast32_t;
4722611e78SIngo Weinhold
4822611e78SIngo Weinholdtypedef int64_t int_fast64_t;
4922611e78SIngo Weinholdtypedef uint64_t uint_fast64_t;
5022611e78SIngo Weinhold
5122611e78SIngo Weinhold/* Integer types capable of holding object pointers */
522222d055SIngo Weinholdtypedef __haiku_saddr_t intptr_t;
532222d055SIngo Weinholdtypedef __haiku_addr_t uintptr_t;
54f8fdd89fSAxel Dörfler
5522611e78SIngo Weinhold/* Greatest-width integer types */
562222d055SIngo Weinholdtypedef int64_t intmax_t;
572222d055SIngo Weinholdtypedef uint64_t uintmax_t;
5822611e78SIngo Weinhold
5922611e78SIngo Weinhold/* Limits of exact-width integer types */
603a79ea54Sshatty#define INT8_MIN 	(-128)
613a79ea54Sshatty#define INT8_MAX 	(127)
623a79ea54Sshatty#define UINT8_MAX	(255U)
63f8fdd89fSAxel Dörfler
643a79ea54Sshatty#define INT16_MIN 	(-32768)
653a79ea54Sshatty#define INT16_MAX 	(32767)
663a79ea54Sshatty#define UINT16_MAX	(65535U)
67f8fdd89fSAxel Dörfler
6822611e78SIngo Weinhold#define INT32_MAX	(2147483647)
698cea73aaSJérôme Duval#define INT32_MIN 	(-INT32_MAX-1)
7022611e78SIngo Weinhold#define UINT32_MAX	(4294967295U)
71c6544683SAxel Dörfler
721d13a609SJérôme Duval#if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ > 4
73d1dc9cf6STimothy Gu#define INT64_MAX	(9223372036854775807L)
741d13a609SJérôme Duval#define UINT64_MAX	(18446744073709551615UL)
751d13a609SJérôme Duval#else
76d1dc9cf6STimothy Gu#define INT64_MAX	(9223372036854775807LL)
773a79ea54Sshatty#define UINT64_MAX	(18446744073709551615ULL)
781d13a609SJérôme Duval#endif
791d13a609SJérôme Duval#define INT64_MIN	(-INT64_MAX-1)
80f8fdd89fSAxel Dörfler
8122611e78SIngo Weinhold/* Limits of minimum-width integer types */
823a79ea54Sshatty#define INT_LEAST8_MIN  	INT8_MIN
833a79ea54Sshatty#define INT_LEAST8_MAX  	INT8_MAX
843a79ea54Sshatty#define UINT_LEAST8_MAX 	UINT8_MAX
8599a35090Sshatty
863a79ea54Sshatty#define INT_LEAST16_MIN 	INT16_MIN
873a79ea54Sshatty#define INT_LEAST16_MAX 	INT16_MAX
883a79ea54Sshatty#define UINT_LEAST16_MAX	UINT16_MAX
8999a35090Sshatty
903a79ea54Sshatty#define INT_LEAST32_MIN 	INT32_MIN
913a79ea54Sshatty#define INT_LEAST32_MAX 	INT32_MAX
923a79ea54Sshatty#define UINT_LEAST32_MAX	UINT32_MAX
9399a35090Sshatty
943a79ea54Sshatty#define INT_LEAST64_MIN 	INT64_MIN
953a79ea54Sshatty#define INT_LEAST64_MAX 	INT64_MAX
963a79ea54Sshatty#define UINT_LEAST64_MAX	UINT64_MAX
973a79ea54Sshatty
9822611e78SIngo Weinhold/* Limits of fastest minimum-width integer types */
993a79ea54Sshatty#define INT_FAST8_MIN  	INT8_MIN
1003a79ea54Sshatty#define INT_FAST8_MAX  	INT8_MAX
1013a79ea54Sshatty#define UINT_FAST8_MAX 	UINT8_MAX
10299a35090Sshatty
1033a79ea54Sshatty#define INT_FAST16_MIN 	INT16_MIN
1043a79ea54Sshatty#define INT_FAST16_MAX 	INT16_MAX
1053a79ea54Sshatty#define UINT_FAST16_MAX	UINT16_MAX
10699a35090Sshatty
1073a79ea54Sshatty#define INT_FAST32_MIN 	INT32_MIN
1083a79ea54Sshatty#define INT_FAST32_MAX 	INT32_MAX
1093a79ea54Sshatty#define UINT_FAST32_MAX	UINT32_MAX
11099a35090Sshatty
1113a79ea54Sshatty#define INT_FAST64_MIN 	INT64_MIN
1123a79ea54Sshatty#define INT_FAST64_MAX 	INT64_MAX
1133a79ea54Sshatty#define UINT_FAST64_MAX	UINT64_MAX
114f8fdd89fSAxel Dörfler
11522611e78SIngo Weinhold/* Limits of Integer types capable of holding object pointers */
1162222d055SIngo Weinhold#define INTPTR_MIN	__HAIKU_SADDR_MIN
1172222d055SIngo Weinhold#define INTPTR_MAX	__HAIKU_SADDR_MAX
1182222d055SIngo Weinhold#define UINTPTR_MAX	__HAIKU_ADDR_MAX
119c6544683SAxel Dörfler
12022611e78SIngo Weinhold/* Limits of Greatest-width integer types */
121c6544683SAxel Dörfler#define INTMAX_MIN	INT64_MIN
122c6544683SAxel Dörfler#define INTMAX_MAX	INT64_MAX
123c6544683SAxel Dörfler#define UINTMAX_MAX	UINT64_MAX
124c6544683SAxel Dörfler
12522611e78SIngo Weinhold/* Limits of other integer types */
1268d250951SAdrien Destugues#define PTRDIFF_MIN __HAIKU_SADDR_MIN
1278d250951SAdrien Destugues#define PTRDIFF_MAX __HAIKU_SADDR_MAX
12822611e78SIngo Weinhold
12922611e78SIngo Weinhold#define SIG_ATOMIC_MIN INT32_MIN
13022611e78SIngo Weinhold#define SIG_ATOMIC_MAX INT32_MAX
131c6544683SAxel Dörfler
1322222d055SIngo Weinhold#define SIZE_MAX 	__HAIKU_ADDR_MAX
133b3918e2fSJérôme Duval
13422611e78SIngo Weinhold#define WINT_MIN 	0
13522611e78SIngo Weinhold#define WINT_MAX 	((wint_t)-1)
136c6544683SAxel Dörfler
137c6544683SAxel Dörfler
138b9320128SIngo Weinhold/* Macros of Integer Constant Expressions */
13922611e78SIngo Weinhold#define INT8_C(value) 	value
14022611e78SIngo Weinhold#define INT16_C(value) 	value
14122611e78SIngo Weinhold#define INT32_C(value) 	value
14222611e78SIngo Weinhold
14322611e78SIngo Weinhold#define UINT8_C(value) 	value ## U
14422611e78SIngo Weinhold#define UINT16_C(value) value ## U
14522611e78SIngo Weinhold#define UINT32_C(value) value ## U
14622611e78SIngo Weinhold
147122d1cddSAlexander von Gluck IV#if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ > 4
148122d1cddSAlexander von Gluck IV#define INT64_C(value)		value ## L
149122d1cddSAlexander von Gluck IV#define UINT64_C(value) 	value ## UL
150122d1cddSAlexander von Gluck IV#define INTMAX_C(value) 	value ## L
151122d1cddSAlexander von Gluck IV#define UINTMAX_C(value)	value ## UL
152122d1cddSAlexander von Gluck IV#else
153122d1cddSAlexander von Gluck IV#define INT64_C(value) 		value ## LL
154122d1cddSAlexander von Gluck IV#define UINT64_C(value) 	value ## ULL
15522611e78SIngo Weinhold#define INTMAX_C(value) 	value ## LL
156122d1cddSAlexander von Gluck IV#define UINTMAX_C(value)	value ## ULL
157122d1cddSAlexander von Gluck IV#endif
15822611e78SIngo Weinhold
15922611e78SIngo Weinhold
16022611e78SIngo Weinhold/* BSD compatibility */
161f8fdd89fSAxel Dörflertypedef uint8_t u_int8_t;
162f8fdd89fSAxel Dörflertypedef uint16_t u_int16_t;
163f8fdd89fSAxel Dörflertypedef uint32_t u_int32_t;
164f8fdd89fSAxel Dörflertypedef uint64_t u_int64_t;
165f8fdd89fSAxel Dörfler
1662222d055SIngo Weinhold
167f8fdd89fSAxel Dörfler#endif	/* _STDINT_H_ */
168