1 /* $MirOS: src/include/stdint.h,v 1.8 2014/02/09 16:15:31 tg Exp $ */
2 
3 /*-
4  * "minimal" replacement for ISO C99 "stdint.h" header file (not com-
5  * plete yet, but pretty near, with some ISO C11 sprinkled in for fun
6  */
7 
8 #ifndef	_STDINT_H
9 #define	_STDINT_H
10 
11 /* get {,u,u_}int8_t definitions and stuff */
12 
13 #include <machine/types.h>
14 
15 /* define extended integer types to be the same as basic ones for now */
16 
17 typedef	int8_t		int_least8_t;
18 typedef	int16_t		int_least16_t;
19 typedef	int32_t		int_least32_t;
20 typedef	int64_t		int_least64_t;
21 typedef	uint8_t		uint_least8_t;
22 typedef	uint16_t	uint_least16_t;
23 typedef	uint32_t	uint_least32_t;
24 typedef	uint64_t	uint_least64_t;
25 
26 typedef	int8_t		int_fast8_t;		/* probably int? */
27 typedef	int16_t		int_fast16_t;		/* probably int? */
28 typedef	int32_t		int_fast32_t;
29 typedef	int64_t		int_fast64_t;
30 typedef	uint8_t		uint_fast8_t;		/* probably unsigned? */
31 typedef	uint16_t	uint_fast16_t;		/* probably unsigned? */
32 typedef	uint32_t	uint_fast32_t;
33 typedef	uint64_t	uint_fast64_t;
34 
35 /* we don't have 128 bits yet ;-) */
36 
37 typedef	int64_t		intmax_t;
38 typedef	uint64_t	uintmax_t;
39 
40 
41 #if (!defined(__cplusplus)) || defined(__STDC_LIMIT_MACROS)
42 
43 /* basic types */
44 
45 #define	INT8_MIN	(-0x7F-1)
46 #define	INT8_MAX	0x7F
47 #define	UINT8_MAX	0xFFU
48 
49 #define	INT16_MIN	(-0x7FFF-1)
50 #define	INT16_MAX	0x7FFF
51 #define	UINT16_MAX	0xFFFFU
52 
53 #define	INT32_MIN	(-0x7FFFFFFFL-1)
54 #define	INT32_MAX	0x7FFFFFFFL
55 #define	UINT32_MAX	0xFFFFFFFFUL
56 
57 #define	INT64_MIN	(-0x7FFFFFFFFFFFFFFFLL-1)
58 #define	INT64_MAX	0x7FFFFFFFFFFFFFFFLL
59 #define	UINT64_MAX	0xFFFFFFFFFFFFFFFFULL
60 
61 /* minimum types - same as basic types for now */
62 
63 #define	INT_LEAST8_MIN		INT8_MIN
64 #define	INT_LEAST8_MAX		INT8_MAX
65 #define	UINT_LEAST8_MAX		UINT8_MAX
66 
67 #define	INT_LEAST16_MIN		INT16_MIN
68 #define	INT_LEAST16_MAX		INT16_MAX
69 #define	UINT_LEAST16_MAX	UINT16_MAX
70 
71 #define	INT_LEAST32_MIN		INT32_MIN
72 #define	INT_LEAST32_MAX		INT32_MAX
73 #define	UINT_LEAST32_MAX	UINT32_MAX
74 
75 #define	INT_LEAST64_MIN		INT64_MIN
76 #define	INT_LEAST64_MAX		INT64_MAX
77 #define	UINT_LEAST64_MAX	UINT64_MAX
78 
79 /* fastest types - same as basic types for now */
80 
81 #define	INT_FAST8_MIN		INT8_MIN
82 #define	INT_FAST8_MAX		INT8_MAX
83 #define	UINT_FAST8_MAX		UINT8_MAX
84 
85 #define	INT_FAST16_MIN		INT16_MIN
86 #define	INT_FAST16_MAX		INT16_MAX
87 #define	UINT_FAST16_MAX		UINT16_MAX
88 
89 #define	INT_FAST32_MIN		INT32_MIN
90 #define	INT_FAST32_MAX		INT32_MAX
91 #define	UINT_FAST32_MAX		UINT32_MAX
92 
93 #define	INT_FAST64_MIN		INT64_MIN
94 #define	INT_FAST64_MAX		INT64_MAX
95 #define	UINT_FAST64_MAX		UINT64_MAX
96 
97 /* pointer types - machdep */
98 
99 #ifdef	__LP64__
100 #define	INTPTR_MIN		INT64_MIN
101 #define	INTPTR_MAX		INT64_MAX
102 #define	UINTPTR_MAX		UINT64_MAX
103 #else
104 #define	INTPTR_MIN		INT32_MIN
105 #define	INTPTR_MAX		INT32_MAX
106 #define	UINTPTR_MAX		UINT32_MAX
107 #endif
108 
109 /* largest integer - 64 bit for now */
110 
111 #define	INTMAX_MIN		INT64_MIN
112 #define	INTMAX_MAX		INT64_MAX
113 #define	UINTMAX_MAX		UINT64_MAX
114 
115 /* misc. types */
116 
117 /* ptrdiff_t is a signed intptr_t */
118 #define	PTRDIFF_MIN		INTPTR_MIN
119 #define	PTRDIFF_MAX		INTPTR_MAX
120 
121 /* sig_atomic_t is an int */
122 #define	SIG_ATOMIC_MIN		INT32_MIN
123 #define	SIG_ATOMIC_MAX		INT32_MAX
124 
125 #ifndef SIZE_MAX
126 /* size_t is the same as an uintptr_t */
127 #define	SIZE_MAX		UINTPTR_MAX
128 #endif
129 #ifndef SSIZE_MAX
130 /* ssize_t is the same as an intptr_t */
131 #define	SSIZE_MAX		INTPTR_MAX
132 #endif
133 
134 /* C11 optional */
135 #if !defined(__STDC_WANT_LIB_EXT1__) || (__STDC_WANT_LIB_EXT1__)
136 #define RSIZE_MAX		(SIZE_MAX >> 1)
137 #endif /* __STDC_WANT_LIB_EXT1__ */
138 
139 /* wchar_t is an unsigned short */
140 #define	WCHAR_MIN		0
141 #define	WCHAR_MAX		0xFFFDU		/* match <wchar.h> */
142 #define	WINT_MIN		INT32_MIN
143 #define	WINT_MAX		INT32_MAX
144 
145 #endif	/* ndef C++ or def __STDC_LIMIT_MACROS */
146 
147 
148 /* Apple says when to not define these */
149 
150 #if (!defined(__cplusplus)) || defined(__STDC_CONSTANT_MACROS)
151 
152 #define	INT8_C(x)	((int8_t)x)
153 #define	INT16_C(x)	((int16_t)x)
154 #define	INT32_C(x)	(x ## L)
155 #define	INT64_C(x)	(x ## LL)
156 
157 #define	UINT8_C(x)	((uint8_t)x)
158 #define	UINT16_C(x)	((uint16_t)x)
159 #define	UINT32_C(x)	(x ## UL)
160 #define	UINT64_C(x)	(x ## ULL)
161 
162 #define	INTMAX_C(x)	(x ## LL)
163 #define	UINTMAX_C(x)	(x ## ULL)
164 
165 #endif	/* ndef C++ or def __STDC_CONSTANT_MACROS */
166 
167 #endif	/* ndef _STDINT_H */
168