1/* $OpenBSD: stdint.h,v 1.11 2019/01/25 00:19:26 millert Exp $ */
2
3/*
4 * Copyright (c) 1997, 2005 Todd C. Miller <millert@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#ifndef _SYS_STDINT_H_
20#define _SYS_STDINT_H_
21
22#include <sys/cdefs.h>
23#include <machine/_types.h>
24
25#ifndef __BIT_TYPES_DEFINED__
26#define __BIT_TYPES_DEFINED__
27#endif
28
29/* 7.18.1.1 Exact-width integer types (also in sys/types.h) */
30#ifndef _INT8_T_DEFINED_
31#define _INT8_T_DEFINED_
32typedef __int8_t int8_t;
33#endif
34
35#ifndef _UINT8_T_DEFINED_
36#define _UINT8_T_DEFINED_
37typedef __uint8_t uint8_t;
38#endif
39
40#ifndef _INT16_T_DEFINED_
41#define _INT16_T_DEFINED_
42typedef __int16_t int16_t;
43#endif
44
45#ifndef _UINT16_T_DEFINED_
46#define _UINT16_T_DEFINED_
47typedef __uint16_t uint16_t;
48#endif
49
50#ifndef _INT32_T_DEFINED_
51#define _INT32_T_DEFINED_
52typedef __int32_t int32_t;
53#endif
54
55#ifndef _UINT32_T_DEFINED_
56#define _UINT32_T_DEFINED_
57typedef __uint32_t uint32_t;
58#endif
59
60#ifndef _INT64_T_DEFINED_
61#define _INT64_T_DEFINED_
62typedef __int64_t int64_t;
63#endif
64
65#ifndef _UINT64_T_DEFINED_
66#define _UINT64_T_DEFINED_
67typedef __uint64_t uint64_t;
68#endif
69
70/* 7.18.1.2 Minimum-width integer types */
71typedef __int_least8_t int_least8_t;
72typedef __uint_least8_t uint_least8_t;
73typedef __int_least16_t int_least16_t;
74typedef __uint_least16_t uint_least16_t;
75typedef __int_least32_t int_least32_t;
76typedef __uint_least32_t uint_least32_t;
77typedef __int_least64_t int_least64_t;
78typedef __uint_least64_t uint_least64_t;
79
80/* 7.18.1.3 Fastest minimum-width integer types */
81typedef __int_fast8_t int_fast8_t;
82typedef __uint_fast8_t uint_fast8_t;
83typedef __int_fast16_t int_fast16_t;
84typedef __uint_fast16_t uint_fast16_t;
85typedef __int_fast32_t int_fast32_t;
86typedef __uint_fast32_t uint_fast32_t;
87typedef __int_fast64_t int_fast64_t;
88typedef __uint_fast64_t uint_fast64_t;
89
90/* 7.18.1.4 Integer types capable of holding object pointers */
91#ifndef _INTPTR_T_DEFINED_
92#define _INTPTR_T_DEFINED_
93typedef __intptr_t intptr_t;
94#endif
95
96typedef __uintptr_t uintptr_t;
97
98/* 7.18.1.5 Greatest-width integer types */
99typedef __intmax_t intmax_t;
100typedef __uintmax_t uintmax_t;
101
102/*
103 * 7.18.2 Limits of specified-width integer types.
104 *
105 * The following object-like macros specify the minimum and maximum limits
106 * of integer types corresponding to the typedef names defined above.
107 */
108
109/* 7.18.2.1 Limits of exact-width integer types */
110#define INT8_MIN (-0x7f - 1)
111#define INT16_MIN (-0x7fff - 1)
112#define INT32_MIN (-0x7fffffff - 1)
113#define INT64_MIN (-0x7fffffffffffffffLL - 1)
114
115#define INT8_MAX 0x7f
116#define INT16_MAX 0x7fff
117#define INT32_MAX 0x7fffffff
118#define INT64_MAX 0x7fffffffffffffffLL
119
120#define UINT8_MAX 0xff
121#define UINT16_MAX 0xffff
122#define UINT32_MAX 0xffffffffU
123#define UINT64_MAX 0xffffffffffffffffULL
124
125/* 7.18.2.2 Limits of minimum-width integer types */
126#define INT_LEAST8_MIN INT8_MIN
127#define INT_LEAST16_MIN INT16_MIN
128#define INT_LEAST32_MIN INT32_MIN
129#define INT_LEAST64_MIN INT64_MIN
130
131#define INT_LEAST8_MAX INT8_MAX
132#define INT_LEAST16_MAX INT16_MAX
133#define INT_LEAST32_MAX INT32_MAX
134#define INT_LEAST64_MAX INT64_MAX
135
136#define UINT_LEAST8_MAX UINT8_MAX
137#define UINT_LEAST16_MAX UINT16_MAX
138#define UINT_LEAST32_MAX UINT32_MAX
139#define UINT_LEAST64_MAX UINT64_MAX
140
141/* 7.18.2.3 Limits of fastest minimum-width integer types */
142#define INT_FAST8_MIN __INT_FAST8_MIN
143#define INT_FAST16_MIN __INT_FAST16_MIN
144#define INT_FAST32_MIN __INT_FAST32_MIN
145#define INT_FAST64_MIN __INT_FAST64_MIN
146
147#define INT_FAST8_MAX __INT_FAST8_MAX
148#define INT_FAST16_MAX __INT_FAST16_MAX
149#define INT_FAST32_MAX __INT_FAST32_MAX
150#define INT_FAST64_MAX __INT_FAST64_MAX
151
152#define UINT_FAST8_MAX __UINT_FAST8_MAX
153#define UINT_FAST16_MAX __UINT_FAST16_MAX
154#define UINT_FAST32_MAX __UINT_FAST32_MAX
155#define UINT_FAST64_MAX __UINT_FAST64_MAX
156
157/* 7.18.2.4 Limits of integer types capable of holding object pointers */
158#ifdef __LP64__
159#define INTPTR_MIN (-0x7fffffffffffffffL - 1)
160#define INTPTR_MAX 0x7fffffffffffffffL
161#define UINTPTR_MAX 0xffffffffffffffffUL
162#else
163#define INTPTR_MIN (-0x7fffffffL - 1)
164#define INTPTR_MAX 0x7fffffffL
165#define UINTPTR_MAX 0xffffffffUL
166#endif
167
168/* 7.18.2.5 Limits of greatest-width integer types */
169#define INTMAX_MIN INT64_MIN
170#define INTMAX_MAX INT64_MAX
171#define UINTMAX_MAX UINT64_MAX
172
173/*
174 * 7.18.3 Limits of other integer types.
175 *
176 * The following object-like macros specify the minimum and maximum limits
177 * of integer types corresponding to types specified in other standard
178 * header files.
179 */
180
181/* Limits of ptrdiff_t */
182#define PTRDIFF_MIN INTPTR_MIN
183#define PTRDIFF_MAX INTPTR_MAX
184
185/* Limits of sig_atomic_t */
186#define SIG_ATOMIC_MIN INT32_MIN
187#define SIG_ATOMIC_MAX INT32_MAX
188
189/* Limit of size_t */
190#ifndef SIZE_MAX
191#define SIZE_MAX UINTPTR_MAX
192#endif
193
194/* Limits of wchar_t */
195#ifndef WCHAR_MIN
196#define WCHAR_MIN INT32_MIN
197#endif
198#ifndef WCHAR_MAX
199#define WCHAR_MAX INT32_MAX
200#endif
201
202/* Limits of wint_t */
203#define WINT_MIN INT32_MIN
204#define WINT_MAX INT32_MAX
205
206/*
207 * 7.18.4 Macros for integer constants.
208 *
209 * The following function-like macros expand to integer constants
210 * suitable for initializing objects that have integer types corresponding
211 * to types defined in <stdint.h>. The argument in any instance of
212 * these macros shall be a decimal, octal, or hexadecimal constant with
213 * a value that does not exceed the limits for the corresponding type.
214 */
215
216/* 7.18.4.1 Macros for minimum-width integer constants. */
217#define INT8_C(_c) (_c)
218#define INT16_C(_c) (_c)
219#define INT32_C(_c) (_c)
220#define INT64_C(_c) __CONCAT(_c, LL)
221
222#define UINT8_C(_c) (_c)
223#define UINT16_C(_c) (_c)
224#define UINT32_C(_c) __CONCAT(_c, U)
225#define UINT64_C(_c) __CONCAT(_c, ULL)
226
227/* 7.18.4.2 Macros for greatest-width integer constants. */
228#define INTMAX_C(_c) __CONCAT(_c, LL)
229#define UINTMAX_C(_c) __CONCAT(_c, ULL)
230
231#endif /* _SYS_STDINT_H_ */