5219
|
1 /* Copyright (C) 2001-2002, 2004 Free Software Foundation, Inc. |
|
2 Written by Bruno Haible, Sam Steingold, Peter Burwood. |
|
3 This file is part of gnulib. |
|
4 |
|
5 This program is free software; you can redistribute it and/or modify |
|
6 it under the terms of the GNU General Public License as published by |
|
7 the Free Software Foundation; either version 2, or (at your option) |
|
8 any later version. |
|
9 |
|
10 This program is distributed in the hope that it will be useful, |
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 GNU General Public License for more details. |
|
14 |
|
15 You should have received a copy of the GNU General Public License |
|
16 along with this program; if not, write to the Free Software Foundation, |
|
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
|
18 |
|
19 #ifndef _STDINT_H |
|
20 #define _STDINT_H |
|
21 |
|
22 /* |
|
23 * ISO C 99 <stdint.h> for platforms that lack it. |
|
24 * <http://www.opengroup.org/onlinepubs/007904975/basedefs/stdint.h.html> |
|
25 */ |
|
26 |
|
27 /* Get wchar_t, WCHAR_MIN, WCHAR_MAX. */ |
|
28 #include <stddef.h> |
|
29 /* Get CHAR_BIT, LONG_MIN, LONG_MAX, ULONG_MAX. */ |
|
30 #include <limits.h> |
|
31 |
|
32 /* Get those types that are already defined in other system include files. */ |
|
33 #if defined(__FreeBSD__) |
|
34 # include <sys/inttypes.h> |
|
35 #endif |
|
36 #if defined(__sun) && HAVE_SYS_INTTYPES_H |
|
37 # include <sys/inttypes.h> |
|
38 /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and |
|
39 the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. |
|
40 But note that <sys/int_types.h> contains only the type definitions! */ |
|
41 # define HAVE_SYSTEM_INTTYPES |
|
42 #endif |
|
43 #if (defined(__hpux) || defined(_AIX)) && HAVE_INTTYPES_H |
|
44 # include <inttypes.h> |
|
45 /* HP-UX 10 <inttypes.h> has nearly everything, except UINT_LEAST8_MAX, |
|
46 UINT_FAST8_MAX, PTRDIFF_MIN, PTRDIFF_MAX. */ |
|
47 /* AIX 4 <inttypes.h> has nearly everything, except INTPTR_MIN, INTPTR_MAX, |
|
48 UINTPTR_MAX, PTRDIFF_MIN, PTRDIFF_MAX. */ |
|
49 # define HAVE_SYSTEM_INTTYPES |
|
50 #endif |
|
51 #if !(defined(UNIX_CYGWIN32) && defined(__BIT_TYPES_DEFINED__)) |
|
52 # define NEED_SIGNED_INT_TYPES |
|
53 #endif |
|
54 |
|
55 #if !defined(HAVE_SYSTEM_INTTYPES) |
|
56 |
|
57 /* 7.18.1.1. Exact-width integer types */ |
|
58 |
|
59 #if !defined(__FreeBSD__) |
|
60 |
|
61 #ifdef NEED_SIGNED_INT_TYPES |
|
62 typedef signed char int8_t; |
|
63 #endif |
|
64 typedef unsigned char uint8_t; |
|
65 |
|
66 #ifdef NEED_SIGNED_INT_TYPES |
|
67 typedef short int16_t; |
|
68 #endif |
|
69 typedef unsigned short uint16_t; |
|
70 |
|
71 #ifdef NEED_SIGNED_INT_TYPES |
|
72 typedef int int32_t; |
|
73 #endif |
|
74 typedef unsigned int uint32_t; |
|
75 |
|
76 #if @HAVE_LONG_64BIT@ |
|
77 #ifdef NEED_SIGNED_INT_TYPES |
|
78 typedef long int64_t; |
|
79 #endif |
|
80 typedef unsigned long uint64_t; |
|
81 #elif @HAVE_LONGLONG_64BIT@ |
|
82 #ifdef NEED_SIGNED_INT_TYPES |
|
83 typedef long long int64_t; |
|
84 #endif |
|
85 typedef unsigned long long uint64_t; |
|
86 #endif |
|
87 |
|
88 #endif /* !FreeBSD */ |
|
89 |
|
90 /* 7.18.1.2. Minimum-width integer types */ |
|
91 |
|
92 typedef int8_t int_least8_t; |
|
93 typedef uint8_t uint_least8_t; |
|
94 typedef int16_t int_least16_t; |
|
95 typedef uint16_t uint_least16_t; |
|
96 typedef int32_t int_least32_t; |
|
97 typedef uint32_t uint_least32_t; |
|
98 #if @HAVE_LONG_64BIT@ || @HAVE_LONGLONG_64BIT@ |
|
99 typedef int64_t int_least64_t; |
|
100 typedef uint64_t uint_least64_t; |
|
101 #endif |
|
102 |
|
103 /* 7.18.1.3. Fastest minimum-width integer types */ |
|
104 |
|
105 typedef int32_t int_fast8_t; |
|
106 typedef uint32_t uint_fast8_t; |
|
107 typedef int32_t int_fast16_t; |
|
108 typedef uint32_t uint_fast16_t; |
|
109 typedef int32_t int_fast32_t; |
|
110 typedef uint32_t uint_fast32_t; |
|
111 #if @HAVE_LONG_64BIT@ || @HAVE_LONGLONG_64BIT@ |
|
112 typedef int64_t int_fast64_t; |
|
113 typedef uint64_t uint_fast64_t; |
|
114 #endif |
|
115 |
|
116 /* 7.18.1.4. Integer types capable of holding object pointers */ |
|
117 |
|
118 #if !defined(__FreeBSD__) |
|
119 |
|
120 /* On some platforms (like IRIX6 MIPS with -n32) sizeof(void*) < sizeof(long), |
|
121 but this doesn't matter here. */ |
|
122 typedef long intptr_t; |
|
123 typedef unsigned long uintptr_t; |
|
124 |
|
125 #endif /* !FreeBSD */ |
|
126 |
|
127 /* 7.18.1.5. Greatest-width integer types */ |
|
128 |
|
129 #if @HAVE_LONG_64BIT@ || @HAVE_LONGLONG_64BIT@ |
|
130 typedef int64_t intmax_t; |
|
131 typedef uint64_t uintmax_t; |
|
132 #else |
|
133 typedef int32_t intmax_t; |
|
134 typedef uint32_t uintmax_t; |
|
135 #endif |
|
136 |
|
137 /* 7.18.2. Limits of specified-width integer types */ |
|
138 |
|
139 #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) |
|
140 |
|
141 /* 7.18.2.1. Limits of exact-width integer types */ |
|
142 |
|
143 #define INT8_MIN -128 |
|
144 #define INT8_MAX 127 |
|
145 #define UINT8_MAX 255U |
|
146 #define INT16_MIN -32768 |
|
147 #define INT16_MAX 32767 |
|
148 #define UINT16_MAX 65535U |
|
149 #define INT32_MIN (~INT32_MAX) |
|
150 #define INT32_MAX 2147483647 |
|
151 #define UINT32_MAX 4294967295U |
|
152 #if @HAVE_LONG_64BIT@ |
|
153 #define INT64_MIN (~INT64_MIN) |
|
154 #define INT64_MAX 9223372036854775807L |
|
155 #define UINT64_MAX 18446744073709551615UL |
|
156 #elif @HAVE_LONGLONG_64BIT@ |
|
157 #define INT64_MIN (~INT64_MIN) |
|
158 #define INT64_MAX 9223372036854775807LL |
|
159 #define UINT64_MAX 18446744073709551615ULL |
|
160 #endif |
|
161 |
|
162 /* 7.18.2.2. Limits of minimum-width integer types */ |
|
163 |
|
164 #define INT_LEAST8_MIN INT8_MIN |
|
165 #define INT_LEAST8_MAX INT8_MAX |
|
166 #define UINT_LEAST8_MAX UINT8_MAX |
|
167 #define INT_LEAST16_MIN INT16_MIN |
|
168 #define INT_LEAST16_MAX INT16_MAX |
|
169 #define UINT_LEAST16_MAX UINT16_MAX |
|
170 #define INT_LEAST32_MIN INT32_MIN |
|
171 #define INT_LEAST32_MAX INT32_MAX |
|
172 #define UINT_LEAST32_MAX UINT32_MAX |
|
173 #if @HAVE_LONG_64BIT@ || @HAVE_LONGLONG_64BIT@ |
|
174 #define INT_LEAST64_MIN INT64_MIN |
|
175 #define INT_LEAST64_MAX INT64_MAX |
|
176 #define UINT_LEAST64_MAX UINT64_MAX |
|
177 #endif |
|
178 |
|
179 /* 7.18.2.3. Limits of fastest minimum-width integer types */ |
|
180 |
|
181 #define INT_FAST8_MIN INT32_MIN |
|
182 #define INT_FAST8_MAX INT32_MAX |
|
183 #define UINT_FAST8_MAX UINT32_MAX |
|
184 #define INT_FAST16_MIN INT32_MIN |
|
185 #define INT_FAST16_MAX INT32_MAX |
|
186 #define UINT_FAST16_MAX UINT32_MAX |
|
187 #define INT_FAST32_MIN INT32_MIN |
|
188 #define INT_FAST32_MAX INT32_MAX |
|
189 #define UINT_FAST32_MAX UINT32_MAX |
|
190 #if @HAVE_LONG_64BIT@ || @HAVE_LONGLONG_64BIT@ |
|
191 #define INT_FAST64_MIN INT64_MIN |
|
192 #define INT_FAST64_MAX INT64_MAX |
|
193 #define UINT_FAST64_MAX UINT64_MAX |
|
194 #endif |
|
195 |
|
196 /* 7.18.2.4. Limits of integer types capable of holding object pointers */ |
|
197 |
|
198 #define INTPTR_MIN LONG_MIN |
|
199 #define INTPTR_MAX LONG_MAX |
|
200 #define UINTPTR_MAX ULONG_MAX |
|
201 |
|
202 /* 7.18.2.5. Limits of greatest-width integer types */ |
|
203 |
|
204 #if @HAVE_LONG_64BIT@ || @HAVE_LONGLONG_64BIT@ |
|
205 #define INTMAX_MIN INT64_MIN |
|
206 #define INTMAX_MAX INT64_MAX |
|
207 #define UINTMAX_MAX UINT64_MAX |
|
208 #else |
|
209 #define INTMAX_MIN INT32_MIN |
|
210 #define INTMAX_MAX INT32_MAX |
|
211 #define UINTMAX_MAX UINT32_MAX |
|
212 #endif |
|
213 |
|
214 /* 7.18.3. Limits of other integer types */ |
|
215 |
|
216 #define PTRDIFF_MIN (~(ptrdiff_t)0 << (sizeof(ptrdiff_t)*CHAR_BIT-1)) |
|
217 #define PTRDIFF_MAX (~PTRDIFF_MIN) |
|
218 |
|
219 /* This may be wrong... */ |
|
220 #define SIG_ATOMIC_MIN 0 |
|
221 #define SIG_ATOMIC_MAX 127 |
|
222 |
|
223 #define SIZE_MAX (~(size_t)0) |
|
224 |
|
225 /* wchar_t limits already defined in <stddef.h>. */ |
|
226 /* wint_t limits already defined in <wchar.h>. */ |
|
227 |
|
228 #endif |
|
229 |
|
230 /* 7.18.4. Macros for integer constants */ |
|
231 |
|
232 #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) |
|
233 |
|
234 /* 7.18.4.1. Macros for minimum-width integer constants */ |
|
235 |
|
236 #define INT8_C(x) x |
|
237 #define UINT8_C(x) x##U |
|
238 #define INT16_C(x) x |
|
239 #define UINT16_C(x) x##U |
|
240 #define INT32_C(x) x |
|
241 #define UINT32_C(x) x##U |
|
242 #if @HAVE_LONG_64BIT@ |
|
243 #define INT64_C(x) x##L |
|
244 #define UINT64_C(x) x##UL |
|
245 #elif @HAVE_LONGLONG_64BIT@ |
|
246 #define INT64_C(x) x##LL |
|
247 #define UINT64_C(x) x##ULL |
|
248 #endif |
|
249 |
|
250 /* 7.18.4.2. Macros for greatest-width integer constants */ |
|
251 |
|
252 #if @HAVE_LONG_64BIT@ |
|
253 #define INTMAX_C(x) x##L |
|
254 #define UINTMAX_C(x) x##UL |
|
255 #elif @HAVE_LONGLONG_64BIT@ |
|
256 #define INTMAX_C(x) x##LL |
|
257 #define UINTMAX_C(x) x##ULL |
|
258 #else |
|
259 #define INTMAX_C(x) x |
|
260 #define UINTMAX_C(x) x##U |
|
261 #endif |
|
262 |
|
263 #endif |
|
264 |
|
265 #endif /* !HAVE_SYSTEM_INTTYPES */ |
|
266 |
|
267 #endif /* _STDINT_H */ |