xref: /PHP-7.4/main/php_stdint.h (revision 92ac598a)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) The PHP Group                                          |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Author: Michael Wallner <mike@php.net>                               |
16    +----------------------------------------------------------------------+
17 */
18 
19 #ifndef PHP_STDINT_H
20 #define PHP_STDINT_H
21 
22 /* C99 requires these for C++ to get the definitions
23  * of INT64_MAX and other macros used by Zend/zend_long.h
24  * C11 drops this requirement, so these effectively
25  * just backport that piece of behavior.
26  *
27  * These defines are placed here instead of
28  * with the include below, because sys/types
29  * and inttypes may include stdint themselves.
30  * And these definitions MUST come first.
31  */
32 #ifdef __cplusplus
33 # ifndef __STDC_LIMIT_MACROS
34 #  define __STDC_LIMIT_MACROS
35 # endif
36 # ifndef __STDC_CONSTANT_MACROS
37 #  define __STDC_CONSTANT_MACROS
38 # endif
39 # ifndef __STDC_FORMAT_MACROS
40 #  define __STDC_FORMAT_MACROS
41 # endif
42 #endif
43 
44 #if defined(_MSC_VER)
45 /* Make sure the regular stdint.h wasn't included already and prevent it to be
46    included afterwards. Though if some other library needs some stuff from
47    stdint.h included afterwards and misses it, we'd have to extend ours. On
48    the other hand, if stdint.h was included before, some conflicts might
49    happen so we'd likewise have to fix ours. */
50 # if !defined(_STDINT)
51 #  define _STDINT
52 #  include "win32/php_stdint.h"
53 #  include "win32/php_inttypes.h"
54 # endif
55 # define HAVE_INT8_T   1
56 # define HAVE_UINT8_T  1
57 # define HAVE_INT16_T  1
58 # define HAVE_UINT16_T 1
59 # define HAVE_INT32_T  1
60 # define HAVE_UINT32_T 1
61 # define HAVE_INT64_T  1
62 # define HAVE_UINT64_T 1
63 #else
64 
65 #include "php_config.h"
66 
67 #if HAVE_SYS_TYPES_H
68 # include <sys/types.h>
69 #endif
70 
71 #if HAVE_INTTYPES_H
72 # include <inttypes.h>
73 #endif
74 
75 #if HAVE_STDINT_H
76 # include <stdint.h>
77 #endif
78 
79 #ifndef HAVE_INT8_T
80 # ifdef HAVE_INT8
81 typedef int8 int8_t;
82 # else
83 typedef signed char int8_t;
84 # endif
85 #endif
86 
87 #ifndef INT8_C
88 # define INT8_C(c) c
89 #endif
90 
91 #ifndef HAVE_UINT8_T
92 # ifdef HAVE_UINT8
93 typedef uint8 uint8_t
94 # elif HAVE_U_INT8_T
95 typedef u_int8_t uint8_t;
96 # else
97 typedef unsigned char uint8_t;
98 # endif
99 #endif
100 
101 #ifndef UINT8_C
102 # define UINT8_C(c) c
103 #endif
104 
105 #ifndef HAVE_INT16_T
106 # ifdef HAVE_INT16
107 typedef int16 int16_t;
108 # elif SIZEOF_SHORT >= 2
109 typedef signed short int16_t;
110 # else
111 #  error "No suitable 16bit integer type found"
112 # endif
113 #endif
114 
115 #ifndef INT16_C
116 # define INT16_C(c) c
117 #endif
118 
119 #ifndef HAVE_UINT16_T
120 # ifdef HAVE_UINT16
121 typedef uint16 uint16_t
122 # elif HAVE_U_INT16_T
123 typedef u_int16_t uint16_t;
124 # elif SIZEOF_SHORT >= 2
125 typedef unsigned short uint16_t;
126 # else
127 #  error "No suitable 16bit integer type found"
128 # endif
129 #endif
130 
131 #ifndef UINT16_C
132 # define UINT16_C(c) c
133 #endif
134 
135 #ifndef HAVE_INT32_T
136 # ifdef HAVE_INT32
137 typedef int32 int32_t;
138 # elif SIZEOF_INT >= 4
139 typedef int int32_t;
140 # elif SIZEOF_LONG >= 4
141 typedef long int32_t;
142 # else
143 #  error "No suitable 32bit integer type found"
144 # endif
145 #endif
146 
147 #ifndef INT32_C
148 # define INT32_C(c) c
149 #endif
150 
151 #ifndef HAVE_UINT32_T
152 # ifdef HAVE_UINT32
153 typedef uint32 uint32_t
154 # elif HAVE_U_INT32_T
155 typedef u_int32_t uint32_t;
156 # elif SIZEOF_INT >= 4
157 typedef unsigned int uint32_t;
158 # elif SIZEOF_LONG >= 4
159 typedef unsigned long uint32_t;
160 # else
161 #  error "No suitable 32bit integer type found"
162 # endif
163 #endif
164 
165 #ifndef UINT32_C
166 # define UINT32_C(c) c ## U
167 #endif
168 
169 #ifndef HAVE_INT64_T
170 # ifdef HAVE_INT64
171 typedef int64 int64_t;
172 # elif SIZEOF_INT >= 8
173 typedef int int64_t;
174 # elif SIZEOF_LONG >= 8
175 typedef long int64_t;
176 # elif SIZEOF_LONG_LONG >= 8
177 typedef long long int64_t;
178 # else
179 #  error "No suitable 64bit integer type found"
180 # endif
181 #endif
182 
183 #ifndef INT64_C
184 # if SIZEOF_INT >= 8
185 #  define INT64_C(c) c
186 # elif SIZEOF_LONG >= 8
187 #  define INT64_C(c) c ## L
188 # elif SIZEOF_LONG_LONG >= 8
189 #  define INT64_C(c) c ## LL
190 # endif
191 #endif
192 
193 #ifndef HAVE_UINT64_T
194 # ifdef HAVE_UINT64
195 typedef uint64 uint64_t
196 # elif HAVE_U_INT64_T
197 typedef u_int64_t uint64_t;
198 # elif SIZEOF_INT >= 8
199 typedef unsigned int uint64_t;
200 # elif SIZEOF_LONG >= 8
201 typedef unsigned long uint64_t;
202 # elif SIZEOF_LONG_LONG >= 8
203 typedef unsigned long long uint64_t;
204 # else
205 #  error "No suitable 64bit integer type found"
206 # endif
207 #endif
208 
209 #ifndef UINT64_C
210 # if SIZEOF_INT >= 8
211 #  define UINT64_C(c) c ## U
212 # elif SIZEOF_LONG >= 8
213 #  define UINT64_C(c) c ## UL
214 # elif SIZEOF_LONG_LONG >= 8
215 #  define UINT64_C(c) c ## ULL
216 # endif
217 #endif
218 
219 #endif /* !PHP_WIN32 */
220 #endif /* PHP_STDINT_H */
221