TizenRT Libs&Environment  v2.0 M2
inttypes.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /****************************************************************************
19  * include/inttypes.h
20  *
21  * Copyright (C) 2010 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name NuttX nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ****************************************************************************/
59 
62 #ifndef __INCLUDE_INTTYPES_H
63 #define __INCLUDE_INTTYPES_H
64 
65 /****************************************************************************
66  * Included Files
67  ****************************************************************************/
68 
69 #include <stddef.h> /* for wchar_t */
70 
71 /* Notes from www.opengroup.org:
72  *
73  * "The <inttypes.h> header shall include the <stdint.h> header."
74  */
75 
76 #include <stdint.h>
77 
78 /****************************************************************************
79  * Pre-processor Definitions
80  ****************************************************************************/
81 
82 /* "The following macros shall be defined. Each expands to a character string
83  * literal containing a conversion specifier, possibly modified by a lengt
84  * modifier, suitable for use within the format argument of a formatted
85  * input/output function when converting the corresponding integer type.
86  * These macros have the general form of PRI (character string literals for
87  * the fprintf() and fwprintf() family of functions) or SCN (character string
88  * literals for the fscanf() and fwscanf() family of functions), followed by
89  * the conversion specifier, followed by a name corresponding to a similar
90  * type name in <stdint.h>. In these names, N represents the width of the
91  * type as described in <stdint.h>. For example, PRIdFAST32 can be used in a
92  * format string to print the value of an integer of type int_fast32_t.
93  *
94  * "The fprintf() macros for signed integers are:
95  *
96  * PRIdN
97  * PRIdLEASTN
98  * PRIdFASTN
99  * PRIdMAX
100  * PRIdPTR
101  *
102  * PRIiN
103  * PRIiLEASTN
104  * PRIiFASTN
105  * PRIiMAX
106  * PRIiPTR
107  *
108  * "The fprintf() macros for unsigned integers are:
109  *
110  * PRIoN
111  * PRIoLEASTN
112  * PRIoFASTN
113  * PRIoMAX
114  * PRIoPTR
115  *
116  * PRIuN
117  * PRIuLEASTN
118  * PRIuFASTN
119  * PRIuMAX
120  * PRIuPTR
121  *
122  * PRIxN
123  * PRIxLEASTN
124  * PRIxFASTN
125  * PRIxMAX
126  * PRIxPTR
127  *
128  * PRIXN
129  * PRIXLEASTN
130  * PRIXFASTN
131  * PRIXMAX
132  * PRIXPTR
133  *
134  * "The fscanf() macros for signed integers are:
135  *
136  * SCNdN
137  * SCNdLEASTN
138  * SCNdFASTN
139  * SCNdMAX
140  * SCNdPTR
141  *
142  * SCNiN
143  * SCNiLEASTN
144  * SCNiFASTN
145  * SCNiMAX
146  * SCNiPTR
147  *
148  * "The fscanf() macros for unsigned integers are:
149  *
150  * SCNoN
151  * SCNoLEASTN
152  * SCNoFASTN
153  * SCNoMAX
154  * SCNoPTR
155  *
156  * SCNuN
157  * SCNuLEASTN
158  * SCNuFASTN
159  * SCNuMAX
160  * SCNuPTR
161  *
162  * SCNxN
163  * SCNxLEASTN
164  * SCNxFASTN
165  * SCNxMAX
166  * SCNxPTR
167  *
168  * "For each type that the implementation provides in <stdint.h>, the
169  * corresponding fprintf() and fwprintf() macros shall be defined and the
170  * corresponding fscanf() and fwscanf() macros shall be defined unless the
171  * implementation does not have a suitable modifier for the type.
172  */
173 
174 /****************************************************************************
175  * Type Definitions
176  ****************************************************************************/
177 
178 /* "The <inttypes.h> header shall include a definition of at least the
179  * following type:
180  *
181  * imaxdiv_t
182  * Structure type that is the type of the value returned by the imaxdiv()
183  * function.
184  */
185 
186 typedef struct {
187  intmax_t quot;
188  intmax_t rem;
189 } imaxdiv_t;
190 
191 /****************************************************************************
192  * Public Function Prototypes
193  ****************************************************************************/
194 
195 #ifdef __cplusplus
196 #define EXTERN extern "C"
197 extern "C" {
198 #else
199 #define EXTERN extern
200 #endif
201 
202 /* "The following shall be declared as functions and may also be defined as
203  * macros. Function prototypes shall be provided."
204  */
205 
212 intmax_t imaxabs(intmax_t j);
219 imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
226 intmax_t strtoimax(FAR const char *nptr, FAR char **endptr, int base);
233 uintmax_t strtoumax(FAR const char *nptr, FAR char **endptr, int base);
238 intmax_t wcstoimax(FAR const wchar_t *nptr, FAR wchar_t **endptr, int base);
242 uintmax_t wcstoumax(FAR const wchar_t *nptr, FAR wchar_t **endptr, int base);
243 
244 #if defined(__WORDSIZE) && __WORDSIZE == 64
245 #define __PRI64_PREFIX "l"
246 #define __PRIPTR_PREFIX "l"
247 #else
248 #define __PRI64_PREFIX "ll"
249 #define __PRIPTR_PREFIX
250 #endif
251 
252 # define PRIdPTR __PRIPTR_PREFIX "d"
253 # define PRIiPTR __PRIPTR_PREFIX "i"
254 # define PRIoPTR __PRIPTR_PREFIX "o"
255 # define PRIuPTR __PRIPTR_PREFIX "u"
256 # define PRIxPTR __PRIPTR_PREFIX "x"
257 # define PRIXPTR __PRIPTR_PREFIX "X"
258 
259 #define PRId64 __PRI64_PREFIX "d"
260 
261 #define PRIu8 "u"
262 #define PRIu16 "u"
263 #define PRIu32 "u"
264 #define PRIu64 __PRI64_PREFIX "u"
265 
266 #define PRIx8 "x"
267 #define PRIx16 "x"
268 #define PRIx32 "x"
269 #define PRIx64 __PRI64_PREFIX "x"
270 
271 #define PRIi8 "i"
272 #define PRIi16 "i"
273 #define PRIi32 "i"
274 #define PRIi64 __PRI64_PREFIX "i"
275 
276 #define SCNu8 "hhu"
277 #define SCNu16 "hu"
278 #define SCNu32 "u"
279 #define SCNu64 __PRI64_PREFIX "u"
280 
281 #define SCNi8 "hhi"
282 #define SCNi16 "hi"
283 #define SCNi32 "i"
284 #define SCNi64 __PRI64_PREFIX "i"
285 
289 #undef EXTERN
290 #ifdef __cplusplus
291 }
292 #endif
293 
294 #endif /* __INCLUDE_INTTYPES_H */
295 
imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom)
return quotient and remainder of an integer division
intmax_t rem
Definition: inttypes.h:188
intmax_t quot
Definition: inttypes.h:187
uintmax_t strtoumax(FAR const char *nptr, FAR char **endptr, int base)
convert string to unsigned integer
intmax_t strtoimax(FAR const char *nptr, FAR char **endptr, int base)
convert string to integer
intmax_t imaxabs(intmax_t j)
return absolute value