1 /* $OpenBSD: inttypes.h,v 1.14 2022/07/31 01:27:31 guenther 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 _INTTYPES_H_ 20 #define _INTTYPES_H_ 21 22 #include <sys/stdint.h> 23 24 #ifdef __cplusplus 25 #define __wchar_t wchar_t 26 #elif __POSIX_VISIBLE >= 200809 && !defined(_WCHAR_T_DEFINED_) 27 #define _WCHAR_T_DEFINED_ 28 typedef __wchar_t wchar_t; 29 #endif 30 31 /* 32 * 7.8.1 Macros for format specifiers 33 * 34 * Each of the following object-like macros expands to a string 35 * literal containing a conversion specifier, possibly modified by 36 * a prefix such as hh, h, l, or ll, suitable for use within the 37 * format argument of a formatted input/output function when 38 * converting the corresponding integer type. These macro names 39 * have the general form of PRI (character string literals for the 40 * fprintf family) or SCN (character string literals for the fscanf 41 * family), followed by the conversion specifier, followed by a 42 * name corresponding to a similar typedef name. For example, 43 * PRIdFAST32 can be used in a format string to print the value of 44 * an integer of type int_fast32_t. 45 */ 46 47 /* fprintf macros for signed integers */ 48 #define PRId8 "d" /* int8_t */ 49 #define PRId16 "d" /* int16_t */ 50 #define PRId32 "d" /* int32_t */ 51 #define PRId64 "lld" /* int64_t */ 52 53 #define PRIdLEAST8 "d" /* int_least8_t */ 54 #define PRIdLEAST16 "d" /* int_least16_t */ 55 #define PRIdLEAST32 "d" /* int_least32_t */ 56 #define PRIdLEAST64 "lld" /* int_least64_t */ 57 58 #define PRIdFAST8 "d" /* int_fast8_t */ 59 #define PRIdFAST16 "d" /* int_fast16_t */ 60 #define PRIdFAST32 "d" /* int_fast32_t */ 61 #define PRIdFAST64 "lld" /* int_fast64_t */ 62 63 #define PRIdMAX "jd" /* intmax_t */ 64 #define PRIdPTR "ld" /* intptr_t */ 65 66 #define PRIi8 "i" /* int8_t */ 67 #define PRIi16 "i" /* int16_t */ 68 #define PRIi32 "i" /* int32_t */ 69 #define PRIi64 "lli" /* int64_t */ 70 71 #define PRIiLEAST8 "i" /* int_least8_t */ 72 #define PRIiLEAST16 "i" /* int_least16_t */ 73 #define PRIiLEAST32 "i" /* int_least32_t */ 74 #define PRIiLEAST64 "lli" /* int_least64_t */ 75 76 #define PRIiFAST8 "i" /* int_fast8_t */ 77 #define PRIiFAST16 "i" /* int_fast16_t */ 78 #define PRIiFAST32 "i" /* int_fast32_t */ 79 #define PRIiFAST64 "lli" /* int_fast64_t */ 80 81 #define PRIiMAX "ji" /* intmax_t */ 82 #define PRIiPTR "li" /* intptr_t */ 83 84 /* fprintf macros for unsigned integers */ 85 #define PRIo8 "o" /* int8_t */ 86 #define PRIo16 "o" /* int16_t */ 87 #define PRIo32 "o" /* int32_t */ 88 #define PRIo64 "llo" /* int64_t */ 89 90 #define PRIoLEAST8 "o" /* int_least8_t */ 91 #define PRIoLEAST16 "o" /* int_least16_t */ 92 #define PRIoLEAST32 "o" /* int_least32_t */ 93 #define PRIoLEAST64 "llo" /* int_least64_t */ 94 95 #define PRIoFAST8 "o" /* int_fast8_t */ 96 #define PRIoFAST16 "o" /* int_fast16_t */ 97 #define PRIoFAST32 "o" /* int_fast32_t */ 98 #define PRIoFAST64 "llo" /* int_fast64_t */ 99 100 #define PRIoMAX "jo" /* intmax_t */ 101 #define PRIoPTR "lo" /* intptr_t */ 102 103 #define PRIu8 "u" /* uint8_t */ 104 #define PRIu16 "u" /* uint16_t */ 105 #define PRIu32 "u" /* uint32_t */ 106 #define PRIu64 "llu" /* uint64_t */ 107 108 #define PRIuLEAST8 "u" /* uint_least8_t */ 109 #define PRIuLEAST16 "u" /* uint_least16_t */ 110 #define PRIuLEAST32 "u" /* uint_least32_t */ 111 #define PRIuLEAST64 "llu" /* uint_least64_t */ 112 113 #define PRIuFAST8 "u" /* uint_fast8_t */ 114 #define PRIuFAST16 "u" /* uint_fast16_t */ 115 #define PRIuFAST32 "u" /* uint_fast32_t */ 116 #define PRIuFAST64 "llu" /* uint_fast64_t */ 117 118 #define PRIuMAX "ju" /* uintmax_t */ 119 #define PRIuPTR "lu" /* uintptr_t */ 120 121 #define PRIx8 "x" /* uint8_t */ 122 #define PRIx16 "x" /* uint16_t */ 123 #define PRIx32 "x" /* uint32_t */ 124 #define PRIx64 "llx" /* uint64_t */ 125 126 #define PRIxLEAST8 "x" /* uint_least8_t */ 127 #define PRIxLEAST16 "x" /* uint_least16_t */ 128 #define PRIxLEAST32 "x" /* uint_least32_t */ 129 #define PRIxLEAST64 "llx" /* uint_least64_t */ 130 131 #define PRIxFAST8 "x" /* uint_fast8_t */ 132 #define PRIxFAST16 "x" /* uint_fast16_t */ 133 #define PRIxFAST32 "x" /* uint_fast32_t */ 134 #define PRIxFAST64 "llx" /* uint_fast64_t */ 135 136 #define PRIxMAX "jx" /* uintmax_t */ 137 #define PRIxPTR "lx" /* uintptr_t */ 138 139 #define PRIX8 "X" /* uint8_t */ 140 #define PRIX16 "X" /* uint16_t */ 141 #define PRIX32 "X" /* uint32_t */ 142 #define PRIX64 "llX" /* uint64_t */ 143 144 #define PRIXLEAST8 "X" /* uint_least8_t */ 145 #define PRIXLEAST16 "X" /* uint_least16_t */ 146 #define PRIXLEAST32 "X" /* uint_least32_t */ 147 #define PRIXLEAST64 "llX" /* uint_least64_t */ 148 149 #define PRIXFAST8 "X" /* uint_fast8_t */ 150 #define PRIXFAST16 "X" /* uint_fast16_t */ 151 #define PRIXFAST32 "X" /* uint_fast32_t */ 152 #define PRIXFAST64 "llX" /* uint_fast64_t */ 153 154 #define PRIXMAX "jX" /* uintmax_t */ 155 #define PRIXPTR "lX" /* uintptr_t */ 156 157 /* fscanf macros for signed integers */ 158 #define SCNd8 "hhd" /* int8_t */ 159 #define SCNd16 "hd" /* int16_t */ 160 #define SCNd32 "d" /* int32_t */ 161 #define SCNd64 "lld" /* int64_t */ 162 163 #define SCNdLEAST8 "hhd" /* int_least8_t */ 164 #define SCNdLEAST16 "hd" /* int_least16_t */ 165 #define SCNdLEAST32 "d" /* int_least32_t */ 166 #define SCNdLEAST64 "lld" /* int_least64_t */ 167 168 #define SCNdFAST8 "d" /* int_fast8_t */ 169 #define SCNdFAST16 "d" /* int_fast16_t */ 170 #define SCNdFAST32 "d" /* int_fast32_t */ 171 #define SCNdFAST64 "lld" /* int_fast64_t */ 172 173 #define SCNdMAX "jd" /* intmax_t */ 174 #define SCNdPTR "ld" /* intptr_t */ 175 176 #define SCNi8 "hhi" /* int8_t */ 177 #define SCNi16 "hi" /* int16_t */ 178 #define SCNi32 "i" /* int32_t */ 179 #define SCNi64 "lli" /* int64_t */ 180 181 #define SCNiLEAST8 "hhi" /* int_least8_t */ 182 #define SCNiLEAST16 "hi" /* int_least16_t */ 183 #define SCNiLEAST32 "i" /* int_least32_t */ 184 #define SCNiLEAST64 "lli" /* int_least64_t */ 185 186 #define SCNiFAST8 "i" /* int_fast8_t */ 187 #define SCNiFAST16 "i" /* int_fast16_t */ 188 #define SCNiFAST32 "i" /* int_fast32_t */ 189 #define SCNiFAST64 "lli" /* int_fast64_t */ 190 191 #define SCNiMAX "ji" /* intmax_t */ 192 #define SCNiPTR "li" /* intptr_t */ 193 194 /* fscanf macros for unsigned integers */ 195 #define SCNo8 "hho" /* uint8_t */ 196 #define SCNo16 "ho" /* uint16_t */ 197 #define SCNo32 "o" /* uint32_t */ 198 #define SCNo64 "llo" /* uint64_t */ 199 200 #define SCNoLEAST8 "hho" /* uint_least8_t */ 201 #define SCNoLEAST16 "ho" /* uint_least16_t */ 202 #define SCNoLEAST32 "o" /* uint_least32_t */ 203 #define SCNoLEAST64 "llo" /* uint_least64_t */ 204 205 #define SCNoFAST8 "o" /* uint_fast8_t */ 206 #define SCNoFAST16 "o" /* uint_fast16_t */ 207 #define SCNoFAST32 "o" /* uint_fast32_t */ 208 #define SCNoFAST64 "llo" /* uint_fast64_t */ 209 210 #define SCNoMAX "jo" /* uintmax_t */ 211 #define SCNoPTR "lo" /* uintptr_t */ 212 213 #define SCNu8 "hhu" /* uint8_t */ 214 #define SCNu16 "hu" /* uint16_t */ 215 #define SCNu32 "u" /* uint32_t */ 216 #define SCNu64 "llu" /* uint64_t */ 217 218 #define SCNuLEAST8 "hhu" /* uint_least8_t */ 219 #define SCNuLEAST16 "hu" /* uint_least16_t */ 220 #define SCNuLEAST32 "u" /* uint_least32_t */ 221 #define SCNuLEAST64 "llu" /* uint_least64_t */ 222 223 #define SCNuFAST8 "u" /* uint_fast8_t */ 224 #define SCNuFAST16 "u" /* uint_fast16_t */ 225 #define SCNuFAST32 "u" /* uint_fast32_t */ 226 #define SCNuFAST64 "llu" /* uint_fast64_t */ 227 228 #define SCNuMAX "ju" /* uintmax_t */ 229 #define SCNuPTR "lu" /* uintptr_t */ 230 231 #define SCNx8 "hhx" /* uint8_t */ 232 #define SCNx16 "hx" /* uint16_t */ 233 #define SCNx32 "x" /* uint32_t */ 234 #define SCNx64 "llx" /* uint64_t */ 235 236 #define SCNxLEAST8 "hhx" /* uint_least8_t */ 237 #define SCNxLEAST16 "hx" /* uint_least16_t */ 238 #define SCNxLEAST32 "x" /* uint_least32_t */ 239 #define SCNxLEAST64 "llx" /* uint_least64_t */ 240 241 #define SCNxFAST8 "x" /* uint_fast8_t */ 242 #define SCNxFAST16 "x" /* uint_fast16_t */ 243 #define SCNxFAST32 "x" /* uint_fast32_t */ 244 #define SCNxFAST64 "llx" /* uint_fast64_t */ 245 246 #define SCNxMAX "jx" /* uintmax_t */ 247 #define SCNxPTR "lx" /* uintptr_t */ 248 249 typedef struct { 250 intmax_t quot; /* quotient */ 251 intmax_t rem; /* remainder */ 252 } imaxdiv_t; 253 254 __BEGIN_DECLS 255 intmax_t imaxabs(intmax_t); 256 imaxdiv_t imaxdiv(intmax_t, intmax_t); 257 intmax_t strtoimax(const char *, char **, int); 258 uintmax_t strtoumax(const char *, char **, int); 259 intmax_t wcstoimax(const __wchar_t * __restrict, 260 __wchar_t ** __restrict, int); 261 uintmax_t wcstoumax(const __wchar_t * __restrict, 262 __wchar_t ** __restrict, int); 263 __END_DECLS 264 265 #endif /* _INTTYPES_H_ */ 266