ICU 50.1.2  50.1.2
platform.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 1997-2012, 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 
125 #define U_PF_ANDROID 4050
126 
127 #define U_PF_CLASSIC_MACOS 8000
128 
129 #define U_PF_OS390 9000
130 
131 #define U_PF_OS400 9400
132 
133 #ifdef U_PLATFORM
134  /* Use the predefined value. */
135 #elif defined(__MINGW32__)
136 # define U_PLATFORM U_PF_MINGW
137 #elif defined(__CYGWIN__)
138 # define U_PLATFORM U_PF_CYGWIN
139 #elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
140 # define U_PLATFORM U_PF_WINDOWS
141 #elif defined(__ANDROID__)
142 # define U_PLATFORM U_PF_ANDROID
143  /* Android wchar_t support depends on the API level. */
144 # include <android/api-level.h>
145 #elif defined(linux) || defined(__linux__) || defined(__linux)
146 # define U_PLATFORM U_PF_LINUX
147 #elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__MirBSD__)
148 # define U_PLATFORM U_PF_BSD
149 #elif defined(sun) || defined(__sun)
150  /* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */
151 # define U_PLATFORM U_PF_SOLARIS
152 # if defined(__GNUC__)
153  /* Solaris/GCC needs this header file to get the proper endianness. Normally, this
154  * header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h
155  * is included which does not include this header file.
156  */
157 # include <sys/isa_defs.h>
158 # endif
159 #elif defined(_AIX) || defined(__TOS_AIX__)
160 # define U_PLATFORM U_PF_AIX
161 #elif defined(_hpux) || defined(hpux) || defined(__hpux)
162 # define U_PLATFORM U_PF_HPUX
163 #elif defined(sgi) || defined(__sgi)
164 # define U_PLATFORM U_PF_IRIX
165 #elif defined(__APPLE__) && defined(__MACH__)
166 # include <TargetConditionals.h>
167 # if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE /* variant of TARGET_OS_MAC */
168 # define U_PLATFORM U_PF_IPHONE
169 # else
170 # define U_PLATFORM U_PF_DARWIN
171 # endif
172 #elif defined(macintosh)
173 # define U_PLATFORM U_PF_CLASSIC_MACOS
174 #elif defined(__QNX__) || defined(__QNXNTO__)
175 # define U_PLATFORM U_PF_QNX
176 #elif defined(__TOS_MVS__)
177 # define U_PLATFORM U_PF_OS390
178 #elif defined(__OS400__) || defined(__TOS_OS400__)
179 # define U_PLATFORM U_PF_OS400
180 #else
181 # define U_PLATFORM U_PF_UNKNOWN
182 #endif
183 
190 /* Commented out because this is already set in mh-cygwin-msvc
191 #if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER)
192 # define CYGWINMSVC
193 #endif
194 */
195 
202 #ifdef U_PLATFORM_USES_ONLY_WIN32_API
203  /* Use the predefined value. */
204 #elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC)
205 # define U_PLATFORM_USES_ONLY_WIN32_API 1
206 #else
207  /* Cygwin implements POSIX. */
208 # define U_PLATFORM_USES_ONLY_WIN32_API 0
209 #endif
210 
217 #ifdef U_PLATFORM_HAS_WIN32_API
218  /* Use the predefined value. */
219 #elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
220 # define U_PLATFORM_HAS_WIN32_API 1
221 #else
222 # define U_PLATFORM_HAS_WIN32_API 0
223 #endif
224 
231 #ifdef U_PLATFORM_IMPLEMENTS_POSIX
232  /* Use the predefined value. */
233 #elif U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM == U_PF_CLASSIC_MACOS
234 # define U_PLATFORM_IMPLEMENTS_POSIX 0
235 #else
236 # define U_PLATFORM_IMPLEMENTS_POSIX 1
237 #endif
238 
244 #ifdef U_PLATFORM_IS_LINUX_BASED
245  /* Use the predefined value. */
246 #elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= U_PF_ANDROID
247 # define U_PLATFORM_IS_LINUX_BASED 1
248 #else
249 # define U_PLATFORM_IS_LINUX_BASED 0
250 #endif
251 
257 #ifdef U_PLATFORM_IS_DARWIN_BASED
258  /* Use the predefined value. */
259 #elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE
260 # define U_PLATFORM_IS_DARWIN_BASED 1
261 #else
262 # define U_PLATFORM_IS_DARWIN_BASED 0
263 #endif
264 
272 #ifdef U_HAVE_STDINT_H
273  /* Use the predefined value. */
274 #elif U_PLATFORM_USES_ONLY_WIN32_API
275 # if defined(__BORLANDC__) || (defined(_MSC_VER) && _MSC_VER>=1600)
276  /* Windows Visual Studio 9 and below do not have stdint.h & inttypes.h, but VS 2010 adds them. */
277 # define U_HAVE_STDINT_H 1
278 # else
279 # define U_HAVE_STDINT_H 0
280 # endif
281 #elif U_PLATFORM == U_PF_SOLARIS
282  /* Solaris has inttypes.h but not stdint.h. */
283 # define U_HAVE_STDINT_H 0
284 #elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER)
285  /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */
286 # define U_HAVE_STDINT_H 0
287 #else
288 # define U_HAVE_STDINT_H 1
289 #endif
290 
297 #ifdef U_HAVE_INTTYPES_H
298  /* Use the predefined value. */
299 #elif U_PLATFORM == U_PF_SOLARIS
300  /* Solaris has inttypes.h but not stdint.h. */
301 # define U_HAVE_INTTYPES_H 1
302 #elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER)
303  /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */
304 # define U_HAVE_INTTYPES_H 1
305 #else
306  /* Most platforms have both inttypes.h and stdint.h, or neither. */
307 # define U_HAVE_INTTYPES_H U_HAVE_STDINT_H
308 #endif
309 
331 #ifndef U_IOSTREAM_SOURCE
332 #define U_IOSTREAM_SOURCE 199711
333 #endif
334 
340 #ifdef U_HAVE_STD_STRING
341  /* Use the predefined value. */
342 #elif U_PLATFORM == U_PF_ANDROID
343 # define U_HAVE_STD_STRING 0
344 #else
345 # define U_HAVE_STD_STRING 1
346 #endif
347 
348 /*===========================================================================*/
350 /*===========================================================================*/
351 
362 #ifdef __GNUC__
363 # define U_GCC_MAJOR_MINOR (__GNUC__ * 100 + __GNUC_MINOR__)
364 #else
365 # define U_GCC_MAJOR_MINOR 0
366 #endif
367 
373 #ifdef U_IS_BIG_ENDIAN
374  /* Use the predefined value. */
375 #elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
376 # define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN)
377 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
378  /* gcc */
379 # define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
380 #elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
381 # define U_IS_BIG_ENDIAN 1
382 #elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN)
383 # define U_IS_BIG_ENDIAN 0
384 #elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400 || defined(__s390__) || defined(__s390x__)
385  /* These platforms do not appear to predefine any endianness macros. */
386 # define U_IS_BIG_ENDIAN 1
387 #elif defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0)
388  /* HPPA do not appear to predefine any endianness macros. */
389 # define U_IS_BIG_ENDIAN 1
390 #elif defined(sparc) || defined(__sparc) || defined(__sparc__)
391  /* Some sparc based systems (e.g. Linux) do not predefine any endianness macros. */
392 # define U_IS_BIG_ENDIAN 1
393 #else
394 # define U_IS_BIG_ENDIAN 0
395 #endif
396 
402 #ifdef U_HAVE_PLACEMENT_NEW
403  /* Use the predefined value. */
404 #elif defined(__BORLANDC__)
405 # define U_HAVE_PLACEMENT_NEW 0
406 #else
407 # define U_HAVE_PLACEMENT_NEW 1
408 #endif
409 
416 #ifdef U_HAVE_DEBUG_LOCATION_NEW
417  /* Use the predefined value. */
418 #elif defined(_MSC_VER)
419 # define U_HAVE_DEBUG_LOCATION_NEW 1
420 #else
421 # define U_HAVE_DEBUG_LOCATION_NEW 0
422 #endif
423 
424 /* Compatibility with non clang compilers */
425 #ifndef __has_attribute
426 # define __has_attribute(x) 0
427 #endif
428 
434 #if defined(__GNUC__) && __GNUC__>=3
435 # define U_MALLOC_ATTR __attribute__ ((__malloc__))
436 #else
437 # define U_MALLOC_ATTR
438 #endif
439 
445 #if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || __has_attribute(alloc_size)
446 # define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X)))
447 # define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y)))
448 #else
449 # define U_ALLOC_SIZE_ATTR(X)
450 # define U_ALLOC_SIZE_ATTR2(X,Y)
451 #endif
452 
455 /*===========================================================================*/
457 /*===========================================================================*/
458 
463 #define U_ASCII_FAMILY 0
464 
469 #define U_EBCDIC_FAMILY 1
470 
513 #ifdef U_CHARSET_FAMILY
514  /* Use the predefined value. */
515 #elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB)
516 # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
517 #elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__)
518 # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
519 #else
520 # define U_CHARSET_FAMILY U_ASCII_FAMILY
521 #endif
522 
543 #ifdef U_CHARSET_IS_UTF8
544  /* Use the predefined value. */
545 #elif U_PLATFORM == U_PF_ANDROID || U_PLATFORM_IS_DARWIN_BASED
546 # define U_CHARSET_IS_UTF8 1
547 #else
548 # define U_CHARSET_IS_UTF8 0
549 #endif
550 
553 /*===========================================================================*/
555 /*===========================================================================*/
556 
563 #ifdef U_HAVE_WCHAR_H
564  /* Use the predefined value. */
565 #elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9
566  /*
567  * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t.
568  * The type and header existed, but the library functions did not work as expected.
569  * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway.
570  */
571 # define U_HAVE_WCHAR_H 0
572 #else
573 # define U_HAVE_WCHAR_H 1
574 #endif
575 
582 #ifdef U_SIZEOF_WCHAR_T
583  /* Use the predefined value. */
584 #elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9) || U_PLATFORM == U_PF_CLASSIC_MACOS
585  /*
586  * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring.
587  * Newer Mac OS X has size 4.
588  */
589 # define U_SIZEOF_WCHAR_T 1
590 #elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN
591 # define U_SIZEOF_WCHAR_T 2
592 #elif U_PLATFORM == U_PF_AIX
593  /*
594  * AIX 6.1 information, section "Wide character data representation":
595  * "... the wchar_t datatype is 32-bit in the 64-bit environment and
596  * 16-bit in the 32-bit environment."
597  * and
598  * "All locales use Unicode for their wide character code values (process code),
599  * except the IBM-eucTW codeset."
600  */
601 # ifdef __64BIT__
602 # define U_SIZEOF_WCHAR_T 4
603 # else
604 # define U_SIZEOF_WCHAR_T 2
605 # endif
606 #elif U_PLATFORM == U_PF_OS390
607  /*
608  * z/OS V1R11 information center, section "LP64 | ILP32":
609  * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes.
610  * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes."
611  */
612 # ifdef _LP64
613 # define U_SIZEOF_WCHAR_T 4
614 # else
615 # define U_SIZEOF_WCHAR_T 2
616 # endif
617 #elif U_PLATFORM == U_PF_OS400
618 # if defined(__UTF32__)
619  /*
620  * LOCALETYPE(*LOCALEUTF) is specified.
621  * Wide-character strings are in UTF-32,
622  * narrow-character strings are in UTF-8.
623  */
624 # define U_SIZEOF_WCHAR_T 4
625 # elif defined(__UCS2__)
626  /*
627  * LOCALETYPE(*LOCALEUCS2) is specified.
628  * Wide-character strings are in UCS-2,
629  * narrow-character strings are in EBCDIC.
630  */
631 # define U_SIZEOF_WCHAR_T 2
632 #else
633  /*
634  * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified.
635  * Wide-character strings are in 16-bit EBCDIC,
636  * narrow-character strings are in EBCDIC.
637  */
638 # define U_SIZEOF_WCHAR_T 2
639 # endif
640 #else
641 # define U_SIZEOF_WCHAR_T 4
642 #endif
643 
644 #ifndef U_HAVE_WCSCPY
645 #define U_HAVE_WCSCPY U_HAVE_WCHAR_H
646 #endif
647 
658 #ifdef U_HAVE_CHAR16_T
659  /* Use the predefined value. */
660 #else
661  /*
662  * Notes:
663  * Visual Studio 10 (_MSC_VER>=1600) defines char16_t but
664  * does not support u"abc" string literals.
665  * gcc 4.4 defines the __CHAR16_TYPE__ macro to a usable type but
666  * does not support u"abc" string literals.
667  * C++11 and C11 require support for UTF-16 literals
668  */
669 # if (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
670 # define U_HAVE_CHAR16_T 1
671 # else
672 # define U_HAVE_CHAR16_T 0
673 # endif
674 #endif
675 
683 #ifdef U_DECLARE_UTF16
684  /* Use the predefined value. */
685 #elif U_HAVE_CHAR16_T \
686  || (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \
687  || (defined(__HP_aCC) && __HP_aCC >= 035000) \
688  || (defined(__HP_cc) && __HP_cc >= 111106)
689 # define U_DECLARE_UTF16(string) u ## string
690 #elif U_SIZEOF_WCHAR_T == 2 \
691  && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__)))
692 # define U_DECLARE_UTF16(string) L ## string
693 #else
694  /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */
695 #endif
696 
699 /*===========================================================================*/
701 /*===========================================================================*/
702 
703 #ifdef U_EXPORT
704  /* Use the predefined value. */
705 #elif defined(U_STATIC_IMPLEMENTATION)
706 # define U_EXPORT
707 #elif defined(__GNUC__)
708 # define U_EXPORT __attribute__((visibility("default")))
709 #elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
710  || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550)
711 # define U_EXPORT __global
712 /*#elif defined(__HP_aCC) || defined(__HP_cc)
713 # define U_EXPORT __declspec(dllexport)*/
714 #elif defined(_MSC_VER)
715 # define U_EXPORT __declspec(dllexport)
716 #else
717 # define U_EXPORT
718 #endif
719 
720 /* U_CALLCONV is releated to U_EXPORT2 */
721 #ifdef U_EXPORT2
722  /* Use the predefined value. */
723 #elif defined(_MSC_VER)
724 # define U_EXPORT2 __cdecl
725 #else
726 # define U_EXPORT2
727 #endif
728 
729 #ifdef U_IMPORT
730  /* Use the predefined value. */
731 #elif defined(_MSC_VER)
732  /* Windows needs to export/import data. */
733 # define U_IMPORT __declspec(dllimport)
734 #else
735 # define U_IMPORT
736 #endif
737 
749 #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
750 # define U_CALLCONV __cdecl
751 #else
752 # define U_CALLCONV U_EXPORT2
753 #endif
754 
755 /* @} */
756 
757 #endif
C API: definitions of ICU version numbers.
User-configurable settings.