1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /* 4 ****************************************************************************** 5 * 6 * Copyright (C) 1997-2016, International Business Machines 7 * Corporation and others. All Rights Reserved. 8 * 9 ****************************************************************************** 10 * 11 * FILE NAME : platform.h 12 * 13 * Date Name Description 14 * 05/13/98 nos Creation (content moved here from ptypes.h). 15 * 03/02/99 stephen Added AS400 support. 16 * 03/30/99 stephen Added Linux support. 17 * 04/13/99 stephen Reworked for autoconf. 18 ****************************************************************************** 19 */ 20 21 #ifndef _PLATFORM_H 22 #define _PLATFORM_H 23 24 #include "unicode/uconfig.h" 25 #include "unicode/uvernum.h" 26 27 /** 28 * \file 29 * \brief Basic types for the platform. 30 * 31 * This file used to be generated by autoconf/configure. 32 * Starting with ICU 49, platform.h is a normal source file, 33 * to simplify cross-compiling and working with non-autoconf/make build systems. 34 * 35 * When a value in this file does not work on a platform, then please 36 * try to derive it from the U_PLATFORM value 37 * (for which we might need a new value constant in rare cases) 38 * and/or from other macros that are predefined by the compiler 39 * or defined in standard (POSIX or platform or compiler) headers. 40 * 41 * As a temporary workaround, you can add an explicit \#define for some macros 42 * before it is first tested, or add an equivalent -D macro definition 43 * to the compiler's command line. 44 * 45 * Note: Some compilers provide ways to show the predefined macros. 46 * For example, with gcc you can compile an empty .c file and have the compiler 47 * print the predefined macros with 48 * \code 49 * gcc -E -dM -x c /dev/null | sort 50 * \endcode 51 * (You can provide an actual empty .c file rather than /dev/null. 52 * <code>-x c++</code> is for C++.) 53 */ 54 55 /** 56 * Define some things so that they can be documented. 57 * @internal 58 */ 59 #ifdef U_IN_DOXYGEN 60 /* 61 * Problem: "platform.h:335: warning: documentation for unknown define U_HAVE_STD_STRING found." means that U_HAVE_STD_STRING is not documented. 62 * Solution: #define any defines for non @internal API here, so that they are visible in the docs. If you just set PREDEFINED in Doxyfile.in, they won't be documented. 63 */ 64 65 /* None for now. */ 66 #endif 67 68 /** 69 * \def U_PLATFORM 70 * The U_PLATFORM macro defines the platform we're on. 71 * 72 * We used to define one different, value-less macro per platform. 73 * That made it hard to know the set of relevant platforms and macros, 74 * and hard to deal with variants of platforms. 75 * 76 * Starting with ICU 49, we define platforms as numeric macros, 77 * with ranges of values for related platforms and their variants. 78 * The U_PLATFORM macro is set to one of these values. 79 * 80 * Historical note from the Solaris Wikipedia article: 81 * AT&T and Sun collaborated on a project to merge the most popular Unix variants 82 * on the market at that time: BSD, System V, and Xenix. 83 * This became Unix System V Release 4 (SVR4). 84 * 85 * @internal 86 */ 87 88 /** Unknown platform. @internal */ 89 #define U_PF_UNKNOWN 0 90 /** Windows @internal */ 91 #define U_PF_WINDOWS 1000 92 /** MinGW. Windows, calls to Win32 API, but using GNU gcc and binutils. @internal */ 93 #define U_PF_MINGW 1800 94 /** 95 * Cygwin. Windows, calls to cygwin1.dll for Posix functions, 96 * using MSVC or GNU gcc and binutils. 97 * @internal 98 */ 99 #define U_PF_CYGWIN 1900 100 /* Reserve 2000 for U_PF_UNIX? */ 101 /** HP-UX is based on UNIX System V. @internal */ 102 #define U_PF_HPUX 2100 103 /** Solaris is a Unix operating system based on SVR4. @internal */ 104 #define U_PF_SOLARIS 2600 105 /** BSD is a UNIX operating system derivative. @internal */ 106 #define U_PF_BSD 3000 107 /** AIX is based on UNIX System V Releases and 4.3 BSD. @internal */ 108 #define U_PF_AIX 3100 109 /** IRIX is based on UNIX System V with BSD extensions. @internal */ 110 #define U_PF_IRIX 3200 111 /** 112 * Darwin is a POSIX-compliant operating system, composed of code developed by Apple, 113 * as well as code derived from NeXTSTEP, BSD, and other projects, 114 * built around the Mach kernel. 115 * Darwin forms the core set of components upon which Mac OS X, Apple TV, and iOS are based. 116 * (Original description modified from WikiPedia.) 117 * @internal 118 */ 119 #define U_PF_DARWIN 3500 120 /** iPhone OS (iOS) is a derivative of Mac OS X. @internal */ 121 #define U_PF_IPHONE 3550 122 /** QNX is a commercial Unix-like real-time operating system related to BSD. @internal */ 123 #define U_PF_QNX 3700 124 /** Linux is a Unix-like operating system. @internal */ 125 #define U_PF_LINUX 4000 126 /** 127 * Native Client is pretty close to Linux. 128 * See https://developer.chrome.com/native-client and 129 * http://www.chromium.org/nativeclient 130 * @internal 131 */ 132 #define U_PF_BROWSER_NATIVE_CLIENT 4020 133 /** Android is based on Linux. @internal */ 134 #define U_PF_ANDROID 4050 135 /** Fuchsia is a POSIX-ish platform. @internal */ 136 #define U_PF_FUCHSIA 4100 137 /* Maximum value for Linux-based platform is 4499 */ 138 /** 139 * Emscripten is a C++ transpiler for the Web that can target asm.js or 140 * WebAssembly. It provides some POSIX-compatible wrappers and stubs and 141 * some Linux-like functionality, but is not fully compatible with 142 * either. 143 * @internal 144 */ 145 #define U_PF_EMSCRIPTEN 5010 146 /** z/OS is the successor to OS/390 which was the successor to MVS. @internal */ 147 #define U_PF_OS390 9000 148 /** "IBM i" is the current name of what used to be i5/OS and earlier OS/400. @internal */ 149 #define U_PF_OS400 9400 150 151 #ifdef U_PLATFORM 152 /* Use the predefined value. */ 153 #elif defined(__MINGW32__) 154 # define U_PLATFORM U_PF_MINGW 155 #elif defined(__CYGWIN__) 156 # define U_PLATFORM U_PF_CYGWIN 157 #elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 158 # define U_PLATFORM U_PF_WINDOWS 159 #elif defined(__ANDROID__) 160 # define U_PLATFORM U_PF_ANDROID 161 /* Android wchar_t support depends on the API level. */ 162 # include <android/api-level.h> 163 #elif defined(__pnacl__) || defined(__native_client__) 164 # define U_PLATFORM U_PF_BROWSER_NATIVE_CLIENT 165 #elif defined(__Fuchsia__) 166 # define U_PLATFORM U_PF_FUCHSIA 167 #elif defined(linux) || defined(__linux__) || defined(__linux) 168 # define U_PLATFORM U_PF_LINUX 169 #elif defined(__APPLE__) && defined(__MACH__) 170 # include <TargetConditionals.h> 171 # if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && (defined(TARGET_OS_MACCATALYST) && !TARGET_OS_MACCATALYST) /* variant of TARGET_OS_MAC */ 172 # define U_PLATFORM U_PF_IPHONE 173 # else 174 # define U_PLATFORM U_PF_DARWIN 175 # endif 176 #elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__MirBSD__) 177 # if defined(__FreeBSD__) 178 # include <sys/endian.h> 179 # endif 180 # define U_PLATFORM U_PF_BSD 181 #elif defined(sun) || defined(__sun) 182 /* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */ 183 # define U_PLATFORM U_PF_SOLARIS 184 # if defined(__GNUC__) 185 /* Solaris/GCC needs this header file to get the proper endianness. Normally, this 186 * header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h 187 * is included which does not include this header file. 188 */ 189 # include <sys/isa_defs.h> 190 # endif 191 #elif defined(_AIX) || defined(__TOS_AIX__) 192 # define U_PLATFORM U_PF_AIX 193 #elif defined(_hpux) || defined(hpux) || defined(__hpux) 194 # define U_PLATFORM U_PF_HPUX 195 #elif defined(sgi) || defined(__sgi) 196 # define U_PLATFORM U_PF_IRIX 197 #elif defined(__QNX__) || defined(__QNXNTO__) 198 # define U_PLATFORM U_PF_QNX 199 #elif defined(__TOS_MVS__) 200 # define U_PLATFORM U_PF_OS390 201 #elif defined(__OS400__) || defined(__TOS_OS400__) 202 # define U_PLATFORM U_PF_OS400 203 #elif defined(__EMSCRIPTEN__) 204 # define U_PLATFORM U_PF_EMSCRIPTEN 205 #else 206 # define U_PLATFORM U_PF_UNKNOWN 207 #endif 208 209 /** 210 * \def CYGWINMSVC 211 * Defined if this is Windows with Cygwin, but using MSVC rather than gcc. 212 * Otherwise undefined. 213 * @internal 214 */ 215 /* Commented out because this is already set in mh-cygwin-msvc 216 #if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER) 217 # define CYGWINMSVC 218 #endif 219 */ 220 #ifdef U_IN_DOXYGEN 221 # define CYGWINMSVC 222 #endif 223 224 /** 225 * \def U_PLATFORM_USES_ONLY_WIN32_API 226 * Defines whether the platform uses only the Win32 API. 227 * Set to 1 for Windows/MSVC and MinGW but not Cygwin. 228 * @internal 229 */ 230 #ifdef U_PLATFORM_USES_ONLY_WIN32_API 231 /* Use the predefined value. */ 232 #elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC) 233 # define U_PLATFORM_USES_ONLY_WIN32_API 1 234 #else 235 /* Cygwin implements POSIX. */ 236 # define U_PLATFORM_USES_ONLY_WIN32_API 0 237 #endif 238 239 /** 240 * \def U_PLATFORM_HAS_WIN32_API 241 * Defines whether the Win32 API is available on the platform. 242 * Set to 1 for Windows/MSVC, MinGW and Cygwin. 243 * @internal 244 */ 245 #ifdef U_PLATFORM_HAS_WIN32_API 246 /* Use the predefined value. */ 247 #elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 248 # define U_PLATFORM_HAS_WIN32_API 1 249 #else 250 # define U_PLATFORM_HAS_WIN32_API 0 251 #endif 252 253 /** 254 * \def U_PLATFORM_HAS_WINUWP_API 255 * Defines whether target is intended for Universal Windows Platform API 256 * Set to 1 for Windows10 Release Solution Configuration 257 * @internal 258 */ 259 #ifdef U_PLATFORM_HAS_WINUWP_API 260 /* Use the predefined value. */ 261 #else 262 # define U_PLATFORM_HAS_WINUWP_API 0 263 #endif 264 265 /** 266 * \def U_PLATFORM_IMPLEMENTS_POSIX 267 * Defines whether the platform implements (most of) the POSIX API. 268 * Set to 1 for Cygwin and most other platforms. 269 * @internal 270 */ 271 #ifdef U_PLATFORM_IMPLEMENTS_POSIX 272 /* Use the predefined value. */ 273 #elif U_PLATFORM_USES_ONLY_WIN32_API 274 # define U_PLATFORM_IMPLEMENTS_POSIX 0 275 #else 276 # define U_PLATFORM_IMPLEMENTS_POSIX 1 277 #endif 278 279 /** 280 * \def U_PLATFORM_IS_LINUX_BASED 281 * Defines whether the platform is Linux or one of its derivatives. 282 * @internal 283 */ 284 #ifdef U_PLATFORM_IS_LINUX_BASED 285 /* Use the predefined value. */ 286 #elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= 4499 287 # define U_PLATFORM_IS_LINUX_BASED 1 288 #else 289 # define U_PLATFORM_IS_LINUX_BASED 0 290 #endif 291 292 /** 293 * \def U_PLATFORM_IS_DARWIN_BASED 294 * Defines whether the platform is Darwin or one of its derivatives. 295 * @internal 296 */ 297 #ifdef U_PLATFORM_IS_DARWIN_BASED 298 /* Use the predefined value. */ 299 #elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE 300 # define U_PLATFORM_IS_DARWIN_BASED 1 301 #else 302 # define U_PLATFORM_IS_DARWIN_BASED 0 303 #endif 304 305 /** 306 * \def U_HAVE_STDINT_H 307 * Defines whether stdint.h is available. It is a C99 standard header. 308 * We used to include inttypes.h which includes stdint.h but we usually do not need 309 * the additional definitions from inttypes.h. 310 * @internal 311 */ 312 #ifdef U_HAVE_STDINT_H 313 /* Use the predefined value. */ 314 #elif U_PLATFORM_USES_ONLY_WIN32_API 315 # if defined(__BORLANDC__) || U_PLATFORM == U_PF_MINGW || (defined(_MSC_VER) && _MSC_VER>=1600) 316 /* Windows Visual Studio 9 and below do not have stdint.h & inttypes.h, but VS 2010 adds them. */ 317 # define U_HAVE_STDINT_H 1 318 # else 319 # define U_HAVE_STDINT_H 0 320 # endif 321 #elif U_PLATFORM == U_PF_SOLARIS 322 /* Solaris has inttypes.h but not stdint.h. */ 323 # define U_HAVE_STDINT_H 0 324 #elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER) 325 /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */ 326 # define U_HAVE_STDINT_H 0 327 #else 328 # define U_HAVE_STDINT_H 1 329 #endif 330 331 /** 332 * \def U_HAVE_INTTYPES_H 333 * Defines whether inttypes.h is available. It is a C99 standard header. 334 * We include inttypes.h where it is available but stdint.h is not. 335 * @internal 336 */ 337 #ifdef U_HAVE_INTTYPES_H 338 /* Use the predefined value. */ 339 #elif U_PLATFORM == U_PF_SOLARIS 340 /* Solaris has inttypes.h but not stdint.h. */ 341 # define U_HAVE_INTTYPES_H 1 342 #elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER) 343 /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */ 344 # define U_HAVE_INTTYPES_H 1 345 #else 346 /* Most platforms have both inttypes.h and stdint.h, or neither. */ 347 # define U_HAVE_INTTYPES_H U_HAVE_STDINT_H 348 #endif 349 350 /*===========================================================================*/ 351 /** @{ Compiler and environment features */ 352 /*===========================================================================*/ 353 354 /** 355 * \def U_GCC_MAJOR_MINOR 356 * Indicates whether the compiler is gcc (test for != 0), 357 * and if so, contains its major (times 100) and minor version numbers. 358 * If the compiler is not gcc, then U_GCC_MAJOR_MINOR == 0. 359 * 360 * For example, for testing for whether we have gcc, and whether it's 4.6 or higher, 361 * use "#if U_GCC_MAJOR_MINOR >= 406". 362 * @internal 363 */ 364 #ifdef __GNUC__ 365 # define U_GCC_MAJOR_MINOR (__GNUC__ * 100 + __GNUC_MINOR__) 366 #else 367 # define U_GCC_MAJOR_MINOR 0 368 #endif 369 370 /** 371 * \def U_IS_BIG_ENDIAN 372 * Determines the endianness of the platform. 373 * @internal 374 */ 375 #ifdef U_IS_BIG_ENDIAN 376 /* Use the predefined value. */ 377 #elif defined(BYTE_ORDER) && defined(BIG_ENDIAN) 378 # define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN) 379 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) 380 /* gcc */ 381 # define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) 382 #elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN) 383 # define U_IS_BIG_ENDIAN 1 384 #elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN) 385 # define U_IS_BIG_ENDIAN 0 386 #elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400 || defined(__s390__) || defined(__s390x__) 387 /* These platforms do not appear to predefine any endianness macros. */ 388 # define U_IS_BIG_ENDIAN 1 389 #elif defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) 390 /* HPPA do not appear to predefine any endianness macros. */ 391 # define U_IS_BIG_ENDIAN 1 392 #elif defined(sparc) || defined(__sparc) || defined(__sparc__) 393 /* Some sparc based systems (e.g. Linux) do not predefine any endianness macros. */ 394 # define U_IS_BIG_ENDIAN 1 395 #else 396 # define U_IS_BIG_ENDIAN 0 397 #endif 398 399 /** 400 * \def U_HAVE_PLACEMENT_NEW 401 * Determines whether to override placement new and delete for STL. 402 * @stable ICU 2.6 403 */ 404 #ifdef U_HAVE_PLACEMENT_NEW 405 /* Use the predefined value. */ 406 #elif defined(__BORLANDC__) 407 # define U_HAVE_PLACEMENT_NEW 0 408 #else 409 # define U_HAVE_PLACEMENT_NEW 1 410 #endif 411 412 /** 413 * \def U_HAVE_DEBUG_LOCATION_NEW 414 * Define this to define the MFC debug version of the operator new. 415 * 416 * @stable ICU 3.4 417 */ 418 #ifdef U_HAVE_DEBUG_LOCATION_NEW 419 /* Use the predefined value. */ 420 #elif defined(_MSC_VER) 421 # define U_HAVE_DEBUG_LOCATION_NEW 1 422 #else 423 # define U_HAVE_DEBUG_LOCATION_NEW 0 424 #endif 425 426 /* Compatibility with compilers other than clang: http://clang.llvm.org/docs/LanguageExtensions.html */ 427 #ifdef __has_attribute 428 # define UPRV_HAS_ATTRIBUTE(x) __has_attribute(x) 429 #else 430 # define UPRV_HAS_ATTRIBUTE(x) 0 431 #endif 432 #ifdef __has_cpp_attribute 433 # define UPRV_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) 434 #else 435 # define UPRV_HAS_CPP_ATTRIBUTE(x) 0 436 #endif 437 #ifdef __has_declspec_attribute 438 # define UPRV_HAS_DECLSPEC_ATTRIBUTE(x) __has_declspec_attribute(x) 439 #else 440 # define UPRV_HAS_DECLSPEC_ATTRIBUTE(x) 0 441 #endif 442 #ifdef __has_builtin 443 # define UPRV_HAS_BUILTIN(x) __has_builtin(x) 444 #else 445 # define UPRV_HAS_BUILTIN(x) 0 446 #endif 447 #ifdef __has_feature 448 # define UPRV_HAS_FEATURE(x) __has_feature(x) 449 #else 450 # define UPRV_HAS_FEATURE(x) 0 451 #endif 452 #ifdef __has_extension 453 # define UPRV_HAS_EXTENSION(x) __has_extension(x) 454 #else 455 # define UPRV_HAS_EXTENSION(x) 0 456 #endif 457 #ifdef __has_warning 458 # define UPRV_HAS_WARNING(x) __has_warning(x) 459 #else 460 # define UPRV_HAS_WARNING(x) 0 461 #endif 462 463 464 #if defined(__clang__) 465 #define UPRV_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined"))) 466 #else 467 #define UPRV_NO_SANITIZE_UNDEFINED 468 #endif 469 470 /** 471 * \def U_MALLOC_ATTR 472 * Attribute to mark functions as malloc-like 473 * @internal 474 */ 475 #if defined(__GNUC__) && __GNUC__>=3 476 # define U_MALLOC_ATTR __attribute__ ((__malloc__)) 477 #else 478 # define U_MALLOC_ATTR 479 #endif 480 481 /** 482 * \def U_ALLOC_SIZE_ATTR 483 * Attribute to specify the size of the allocated buffer for malloc-like functions 484 * @internal 485 */ 486 #if (defined(__GNUC__) && \ 487 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || \ 488 UPRV_HAS_ATTRIBUTE(alloc_size) 489 # define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X))) 490 # define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y))) 491 #else 492 # define U_ALLOC_SIZE_ATTR(X) 493 # define U_ALLOC_SIZE_ATTR2(X,Y) 494 #endif 495 496 /** 497 * \def U_CPLUSPLUS_VERSION 498 * 0 if no C++; 1, 11, 14, ... if C++. 499 * Support for specific features cannot always be determined by the C++ version alone. 500 * @internal 501 */ 502 #ifdef U_CPLUSPLUS_VERSION 503 # if U_CPLUSPLUS_VERSION != 0 && !defined(__cplusplus) 504 # undef U_CPLUSPLUS_VERSION 505 # define U_CPLUSPLUS_VERSION 0 506 # endif 507 /* Otherwise use the predefined value. */ 508 #elif !defined(__cplusplus) 509 # define U_CPLUSPLUS_VERSION 0 510 #elif __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) 511 # define U_CPLUSPLUS_VERSION 14 512 #elif __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L) 513 # define U_CPLUSPLUS_VERSION 11 514 #else 515 // C++98 or C++03 516 # define U_CPLUSPLUS_VERSION 1 517 #endif 518 519 /** 520 * \def U_FALLTHROUGH 521 * Annotate intentional fall-through between switch labels. 522 * http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough 523 * @internal 524 */ 525 #ifndef __cplusplus 526 // Not for C. 527 #elif defined(U_FALLTHROUGH) 528 // Use the predefined value. 529 #elif defined(__clang__) 530 // Test for compiler vs. feature separately. 531 // Other compilers might choke on the feature test. 532 # if UPRV_HAS_CPP_ATTRIBUTE(clang::fallthrough) || \ 533 (UPRV_HAS_FEATURE(cxx_attributes) && \ 534 UPRV_HAS_WARNING("-Wimplicit-fallthrough")) 535 # define U_FALLTHROUGH [[clang::fallthrough]] 536 # endif 537 #elif defined(__GNUC__) && (__GNUC__ >= 7) 538 # define U_FALLTHROUGH __attribute__((fallthrough)) 539 #endif 540 541 #ifndef U_FALLTHROUGH 542 # define U_FALLTHROUGH 543 #endif 544 545 /** @} */ 546 547 /*===========================================================================*/ 548 /** @{ Character data types */ 549 /*===========================================================================*/ 550 551 /** 552 * U_CHARSET_FAMILY is equal to this value when the platform is an ASCII based platform. 553 * @stable ICU 2.0 554 */ 555 #define U_ASCII_FAMILY 0 556 557 /** 558 * U_CHARSET_FAMILY is equal to this value when the platform is an EBCDIC based platform. 559 * @stable ICU 2.0 560 */ 561 #define U_EBCDIC_FAMILY 1 562 563 /** 564 * \def U_CHARSET_FAMILY 565 * 566 * <p>These definitions allow to specify the encoding of text 567 * in the char data type as defined by the platform and the compiler. 568 * It is enough to determine the code point values of "invariant characters", 569 * which are the ones shared by all encodings that are in use 570 * on a given platform.</p> 571 * 572 * <p>Those "invariant characters" should be all the uppercase and lowercase 573 * latin letters, the digits, the space, and "basic punctuation". 574 * Also, '\\n', '\\r', '\\t' should be available.</p> 575 * 576 * <p>The list of "invariant characters" is:<br> 577 * \code 578 * A-Z a-z 0-9 SPACE " % & ' ( ) * + , - . / : ; < = > ? _ 579 * \endcode 580 * <br> 581 * (52 letters + 10 numbers + 20 punc/sym/space = 82 total)</p> 582 * 583 * <p>This matches the IBM Syntactic Character Set (CS 640).</p> 584 * 585 * <p>In other words, all the graphic characters in 7-bit ASCII should 586 * be safely accessible except the following:</p> 587 * 588 * \code 589 * '\' <backslash> 590 * '[' <left bracket> 591 * ']' <right bracket> 592 * '{' <left brace> 593 * '}' <right brace> 594 * '^' <circumflex> 595 * '~' <tilde> 596 * '!' <exclamation mark> 597 * '#' <number sign> 598 * '|' <vertical line> 599 * '$' <dollar sign> 600 * '@' <commercial at> 601 * '`' <grave accent> 602 * \endcode 603 * @stable ICU 2.0 604 */ 605 #ifdef U_CHARSET_FAMILY 606 /* Use the predefined value. */ 607 #elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB) 608 # define U_CHARSET_FAMILY U_EBCDIC_FAMILY 609 #elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__) 610 # define U_CHARSET_FAMILY U_EBCDIC_FAMILY 611 #else 612 # define U_CHARSET_FAMILY U_ASCII_FAMILY 613 #endif 614 615 /** 616 * \def U_CHARSET_IS_UTF8 617 * 618 * Hardcode the default charset to UTF-8. 619 * 620 * If this is set to 1, then 621 * - ICU will assume that all non-invariant char*, StringPiece, std::string etc. 622 * contain UTF-8 text, regardless of what the system API uses 623 * - some ICU code will use fast functions like u_strFromUTF8() 624 * rather than the more general and more heavy-weight conversion API (ucnv.h) 625 * - ucnv_getDefaultName() always returns "UTF-8" 626 * - ucnv_setDefaultName() is disabled and will not change the default charset 627 * - static builds of ICU are smaller 628 * - more functionality is available with the UCONFIG_NO_CONVERSION build-time 629 * configuration option (see unicode/uconfig.h) 630 * - the UCONFIG_NO_CONVERSION build option in uconfig.h is more usable 631 * 632 * @stable ICU 4.2 633 * @see UCONFIG_NO_CONVERSION 634 */ 635 #ifdef U_CHARSET_IS_UTF8 636 /* Use the predefined value. */ 637 #elif U_PLATFORM_IS_LINUX_BASED || U_PLATFORM_IS_DARWIN_BASED || \ 638 U_PLATFORM == U_PF_EMSCRIPTEN 639 # define U_CHARSET_IS_UTF8 1 640 #else 641 # define U_CHARSET_IS_UTF8 0 642 #endif 643 644 /** @} */ 645 646 /*===========================================================================*/ 647 /** @{ Information about wchar support */ 648 /*===========================================================================*/ 649 650 /** 651 * \def U_HAVE_WCHAR_H 652 * Indicates whether <wchar.h> is available (1) or not (0). Set to 1 by default. 653 * 654 * @stable ICU 2.0 655 */ 656 #ifdef U_HAVE_WCHAR_H 657 /* Use the predefined value. */ 658 #elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9 659 /* 660 * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t. 661 * The type and header existed, but the library functions did not work as expected. 662 * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway. 663 */ 664 # define U_HAVE_WCHAR_H 0 665 #else 666 # define U_HAVE_WCHAR_H 1 667 #endif 668 669 /** 670 * \def U_SIZEOF_WCHAR_T 671 * U_SIZEOF_WCHAR_T==sizeof(wchar_t) 672 * 673 * @stable ICU 2.0 674 */ 675 #ifdef U_SIZEOF_WCHAR_T 676 /* Use the predefined value. */ 677 #elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9) 678 /* 679 * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring. 680 * Newer Mac OS X has size 4. 681 */ 682 # define U_SIZEOF_WCHAR_T 1 683 #elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN 684 # define U_SIZEOF_WCHAR_T 2 685 #elif U_PLATFORM == U_PF_AIX 686 /* 687 * AIX 6.1 information, section "Wide character data representation": 688 * "... the wchar_t datatype is 32-bit in the 64-bit environment and 689 * 16-bit in the 32-bit environment." 690 * and 691 * "All locales use Unicode for their wide character code values (process code), 692 * except the IBM-eucTW codeset." 693 */ 694 # ifdef __64BIT__ 695 # define U_SIZEOF_WCHAR_T 4 696 # else 697 # define U_SIZEOF_WCHAR_T 2 698 # endif 699 #elif U_PLATFORM == U_PF_OS390 700 /* 701 * z/OS V1R11 information center, section "LP64 | ILP32": 702 * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes. 703 * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes." 704 */ 705 # ifdef _LP64 706 # define U_SIZEOF_WCHAR_T 4 707 # else 708 # define U_SIZEOF_WCHAR_T 2 709 # endif 710 #elif U_PLATFORM == U_PF_OS400 711 # if defined(__UTF32__) 712 /* 713 * LOCALETYPE(*LOCALEUTF) is specified. 714 * Wide-character strings are in UTF-32, 715 * narrow-character strings are in UTF-8. 716 */ 717 # define U_SIZEOF_WCHAR_T 4 718 # elif defined(__UCS2__) 719 /* 720 * LOCALETYPE(*LOCALEUCS2) is specified. 721 * Wide-character strings are in UCS-2, 722 * narrow-character strings are in EBCDIC. 723 */ 724 # define U_SIZEOF_WCHAR_T 2 725 # else 726 /* 727 * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified. 728 * Wide-character strings are in 16-bit EBCDIC, 729 * narrow-character strings are in EBCDIC. 730 */ 731 # define U_SIZEOF_WCHAR_T 2 732 # endif 733 #else 734 # define U_SIZEOF_WCHAR_T 4 735 #endif 736 737 #ifndef U_HAVE_WCSCPY 738 #define U_HAVE_WCSCPY U_HAVE_WCHAR_H 739 #endif 740 741 /** @} */ 742 743 /** 744 * \def U_HAVE_CHAR16_T 745 * Defines whether the char16_t type is available for UTF-16 746 * and u"abc" UTF-16 string literals are supported. 747 * This is a new standard type and standard string literal syntax in C++11 748 * but has been available in some compilers before. 749 * @internal 750 */ 751 #ifdef U_HAVE_CHAR16_T 752 /* Use the predefined value. */ 753 #else 754 /* 755 * Notes: 756 * C++11 and C11 require support for UTF-16 literals 757 * TODO: Fix for plain C. Doesn't work on Mac. 758 */ 759 # if U_CPLUSPLUS_VERSION >= 11 || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) 760 # define U_HAVE_CHAR16_T 1 761 # else 762 # define U_HAVE_CHAR16_T 0 763 # endif 764 #endif 765 766 /** 767 * @{ 768 * \def U_DECLARE_UTF16 769 * Do not use this macro because it is not defined on all platforms. 770 * Use the UNICODE_STRING or U_STRING_DECL macros instead. 771 * @internal 772 */ 773 #ifdef U_DECLARE_UTF16 774 /* Use the predefined value. */ 775 #elif U_HAVE_CHAR16_T \ 776 || (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \ 777 || (defined(__HP_aCC) && __HP_aCC >= 035000) \ 778 || (defined(__HP_cc) && __HP_cc >= 111106) \ 779 || (defined(U_IN_DOXYGEN)) 780 # define U_DECLARE_UTF16(string) u ## string 781 #elif U_SIZEOF_WCHAR_T == 2 \ 782 && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__))) 783 # define U_DECLARE_UTF16(string) L ## string 784 #else 785 /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */ 786 #endif 787 788 /** @} */ 789 790 /*===========================================================================*/ 791 /** @{ Symbol import-export control */ 792 /*===========================================================================*/ 793 794 #ifdef U_EXPORT 795 /* Use the predefined value. */ 796 #elif defined(U_STATIC_IMPLEMENTATION) 797 # define U_EXPORT 798 #elif defined(_MSC_VER) || (UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllexport__) && \ 799 UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllimport__)) 800 # define U_EXPORT __declspec(dllexport) 801 #elif defined(__GNUC__) 802 # define U_EXPORT __attribute__((visibility("default"))) 803 #elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \ 804 || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550) 805 # define U_EXPORT __global 806 /*#elif defined(__HP_aCC) || defined(__HP_cc) 807 # define U_EXPORT __declspec(dllexport)*/ 808 #else 809 # define U_EXPORT 810 #endif 811 812 /* U_CALLCONV is related to U_EXPORT2 */ 813 #ifdef U_EXPORT2 814 /* Use the predefined value. */ 815 #elif defined(_MSC_VER) 816 # define U_EXPORT2 __cdecl 817 #else 818 # define U_EXPORT2 819 #endif 820 821 #ifdef U_IMPORT 822 /* Use the predefined value. */ 823 #elif defined(_MSC_VER) || (UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllexport__) && \ 824 UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllimport__)) 825 /* Windows needs to export/import data. */ 826 # define U_IMPORT __declspec(dllimport) 827 #else 828 # define U_IMPORT 829 #endif 830 831 /** 832 * \def U_HIDDEN 833 * This is used to mark internal structs declared within external classes, 834 * to prevent the internal structs from having the same visibility as the 835 * class within which they are declared. 836 * @internal 837 */ 838 #ifdef U_HIDDEN 839 /* Use the predefined value. */ 840 #elif defined(__GNUC__) 841 # define U_HIDDEN __attribute__((visibility("hidden"))) 842 #else 843 # define U_HIDDEN 844 #endif 845 846 /** 847 * \def U_CALLCONV 848 * Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary 849 * in callback function typedefs to make sure that the calling convention 850 * is compatible. 851 * 852 * This is only used for non-ICU-API functions. 853 * When a function is a public ICU API, 854 * you must use the U_CAPI and U_EXPORT2 qualifiers. 855 * 856 * Please note, you need to use U_CALLCONV after the *. 857 * 858 * NO : "static const char U_CALLCONV *func( . . . )" 859 * YES: "static const char* U_CALLCONV func( . . . )" 860 * 861 * @stable ICU 2.0 862 */ 863 #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus) 864 # define U_CALLCONV __cdecl 865 #else 866 # define U_CALLCONV U_EXPORT2 867 #endif 868 869 /** 870 * \def U_CALLCONV_FPTR 871 * Similar to U_CALLCONV, but only used on function pointers. 872 * @internal 873 */ 874 #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus) 875 # define U_CALLCONV_FPTR U_CALLCONV 876 #else 877 # define U_CALLCONV_FPTR 878 #endif 879 /** @} */ 880 881 #endif // _PLATFORM_H 882