ICU 62.1  62.1
platform.h
Go to the documentation of this file.
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 
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 
89 #define U_PF_UNKNOWN 0
90 
91 #define U_PF_WINDOWS 1000
92 
93 #define U_PF_MINGW 1800
94 
99 #define U_PF_CYGWIN 1900
100 /* Reserve 2000 for U_PF_UNIX? */
102 #define U_PF_HPUX 2100
103 
104 #define U_PF_SOLARIS 2600
105 
106 #define U_PF_BSD 3000
107 
108 #define U_PF_AIX 3100
109 
110 #define U_PF_IRIX 3200
111 
119 #define U_PF_DARWIN 3500
120 
121 #define U_PF_IPHONE 3550
122 
123 #define U_PF_QNX 3700
124 
125 #define U_PF_LINUX 4000
126 
132 #define U_PF_BROWSER_NATIVE_CLIENT 4020
133 
134 #define U_PF_ANDROID 4050
135 
136 #define U_PF_FUCHSIA 4100
137 /* Maximum value for Linux-based platform is 4499 */
139 #define U_PF_OS390 9000
140 
141 #define U_PF_OS400 9400
142 
143 #ifdef U_PLATFORM
144  /* Use the predefined value. */
145 #elif defined(__MINGW32__)
146 # define U_PLATFORM U_PF_MINGW
147 #elif defined(__CYGWIN__)
148 # define U_PLATFORM U_PF_CYGWIN
149 #elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
150 # define U_PLATFORM U_PF_WINDOWS
151 #elif defined(__ANDROID__)
152 # define U_PLATFORM U_PF_ANDROID
153  /* Android wchar_t support depends on the API level. */
154 # include <android/api-level.h>
155 #elif defined(__pnacl__) || defined(__native_client__)
156 # define U_PLATFORM U_PF_BROWSER_NATIVE_CLIENT
157 #elif defined(__Fuchsia__)
158 # define U_PLATFORM U_PF_FUCHSIA
159 #elif defined(linux) || defined(__linux__) || defined(__linux)
160 # define U_PLATFORM U_PF_LINUX
161 #elif defined(__APPLE__) && defined(__MACH__)
162 # include <TargetConditionals.h>
163 # if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE /* variant of TARGET_OS_MAC */
164 # define U_PLATFORM U_PF_IPHONE
165 # else
166 # define U_PLATFORM U_PF_DARWIN
167 # endif
168 #elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__MirBSD__)
169 # if defined(__FreeBSD__)
170 # include <sys/endian.h>
171 # endif
172 # define U_PLATFORM U_PF_BSD
173 #elif defined(sun) || defined(__sun)
174  /* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */
175 # define U_PLATFORM U_PF_SOLARIS
176 # if defined(__GNUC__)
177  /* Solaris/GCC needs this header file to get the proper endianness. Normally, this
178  * header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h
179  * is included which does not include this header file.
180  */
181 # include <sys/isa_defs.h>
182 # endif
183 #elif defined(_AIX) || defined(__TOS_AIX__)
184 # define U_PLATFORM U_PF_AIX
185 #elif defined(_hpux) || defined(hpux) || defined(__hpux)
186 # define U_PLATFORM U_PF_HPUX
187 #elif defined(sgi) || defined(__sgi)
188 # define U_PLATFORM U_PF_IRIX
189 #elif defined(__QNX__) || defined(__QNXNTO__)
190 # define U_PLATFORM U_PF_QNX
191 #elif defined(__TOS_MVS__)
192 # define U_PLATFORM U_PF_OS390
193 #elif defined(__OS400__) || defined(__TOS_OS400__)
194 # define U_PLATFORM U_PF_OS400
195 #else
196 # define U_PLATFORM U_PF_UNKNOWN
197 #endif
198 
205 /* Commented out because this is already set in mh-cygwin-msvc
206 #if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER)
207 # define CYGWINMSVC
208 #endif
209 */
210 
217 #ifdef U_PLATFORM_USES_ONLY_WIN32_API
218  /* Use the predefined value. */
219 #elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC)
220 # define U_PLATFORM_USES_ONLY_WIN32_API 1
221 #else
222  /* Cygwin implements POSIX. */
223 # define U_PLATFORM_USES_ONLY_WIN32_API 0
224 #endif
225 
232 #ifdef U_PLATFORM_HAS_WIN32_API
233  /* Use the predefined value. */
234 #elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
235 # define U_PLATFORM_HAS_WIN32_API 1
236 #else
237 # define U_PLATFORM_HAS_WIN32_API 0
238 #endif
239 
246 #ifdef U_PLATFORM_HAS_WINUWP_API
247  /* Use the predefined value. */
248 #else
249 # define U_PLATFORM_HAS_WINUWP_API 0
250 #endif
251 
258 #ifdef U_PLATFORM_IMPLEMENTS_POSIX
259  /* Use the predefined value. */
260 #elif U_PLATFORM_USES_ONLY_WIN32_API
261 # define U_PLATFORM_IMPLEMENTS_POSIX 0
262 #else
263 # define U_PLATFORM_IMPLEMENTS_POSIX 1
264 #endif
265 
271 #ifdef U_PLATFORM_IS_LINUX_BASED
272  /* Use the predefined value. */
273 #elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= 4499
274 # define U_PLATFORM_IS_LINUX_BASED 1
275 #else
276 # define U_PLATFORM_IS_LINUX_BASED 0
277 #endif
278 
284 #ifdef U_PLATFORM_IS_DARWIN_BASED
285  /* Use the predefined value. */
286 #elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE
287 # define U_PLATFORM_IS_DARWIN_BASED 1
288 #else
289 # define U_PLATFORM_IS_DARWIN_BASED 0
290 #endif
291 
299 #ifdef U_HAVE_STDINT_H
300  /* Use the predefined value. */
301 #elif U_PLATFORM_USES_ONLY_WIN32_API
302 # if defined(__BORLANDC__) || U_PLATFORM == U_PF_MINGW || (defined(_MSC_VER) && _MSC_VER>=1600)
303  /* Windows Visual Studio 9 and below do not have stdint.h & inttypes.h, but VS 2010 adds them. */
304 # define U_HAVE_STDINT_H 1
305 # else
306 # define U_HAVE_STDINT_H 0
307 # endif
308 #elif U_PLATFORM == U_PF_SOLARIS
309  /* Solaris has inttypes.h but not stdint.h. */
310 # define U_HAVE_STDINT_H 0
311 #elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER)
312  /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */
313 # define U_HAVE_STDINT_H 0
314 #else
315 # define U_HAVE_STDINT_H 1
316 #endif
317 
324 #ifdef U_HAVE_INTTYPES_H
325  /* Use the predefined value. */
326 #elif U_PLATFORM == U_PF_SOLARIS
327  /* Solaris has inttypes.h but not stdint.h. */
328 # define U_HAVE_INTTYPES_H 1
329 #elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER)
330  /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */
331 # define U_HAVE_INTTYPES_H 1
332 #else
333  /* Most platforms have both inttypes.h and stdint.h, or neither. */
334 # define U_HAVE_INTTYPES_H U_HAVE_STDINT_H
335 #endif
336 
337 /*===========================================================================*/
339 /*===========================================================================*/
340 
351 #ifdef __GNUC__
352 # define U_GCC_MAJOR_MINOR (__GNUC__ * 100 + __GNUC_MINOR__)
353 #else
354 # define U_GCC_MAJOR_MINOR 0
355 #endif
356 
362 #ifdef U_IS_BIG_ENDIAN
363  /* Use the predefined value. */
364 #elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
365 # define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN)
366 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
367  /* gcc */
368 # define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
369 #elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
370 # define U_IS_BIG_ENDIAN 1
371 #elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN)
372 # define U_IS_BIG_ENDIAN 0
373 #elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400 || defined(__s390__) || defined(__s390x__)
374  /* These platforms do not appear to predefine any endianness macros. */
375 # define U_IS_BIG_ENDIAN 1
376 #elif defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0)
377  /* HPPA do not appear to predefine any endianness macros. */
378 # define U_IS_BIG_ENDIAN 1
379 #elif defined(sparc) || defined(__sparc) || defined(__sparc__)
380  /* Some sparc based systems (e.g. Linux) do not predefine any endianness macros. */
381 # define U_IS_BIG_ENDIAN 1
382 #else
383 # define U_IS_BIG_ENDIAN 0
384 #endif
385 
391 #ifdef U_HAVE_PLACEMENT_NEW
392  /* Use the predefined value. */
393 #elif defined(__BORLANDC__)
394 # define U_HAVE_PLACEMENT_NEW 0
395 #else
396 # define U_HAVE_PLACEMENT_NEW 1
397 #endif
398 
405 #ifdef U_HAVE_DEBUG_LOCATION_NEW
406  /* Use the predefined value. */
407 #elif defined(_MSC_VER)
408 # define U_HAVE_DEBUG_LOCATION_NEW 1
409 #else
410 # define U_HAVE_DEBUG_LOCATION_NEW 0
411 #endif
412 
413 /* Compatibility with compilers other than clang: http://clang.llvm.org/docs/LanguageExtensions.html */
414 #ifndef __has_attribute
415 # define __has_attribute(x) 0
416 #endif
417 #ifndef __has_cpp_attribute
418 # define __has_cpp_attribute(x) 0
419 #endif
420 #ifndef __has_builtin
421 # define __has_builtin(x) 0
422 #endif
423 #ifndef __has_feature
424 # define __has_feature(x) 0
425 #endif
426 #ifndef __has_extension
427 # define __has_extension(x) 0
428 #endif
429 #ifndef __has_warning
430 # define __has_warning(x) 0
431 #endif
432 
438 #if defined(__GNUC__) && __GNUC__>=3
439 # define U_MALLOC_ATTR __attribute__ ((__malloc__))
440 #else
441 # define U_MALLOC_ATTR
442 #endif
443 
449 #if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || __has_attribute(alloc_size)
450 # define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X)))
451 # define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y)))
452 #else
453 # define U_ALLOC_SIZE_ATTR(X)
454 # define U_ALLOC_SIZE_ATTR2(X,Y)
455 #endif
456 
463 #ifdef U_CPLUSPLUS_VERSION
464 # if U_CPLUSPLUS_VERSION != 0 && !defined(__cplusplus)
465 # undef U_CPLUSPLUS_VERSION
466 # define U_CPLUSPLUS_VERSION 0
467 # endif
468  /* Otherwise use the predefined value. */
469 #elif !defined(__cplusplus)
470 # define U_CPLUSPLUS_VERSION 0
471 #elif __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
472 # define U_CPLUSPLUS_VERSION 14
473 #elif __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
474 # define U_CPLUSPLUS_VERSION 11
475 #else
476  // C++98 or C++03
477 # define U_CPLUSPLUS_VERSION 1
478 #endif
479 
480 #if (U_PLATFORM == U_PF_AIX || U_PLATFORM == U_PF_OS390) && defined(__cplusplus) &&(U_CPLUSPLUS_VERSION < 11)
481 // add in std::nullptr_t
482 namespace std {
483  typedef decltype(nullptr) nullptr_t;
484 };
485 #endif
486 
494 #ifdef U_NOEXCEPT
495  /* Use the predefined value. */
496 #elif defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS /* Visual Studio */
497 # define U_NOEXCEPT
498 #elif U_CPLUSPLUS_VERSION >= 11 || __has_feature(cxx_noexcept) || __has_extension(cxx_noexcept) \
499  || (defined(_MSC_VER) && _MSC_VER >= 1900) /* Visual Studio 2015 */
500 # define U_NOEXCEPT noexcept
501 #else
502 # define U_NOEXCEPT
503 #endif
504 
511 #ifndef __cplusplus
512  // Not for C.
513 #elif defined(U_FALLTHROUGH)
514  // Use the predefined value.
515 #elif defined(__clang__)
516  // Test for compiler vs. feature separately.
517  // Other compilers might choke on the feature test.
518 # if __has_cpp_attribute(clang::fallthrough) || \
519  (__has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough"))
520 # define U_FALLTHROUGH [[clang::fallthrough]]
521 # endif
522 #endif
523 
524 #ifndef U_FALLTHROUGH
525 # define U_FALLTHROUGH
526 #endif
527 
530 /*===========================================================================*/
532 /*===========================================================================*/
533 
538 #define U_ASCII_FAMILY 0
539 
544 #define U_EBCDIC_FAMILY 1
545 
588 #ifdef U_CHARSET_FAMILY
589  /* Use the predefined value. */
590 #elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB)
591 # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
592 #elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__)
593 # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
594 #else
595 # define U_CHARSET_FAMILY U_ASCII_FAMILY
596 #endif
597 
618 #ifdef U_CHARSET_IS_UTF8
619  /* Use the predefined value. */
620 #elif U_PLATFORM_IS_LINUX_BASED || U_PLATFORM_IS_DARWIN_BASED
621 # define U_CHARSET_IS_UTF8 1
622 #else
623 # define U_CHARSET_IS_UTF8 0
624 #endif
625 
628 /*===========================================================================*/
630 /*===========================================================================*/
631 
638 #ifdef U_HAVE_WCHAR_H
639  /* Use the predefined value. */
640 #elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9
641  /*
642  * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t.
643  * The type and header existed, but the library functions did not work as expected.
644  * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway.
645  */
646 # define U_HAVE_WCHAR_H 0
647 #else
648 # define U_HAVE_WCHAR_H 1
649 #endif
650 
657 #ifdef U_SIZEOF_WCHAR_T
658  /* Use the predefined value. */
659 #elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9)
660  /*
661  * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring.
662  * Newer Mac OS X has size 4.
663  */
664 # define U_SIZEOF_WCHAR_T 1
665 #elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN
666 # define U_SIZEOF_WCHAR_T 2
667 #elif U_PLATFORM == U_PF_AIX
668  /*
669  * AIX 6.1 information, section "Wide character data representation":
670  * "... the wchar_t datatype is 32-bit in the 64-bit environment and
671  * 16-bit in the 32-bit environment."
672  * and
673  * "All locales use Unicode for their wide character code values (process code),
674  * except the IBM-eucTW codeset."
675  */
676 # ifdef __64BIT__
677 # define U_SIZEOF_WCHAR_T 4
678 # else
679 # define U_SIZEOF_WCHAR_T 2
680 # endif
681 #elif U_PLATFORM == U_PF_OS390
682  /*
683  * z/OS V1R11 information center, section "LP64 | ILP32":
684  * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes.
685  * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes."
686  */
687 # ifdef _LP64
688 # define U_SIZEOF_WCHAR_T 4
689 # else
690 # define U_SIZEOF_WCHAR_T 2
691 # endif
692 #elif U_PLATFORM == U_PF_OS400
693 # if defined(__UTF32__)
694  /*
695  * LOCALETYPE(*LOCALEUTF) is specified.
696  * Wide-character strings are in UTF-32,
697  * narrow-character strings are in UTF-8.
698  */
699 # define U_SIZEOF_WCHAR_T 4
700 # elif defined(__UCS2__)
701  /*
702  * LOCALETYPE(*LOCALEUCS2) is specified.
703  * Wide-character strings are in UCS-2,
704  * narrow-character strings are in EBCDIC.
705  */
706 # define U_SIZEOF_WCHAR_T 2
707 #else
708  /*
709  * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified.
710  * Wide-character strings are in 16-bit EBCDIC,
711  * narrow-character strings are in EBCDIC.
712  */
713 # define U_SIZEOF_WCHAR_T 2
714 # endif
715 #else
716 # define U_SIZEOF_WCHAR_T 4
717 #endif
718 
719 #ifndef U_HAVE_WCSCPY
720 #define U_HAVE_WCSCPY U_HAVE_WCHAR_H
721 #endif
722 
733 #ifdef U_HAVE_CHAR16_T
734  /* Use the predefined value. */
735 #else
736  /*
737  * Notes:
738  * Visual Studio 2010 (_MSC_VER==1600) defines char16_t as a typedef
739  * and does not support u"abc" string literals.
740  * Visual Studio 2015 (_MSC_VER>=1900) and above adds support for
741  * both char16_t and u"abc" string literals.
742  * gcc 4.4 defines the __CHAR16_TYPE__ macro to a usable type but
743  * does not support u"abc" string literals.
744  * C++11 and C11 require support for UTF-16 literals
745  * TODO: Fix for plain C. Doesn't work on Mac.
746  */
747 # if U_CPLUSPLUS_VERSION >= 11 || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
748 # define U_HAVE_CHAR16_T 1
749 # else
750 # define U_HAVE_CHAR16_T 0
751 # endif
752 #endif
753 
761 #ifdef U_DECLARE_UTF16
762  /* Use the predefined value. */
763 #elif U_HAVE_CHAR16_T \
764  || (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \
765  || (defined(__HP_aCC) && __HP_aCC >= 035000) \
766  || (defined(__HP_cc) && __HP_cc >= 111106)
767 # define U_DECLARE_UTF16(string) u ## string
768 #elif U_SIZEOF_WCHAR_T == 2 \
769  && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__)))
770 # define U_DECLARE_UTF16(string) L ## string
771 #else
772  /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */
773 #endif
774 
777 /*===========================================================================*/
779 /*===========================================================================*/
780 
781 #ifdef U_EXPORT
782  /* Use the predefined value. */
783 #elif defined(U_STATIC_IMPLEMENTATION)
784 # define U_EXPORT
785 #elif defined(__GNUC__)
786 # define U_EXPORT __attribute__((visibility("default")))
787 #elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
788  || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550)
789 # define U_EXPORT __global
790 /*#elif defined(__HP_aCC) || defined(__HP_cc)
791 # define U_EXPORT __declspec(dllexport)*/
792 #elif defined(_MSC_VER)
793 # define U_EXPORT __declspec(dllexport)
794 #else
795 # define U_EXPORT
796 #endif
797 
798 /* U_CALLCONV is releated to U_EXPORT2 */
799 #ifdef U_EXPORT2
800  /* Use the predefined value. */
801 #elif defined(_MSC_VER)
802 # define U_EXPORT2 __cdecl
803 #else
804 # define U_EXPORT2
805 #endif
806 
807 #ifdef U_IMPORT
808  /* Use the predefined value. */
809 #elif defined(_MSC_VER)
810  /* Windows needs to export/import data. */
811 # define U_IMPORT __declspec(dllimport)
812 #else
813 # define U_IMPORT
814 #endif
815 
833 #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
834 # define U_CALLCONV __cdecl
835 #else
836 # define U_CALLCONV U_EXPORT2
837 #endif
838 
844 #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
845 # define U_CALLCONV_FPTR U_CALLCONV
846 #else
847 # define U_CALLCONV_FPTR
848 #endif
849 /* @} */
850 
851 #endif
C API: definitions of ICU version numbers.
User-configurable settings.