blob: 9bdfb0506cc5d17e17efc5d30e3d3804020d8423 [file] [log] [blame]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
Elliott Hughesa9a02ac2013-09-30 14:46:47 -070028
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070029#ifndef _STDINT_H
30#define _STDINT_H
31
32#include <stddef.h>
33#include <sys/_types.h>
34
Elliott Hughesa9a02ac2013-09-30 14:46:47 -070035#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) || (__cplusplus >= 201103L)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070036# define __STDINT_LIMITS
37#endif
38
Elliott Hughesa9a02ac2013-09-30 14:46:47 -070039#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) || (__cplusplus >= 201103L)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070040# define __STDINT_MACROS
41#endif
42
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070043typedef __int8_t int8_t;
44typedef __uint8_t uint8_t;
45typedef __int16_t int16_t;
46typedef __uint16_t uint16_t;
47typedef __int32_t int32_t;
48typedef __uint32_t uint32_t;
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070049typedef __int64_t int64_t;
50typedef __uint64_t uint64_t;
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070051
52/*
53 * int8_t & uint8_t
54 */
55
56typedef int8_t int_least8_t;
57typedef int8_t int_fast8_t;
58
59typedef uint8_t uint_least8_t;
60typedef uint8_t uint_fast8_t;
61
62#ifdef __STDINT_LIMITS
63# define INT8_MIN (-128)
64# define INT8_MAX (127)
65# define INT_LEAST8_MIN INT8_MIN
66# define INT_LEAST8_MAX INT8_MAX
67# define INT_FAST8_MIN INT8_MIN
68# define INT_FAST8_MAX INT8_MAX
69
Sergey Melnikovdc5d3422012-11-22 15:23:48 +040070# define UINT8_MAX (255)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070071# define UINT_LEAST8_MAX UINT8_MAX
72# define UINT_FAST8_MAX UINT8_MAX
73#endif
74
75#ifdef __STDINT_MACROS
76# define INT8_C(c) c
77# define INT_LEAST8_C(c) INT8_C(c)
78# define INT_FAST8_C(c) INT8_C(c)
79
Sergey Melnikovdc5d3422012-11-22 15:23:48 +040080# define UINT8_C(c) c
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070081# define UINT_LEAST8_C(c) UINT8_C(c)
82# define UINT_FAST8_C(c) UINT8_C(c)
83#endif
84
85/*
86 * int16_t & uint16_t
87 */
88
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070089typedef int16_t int_least16_t;
90typedef int32_t int_fast16_t;
91
92typedef uint16_t uint_least16_t;
93typedef uint32_t uint_fast16_t;
94
95#ifdef __STDINT_LIMITS
96# define INT16_MIN (-32768)
97# define INT16_MAX (32767)
98# define INT_LEAST16_MIN INT16_MIN
99# define INT_LEAST16_MAX INT16_MAX
100# define INT_FAST16_MIN INT32_MIN
101# define INT_FAST16_MAX INT32_MAX
102
Sergey Melnikovdc5d3422012-11-22 15:23:48 +0400103# define UINT16_MAX (65535)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700104# define UINT_LEAST16_MAX UINT16_MAX
105# define UINT_FAST16_MAX UINT32_MAX
106#endif
107
108#ifdef __STDINT_MACROS
109# define INT16_C(c) c
110# define INT_LEAST16_C(c) INT16_C(c)
111# define INT_FAST16_C(c) INT32_C(c)
112
Sergey Melnikovdc5d3422012-11-22 15:23:48 +0400113# define UINT16_C(c) c
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700114# define UINT_LEAST16_C(c) UINT16_C(c)
115# define UINT_FAST16_C(c) UINT32_C(c)
116#endif
117
118/*
119 * int32_t & uint32_t
120 */
121
122typedef int32_t int_least32_t;
123typedef int32_t int_fast32_t;
124
125typedef uint32_t uint_least32_t;
126typedef uint32_t uint_fast32_t;
127
128#ifdef __STDINT_LIMITS
129# define INT32_MIN (-2147483647-1)
130# define INT32_MAX (2147483647)
131# define INT_LEAST32_MIN INT32_MIN
132# define INT_LEAST32_MAX INT32_MAX
133# define INT_FAST32_MIN INT32_MIN
134# define INT_FAST32_MAX INT32_MAX
135
136# define UINT32_MAX (4294967295U)
137# define UINT_LEAST32_MAX UINT32_MAX
138# define UINT_FAST32_MAX UINT32_MAX
139#endif
140
141#ifdef __STDINT_MACROS
142# define INT32_C(c) c
143# define INT_LEAST32_C(c) INT32_C(c)
144# define INT_FAST32_C(c) INT32_C(c)
145
146# define UINT32_C(c) c ## U
147# define UINT_LEAST32_C(c) UINT32_C(c)
148# define UINT_FAST32_C(c) UINT32_C(c)
149#endif
150
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700151/*
152 * int64_t
153 */
Elliott Hughes6d6731a2012-08-17 14:30:06 -0700154
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700155typedef int64_t int_least64_t;
156typedef int64_t int_fast64_t;
157
158typedef uint64_t uint_least64_t;
159typedef uint64_t uint_fast64_t;
160
Elliott Hughesa9a02ac2013-09-30 14:46:47 -0700161#if __LP64__
162# define __INT64_C(c) c ## L
163# define __UINT64_C(c) c ## UL
164#else
165# define __INT64_C(c) c ## LL
166# define __UINT64_C(c) c ## ULL
167#endif
168
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700169#ifdef __STDINT_LIMITS
170# define INT64_MIN (__INT64_C(-9223372036854775807)-1)
171# define INT64_MAX (__INT64_C(9223372036854775807))
172# define INT_LEAST64_MIN INT64_MIN
173# define INT_LEAST64_MAX INT64_MAX
174# define INT_FAST64_MIN INT64_MIN
175# define INT_FAST64_MAX INT64_MAX
176# define UINT64_MAX (__UINT64_C(18446744073709551615))
177
178# define UINT_LEAST64_MAX UINT64_MAX
179# define UINT_FAST64_MAX UINT64_MAX
180#endif
181
182#ifdef __STDINT_MACROS
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700183# define INT64_C(c) __INT64_C(c)
184# define INT_LEAST64_C(c) INT64_C(c)
185# define INT_FAST64_C(c) INT64_C(c)
186
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700187# define UINT64_C(c) __UINT64_C(c)
188# define UINT_LEAST64_C(c) UINT64_C(c)
189# define UINT_FAST64_C(c) UINT64_C(c)
190#endif
191
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700192# define __PRI64_RANK "ll"
193# define __PRIFAST_RANK ""
194# define __PRIPTR_RANK ""
195
Serban Constantinescudebc0212013-10-08 21:45:02 +0100196
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700197/*
198 * intptr_t & uintptr_t
199 */
200
Pavel Chupin0a9c6152012-12-18 17:25:01 +0400201#ifdef __LP64__
Serban Constantinescudebc0212013-10-08 21:45:02 +0100202
Pavel Chupin0a9c6152012-12-18 17:25:01 +0400203typedef long intptr_t;
204typedef unsigned long uintptr_t;
Serban Constantinescudebc0212013-10-08 21:45:02 +0100205
206#ifdef __STDINT_LIMITS
207# define INTPTR_MIN INT64_MIN
208# define INTPTR_MAX INT64_MAX
209# define UINTPTR_MAX UINT64_MAX
210# define PTRDIFF_MIN INT64_MIN
211# define PTRDIFF_MAX INT64_MAX
212#endif
213#ifdef __STDINT_MACROS
214# define INTPTR_C(c) INT64_C(c)
215# define UINTPTR_C(c) UINT64_C(c)
216# define PTRDIFF_C(c) INT64_C(c)
217#endif
218
Pavel Chupin0a9c6152012-12-18 17:25:01 +0400219#else
Serban Constantinescudebc0212013-10-08 21:45:02 +0100220
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700221typedef int intptr_t;
222typedef unsigned int uintptr_t;
223
David 'Digit' Turner08ff1a62011-03-10 18:02:01 +0100224#ifdef __STDINT_LIMITS
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700225# define INTPTR_MIN INT32_MIN
226# define INTPTR_MAX INT32_MAX
227# define UINTPTR_MAX UINT32_MAX
David 'Digit' Turner08ff1a62011-03-10 18:02:01 +0100228# define PTRDIFF_MIN INT32_MIN
229# define PTRDIFF_MAX INT32_MAX
230#endif
David 'Digit' Turner08ff1a62011-03-10 18:02:01 +0100231#ifdef __STDINT_MACROS
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700232# define INTPTR_C(c) INT32_C(c)
233# define UINTPTR_C(c) UINT32_C(c)
234# define PTRDIFF_C(c) INT32_C(c)
David 'Digit' Turner08ff1a62011-03-10 18:02:01 +0100235#endif
236
Serban Constantinescudebc0212013-10-08 21:45:02 +0100237#endif /* __LP64__ */
238
239
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700240/*
241 * intmax_t & uintmax_t
242 */
243
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700244typedef uint64_t uintmax_t;
245typedef int64_t intmax_t;
246
David 'Digit' Turner08ff1a62011-03-10 18:02:01 +0100247#ifdef __STDINT_LIMITS
248# define INTMAX_MIN INT64_MIN
249# define INTMAX_MAX INT64_MAX
250# define UINTMAX_MAX UINT64_MAX
251#endif
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700252
David 'Digit' Turner0e5411b2011-03-10 20:34:23 +0100253#ifdef __STDINT_MACROS
David 'Digit' Turner08ff1a62011-03-10 18:02:01 +0100254# define INTMAX_C(c) INT64_C(c)
255# define UINTMAX_C(c) UINT64_C(c)
256#endif
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700257
Elliott Hughes7c895062013-06-13 16:02:53 -0700258/*
259 * sig_atomic_t, size_t, wchar_t, and wint_t.
260 */
261
262#ifdef __STDINT_LIMITS
263# define SIG_ATOMIC_MAX INT32_MAX
264# define SIG_ATOMIC_MIN INT32_MIN
265
266# define SIZE_MAX UINT32_MAX
267
268# ifndef WCHAR_MAX /* These might also have been defined by <wchar.h>. */
269# define WCHAR_MAX INT32_MAX
270# define WCHAR_MIN INT32_MIN
271# endif
272
273# define WINT_MAX INT32_MAX
274# define WINT_MIN INT32_MIN
275#endif
276
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700277/* Keep the kernel from trying to define these types... */
278#define __BIT_TYPES_DEFINED__
279
280#endif /* _STDINT_H */