]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/unicode/platform.h
2 ******************************************************************************
4 * Copyright (C) 1997-2012, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
9 * FILE NAME : platform.h
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 ******************************************************************************
22 #include "unicode/uconfig.h"
23 #include "unicode/uvernum.h"
27 * \brief Basic types for the platform.
29 * This file used to be generated by autoconf/configure.
30 * Starting with ICU 49, platform.h is a normal source file,
31 * to simplify cross-compiling and working with non-autoconf/make build systems.
33 * When a value in this file does not work on a platform, then please
34 * try to derive it from the U_PLATFORM value
35 * (for which we might need a new value constant in rare cases)
36 * and/or from other macros that are predefined by the compiler
37 * or defined in standard (POSIX or platform or compiler) headers.
39 * As a temporary workaround, you can add an explicit #define for some macros
40 * before it is first tested, or add an equivalent -D macro definition
41 * to the compiler's command line.
43 * Note: Some compilers provide ways to show the predefined macros.
44 * For example, with gcc you can compile an empty .c file and have the compiler
45 * print the predefined macros with
47 * gcc -E -dM -x c /dev/null | sort
49 * (You can provide an actual empty .c file rather than /dev/null.
50 * <code>-x c++</code> is for C++.)
55 * The U_PLATFORM macro defines the platform we're on.
57 * We used to define one different, value-less macro per platform.
58 * That made it hard to know the set of relevant platforms and macros,
59 * and hard to deal with variants of platforms.
61 * Starting with ICU 49, we define platforms as numeric macros,
62 * with ranges of values for related platforms and their variants.
63 * The U_PLATFORM macro is set to one of these values.
65 * Historical note from the Solaris Wikipedia article:
66 * AT&T and Sun collaborated on a project to merge the most popular Unix variants
67 * on the market at that time: BSD, System V, and Xenix.
68 * This became Unix System V Release 4 (SVR4).
73 /** Unknown platform. @internal */
74 #define U_PF_UNKNOWN 0
75 /** Windows @internal */
76 #define U_PF_WINDOWS 1000
77 /** MinGW. Windows, calls to Win32 API, but using GNU gcc and binutils. @internal */
78 #define U_PF_MINGW 1800
80 * Cygwin. Windows, calls to cygwin1.dll for Posix functions,
81 * using MSVC or GNU gcc and binutils.
84 #define U_PF_CYGWIN 1900
85 /* Reserve 2000 for U_PF_UNIX? */
86 /** HP-UX is based on UNIX System V. @internal */
87 #define U_PF_HPUX 2100
88 /** Solaris is a Unix operating system based on SVR4. @internal */
89 #define U_PF_SOLARIS 2600
90 /** BSD is a UNIX operating system derivative. @internal */
92 /** AIX is based on UNIX System V Releases and 4.3 BSD. @internal */
94 /** IRIX is based on UNIX System V with BSD extensions. @internal */
95 #define U_PF_IRIX 3200
97 * Darwin is a POSIX-compliant operating system, composed of code developed by Apple,
98 * as well as code derived from NeXTSTEP, BSD, and other projects,
99 * built around the Mach kernel.
100 * Darwin forms the core set of components upon which Mac OS X, Apple TV, and iOS are based.
101 * (Original description modified from WikiPedia.)
104 #define U_PF_DARWIN 3500
105 /** iPhone OS (iOS) is a derivative of Mac OS X. @internal */
106 #define U_PF_IPHONE 3550
107 /** QNX is a commercial Unix-like real-time operating system related to BSD. @internal */
108 #define U_PF_QNX 3700
109 /** Linux is a Unix-like operating system. @internal */
110 #define U_PF_LINUX 4000
111 /** Android is based on Linux. @internal */
112 #define U_PF_ANDROID 4050
113 /** "Classic" Mac OS (1984-2001) @internal */
114 #define U_PF_CLASSIC_MACOS 8000
115 /** z/OS is the successor to OS/390 which was the successor to MVS. @internal */
116 #define U_PF_OS390 9000
117 /** "IBM i" is the current name of what used to be i5/OS and earlier OS/400. @internal */
118 #define U_PF_OS400 9400
121 /* Use the predefined value. */
122 #elif defined(__MINGW32__)
123 # define U_PLATFORM U_PF_MINGW
124 #elif defined(__CYGWIN__)
125 # define U_PLATFORM U_PF_CYGWIN
126 #elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
127 # define U_PLATFORM U_PF_WINDOWS
128 #elif defined(__ANDROID__)
129 # define U_PLATFORM U_PF_ANDROID
130 /* Android wchar_t support depends on the API level. */
131 # include <android/api-level.h>
132 #elif defined(linux) || defined(__linux__) || defined(__linux)
133 # define U_PLATFORM U_PF_LINUX
134 #elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
135 # define U_PLATFORM U_PF_BSD
136 #elif defined(sun) || defined(__sun)
137 /* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */
138 # define U_PLATFORM U_PF_SOLARIS
139 # if defined(__GNUC__)
140 /* Solaris/GCC needs this header file to get the proper endianness. Normally, this
141 * header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h
142 * is included which does not include this header file.
144 # include <sys/isa_defs.h>
146 #elif defined(_AIX) || defined(__TOS_AIX__)
147 # define U_PLATFORM U_PF_AIX
148 #elif defined(_hpux) || defined(hpux) || defined(__hpux)
149 # define U_PLATFORM U_PF_HPUX
150 #elif defined(sgi) || defined(__sgi)
151 # define U_PLATFORM U_PF_IRIX
152 #elif defined(__APPLE__) && defined(__MACH__)
153 # include <TargetConditionals.h>
154 # if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE /* variant of TARGET_OS_MAC */
155 # define U_PLATFORM U_PF_IPHONE
157 # define U_PLATFORM U_PF_DARWIN
159 #elif defined(macintosh)
160 # define U_PLATFORM U_PF_CLASSIC_MACOS
161 #elif defined(__QNX__) || defined(__QNXNTO__)
162 # define U_PLATFORM U_PF_QNX
163 #elif defined(__TOS_MVS__)
164 # define U_PLATFORM U_PF_OS390
165 #elif defined(__OS400__) || defined(__TOS_OS400__)
166 # define U_PLATFORM U_PF_OS400
168 # define U_PLATFORM U_PF_UNKNOWN
173 * Defined if this is Windows with Cygwin, but using MSVC rather than gcc.
174 * Otherwise undefined.
177 /* Commented out because this is already set in mh-cygwin-msvc
178 #if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER)
184 * \def U_PLATFORM_USES_ONLY_WIN32_API
185 * Defines whether the platform uses only the Win32 API.
186 * Set to 1 for Windows/MSVC and MinGW but not Cygwin.
189 #ifdef U_PLATFORM_USES_ONLY_WIN32_API
190 /* Use the predefined value. */
191 #elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC)
192 # define U_PLATFORM_USES_ONLY_WIN32_API 1
194 /* Cygwin implements POSIX. */
195 # define U_PLATFORM_USES_ONLY_WIN32_API 0
199 * \def U_PLATFORM_HAS_WIN32_API
200 * Defines whether the Win32 API is available on the platform.
201 * Set to 1 for Windows/MSVC, MinGW and Cygwin.
204 #ifdef U_PLATFORM_HAS_WIN32_API
205 /* Use the predefined value. */
206 #elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
207 # define U_PLATFORM_HAS_WIN32_API 1
209 # define U_PLATFORM_HAS_WIN32_API 0
213 * \def U_PLATFORM_IMPLEMENTS_POSIX
214 * Defines whether the platform implements (most of) the POSIX API.
215 * Set to 1 for Cygwin and most other platforms.
218 #ifdef U_PLATFORM_IMPLEMENTS_POSIX
219 /* Use the predefined value. */
220 #elif U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM == U_PF_CLASSIC_MACOS
221 # define U_PLATFORM_IMPLEMENTS_POSIX 0
223 # define U_PLATFORM_IMPLEMENTS_POSIX 1
227 * \def U_PLATFORM_IS_LINUX_BASED
228 * Defines whether the platform is Linux or one of its derivatives.
231 #ifdef U_PLATFORM_IS_LINUX_BASED
232 /* Use the predefined value. */
233 #elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= U_PF_ANDROID
234 # define U_PLATFORM_IS_LINUX_BASED 1
236 # define U_PLATFORM_IS_LINUX_BASED 0
240 * \def U_PLATFORM_IS_DARWIN_BASED
241 * Defines whether the platform is Darwin or one of its derivatives.
244 #ifdef U_PLATFORM_IS_DARWIN_BASED
245 /* Use the predefined value. */
246 #elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE
247 # define U_PLATFORM_IS_DARWIN_BASED 1
249 # define U_PLATFORM_IS_DARWIN_BASED 0
253 * \def U_HAVE_STDINT_H
254 * Defines whether stdint.h is available. It is a C99 standard header.
255 * We used to include inttypes.h which includes stdint.h but we usually do not need
256 * the additional definitions from inttypes.h.
259 #ifdef U_HAVE_STDINT_H
260 /* Use the predefined value. */
261 #elif U_PLATFORM_USES_ONLY_WIN32_API
262 # if defined(__BORLANDC__) || (defined(_MSC_VER) && _MSC_VER>=1600)
263 /* Windows Visual Studio 9 and below do not have stdint.h & inttypes.h, but VS 2010 adds them. */
264 # define U_HAVE_STDINT_H 1
266 # define U_HAVE_STDINT_H 0
268 #elif U_PLATFORM == U_PF_SOLARIS
269 /* Solaris has inttypes.h but not stdint.h. */
270 # define U_HAVE_STDINT_H 0
272 # define U_HAVE_STDINT_H 1
276 * \def U_HAVE_INTTYPES_H
277 * Defines whether inttypes.h is available. It is a C99 standard header.
278 * We include inttypes.h where it is available but stdint.h is not.
281 #ifdef U_HAVE_INTTYPES_H
282 /* Use the predefined value. */
283 #elif U_PLATFORM == U_PF_SOLARIS
284 /* Solaris has inttypes.h but not stdint.h. */
285 # define U_HAVE_INTTYPES_H 1
287 /* Most platforms have both inttypes.h and stdint.h, or neither. */
288 # define U_HAVE_INTTYPES_H U_HAVE_STDINT_H
292 * \def U_IOSTREAM_SOURCE
293 * Defines what support for C++ streams is available.
295 * If U_IOSTREAM_SOURCE is set to 199711, then <iostream> is available
296 * (the ISO/IEC C++ FDIS was published in November 1997), and then
297 * one should qualify streams using the std namespace in ICU header
299 * Starting with ICU 49, this is the only supported version.
301 * If U_IOSTREAM_SOURCE is set to 198506, then <iostream.h> is
302 * available instead (in June 1985 Stroustrup published
303 * "An Extensible I/O Facility for C++" at the summer USENIX conference).
304 * Starting with ICU 49, this version is not supported any more.
306 * If U_IOSTREAM_SOURCE is 0 (or any value less than 199711),
307 * then C++ streams are not available and
308 * support for them will be silently suppressed in ICU.
312 #ifndef U_IOSTREAM_SOURCE
313 #define U_IOSTREAM_SOURCE 199711
317 * \def U_HAVE_STD_STRING
318 * Defines whether the standard C++ (STL) <string> header is available.
321 #ifdef U_HAVE_STD_STRING
322 /* Use the predefined value. */
323 #elif U_PLATFORM == U_PF_ANDROID
324 # define U_HAVE_STD_STRING 0
326 # define U_HAVE_STD_STRING 1
329 /*===========================================================================*/
330 /** @{ Compiler and environment features */
331 /*===========================================================================*/
334 * \def U_IS_BIG_ENDIAN
335 * Determines the endianness of the platform.
338 #ifdef U_IS_BIG_ENDIAN
339 /* Use the predefined value. */
340 #elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
341 # define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN)
342 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
344 # define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
345 #elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
346 # define U_IS_BIG_ENDIAN 1
347 #elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN)
348 # define U_IS_BIG_ENDIAN 0
349 #elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400
350 /* These platforms do not appear to predefine any endianness macros. */
351 # define U_IS_BIG_ENDIAN 1
353 # define U_IS_BIG_ENDIAN 0
357 * \def U_HAVE_PLACEMENT_NEW
358 * Determines whether to override placement new and delete for STL.
361 #ifdef U_HAVE_PLACEMENT_NEW
362 /* Use the predefined value. */
363 #elif defined(__BORLANDC__)
364 # define U_HAVE_PLACEMENT_NEW 0
366 # define U_HAVE_PLACEMENT_NEW 1
370 * \def U_HAVE_DEBUG_LOCATION_NEW
371 * Define this to define the MFC debug version of the operator new.
375 #ifdef U_HAVE_DEBUG_LOCATION_NEW
376 /* Use the predefined value. */
377 #elif defined(_MSC_VER)
378 # define U_HAVE_DEBUG_LOCATION_NEW 1
380 # define U_HAVE_DEBUG_LOCATION_NEW 0
385 /*===========================================================================*/
386 /** @{ Character data types */
387 /*===========================================================================*/
390 * U_CHARSET_FAMILY is equal to this value when the platform is an ASCII based platform.
393 #define U_ASCII_FAMILY 0
396 * U_CHARSET_FAMILY is equal to this value when the platform is an EBCDIC based platform.
399 #define U_EBCDIC_FAMILY 1
402 * \def U_CHARSET_FAMILY
404 * <p>These definitions allow to specify the encoding of text
405 * in the char data type as defined by the platform and the compiler.
406 * It is enough to determine the code point values of "invariant characters",
407 * which are the ones shared by all encodings that are in use
408 * on a given platform.</p>
410 * <p>Those "invariant characters" should be all the uppercase and lowercase
411 * latin letters, the digits, the space, and "basic punctuation".
412 * Also, '\\n', '\\r', '\\t' should be available.</p>
414 * <p>The list of "invariant characters" is:<br>
416 * A-Z a-z 0-9 SPACE " % & ' ( ) * + , - . / : ; < = > ? _
419 * (52 letters + 10 numbers + 20 punc/sym/space = 82 total)</p>
421 * <p>This matches the IBM Syntactic Character Set (CS 640).</p>
423 * <p>In other words, all the graphic characters in 7-bit ASCII should
424 * be safely accessible except the following:</p>
429 * ']' <right bracket>
434 * '!' <exclamation mark>
436 * '|' <vertical line>
438 * '@' <commercial at>
443 #ifdef U_CHARSET_FAMILY
444 /* Use the predefined value. */
445 #elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB)
446 # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
447 #elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__)
448 # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
450 # define U_CHARSET_FAMILY U_ASCII_FAMILY
454 * \def U_CHARSET_IS_UTF8
456 * Hardcode the default charset to UTF-8.
458 * If this is set to 1, then
459 * - ICU will assume that all non-invariant char*, StringPiece, std::string etc.
460 * contain UTF-8 text, regardless of what the system API uses
461 * - some ICU code will use fast functions like u_strFromUTF8()
462 * rather than the more general and more heavy-weight conversion API (ucnv.h)
463 * - ucnv_getDefaultName() always returns "UTF-8"
464 * - ucnv_setDefaultName() is disabled and will not change the default charset
465 * - static builds of ICU are smaller
466 * - more functionality is available with the UCONFIG_NO_CONVERSION build-time
467 * configuration option (see unicode/uconfig.h)
468 * - the UCONFIG_NO_CONVERSION build option in uconfig.h is more usable
471 * @see UCONFIG_NO_CONVERSION
473 #ifdef U_CHARSET_IS_UTF8
474 /* Use the predefined value. */
475 #elif U_PLATFORM == U_PF_ANDROID || U_PLATFORM_IS_DARWIN_BASED
476 # define U_CHARSET_IS_UTF8 1
478 # define U_CHARSET_IS_UTF8 0
483 /*===========================================================================*/
484 /** @{ Information about wchar support */
485 /*===========================================================================*/
488 * \def U_HAVE_WCHAR_H
489 * Indicates whether <wchar.h> is available (1) or not (0). Set to 1 by default.
493 #ifdef U_HAVE_WCHAR_H
494 /* Use the predefined value. */
495 #elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9
497 * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t.
498 * The type and header existed, but the library functions did not work as expected.
499 * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway.
501 # define U_HAVE_WCHAR_H 0
503 # define U_HAVE_WCHAR_H 1
507 * \def U_SIZEOF_WCHAR_T
508 * U_SIZEOF_WCHAR_T==sizeof(wchar_t)
512 #ifdef U_SIZEOF_WCHAR_T
513 /* Use the predefined value. */
514 #elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9) || U_PLATFORM == U_PF_CLASSIC_MACOS
516 * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring.
517 * Newer Mac OS X has size 4.
519 # define U_SIZEOF_WCHAR_T 1
520 #elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN
521 # define U_SIZEOF_WCHAR_T 2
522 #elif U_PLATFORM == U_PF_AIX
524 * AIX 6.1 information, section "Wide character data representation":
525 * "... the wchar_t datatype is 32-bit in the 64-bit environment and
526 * 16-bit in the 32-bit environment."
528 * "All locales use Unicode for their wide character code values (process code),
529 * except the IBM-eucTW codeset."
532 # define U_SIZEOF_WCHAR_T 4
534 # define U_SIZEOF_WCHAR_T 2
536 #elif U_PLATFORM == U_PF_OS390
538 * z/OS V1R11 information center, section "LP64 | ILP32":
539 * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes.
540 * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes."
543 # define U_SIZEOF_WCHAR_T 4
545 # define U_SIZEOF_WCHAR_T 2
547 #elif U_PLATFORM == U_PF_OS400
548 # if defined(__UTF32__)
550 * LOCALETYPE(*LOCALEUTF) is specified.
551 * Wide-character strings are in UTF-32,
552 * narrow-character strings are in UTF-8.
554 # define U_SIZEOF_WCHAR_T 4
555 # elif defined(__UCS2__)
557 * LOCALETYPE(*LOCALEUCS2) is specified.
558 * Wide-character strings are in UCS-2,
559 * narrow-character strings are in EBCDIC.
561 # define U_SIZEOF_WCHAR_T 2
564 * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified.
565 * Wide-character strings are in 16-bit EBCDIC,
566 * narrow-character strings are in EBCDIC.
568 # define U_SIZEOF_WCHAR_T 2
571 # define U_SIZEOF_WCHAR_T 4
574 #ifndef U_HAVE_WCSCPY
575 #define U_HAVE_WCSCPY U_HAVE_WCHAR_H
581 * \def U_HAVE_CHAR16_T
582 * Defines whether the char16_t type is available for UTF-16
583 * and u"abc" UTF-16 string literals are supported.
584 * This is a new standard type and standard string literal syntax in C++0x
585 * but has been available in some compilers before.
588 #ifdef U_HAVE_CHAR16_T
589 /* Use the predefined value. */
593 * Visual Studio 10 (_MSC_VER>=1600) defines char16_t but
594 * does not support u"abc" string literals.
595 * gcc 4.4 defines the __CHAR16_TYPE__ macro to a usable type but
596 * does not support u"abc" string literals.
598 # define U_HAVE_CHAR16_T 0
603 * \def U_DECLARE_UTF16
604 * Do not use this macro because it is not defined on all platforms.
605 * Use the UNICODE_STRING or U_STRING_DECL macros instead.
608 #ifdef U_DECLARE_UTF16
609 /* Use the predefined value. */
610 #elif (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \
611 || (defined(__HP_aCC) && __HP_aCC >= 035000) \
612 || (defined(__HP_cc) && __HP_cc >= 111106) \
614 # define U_DECLARE_UTF16(string) u ## string
615 #elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550)
616 /* || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x580) */
617 /* Sun's C compiler has issues with this notation, and it's unreliable. */
618 # define U_DECLARE_UTF16(string) U ## string
619 #elif U_SIZEOF_WCHAR_T == 2 \
620 && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__)))
621 # define U_DECLARE_UTF16(string) L ## string
623 /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */
628 /*===========================================================================*/
629 /** @{ Symbol import-export control */
630 /*===========================================================================*/
633 /* Use the predefined value. */
634 #elif defined(U_STATIC_IMPLEMENTATION)
636 #elif defined(__GNUC__)
637 # define U_EXPORT __attribute__((visibility("default")))
638 #elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
639 || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550)
640 # define U_EXPORT __global
641 /*#elif defined(__HP_aCC) || defined(__HP_cc)
642 # define U_EXPORT __declspec(dllexport)*/
643 #elif defined(_MSC_VER)
644 # define U_EXPORT __declspec(dllexport)
649 /* U_CALLCONV is releated to U_EXPORT2 */
651 /* Use the predefined value. */
652 #elif defined(_MSC_VER)
653 # define U_EXPORT2 __cdecl
659 /* Use the predefined value. */
660 #elif defined(_MSC_VER)
661 /* Windows needs to export/import data. */
662 # define U_IMPORT __declspec(dllimport)
669 * Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary
670 * in callback function typedefs to make sure that the calling convention
673 * This is only used for non-ICU-API functions.
674 * When a function is a public ICU API,
675 * you must use the U_CAPI and U_EXPORT2 qualifiers.
678 #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
679 # define U_CALLCONV __cdecl
681 # define U_CALLCONV U_EXPORT2