]> sourceware.org Git - newlib-cygwin.git/blame - newlib/libc/include/stdint.h
Cygwin: console: Fix clean up conditions in close()
[newlib-cygwin.git] / newlib / libc / include / stdint.h
CommitLineData
df5a5b35
JJ
1/*
2 * Copyright (c) 2004, 2005 by
3 * Ralf Corsepius, Ulm/Germany. All rights reserved.
4 *
5 * Permission to use, copy, modify, and distribute this software
6 * is freely granted, provided that this notice is preserved.
7 */
8
df5a5b35
JJ
9#ifndef _STDINT_H
10#define _STDINT_H
11
9bd3bcc6 12#include <machine/_default_types.h>
50f79924 13#include <sys/_intsup.h>
897d3a3c 14#include <sys/_stdint.h>
5eceb395 15
df5a5b35
JJ
16#ifdef __cplusplus
17extern "C" {
18#endif
19
9bd3bcc6
CV
20#ifdef ___int_least8_t_defined
21typedef __int_least8_t int_least8_t;
22typedef __uint_least8_t uint_least8_t;
df5a5b35
JJ
23#define __int_least8_t_defined 1
24#endif
25
9bd3bcc6
CV
26#ifdef ___int_least16_t_defined
27typedef __int_least16_t int_least16_t;
28typedef __uint_least16_t uint_least16_t;
df5a5b35 29#define __int_least16_t_defined 1
df5a5b35
JJ
30#endif
31
9bd3bcc6
CV
32#ifdef ___int_least32_t_defined
33typedef __int_least32_t int_least32_t;
34typedef __uint_least32_t uint_least32_t;
df5a5b35 35#define __int_least32_t_defined 1
df5a5b35
JJ
36#endif
37
9bd3bcc6
CV
38#ifdef ___int_least64_t_defined
39typedef __int_least64_t int_least64_t;
40typedef __uint_least64_t uint_least64_t;
df5a5b35 41#define __int_least64_t_defined 1
df5a5b35
JJ
42#endif
43
bc037f3a
JJ
44/*
45 * Fastest minimum-width integer types
46 *
47 * Assume int to be the fastest type for all types with a width
48 * less than __INT_MAX__ rsp. INT_MAX
49 */
9bd3bcc6
CV
50#ifdef __INT_FAST8_TYPE__
51 typedef __INT_FAST8_TYPE__ int_fast8_t;
52 typedef __UINT_FAST8_TYPE__ uint_fast8_t;
53#define __int_fast8_t_defined 1
54#elif __STDINT_EXP(INT_MAX) >= 0x7f
bc037f3a
JJ
55 typedef signed int int_fast8_t;
56 typedef unsigned int uint_fast8_t;
57#define __int_fast8_t_defined 1
58#endif
59
9bd3bcc6
CV
60#ifdef __INT_FAST16_TYPE__
61 typedef __INT_FAST16_TYPE__ int_fast16_t;
62 typedef __UINT_FAST16_TYPE__ uint_fast16_t;
63#define __int_fast16_t_defined 1
64#elif __STDINT_EXP(INT_MAX) >= 0x7fff
bc037f3a
JJ
65 typedef signed int int_fast16_t;
66 typedef unsigned int uint_fast16_t;
67#define __int_fast16_t_defined 1
68#endif
69
9bd3bcc6
CV
70#ifdef __INT_FAST32_TYPE__
71 typedef __INT_FAST32_TYPE__ int_fast32_t;
72 typedef __UINT_FAST32_TYPE__ uint_fast32_t;
73#define __int_fast32_t_defined 1
74#elif __STDINT_EXP(INT_MAX) >= 0x7fffffff
bc037f3a
JJ
75 typedef signed int int_fast32_t;
76 typedef unsigned int uint_fast32_t;
77#define __int_fast32_t_defined 1
78#endif
79
9bd3bcc6
CV
80#ifdef __INT_FAST64_TYPE__
81 typedef __INT_FAST64_TYPE__ int_fast64_t;
82 typedef __UINT_FAST64_TYPE__ uint_fast64_t;
83#define __int_fast64_t_defined 1
84#elif __STDINT_EXP(INT_MAX) > 0x7fffffff
bc037f3a
JJ
85 typedef signed int int_fast64_t;
86 typedef unsigned int uint_fast64_t;
87#define __int_fast64_t_defined 1
88#endif
89
90/*
91 * Fall back to [u]int_least<N>_t for [u]int_fast<N>_t types
92 * not having been defined, yet.
93 * Leave undefined, if [u]int_least<N>_t should not be available.
94 */
95#if !__int_fast8_t_defined
96#if __int_least8_t_defined
97 typedef int_least8_t int_fast8_t;
98 typedef uint_least8_t uint_fast8_t;
99#define __int_fast8_t_defined 1
100#endif
101#endif
102
103#if !__int_fast16_t_defined
104#if __int_least16_t_defined
105 typedef int_least16_t int_fast16_t;
106 typedef uint_least16_t uint_fast16_t;
107#define __int_fast16_t_defined 1
108#endif
109#endif
110
111#if !__int_fast32_t_defined
112#if __int_least32_t_defined
113 typedef int_least32_t int_fast32_t;
114 typedef uint_least32_t uint_fast32_t;
115#define __int_fast32_t_defined 1
116#endif
117#endif
118
119#if !__int_fast64_t_defined
120#if __int_least64_t_defined
121 typedef int_least64_t int_fast64_t;
122 typedef uint_least64_t uint_fast64_t;
123#define __int_fast64_t_defined 1
124#endif
125#endif
126
9bd3bcc6
CV
127#ifdef __INTPTR_TYPE__
128#define INTPTR_MIN (-__INTPTR_MAX__ - 1)
50adb19f
CV
129#define INTPTR_MAX (__INTPTR_MAX__)
130#define UINTPTR_MAX (__UINTPTR_MAX__)
9bd3bcc6 131#elif defined(__PTRDIFF_TYPE__)
34c5e58e
JJ
132#define INTPTR_MAX PTRDIFF_MAX
133#define INTPTR_MIN PTRDIFF_MIN
de194872 134#ifdef __UINTPTR_MAX__
50adb19f 135#define UINTPTR_MAX (__UINTPTR_MAX__)
de194872 136#else
34c5e58e 137#define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1)
de194872 138#endif
df5a5b35
JJ
139#else
140/*
141 * Fallback to hardcoded values,
142 * should be valid on cpu's with 32bit int/32bit void*
143 */
50adb19f 144#define INTPTR_MAX (__STDINT_EXP(LONG_MAX))
34c5e58e
JJ
145#define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1)
146#define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
df5a5b35
JJ
147#endif
148
149/* Limits of Specified-Width Integer Types */
150
9bd3bcc6
CV
151#ifdef __INT8_MAX__
152#define INT8_MIN (-__INT8_MAX__ - 1)
50adb19f
CV
153#define INT8_MAX (__INT8_MAX__)
154#define UINT8_MAX (__UINT8_MAX__)
9bd3bcc6 155#elif defined(__int8_t_defined)
50adb19f
CV
156#define INT8_MIN (-128)
157#define INT8_MAX (127)
158#define UINT8_MAX (255)
df5a5b35
JJ
159#endif
160
9bd3bcc6
CV
161#ifdef __INT_LEAST8_MAX__
162#define INT_LEAST8_MIN (-__INT_LEAST8_MAX__ - 1)
50adb19f
CV
163#define INT_LEAST8_MAX (__INT_LEAST8_MAX__)
164#define UINT_LEAST8_MAX (__UINT_LEAST8_MAX__)
9bd3bcc6 165#elif defined(__int_least8_t_defined)
50adb19f
CV
166#define INT_LEAST8_MIN (-128)
167#define INT_LEAST8_MAX (127)
168#define UINT_LEAST8_MAX (255)
df5a5b35
JJ
169#else
170#error required type int_least8_t missing
171#endif
172
9bd3bcc6
CV
173#ifdef __INT16_MAX__
174#define INT16_MIN (-__INT16_MAX__ - 1)
50adb19f
CV
175#define INT16_MAX (__INT16_MAX__)
176#define UINT16_MAX (__UINT16_MAX__)
9bd3bcc6 177#elif defined(__int16_t_defined)
50adb19f
CV
178#define INT16_MIN (-32768)
179#define INT16_MAX (32767)
180#define UINT16_MAX (65535)
df5a5b35
JJ
181#endif
182
9bd3bcc6
CV
183#ifdef __INT_LEAST16_MAX__
184#define INT_LEAST16_MIN (-__INT_LEAST16_MAX__ - 1)
50adb19f
CV
185#define INT_LEAST16_MAX (__INT_LEAST16_MAX__)
186#define UINT_LEAST16_MAX (__UINT_LEAST16_MAX__)
9bd3bcc6 187#elif defined(__int_least16_t_defined)
50adb19f
CV
188#define INT_LEAST16_MIN (-32768)
189#define INT_LEAST16_MAX (32767)
190#define UINT_LEAST16_MAX (65535)
df5a5b35
JJ
191#else
192#error required type int_least16_t missing
193#endif
194
9bd3bcc6
CV
195#ifdef __INT32_MAX__
196#define INT32_MIN (-__INT32_MAX__ - 1)
50adb19f
CV
197#define INT32_MAX (__INT32_MAX__)
198#define UINT32_MAX (__UINT32_MAX__)
9bd3bcc6 199#elif defined(__int32_t_defined)
6109eadf 200#if defined (_INT32_EQ_LONG)
11a985e0 201#define INT32_MIN (-2147483647L-1)
50adb19f
CV
202#define INT32_MAX (2147483647L)
203#define UINT32_MAX (4294967295UL)
11a985e0 204#else
0ce4fcef 205#define INT32_MIN (-2147483647-1)
50adb19f
CV
206#define INT32_MAX (2147483647)
207#define UINT32_MAX (4294967295U)
df5a5b35 208#endif
11a985e0 209#endif
df5a5b35 210
9bd3bcc6
CV
211#ifdef __INT_LEAST32_MAX__
212#define INT_LEAST32_MIN (-__INT_LEAST32_MAX__ - 1)
50adb19f
CV
213#define INT_LEAST32_MAX (__INT_LEAST32_MAX__)
214#define UINT_LEAST32_MAX (__UINT_LEAST32_MAX__)
9bd3bcc6 215#elif defined(__int_least32_t_defined)
6109eadf 216#if defined (_INT32_EQ_LONG)
11a985e0 217#define INT_LEAST32_MIN (-2147483647L-1)
50adb19f
CV
218#define INT_LEAST32_MAX (2147483647L)
219#define UINT_LEAST32_MAX (4294967295UL)
11a985e0 220#else
0ce4fcef 221#define INT_LEAST32_MIN (-2147483647-1)
50adb19f
CV
222#define INT_LEAST32_MAX (2147483647)
223#define UINT_LEAST32_MAX (4294967295U)
11a985e0 224#endif
df5a5b35
JJ
225#else
226#error required type int_least32_t missing
227#endif
228
9bd3bcc6
CV
229#ifdef __INT64_MAX__
230#define INT64_MIN (-__INT64_MAX__ - 1)
50adb19f
CV
231#define INT64_MAX (__INT64_MAX__)
232#define UINT64_MAX (__UINT64_MAX__)
9bd3bcc6 233#elif defined(__int64_t_defined)
71ac53ee 234#if __have_long64
0ce4fcef 235#define INT64_MIN (-9223372036854775807L-1L)
50adb19f
CV
236#define INT64_MAX (9223372036854775807L)
237#define UINT64_MAX (18446744073709551615U)
c7e20979 238#elif __have_longlong64
0ce4fcef 239#define INT64_MIN (-9223372036854775807LL-1LL)
50adb19f
CV
240#define INT64_MAX (9223372036854775807LL)
241#define UINT64_MAX (18446744073709551615ULL)
0ce4fcef 242#endif
df5a5b35
JJ
243#endif
244
9bd3bcc6
CV
245#ifdef __INT_LEAST64_MAX__
246#define INT_LEAST64_MIN (-__INT_LEAST64_MAX__ - 1)
50adb19f
CV
247#define INT_LEAST64_MAX (__INT_LEAST64_MAX__)
248#define UINT_LEAST64_MAX (__UINT_LEAST64_MAX__)
9bd3bcc6 249#elif defined(__int_least64_t_defined)
71ac53ee 250#if __have_long64
0ce4fcef 251#define INT_LEAST64_MIN (-9223372036854775807L-1L)
50adb19f
CV
252#define INT_LEAST64_MAX (9223372036854775807L)
253#define UINT_LEAST64_MAX (18446744073709551615U)
c7e20979 254#elif __have_longlong64
0ce4fcef 255#define INT_LEAST64_MIN (-9223372036854775807LL-1LL)
50adb19f
CV
256#define INT_LEAST64_MAX (9223372036854775807LL)
257#define UINT_LEAST64_MAX (18446744073709551615ULL)
0ce4fcef 258#endif
df5a5b35
JJ
259#endif
260
9bd3bcc6
CV
261#ifdef __INT_FAST8_MAX__
262#define INT_FAST8_MIN (-__INT_FAST8_MAX__ - 1)
50adb19f
CV
263#define INT_FAST8_MAX (__INT_FAST8_MAX__)
264#define UINT_FAST8_MAX (__UINT_FAST8_MAX__)
9bd3bcc6 265#elif defined(__int_fast8_t_defined)
11a985e0
JJ
266#if __STDINT_EXP(INT_MAX) >= 0x7f
267#define INT_FAST8_MIN (-__STDINT_EXP(INT_MAX)-1)
50adb19f 268#define INT_FAST8_MAX (__STDINT_EXP(INT_MAX))
11a985e0
JJ
269#define UINT_FAST8_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
270#else
271#define INT_FAST8_MIN INT_LEAST8_MIN
272#define INT_FAST8_MAX INT_LEAST8_MAX
273#define UINT_FAST8_MAX UINT_LEAST8_MAX
274#endif
bc037f3a
JJ
275#endif
276
9bd3bcc6
CV
277#ifdef __INT_FAST16_MAX__
278#define INT_FAST16_MIN (-__INT_FAST16_MAX__ - 1)
50adb19f
CV
279#define INT_FAST16_MAX (__INT_FAST16_MAX__)
280#define UINT_FAST16_MAX (__UINT_FAST16_MAX__)
9bd3bcc6 281#elif defined(__int_fast16_t_defined)
11a985e0
JJ
282#if __STDINT_EXP(INT_MAX) >= 0x7fff
283#define INT_FAST16_MIN (-__STDINT_EXP(INT_MAX)-1)
50adb19f 284#define INT_FAST16_MAX (__STDINT_EXP(INT_MAX))
11a985e0
JJ
285#define UINT_FAST16_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
286#else
287#define INT_FAST16_MIN INT_LEAST16_MIN
288#define INT_FAST16_MAX INT_LEAST16_MAX
289#define UINT_FAST16_MAX UINT_LEAST16_MAX
290#endif
bc037f3a
JJ
291#endif
292
9bd3bcc6
CV
293#ifdef __INT_FAST32_MAX__
294#define INT_FAST32_MIN (-__INT_FAST32_MAX__ - 1)
50adb19f
CV
295#define INT_FAST32_MAX (__INT_FAST32_MAX__)
296#define UINT_FAST32_MAX (__UINT_FAST32_MAX__)
9bd3bcc6 297#elif defined(__int_fast32_t_defined)
11a985e0
JJ
298#if __STDINT_EXP(INT_MAX) >= 0x7fffffff
299#define INT_FAST32_MIN (-__STDINT_EXP(INT_MAX)-1)
50adb19f 300#define INT_FAST32_MAX (__STDINT_EXP(INT_MAX))
11a985e0
JJ
301#define UINT_FAST32_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
302#else
303#define INT_FAST32_MIN INT_LEAST32_MIN
304#define INT_FAST32_MAX INT_LEAST32_MAX
305#define UINT_FAST32_MAX UINT_LEAST32_MAX
306#endif
bc037f3a
JJ
307#endif
308
9bd3bcc6
CV
309#ifdef __INT_FAST64_MAX__
310#define INT_FAST64_MIN (-__INT_FAST64_MAX__ - 1)
50adb19f
CV
311#define INT_FAST64_MAX (__INT_FAST64_MAX__)
312#define UINT_FAST64_MAX (__UINT_FAST64_MAX__)
9bd3bcc6 313#elif defined(__int_fast64_t_defined)
11a985e0
JJ
314#if __STDINT_EXP(INT_MAX) > 0x7fffffff
315#define INT_FAST64_MIN (-__STDINT_EXP(INT_MAX)-1)
50adb19f 316#define INT_FAST64_MAX (__STDINT_EXP(INT_MAX))
11a985e0
JJ
317#define UINT_FAST64_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
318#else
319#define INT_FAST64_MIN INT_LEAST64_MIN
320#define INT_FAST64_MAX INT_LEAST64_MAX
321#define UINT_FAST64_MAX UINT_LEAST64_MAX
322#endif
323#endif
324
325#ifdef __INTMAX_MAX__
50adb19f 326#define INTMAX_MAX (__INTMAX_MAX__)
11a985e0
JJ
327#define INTMAX_MIN (-INTMAX_MAX - 1)
328#elif defined(__INTMAX_TYPE__)
329/* All relevant GCC versions prefer long to long long for intmax_t. */
330#define INTMAX_MAX INT64_MAX
331#define INTMAX_MIN INT64_MIN
332#endif
333
334#ifdef __UINTMAX_MAX__
50adb19f 335#define UINTMAX_MAX (__UINTMAX_MAX__)
11a985e0
JJ
336#elif defined(__UINTMAX_TYPE__)
337/* All relevant GCC versions prefer long to long long for intmax_t. */
338#define UINTMAX_MAX UINT64_MAX
bc037f3a
JJ
339#endif
340
df5a5b35 341/* This must match size_t in stddef.h, currently long unsigned int */
11a985e0 342#ifdef __SIZE_MAX__
50adb19f 343#define SIZE_MAX (__SIZE_MAX__)
11a985e0 344#else
df93e6f1 345#define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
11a985e0 346#endif
df5a5b35
JJ
347
348/* This must match sig_atomic_t in <signal.h> (currently int) */
0ce4fcef 349#define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1)
50adb19f 350#define SIG_ATOMIC_MAX (__STDINT_EXP(INT_MAX))
df5a5b35
JJ
351
352/* This must match ptrdiff_t in <stddef.h> (currently long int) */
11a985e0 353#ifdef __PTRDIFF_MAX__
50adb19f 354#define PTRDIFF_MAX (__PTRDIFF_MAX__)
11a985e0 355#else
50adb19f 356#define PTRDIFF_MAX (__STDINT_EXP(LONG_MAX))
11a985e0
JJ
357#endif
358#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
359
c57ccec6
CV
360/* This must match definition in <wchar.h> */
361#ifndef WCHAR_MIN
362#ifdef __WCHAR_MIN__
50adb19f 363#define WCHAR_MIN (__WCHAR_MIN__)
c57ccec6
CV
364#elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0)
365#define WCHAR_MIN (0 + L'\0')
366#else
367#define WCHAR_MIN (-0x7fffffff - 1 + L'\0')
368#endif
369#endif
370
371/* This must match definition in <wchar.h> */
372#ifndef WCHAR_MAX
11a985e0 373#ifdef __WCHAR_MAX__
50adb19f 374#define WCHAR_MAX (__WCHAR_MAX__)
c57ccec6
CV
375#elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0)
376#define WCHAR_MAX (0xffffffffu + L'\0')
377#else
378#define WCHAR_MAX (0x7fffffff + L'\0')
11a985e0 379#endif
11a985e0
JJ
380#endif
381
382/* wint_t is unsigned int on almost all GCC targets. */
383#ifdef __WINT_MAX__
50adb19f 384#define WINT_MAX (__WINT_MAX__)
11a985e0
JJ
385#else
386#define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U)
387#endif
388#ifdef __WINT_MIN__
50adb19f 389#define WINT_MIN (__WINT_MIN__)
11a985e0 390#else
50adb19f 391#define WINT_MIN (0U)
11a985e0 392#endif
df5a5b35
JJ
393
394/** Macros for minimum-width integer constant expressions */
9bd3bcc6
CV
395#ifdef __INT8_C
396#define INT8_C(x) __INT8_C(x)
397#define UINT8_C(x) __UINT8_C(x)
398#else
df5a5b35 399#define INT8_C(x) x
11a985e0
JJ
400#if __STDINT_EXP(INT_MAX) > 0x7f
401#define UINT8_C(x) x
402#else
df5a5b35 403#define UINT8_C(x) x##U
11a985e0 404#endif
9bd3bcc6 405#endif
df5a5b35 406
9bd3bcc6
CV
407#ifdef __INT16_C
408#define INT16_C(x) __INT16_C(x)
409#define UINT16_C(x) __UINT16_C(x)
410#else
df5a5b35 411#define INT16_C(x) x
11a985e0
JJ
412#if __STDINT_EXP(INT_MAX) > 0x7fff
413#define UINT16_C(x) x
414#else
df5a5b35 415#define UINT16_C(x) x##U
11a985e0 416#endif
9bd3bcc6 417#endif
df5a5b35 418
9bd3bcc6
CV
419#ifdef __INT32_C
420#define INT32_C(x) __INT32_C(x)
421#define UINT32_C(x) __UINT32_C(x)
422#else
6109eadf 423#if defined (_INT32_EQ_LONG)
df5a5b35
JJ
424#define INT32_C(x) x##L
425#define UINT32_C(x) x##UL
426#else
427#define INT32_C(x) x
428#define UINT32_C(x) x##U
429#endif
9bd3bcc6 430#endif
df5a5b35 431
9bd3bcc6
CV
432#ifdef __INT64_C
433#define INT64_C(x) __INT64_C(x)
434#define UINT64_C(x) __UINT64_C(x)
435#else
df5a5b35 436#if __int64_t_defined
2e287a63 437#if __have_long64
df5a5b35
JJ
438#define INT64_C(x) x##L
439#define UINT64_C(x) x##UL
2e287a63
JJ
440#else
441#define INT64_C(x) x##LL
442#define UINT64_C(x) x##ULL
df5a5b35
JJ
443#endif
444#endif
9bd3bcc6 445#endif
df5a5b35
JJ
446
447/** Macros for greatest-width integer constant expression */
9bd3bcc6
CV
448#ifdef __INTMAX_C
449#define INTMAX_C(x) __INTMAX_C(x)
450#define UINTMAX_C(x) __UINTMAX_C(x)
451#else
2e287a63 452#if __have_long64
df5a5b35
JJ
453#define INTMAX_C(x) x##L
454#define UINTMAX_C(x) x##UL
2e287a63
JJ
455#else
456#define INTMAX_C(x) x##LL
457#define UINTMAX_C(x) x##ULL
df5a5b35 458#endif
9bd3bcc6 459#endif
df5a5b35
JJ
460
461
462#ifdef __cplusplus
463}
464#endif
465
466#endif /* _STDINT_H */
This page took 0.283908 seconds and 6 git commands to generate.