]> git.saurik.com Git - apple/libc.git/blob - include/inttypes.h
Libc-391.5.18.tar.gz
[apple/libc.git] / include / inttypes.h
1 /*
2 * Copyright (c) 2000, 2001, 2002, 2003, 2004 Apple Computer, Inc.
3 * All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * The contents of this file constitute Original Code as defined in and
8 * are subject to the Apple Public Source License Version 1.1 (the
9 * "License"). You may not use this file except in compliance with the
10 * License. Please obtain a copy of the License at
11 * http://www.apple.com/publicsource and read it before using this file.
12 *
13 * This Original Code and all software distributed under the License are
14 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
18 * License for the specific language governing rights and limitations
19 * under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * <inttypes.h> -- Standard C header, defined in ISO/IEC 9899:1999
26 * (aka "C99"), section 7.8. This defines format string conversion
27 * specifiers suitable for use within arguments to fprintf and fscanf
28 * and their ilk.
29 */
30
31 #if !defined(_INTTYPES_H_)
32 #define _INTTYPES_H_
33
34 #include <sys/cdefs.h> /* For __BEGIN_DECLS and __END_DECLS */
35 #include <_types.h> /* For __darwin_wchar_t */
36 #include <stdint.h>
37
38 #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
39 /* Translator is not ISO/IEC 9899:1999-compliant. */
40 # if !defined(restrict)
41 # define restrict
42 # define __RESTRICT_KEYWORD_DEFINED__
43 # endif
44 #endif
45
46 /* "C++ implementations should define these macros only when
47 * __STDC_FORMAT_MACROS is defined before <inttypes.h> is included."
48 */
49 #if (! defined(__cplusplus)) || defined(__STDC_FORMAT_MACROS)
50
51 # undef __PRI_8_LENGTH_MODIFIER__
52 # undef __PRI_64_LENGTH_MODIFIER__
53 # undef __SCN_64_LENGTH_MODIFIER__
54
55 /* These could be "hh", "ll", and "ll" respectively, but that doesn't work on
56 10.2, and these do. Note that there's no way to use scanf to scan a
57 decimal into a 'char' argument on 10.2, so "hh" is used unconditionally
58 and programs that use it won't work on Jaguar. */
59 # define __PRI_8_LENGTH_MODIFIER__ "" /* none */
60 # define __PRI_64_LENGTH_MODIFIER__ "q"
61 # define __SCN_64_LENGTH_MODIFIER__ "q"
62 # define __PRI_MAX_LENGTH_MODIFIER__ "j"
63 # define __SCN_MAX_LENGTH_MODIFIER__ "j"
64
65 # define PRId8 __PRI_8_LENGTH_MODIFIER__ "d"
66 # define PRIi8 __PRI_8_LENGTH_MODIFIER__ "i"
67 # define PRIo8 __PRI_8_LENGTH_MODIFIER__ "o"
68 # define PRIu8 __PRI_8_LENGTH_MODIFIER__ "u"
69 # define PRIx8 __PRI_8_LENGTH_MODIFIER__ "x"
70 # define PRIX8 __PRI_8_LENGTH_MODIFIER__ "X"
71
72 # define PRId16 "hd"
73 # define PRIi16 "hi"
74 # define PRIo16 "ho"
75 # define PRIu16 "hu"
76 # define PRIx16 "hx"
77 # define PRIX16 "hX"
78
79 # define PRId32 "d"
80 # define PRIi32 "i"
81 # define PRIo32 "o"
82 # define PRIu32 "u"
83 # define PRIx32 "x"
84 # define PRIX32 "X"
85
86 # define PRId64 __PRI_64_LENGTH_MODIFIER__ "d"
87 # define PRIi64 __PRI_64_LENGTH_MODIFIER__ "i"
88 # define PRIo64 __PRI_64_LENGTH_MODIFIER__ "o"
89 # define PRIu64 __PRI_64_LENGTH_MODIFIER__ "u"
90 # define PRIx64 __PRI_64_LENGTH_MODIFIER__ "x"
91 # define PRIX64 __PRI_64_LENGTH_MODIFIER__ "X"
92
93 # define PRIdLEAST8 PRId8
94 # define PRIiLEAST8 PRIi8
95 # define PRIoLEAST8 PRIo8
96 # define PRIuLEAST8 PRIu8
97 # define PRIxLEAST8 PRIx8
98 # define PRIXLEAST8 PRIX8
99
100 # define PRIdLEAST16 PRId16
101 # define PRIiLEAST16 PRIi16
102 # define PRIoLEAST16 PRIo16
103 # define PRIuLEAST16 PRIu16
104 # define PRIxLEAST16 PRIx16
105 # define PRIXLEAST16 PRIX16
106
107 # define PRIdLEAST32 PRId32
108 # define PRIiLEAST32 PRIi32
109 # define PRIoLEAST32 PRIo32
110 # define PRIuLEAST32 PRIu32
111 # define PRIxLEAST32 PRIx32
112 # define PRIXLEAST32 PRIX32
113
114 # define PRIdLEAST64 PRId64
115 # define PRIiLEAST64 PRIi64
116 # define PRIoLEAST64 PRIo64
117 # define PRIuLEAST64 PRIu64
118 # define PRIxLEAST64 PRIx64
119 # define PRIXLEAST64 PRIX64
120
121 # define PRIdFAST8 PRId8
122 # define PRIiFAST8 PRIi8
123 # define PRIoFAST8 PRIo8
124 # define PRIuFAST8 PRIu8
125 # define PRIxFAST8 PRIx8
126 # define PRIXFAST8 PRIX8
127
128 # define PRIdFAST16 PRId16
129 # define PRIiFAST16 PRIi16
130 # define PRIoFAST16 PRIo16
131 # define PRIuFAST16 PRIu16
132 # define PRIxFAST16 PRIx16
133 # define PRIXFAST16 PRIX16
134
135 # define PRIdFAST32 PRId32
136 # define PRIiFAST32 PRIi32
137 # define PRIoFAST32 PRIo32
138 # define PRIuFAST32 PRIu32
139 # define PRIxFAST32 PRIx32
140 # define PRIXFAST32 PRIX32
141
142 # define PRIdFAST64 PRId64
143 # define PRIiFAST64 PRIi64
144 # define PRIoFAST64 PRIo64
145 # define PRIuFAST64 PRIu64
146 # define PRIxFAST64 PRIx64
147 # define PRIXFAST64 PRIX64
148
149 /* int32_t is 'int', but intptr_t is 'long'. */
150 # define PRIdPTR "ld"
151 # define PRIiPTR "li"
152 # define PRIoPTR "lo"
153 # define PRIuPTR "lu"
154 # define PRIxPTR "lx"
155 # define PRIXPTR "lX"
156
157 # define PRIdMAX __PRI_MAX_LENGTH_MODIFIER__ "d"
158 # define PRIiMAX __PRI_MAX_LENGTH_MODIFIER__ "i"
159 # define PRIoMAX __PRI_MAX_LENGTH_MODIFIER__ "o"
160 # define PRIuMAX __PRI_MAX_LENGTH_MODIFIER__ "u"
161 # define PRIxMAX __PRI_MAX_LENGTH_MODIFIER__ "x"
162 # define PRIXMAX __PRI_MAX_LENGTH_MODIFIER__ "X"
163
164 # define SCNd8 "hhd"
165 # define SCNi8 "hhi"
166 # define SCNo8 "hho"
167 # define SCNu8 "hhu"
168 # define SCNx8 "hhx"
169
170 # define SCNd16 "hd"
171 # define SCNi16 "hi"
172 # define SCNo16 "ho"
173 # define SCNu16 "hu"
174 # define SCNx16 "hx"
175
176 # define SCNd32 "d"
177 # define SCNi32 "i"
178 # define SCNo32 "o"
179 # define SCNu32 "u"
180 # define SCNx32 "x"
181
182 # define SCNd64 __SCN_64_LENGTH_MODIFIER__ "d"
183 # define SCNi64 __SCN_64_LENGTH_MODIFIER__ "i"
184 # define SCNo64 __SCN_64_LENGTH_MODIFIER__ "o"
185 # define SCNu64 __SCN_64_LENGTH_MODIFIER__ "u"
186 # define SCNx64 __SCN_64_LENGTH_MODIFIER__ "x"
187
188 # define SCNdLEAST8 SCNd8
189 # define SCNiLEAST8 SCNi8
190 # define SCNoLEAST8 SCNo8
191 # define SCNuLEAST8 SCNu8
192 # define SCNxLEAST8 SCNx8
193
194 # define SCNdLEAST16 SCNd16
195 # define SCNiLEAST16 SCNi16
196 # define SCNoLEAST16 SCNo16
197 # define SCNuLEAST16 SCNu16
198 # define SCNxLEAST16 SCNx16
199
200 # define SCNdLEAST32 SCNd32
201 # define SCNiLEAST32 SCNi32
202 # define SCNoLEAST32 SCNo32
203 # define SCNuLEAST32 SCNu32
204 # define SCNxLEAST32 SCNx32
205
206 # define SCNdLEAST64 SCNd64
207 # define SCNiLEAST64 SCNi64
208 # define SCNoLEAST64 SCNo64
209 # define SCNuLEAST64 SCNu64
210 # define SCNxLEAST64 SCNx64
211
212 # define SCNdFAST8 SCNd8
213 # define SCNiFAST8 SCNi8
214 # define SCNoFAST8 SCNo8
215 # define SCNuFAST8 SCNu8
216 # define SCNxFAST8 SCNx8
217
218 # define SCNdFAST16 SCNd16
219 # define SCNiFAST16 SCNi16
220 # define SCNoFAST16 SCNo16
221 # define SCNuFAST16 SCNu16
222 # define SCNxFAST16 SCNx16
223
224 # define SCNdFAST32 SCNd32
225 # define SCNiFAST32 SCNi32
226 # define SCNoFAST32 SCNo32
227 # define SCNuFAST32 SCNu32
228 # define SCNxFAST32 SCNx32
229
230 # define SCNdFAST64 SCNd64
231 # define SCNiFAST64 SCNi64
232 # define SCNoFAST64 SCNo64
233 # define SCNuFAST64 SCNu64
234 # define SCNxFAST64 SCNx64
235
236 # define SCNdPTR "ld"
237 # define SCNiPTR "li"
238 # define SCNoPTR "lo"
239 # define SCNuPTR "lu"
240 # define SCNxPTR "lx"
241
242 # define SCNdMAX __SCN_MAX_LENGTH_MODIFIER__ "d"
243 # define SCNiMAX __SCN_MAX_LENGTH_MODIFIER__ "i"
244 # define SCNoMAX __SCN_MAX_LENGTH_MODIFIER__ "o"
245 # define SCNuMAX __SCN_MAX_LENGTH_MODIFIER__ "u"
246 # define SCNxMAX __SCN_MAX_LENGTH_MODIFIER__ "x"
247
248 #endif /* if C++, then __STDC_FORMAT_MACROS enables the above macros */
249
250 __BEGIN_DECLS
251
252 /* 7.8.2.1 */
253 extern intmax_t imaxabs(intmax_t j);
254
255 /* 7.8.2.2 */
256 typedef struct {
257 intmax_t quot;
258 intmax_t rem;
259 } imaxdiv_t;
260
261 extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
262
263 /* 7.8.2.3 */
264 extern intmax_t strtoimax(const char * restrict nptr, char ** restrict endptr, int base);
265 extern uintmax_t strtoumax(const char * restrict nptr, char ** restrict endptr, int base);
266
267 #ifndef __cplusplus /* wchar_t is a built-in type in C++ */
268 # ifndef _WCHAR_T
269 # define _WCHAR_T
270 typedef __darwin_wchar_t wchar_t;
271 # endif /* _WCHAR_T */
272 #endif /* __cplusplus */
273
274 /* 7.8.2.4 */
275 extern intmax_t wcstoimax(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base);
276 extern uintmax_t wcstoumax(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base);
277
278 __END_DECLS
279
280 #ifdef _USE_EXTENDED_LOCALES_
281 #include <xlocale/_inttypes.h>
282 #endif /* _USE_EXTENDED_LOCALES_ */
283
284 /*
285 No need to #undef the __*_{8,64}_LENGTH_MODIFIER__ macros;
286 in fact, you can't #undef them, because later uses of any of
287 their dependents will *not* then do the intended substitution.
288 Expansion of a #define like this one:
289
290 #define x IDENT y
291
292 uses the cpp value of IDENT at the location where x is *expanded*,
293 not where it is #defined.
294 */
295
296 #if defined(__RESTRICT_KEYWORD_DEFINED__)
297 # undef restrict
298 # undef __RESTRICT_KEYWORD_DEFINED__
299 #endif
300
301 #endif /* !_INTTYPES_H_ */