ICU 56.1  56.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
platform.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 1997-2015, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 ******************************************************************************
8 *
9 * FILE NAME : platform.h
10 *
11 * Date Name Description
12 * 05/13/98 nos Creation (content moved here from ptypes.h).
13 * 03/02/99 stephen Added AS400 support.
14 * 03/30/99 stephen Added Linux support.
15 * 04/13/99 stephen Reworked for autoconf.
16 ******************************************************************************
17 */
18 
19 #ifndef _PLATFORM_H
20 #define _PLATFORM_H
21 
22 #include "unicode/uconfig.h"
23 #include "unicode/uvernum.h"
24 
57 #ifdef U_IN_DOXYGEN
58 /*
59  * Problem: "platform.h:335: warning: documentation for unknown define U_HAVE_STD_STRING found." means that U_HAVE_STD_STRING is not documented.
60  * 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.
61  */
62 
63 /* None for now. */
64 #endif
65 
87 #define U_PF_UNKNOWN 0
88 
89 #define U_PF_WINDOWS 1000
90 
91 #define U_PF_MINGW 1800
92 
97 #define U_PF_CYGWIN 1900
98 /* Reserve 2000 for U_PF_UNIX? */
100 #define U_PF_HPUX 2100
101 
102 #define U_PF_SOLARIS 2600
103 
104 #define U_PF_BSD 3000
105 
106 #define U_PF_AIX 3100
107 
108 #define U_PF_IRIX 3200
109 
117 #define U_PF_DARWIN 3500
118 
119 #define U_PF_IPHONE 3550
120 
121 #define U_PF_QNX 3700
122 
123 #define U_PF_LINUX 4000
124 
130 #define U_PF_BROWSER_NATIVE_CLIENT 4020
131 
132 #define U_PF_ANDROID 4050
133 /* Maximum value for Linux-based platform is 4499 */
135 #define U_PF_OS390 9000
136 
137 #define U_PF_OS400 9400
138 
139 #ifdef U_PLATFORM
140  /* Use the predefined value. */
141 #elif defined(__MINGW32__)
142 # define U_PLATFORM U_PF_MINGW
143 #elif defined(__CYGWIN__)
144 # define U_PLATFORM U_PF_CYGWIN
145 #elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
146 # define U_PLATFORM U_PF_WINDOWS
147 #elif defined(__ANDROID__)
148 # define U_PLATFORM U_PF_ANDROID
149  /* Android wchar_t support depends on the API level. */
150 # include <android/api-level.h>
151 #elif defined(__native_client__)
152 # define U_PLATFORM U_PF_BROWSER_NATIVE_CLIENT
153 #elif defined(linux) || defined(__linux__) || defined(__linux)
154 # define U_PLATFORM U_PF_LINUX
155 #elif defined(__APPLE__) && defined(__MACH__)
156 # include <TargetConditionals.h>
157 # if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE /* variant of TARGET_OS_MAC */
158 # define U_PLATFORM U_PF_IPHONE
159 # else
160 # define U_PLATFORM U_PF_DARWIN
161 # endif
162 #elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__MirBSD__)
163 # if defined(__FreeBSD__)
164 # include <sys/endian.h>
165 # endif
166 # define U_PLATFORM U_PF_BSD
167 #elif defined(sun) || defined(__sun)
168  /* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */
169 # define U_PLATFORM U_PF_SOLARIS
170 # if defined(__GNUC__)
171  /* Solaris/GCC needs this header file to get the proper endianness. Normally, this
172  * header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h
173  * is included which does not include this header file.
174  */
175 # include <sys/isa_defs.h>
176 # endif
177 #elif defined(_AIX) || defined(__TOS_AIX__)
178 # define U_PLATFORM U_PF_AIX
179 #elif defined(_hpux) || defined(hpux) || defined(__hpux)
180 # define U_PLATFORM U_PF_HPUX
181 #elif defined(sgi) || defined(__sgi)
182 # define U_PLATFORM U_PF_IRIX
183 #elif defined(__QNX__) || defined(__QNXNTO__)
184 # define U_PLATFORM U_PF_QNX
185 #elif defined(__TOS_MVS__)
186 # define U_PLATFORM U_PF_OS390
187 #elif defined(__OS400__) || defined(__TOS_OS400__)
188 # define U_PLATFORM U_PF_OS400
189 #else
190 # define U_PLATFORM U_PF_UNKNOWN
191 #endif
192 
199 /* Commented out because this is already set in mh-cygwin-msvc
200 #if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER)
201 # define CYGWINMSVC
202 #endif
203 */
204 
211 #ifdef U_PLATFORM_USES_ONLY_WIN32_API
212  /* Use the predefined value. */
213 #elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC)
214 # define U_PLATFORM_USES_ONLY_WIN32_API 1
215 #else
216  /* Cygwin implements POSIX. */
217 # define U_PLATFORM_USES_ONLY_WIN32_API 0
218 #endif
219 
226 #ifdef U_PLATFORM_HAS_WIN32_API
227  /* Use the predefined value. */
228 #elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
229 # define U_PLATFORM_HAS_WIN32_API 1
230 #else
231 # define U_PLATFORM_HAS_WIN32_API 0
232 #endif
233 
240 #ifdef U_PLATFORM_IMPLEMENTS_POSIX
241  /* Use the predefined value. */
242 #elif U_PLATFORM_USES_ONLY_WIN32_API
243 # define U_PLATFORM_IMPLEMENTS_POSIX 0
244 #else
245 # define U_PLATFORM_IMPLEMENTS_POSIX 1
246 #endif
247 
253 #ifdef U_PLATFORM_IS_LINUX_BASED
254  /* Use the predefined value. */
255 #elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= 4499
256 # define U_PLATFORM_IS_LINUX_BASED 1
257 #else
258 # define U_PLATFORM_IS_LINUX_BASED 0
259 #endif
260 
266 #ifdef U_PLATFORM_IS_DARWIN_BASED
267  /* Use the predefined value. */
268 #elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE
269 # define U_PLATFORM_IS_DARWIN_BASED 1
270 #else
271 # define U_PLATFORM_IS_DARWIN_BASED 0
272 #endif
273 
281 #ifdef U_HAVE_STDINT_H
282  /* Use the predefined value. */
283 #elif U_PLATFORM_USES_ONLY_WIN32_API
284 # if defined(__BORLANDC__) || U_PLATFORM == U_PF_MINGW || (defined(_MSC_VER) && _MSC_VER>=1600)
285  /* Windows Visual Studio 9 and below do not have stdint.h & inttypes.h, but VS 2010 adds them. */
286 # define U_HAVE_STDINT_H 1
287 # else
288 # define U_HAVE_STDINT_H 0
289 # endif
290 #elif U_PLATFORM == U_PF_SOLARIS
291  /* Solaris has inttypes.h but not stdint.h. */
292 # define U_HAVE_STDINT_H 0
293 #elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER)
294  /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */
295 # define U_HAVE_STDINT_H 0
296 #else
297 # define U_HAVE_STDINT_H 1
298 #endif
299 
306 #ifdef U_HAVE_INTTYPES_H
307  /* Use the predefined value. */
308 #elif U_PLATFORM == U_PF_SOLARIS
309  /* Solaris has inttypes.h but not stdint.h. */
310 # define U_HAVE_INTTYPES_H 1
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_INTTYPES_H 1
314 #else
315  /* Most platforms have both inttypes.h and stdint.h, or neither. */
316 # define U_HAVE_INTTYPES_H U_HAVE_STDINT_H
317 #endif
318 
340 #ifndef U_IOSTREAM_SOURCE
341 #define U_IOSTREAM_SOURCE 199711
342 #endif
343 
349 #ifdef U_HAVE_STD_STRING
350  /* Use the predefined value. */
351 #else
352 # define U_HAVE_STD_STRING 1
353 #endif
354 
355 /*===========================================================================*/
357 /*===========================================================================*/
358 
369 #ifdef __GNUC__
370 # define U_GCC_MAJOR_MINOR (__GNUC__ * 100 + __GNUC_MINOR__)
371 #else
372 # define U_GCC_MAJOR_MINOR 0
373 #endif
374 
380 #ifdef U_IS_BIG_ENDIAN
381  /* Use the predefined value. */
382 #elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
383 # define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN)
384 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
385  /* gcc */
386 # define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
387 #elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
388 # define U_IS_BIG_ENDIAN 1
389 #elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN)
390 # define U_IS_BIG_ENDIAN 0
391 #elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400 || defined(__s390__) || defined(__s390x__)
392  /* These platforms do not appear to predefine any endianness macros. */
393 # define U_IS_BIG_ENDIAN 1
394 #elif defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0)
395  /* HPPA do not appear to predefine any endianness macros. */
396 # define U_IS_BIG_ENDIAN 1
397 #elif defined(sparc) || defined(__sparc) || defined(__sparc__)
398  /* Some sparc based systems (e.g. Linux) do not predefine any endianness macros. */
399 # define U_IS_BIG_ENDIAN 1
400 #else
401 # define U_IS_BIG_ENDIAN 0
402 #endif
403 
409 #ifdef U_HAVE_PLACEMENT_NEW
410  /* Use the predefined value. */
411 #elif defined(__BORLANDC__)
412 # define U_HAVE_PLACEMENT_NEW 0
413 #else
414 # define U_HAVE_PLACEMENT_NEW 1
415 #endif
416 
423 #ifdef U_HAVE_DEBUG_LOCATION_NEW
424  /* Use the predefined value. */
425 #elif defined(_MSC_VER)
426 # define U_HAVE_DEBUG_LOCATION_NEW 1
427 #else
428 # define U_HAVE_DEBUG_LOCATION_NEW 0
429 #endif
430 
431 /* Compatibility with non clang compilers */
432 #ifndef __has_attribute
433 # define __has_attribute(x) 0
434 #endif
435 #ifndef __has_builtin
436 # define __has_builtin(x) 0
437 #endif
438 #ifndef __has_feature
439 # define __has_feature(x) 0
440 #endif
441 #ifndef __has_extension
442 # define __has_extension(x) 0
443 #endif
444 
450 #if defined(__GNUC__) && __GNUC__>=3
451 # define U_MALLOC_ATTR __attribute__ ((__malloc__))
452 #else
453 # define U_MALLOC_ATTR
454 #endif
455 
461 #if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || __has_attribute(alloc_size)
462 # define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X)))
463 # define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y)))
464 #else
465 # define U_ALLOC_SIZE_ATTR(X)
466 # define U_ALLOC_SIZE_ATTR2(X,Y)
467 #endif
468 
475 #ifdef U_CPLUSPLUS_VERSION
476 # if U_CPLUSPLUS_VERSION != 0 && !defined(__cplusplus)
477 # undef U_CPLUSPLUS_VERSION
478 # define U_CPLUSPLUS_VERSION 0
479 # endif
480  /* Otherwise use the predefined value. */
481 #elif !defined(__cplusplus)
482 # define U_CPLUSPLUS_VERSION 0
483 #elif __cplusplus >= 201402L
484 # define U_CPLUSPLUS_VERSION 14
485 #elif __cplusplus >= 201103L
486 # define U_CPLUSPLUS_VERSION 11
487 #else
488  // C++98 or C++03
489 # define U_CPLUSPLUS_VERSION 1
490 #endif
491 
498 #ifdef U_HAVE_RVALUE_REFERENCES
499  /* Use the predefined value. */
500 #elif U_CPLUSPLUS_VERSION >= 11 || __has_feature(cxx_rvalue_references) \
501  || defined(__GXX_EXPERIMENTAL_CXX0X__) \
502  || (defined(_MSC_VER) && _MSC_VER >= 1600) /* Visual Studio 2010 */
503 # define U_HAVE_RVALUE_REFERENCES 1
504 #else
505 # define U_HAVE_RVALUE_REFERENCES 0
506 #endif
507 
515 #ifdef U_NOEXCEPT
516  /* Use the predefined value. */
517 #elif U_CPLUSPLUS_VERSION >= 11 || __has_feature(cxx_noexcept) || __has_extension(cxx_noexcept) \
518  || (defined(_MSC_VER) && _MSC_VER >= 1900) /* Visual Studio 2015 */
519 # define U_NOEXCEPT noexcept
520 #else
521 # define U_NOEXCEPT
522 #endif
523 
526 /*===========================================================================*/
528 /*===========================================================================*/
529 
534 #define U_ASCII_FAMILY 0
535 
540 #define U_EBCDIC_FAMILY 1
541 
584 #ifdef U_CHARSET_FAMILY
585  /* Use the predefined value. */
586 #elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB)
587 # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
588 #elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__)
589 # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
590 #else
591 # define U_CHARSET_FAMILY U_ASCII_FAMILY
592 #endif
593 
614 #ifdef U_CHARSET_IS_UTF8
615  /* Use the predefined value. */
616 #elif U_PLATFORM == U_PF_ANDROID || U_PLATFORM_IS_DARWIN_BASED
617 # define U_CHARSET_IS_UTF8 1
618 #else
619 # define U_CHARSET_IS_UTF8 0
620 #endif
621 
624 /*===========================================================================*/
626 /*===========================================================================*/
627 
634 #ifdef U_HAVE_WCHAR_H
635  /* Use the predefined value. */
636 #elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9
637  /*
638  * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t.
639  * The type and header existed, but the library functions did not work as expected.
640  * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway.
641  */
642 # define U_HAVE_WCHAR_H 0
643 #else
644 # define U_HAVE_WCHAR_H 1
645 #endif
646 
653 #ifdef U_SIZEOF_WCHAR_T
654  /* Use the predefined value. */
655 #elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9)
656  /*
657  * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring.
658  * Newer Mac OS X has size 4.
659  */
660 # define U_SIZEOF_WCHAR_T 1
661 #elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN
662 # define U_SIZEOF_WCHAR_T 2
663 #elif U_PLATFORM == U_PF_AIX
664  /*
665  * AIX 6.1 information, section "Wide character data representation":
666  * "... the wchar_t datatype is 32-bit in the 64-bit environment and
667  * 16-bit in the 32-bit environment."
668  * and
669  * "All locales use Unicode for their wide character code values (process code),
670  * except the IBM-eucTW codeset."
671  */
672 # ifdef __64BIT__
673 # define U_SIZEOF_WCHAR_T 4
674 # else
675 # define U_SIZEOF_WCHAR_T 2
676 # endif
677 #elif U_PLATFORM == U_PF_OS390
678  /*
679  * z/OS V1R11 information center, section "LP64 | ILP32":
680  * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes.
681  * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes."
682  */
683 # ifdef _LP64
684 # define U_SIZEOF_WCHAR_T 4
685 # else
686 # define U_SIZEOF_WCHAR_T 2
687 # endif
688 #elif U_PLATFORM == U_PF_OS400
689 # if defined(__UTF32__)
690  /*
691  * LOCALETYPE(*LOCALEUTF) is specified.
692  * Wide-character strings are in UTF-32,
693  * narrow-character strings are in UTF-8.
694  */
695 # define U_SIZEOF_WCHAR_T 4
696 # elif defined(__UCS2__)
697  /*
698  * LOCALETYPE(*LOCALEUCS2) is specified.
699  * Wide-character strings are in UCS-2,
700  * narrow-character strings are in EBCDIC.
701  */
702 # define U_SIZEOF_WCHAR_T 2
703 #else
704  /*
705  * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified.
706  * Wide-character strings are in 16-bit EBCDIC,
707  * narrow-character strings are in EBCDIC.
708  */
709 # define U_SIZEOF_WCHAR_T 2
710 # endif
711 #else
712 # define U_SIZEOF_WCHAR_T 4
713 #endif
714 
715 #ifndef U_HAVE_WCSCPY
716 #define U_HAVE_WCSCPY U_HAVE_WCHAR_H
717 #endif
718 
729 #ifdef U_HAVE_CHAR16_T
730  /* Use the predefined value. */
731 #else
732  /*
733  * Notes:
734  * Visual Studio 10 (_MSC_VER>=1600) defines char16_t but
735  * does not support u"abc" string literals.
736  * gcc 4.4 defines the __CHAR16_TYPE__ macro to a usable type but
737  * does not support u"abc" string literals.
738  * C++11 and C11 require support for UTF-16 literals
739  */
740 # if U_CPLUSPLUS_VERSION >= 11 || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
741 # define U_HAVE_CHAR16_T 1
742 # else
743 # define U_HAVE_CHAR16_T 0
744 # endif
745 #endif
746 
754 #ifdef U_DECLARE_UTF16
755  /* Use the predefined value. */
756 #elif U_HAVE_CHAR16_T \
757  || (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \
758  || (defined(__HP_aCC) && __HP_aCC >= 035000) \
759  || (defined(__HP_cc) && __HP_cc >= 111106)
760 # define U_DECLARE_UTF16(string) u ## string
761 #elif U_SIZEOF_WCHAR_T == 2 \
762  && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__)))
763 # define U_DECLARE_UTF16(string) L ## string
764 #else
765  /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */
766 #endif
767 
770 /*===========================================================================*/
772 /*===========================================================================*/
773 
774 #ifdef U_EXPORT
775  /* Use the predefined value. */
776 #elif defined(U_STATIC_IMPLEMENTATION)
777 # define U_EXPORT
778 #elif defined(__GNUC__)
779 # define U_EXPORT __attribute__((visibility("default")))
780 #elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
781  || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550)
782 # define U_EXPORT __global
783 /*#elif defined(__HP_aCC) || defined(__HP_cc)
784 # define U_EXPORT __declspec(dllexport)*/
785 #elif defined(_MSC_VER)
786 # define U_EXPORT __declspec(dllexport)
787 #else
788 # define U_EXPORT
789 #endif
790 
791 /* U_CALLCONV is releated to U_EXPORT2 */
792 #ifdef U_EXPORT2
793  /* Use the predefined value. */
794 #elif defined(_MSC_VER)
795 # define U_EXPORT2 __cdecl
796 #else
797 # define U_EXPORT2
798 #endif
799 
800 #ifdef U_IMPORT
801  /* Use the predefined value. */
802 #elif defined(_MSC_VER)
803  /* Windows needs to export/import data. */
804 # define U_IMPORT __declspec(dllimport)
805 #else
806 # define U_IMPORT
807 #endif
808 
820 #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
821 # define U_CALLCONV __cdecl
822 #else
823 # define U_CALLCONV U_EXPORT2
824 #endif
825 
826 /* @} */
827 
828 #endif