libpayload: Some more compatibility (for flashrom)
[coreboot.git] / payloads / libpayload / include / sys / stdint.h
1 /*      $OpenBSD: stdint.h,v 1.4 2006/12/10 22:17:55 deraadt Exp $      */
2
3 /*
4  * Copyright (c) 1997, 2005 Todd C. Miller <Todd.Miller@courtesan.com>
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 <arch/types.h>
23 //#include <sys/cdefs.h>
24 //#include <machine/_types.h>
25
26 #ifndef __BIT_TYPES_DEFINED__
27 #define __BIT_TYPES_DEFINED__
28 #endif
29
30 /* 7.18.1.2 Minimum-width integer types */
31 typedef int8_t          int_least8_t;
32 typedef uint8_t         uint_least8_t;
33 typedef int16_t         int_least16_t;
34 typedef uint16_t        uint_least16_t;
35 typedef int32_t         int_least32_t;
36 typedef uint32_t        uint_least32_t;
37 typedef int64_t         int_least64_t;
38 typedef uint64_t        uint_least64_t;
39
40 /* 7.18.1.3 Fastest minimum-width integer types */
41 typedef int8_t          int_fast8_t;
42 typedef uint8_t         uint_fast8_t;
43 typedef int16_t         int_fast16_t;
44 typedef uint16_t        uint_fast16_t;
45 typedef int32_t         int_fast32_t;
46 typedef uint32_t        uint_fast32_t;
47 typedef int64_t         int_fast64_t;
48 typedef uint64_t        uint_fast64_t;
49
50 /* 7.18.1.5 Greatest-width integer types */
51 typedef int64_t         intmax_t;
52 typedef uint64_t        uintmax_t;
53
54 #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
55 /*
56  * 7.18.2 Limits of specified-width integer types.
57  *
58  * The following object-like macros specify the minimum and maximum limits
59  * of integer types corresponding to the typedef names defined above.
60  */
61
62 /* 7.18.2.1 Limits of exact-width integer types */
63 #define INT8_MIN                (-0x7f - 1)
64 #define INT16_MIN               (-0x7fff - 1)
65 #define INT32_MIN               (-0x7fffffff - 1)
66 #define INT64_MIN               (-0x7fffffffffffffffLL - 1)
67
68 #define INT8_MAX                0x7f
69 #define INT16_MAX               0x7fff
70 #define INT32_MAX               0x7fffffff
71 #define INT64_MAX               0x7fffffffffffffffLL
72
73 #define UINT8_MAX               0xff
74 #define UINT16_MAX              0xffff
75 #define UINT32_MAX              0xffffffffU
76 #define UINT64_MAX              0xffffffffffffffffULL
77
78 /* 7.18.2.2 Limits of minimum-width integer types */
79 #define INT_LEAST8_MIN          INT8_MIN
80 #define INT_LEAST16_MIN         INT16_MIN
81 #define INT_LEAST32_MIN         INT32_MIN
82 #define INT_LEAST64_MIN         INT64_MIN
83
84 #define INT_LEAST8_MAX          INT8_MAX
85 #define INT_LEAST16_MAX         INT16_MAX
86 #define INT_LEAST32_MAX         INT32_MAX
87 #define INT_LEAST64_MAX         INT64_MAX
88
89 #define UINT_LEAST8_MAX         UINT8_MAX
90 #define UINT_LEAST16_MAX        UINT16_MAX
91 #define UINT_LEAST32_MAX        UINT32_MAX
92 #define UINT_LEAST64_MAX        UINT64_MAX
93
94 /* 7.18.2.3 Limits of fastest minimum-width integer types */
95 #define INT_FAST8_MIN           INT8_MIN
96 #define INT_FAST16_MIN          INT16_MIN
97 #define INT_FAST32_MIN          INT32_MIN
98 #define INT_FAST64_MIN          INT64_MIN
99
100 #define INT_FAST8_MAX           INT8_MAX
101 #define INT_FAST16_MAX          INT16_MAX
102 #define INT_FAST32_MAX          INT32_MAX
103 #define INT_FAST64_MAX          INT64_MAX
104
105 #define UINT_FAST8_MAX          UINT8_MAX
106 #define UINT_FAST16_MAX         UINT16_MAX
107 #define UINT_FAST32_MAX         UINT32_MAX
108 #define UINT_FAST64_MAX         UINT64_MAX
109
110 /* 7.18.2.4 Limits of integer types capable of holding object pointers */
111 #ifdef __LP64__
112 #define INTPTR_MIN              INT64_MIN
113 #define INTPTR_MAX              INT64_MAX
114 #define UINTPTR_MAX             UINT64_MAX
115 #else
116 #define INTPTR_MIN              INT32_MIN
117 #define INTPTR_MAX              INT32_MAX
118 #define UINTPTR_MAX             UINT32_MAX
119 #endif
120
121 /* 7.18.2.5 Limits of greatest-width integer types */
122 #define INTMAX_MIN              INT64_MIN
123 #define INTMAX_MAX              INT64_MAX
124 #define UINTMAX_MAX             UINT64_MAX
125
126 /*
127  * 7.18.3 Limits of other integer types.
128  *
129  * The following object-like macros specify the minimum and maximum limits
130  * of integer types corresponding to types specified in other standard
131  * header files.
132  */
133
134 /* Limits of ptrdiff_t */
135 #define PTRDIFF_MIN             INTPTR_MIN
136 #define PTRDIFF_MAX             INTPTR_MAX
137
138 /* Limits of sig_atomic_t */
139 #define SIG_ATOMIC_MIN          INT32_MIN
140 #define SIG_ATOMIC_MAX          INT32_MAX
141
142 /* Limits of size_t (also in limits.h) */
143 #ifndef SIZE_MAX
144 #define SIZE_MAX                UINTPTR_MAX
145 #endif
146
147 /* Limits of wchar_t */
148 #define WCHAR_MIN               INT32_MIN
149 #define WCHAR_MAX               INT32_MAX
150
151 /* Limits of wint_t */
152 #define WINT_MIN                INT32_MIN
153 #define WINT_MAX                INT32_MAX
154
155 #endif /* __cplusplus || __STDC_LIMIT_MACROS */
156
157 #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
158 /*
159  * 7.18.4 Macros for integer constants.
160  *
161  * The following function-like macros expand to integer constants
162  * suitable for initializing objects that have integer types corresponding
163  * to types defined in <stdint.h>.  The argument in any instance of
164  * these macros shall be a decimal, octal, or hexadecimal constant with
165  * a value that does not exceed the limits for the corresponding type.
166  */
167
168 /* 7.18.4.1 Macros for minimum-width integer constants. */
169 #define INT8_C(_c)              (_c)
170 #define INT16_C(_c)             (_c)
171 #define INT32_C(_c)             (_c)
172 #define INT64_C(_c)             __CONCAT(_c, LL)
173
174 #define UINT8_C(_c)             (_c)
175 #define UINT16_C(_c)            (_c)
176 #define UINT32_C(_c)            __CONCAT(_c, U)
177 #define UINT64_C(_c)            __CONCAT(_c, ULL)
178
179 /* 7.18.4.2 Macros for greatest-width integer constants. */
180 #define INTMAX_C(_c)            __CONCAT(_c, LL)
181 #define UINTMAX_C(_c)           __CONCAT(_c, ULL)
182
183 #endif /* __cplusplus || __STDC_CONSTANT_MACROS */
184
185 #endif /* _SYS_STDINT_H_ */