1/* 2 * Type and type-support definitions 3 * 4 * Copyright (C) 2014-2021, Joachim Metz <joachim.metz@gmail.com> 5 * 6 * Refer to AUTHORS for acknowledgements. 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with this program. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22#if !defined( _TYPES_H ) 23#define _TYPES_H 24 25#include "common.h" 26 27#if defined( HAVE_LIMITS_H ) || defined( WINAPI ) 28#include <limits.h> 29#endif 30 31/* Make sure to include inttypes.h or stdint.h before 32 * PRI definitions are defined 33 */ 34#include <@PACKAGE@/types.h> 35 36#if defined( WINAPI ) && ( defined( _UNICODE ) || defined( UNICODE ) ) 37 38#define HAVE_WIDE_SYSTEM_CHARACTER 1 39 40/* The system character type is wide 41 * A system string contains either UTF-16 or UTF-32 42 */ 43typedef wchar_t system_character_t; 44typedef wint_t system_integer_t; 45 46#define PRIc_SYSTEM "lc" 47#define PRIs_SYSTEM "ls" 48 49#else 50 51/* The system character type is narrow 52 * A system string contains either UTF-8 or extended ASCII with a codepage 53 */ 54typedef char system_character_t; 55typedef int system_integer_t; 56 57#define PRIc_SYSTEM "c" 58#define PRIs_SYSTEM "s" 59 60#endif /* defined( WINAPI ) && ( defined( _UNICODE ) || defined( UNICODE ) ) */ 61 62/* Fallback for systems without PRI definitions 63 */ 64#if !defined( PRId8 ) 65#define PRId8 "d" 66#endif 67 68#if !defined( PRId16 ) 69#define PRId16 "d" 70#endif 71 72#if !defined( PRId32 ) 73#if defined( WINAPI ) 74#define PRId32 "I32d" 75 76#else 77#define PRId32 "d" 78 79#endif 80#endif /* !defined( PRId32 ) */ 81 82#if !defined( PRId64 ) 83#if defined( WINAPI ) 84#define PRId64 "I64d" 85 86#elif __WORDSIZE == 64 87#define PRId64 "ld" 88 89#else 90#define PRId64 "lld" 91 92#endif 93#endif /* !defined( PRId64 ) */ 94 95#if !defined( PRIi8 ) 96#define PRIi8 "i" 97#endif 98 99#if !defined( PRIi16 ) 100#define PRIi16 "i" 101#endif 102 103#if !defined( PRIi32 ) 104#if defined( WINAPI ) 105#define PRIi32 "I32i" 106 107#else 108#define PRIi32 "i" 109 110#endif 111#endif /* !defined( PRIi32 ) */ 112 113#if !defined( PRIi64 ) 114#if defined( WINAPI ) 115#define PRIi64 "I64i" 116 117#elif __WORDSIZE == 64 118#define PRIi64 "li" 119 120#else 121#define PRIi64 "lli" 122 123#endif 124#endif /* !defined( PRIi64 ) */ 125 126#if !defined( PRIu8 ) 127#define PRIu8 "u" 128#endif 129 130#if !defined( PRIu16 ) 131#define PRIu16 "u" 132#endif 133 134#if !defined( PRIu32 ) 135#if defined( WINAPI ) 136#define PRIu32 "I32u" 137 138#else 139#define PRIu32 "u" 140 141#endif 142#endif /* !defined( PRIu32 ) */ 143 144#if !defined( PRIu64 ) 145#if defined( WINAPI ) 146#define PRIu64 "I64u" 147 148#elif __WORDSIZE == 64 149#define PRIu64 "lu" 150 151#else 152#define PRIu64 "llu" 153 154#endif 155#endif /* !defined( PRIu64 ) */ 156 157#if !defined( PRIo8 ) 158#define PRIo8 "o" 159#endif 160 161#if !defined( PRIo16 ) 162#define PRIo16 "o" 163#endif 164 165#if !defined( PRIo32 ) 166#if defined( WINAPI ) 167#define PRIo32 "I32o" 168 169#else 170#define PRIo32 "o" 171 172#endif 173#endif /* !defined( PRIo32 ) */ 174 175#if !defined( PRIo64 ) 176#if defined( WINAPI ) 177#define PRIo64 "I64o" 178 179#elif __WORDSIZE == 64 180#define PRIo64 "lo" 181 182#else 183#define PRIo64 "llo" 184 185#endif 186#endif /* !defined( PRIo64 ) */ 187 188#if !defined( PRIx8 ) 189#define PRIx8 "x" 190#endif 191 192#if !defined( PRIx16 ) 193#define PRIx16 "x" 194#endif 195 196#if !defined( PRIx32 ) 197#if defined( WINAPI ) 198#define PRIx32 "I32x" 199 200#else 201#define PRIx32 "x" 202 203#endif 204#endif /* !defined( PRIx32 ) */ 205 206#if !defined( PRIx64 ) 207#if defined( WINAPI ) 208#define PRIx64 "I64x" 209 210#elif __WORDSIZE == 64 211#define PRIx64 "lx" 212 213#else 214#define PRIx64 "llx" 215 216#endif 217#endif /* !defined( PRIx64 ) */ 218 219/* Fallback for systems without printf %jd definition 220 */ 221#if defined( HAVE_PRINTF_JD ) 222#define PRIjd "jd" 223#define PRIji "ji" 224#define PRIju "ju" 225#define PRIjx "jx" 226 227#elif SIZEOF_OFF_T == 8 228#define PRIjd PRId64 229#define PRIji PRIi64 230#define PRIju PRIu64 231#define PRIjx PRIx64 232 233#else 234#define PRIjd PRId32 235#define PRIji PRIi32 236#define PRIju PRIu32 237#define PRIjx PRIx32 238 239#endif /* defined( HAVE_PRINTF_JD ) */ 240 241/* Fallback for systems without printf %zd definition 242 */ 243#if defined( HAVE_PRINTF_ZD ) 244#define PRIzd "zd" 245#define PRIzi "zi" 246#define PRIzu "zu" 247#define PRIzx "zx" 248 249#elif defined( _MSC_VER ) 250#define PRIzd "Id" 251#define PRIzi "Ii" 252#define PRIzu "Iu" 253#define PRIzx "Ix" 254 255#elif SIZEOF_SIZE_T == 8 256#define PRIzd PRId64 257#define PRIzi PRIi64 258#define PRIzu PRIu64 259#define PRIzx PRIx64 260 261#else 262#define PRIzd PRId32 263#define PRIzi PRIi32 264#define PRIzu PRIu32 265#define PRIzx PRIx32 266 267#endif /* defined( HAVE_PRINTF_ZD ) */ 268 269/* Fallback for systems without (U)INTx_MAX definitions 270 */ 271 272/* The maximum signed 8-bit integer is 127 (0x7f) 273 */ 274#if !defined( INT8_MAX ) 275#define INT8_MAX (0x7f) 276#endif 277 278/* The maximum unsigned 8-bit integer is 256 (0xff) 279 */ 280#if !defined( UINT8_MAX ) 281#define UINT8_MAX (0xff) 282#endif 283 284/* The maximum signed 16-bit integer is 32767 (0x7ffff) 285 */ 286#if !defined( INT16_MAX ) 287#define INT16_MAX (0x7fff) 288#endif 289 290/* The maximum unsigned 16-bit integer is 65535 (0xffff) 291 */ 292#if !defined( UINT16_MAX ) 293#define UINT16_MAX (0xffff) 294#endif 295 296/* The maximum signed 32-bit integer is 2147483647 (0x7fffffff) 297 */ 298#if !defined( INT32_MAX ) 299#define INT32_MAX (0x7fffffffL) 300#endif 301 302/* The maximum unsigned 32-bit integer is 4294967295 (0xffffffff) 303 */ 304#if !defined( UINT32_MAX ) 305#define UINT32_MAX (0xffffffffUL) 306#endif 307 308/* The maximum signed 64-bit integer is 9223372036854775807 (0x7fffffffffffffff) 309 */ 310#if !defined( INT64_MAX ) 311#if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) 312#define INT64_MAX (0x7fffffffffffffffUL) 313#else 314#define INT64_MAX (0x7fffffffffffffffULL) 315#endif 316#endif /* !defined( INT64_MAX ) */ 317 318/* The maximum unsigned 64-bit integer is 18446744073709551615 (0xffffffffffffffff) 319 */ 320#if !defined( UINT64_MAX ) 321#if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) 322#define UINT64_MAX (0xffffffffffffffffUL) 323#else 324#define UINT64_MAX (0xffffffffffffffffULL) 325#endif 326#endif /* !defined( UINT64_MAX ) */ 327 328/* The maximum signed integer 329 */ 330#if !defined( INT_MAX ) 331#define INT_MAX INT32_MAX 332#endif 333 334/* The maximum unsigned integer 335 */ 336#if !defined( UINT_MAX ) 337#define UINT_MAX UINT32_MAX 338#endif 339 340/* The maximum signed long integer 341 */ 342#if !defined( LONG_MAX ) 343#define LONG_MAX INT32_MAX 344#endif 345 346/* The maximum unsigned long integer 347 */ 348#if !defined( ULONG_MAX ) 349#define ULONG_MAX UINT32_MAX 350#endif 351 352/* The maximum signed size type is platform dependent 353 */ 354#if !defined( SSIZE_MAX ) 355 356#if defined( WINAPI ) 357 358#if defined( _WIN64 ) 359#define SSIZE_MAX INT64_MAX 360#else 361#define SSIZE_MAX INT32_MAX 362#endif 363 364#else 365 366#if __WORDSIZE == 64 367#define SSIZE_MAX INT64_MAX 368#else 369#define SSIZE_MAX INT32_MAX 370#endif 371 372#endif /* WINAPI */ 373 374#endif /* SSIZE_MAX */ 375 376#endif /* !defined( _TYPES_H ) */ 377 378