ICU 57.1 57.1
platform.h
Go to the documentation of this file.
1/*
2******************************************************************************
3*
4* Copyright (C) 1997-2016, 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
89#define U_PF_WINDOWS 1000
91#define U_PF_MINGW 1800
97#define U_PF_CYGWIN 1900
98/* Reserve 2000 for U_PF_UNIX? */
100#define U_PF_HPUX 2100
102#define U_PF_SOLARIS 2600
104#define U_PF_BSD 3000
106#define U_PF_AIX 3100
108#define U_PF_IRIX 3200
117#define U_PF_DARWIN 3500
119#define U_PF_IPHONE 3550
121#define U_PF_QNX 3700
123#define U_PF_LINUX 4000
130#define U_PF_BROWSER_NATIVE_CLIENT 4020
132#define U_PF_ANDROID 4050
133/* Maximum value for Linux-based platform is 4499 */
135#define U_PF_OS390 9000
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: http://clang.llvm.org/docs/LanguageExtensions.html */
432#ifndef __has_attribute
433# define __has_attribute(x) 0
434#endif
435#ifndef __has_cpp_attribute
436# define __has_cpp_attribute(x) 0
437#endif
438#ifndef __has_builtin
439# define __has_builtin(x) 0
440#endif
441#ifndef __has_feature
442# define __has_feature(x) 0
443#endif
444#ifndef __has_extension
445# define __has_extension(x) 0
446#endif
447#ifndef __has_warning
448# define __has_warning(x) 0
449#endif
450
456#if defined(__GNUC__) && __GNUC__>=3
457# define U_MALLOC_ATTR __attribute__ ((__malloc__))
458#else
459# define U_MALLOC_ATTR
460#endif
461
467#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || __has_attribute(alloc_size)
468# define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X)))
469# define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y)))
470#else
471# define U_ALLOC_SIZE_ATTR(X)
472# define U_ALLOC_SIZE_ATTR2(X,Y)
473#endif
474
481#ifdef U_CPLUSPLUS_VERSION
482# if U_CPLUSPLUS_VERSION != 0 && !defined(__cplusplus)
483# undef U_CPLUSPLUS_VERSION
484# define U_CPLUSPLUS_VERSION 0
485# endif
486 /* Otherwise use the predefined value. */
487#elif !defined(__cplusplus)
488# define U_CPLUSPLUS_VERSION 0
489#elif __cplusplus >= 201402L
490# define U_CPLUSPLUS_VERSION 14
491#elif __cplusplus >= 201103L
492# define U_CPLUSPLUS_VERSION 11
493#else
494 // C++98 or C++03
495# define U_CPLUSPLUS_VERSION 1
496#endif
497
504#ifdef U_HAVE_RVALUE_REFERENCES
505 /* Use the predefined value. */
506#elif U_CPLUSPLUS_VERSION >= 11 || __has_feature(cxx_rvalue_references) \
507 || defined(__GXX_EXPERIMENTAL_CXX0X__) \
508 || (defined(_MSC_VER) && _MSC_VER >= 1600) /* Visual Studio 2010 */
509# define U_HAVE_RVALUE_REFERENCES 1
510#else
511# define U_HAVE_RVALUE_REFERENCES 0
512#endif
513
521#ifdef U_NOEXCEPT
522 /* Use the predefined value. */
523#elif defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS /* Visual Studio */
524# define U_NOEXCEPT
525#elif U_CPLUSPLUS_VERSION >= 11 || __has_feature(cxx_noexcept) || __has_extension(cxx_noexcept) \
526 || (defined(_MSC_VER) && _MSC_VER >= 1900) /* Visual Studio 2015 */
527# define U_NOEXCEPT noexcept
528#else
529# define U_NOEXCEPT
530#endif
531
538#ifdef __cplusplus
539# if __has_cpp_attribute(clang::fallthrough) || \
540 (__has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough"))
541# define U_FALLTHROUGH [[clang::fallthrough]]
542# else
543# define U_FALLTHROUGH
544# endif
545#else
546# define U_FALLTHROUGH
547#endif
548
549
552/*===========================================================================*/
554/*===========================================================================*/
555
560#define U_ASCII_FAMILY 0
561
566#define U_EBCDIC_FAMILY 1
567
610#ifdef U_CHARSET_FAMILY
611 /* Use the predefined value. */
612#elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB)
613# define U_CHARSET_FAMILY U_EBCDIC_FAMILY
614#elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__)
615# define U_CHARSET_FAMILY U_EBCDIC_FAMILY
616#else
617# define U_CHARSET_FAMILY U_ASCII_FAMILY
618#endif
619
640#ifdef U_CHARSET_IS_UTF8
641 /* Use the predefined value. */
642#elif U_PLATFORM == U_PF_ANDROID || U_PLATFORM_IS_DARWIN_BASED
643# define U_CHARSET_IS_UTF8 1
644#else
645# define U_CHARSET_IS_UTF8 0
646#endif
647
650/*===========================================================================*/
652/*===========================================================================*/
653
660#ifdef U_HAVE_WCHAR_H
661 /* Use the predefined value. */
662#elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9
663 /*
664 * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t.
665 * The type and header existed, but the library functions did not work as expected.
666 * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway.
667 */
668# define U_HAVE_WCHAR_H 0
669#else
670# define U_HAVE_WCHAR_H 1
671#endif
672
679#ifdef U_SIZEOF_WCHAR_T
680 /* Use the predefined value. */
681#elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9)
682 /*
683 * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring.
684 * Newer Mac OS X has size 4.
685 */
686# define U_SIZEOF_WCHAR_T 1
687#elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN
688# define U_SIZEOF_WCHAR_T 2
689#elif U_PLATFORM == U_PF_AIX
690 /*
691 * AIX 6.1 information, section "Wide character data representation":
692 * "... the wchar_t datatype is 32-bit in the 64-bit environment and
693 * 16-bit in the 32-bit environment."
694 * and
695 * "All locales use Unicode for their wide character code values (process code),
696 * except the IBM-eucTW codeset."
697 */
698# ifdef __64BIT__
699# define U_SIZEOF_WCHAR_T 4
700# else
701# define U_SIZEOF_WCHAR_T 2
702# endif
703#elif U_PLATFORM == U_PF_OS390
704 /*
705 * z/OS V1R11 information center, section "LP64 | ILP32":
706 * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes.
707 * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes."
708 */
709# ifdef _LP64
710# define U_SIZEOF_WCHAR_T 4
711# else
712# define U_SIZEOF_WCHAR_T 2
713# endif
714#elif U_PLATFORM == U_PF_OS400
715# if defined(__UTF32__)
716 /*
717 * LOCALETYPE(*LOCALEUTF) is specified.
718 * Wide-character strings are in UTF-32,
719 * narrow-character strings are in UTF-8.
720 */
721# define U_SIZEOF_WCHAR_T 4
722# elif defined(__UCS2__)
723 /*
724 * LOCALETYPE(*LOCALEUCS2) is specified.
725 * Wide-character strings are in UCS-2,
726 * narrow-character strings are in EBCDIC.
727 */
728# define U_SIZEOF_WCHAR_T 2
729#else
730 /*
731 * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified.
732 * Wide-character strings are in 16-bit EBCDIC,
733 * narrow-character strings are in EBCDIC.
734 */
735# define U_SIZEOF_WCHAR_T 2
736# endif
737#else
738# define U_SIZEOF_WCHAR_T 4
739#endif
740
741#ifndef U_HAVE_WCSCPY
742#define U_HAVE_WCSCPY U_HAVE_WCHAR_H
743#endif
744
755#ifdef U_HAVE_CHAR16_T
756 /* Use the predefined value. */
757#else
758 /*
759 * Notes:
760 * Visual Studio 10 (_MSC_VER>=1600) defines char16_t but
761 * does not support u"abc" string literals.
762 * gcc 4.4 defines the __CHAR16_TYPE__ macro to a usable type but
763 * does not support u"abc" string literals.
764 * C++11 and C11 require support for UTF-16 literals
765 */
766# if U_CPLUSPLUS_VERSION >= 11 || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
767# define U_HAVE_CHAR16_T 1
768# else
769# define U_HAVE_CHAR16_T 0
770# endif
771#endif
772
780#ifdef U_DECLARE_UTF16
781 /* Use the predefined value. */
782#elif U_HAVE_CHAR16_T \
783 || (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \
784 || (defined(__HP_aCC) && __HP_aCC >= 035000) \
785 || (defined(__HP_cc) && __HP_cc >= 111106)
786# define U_DECLARE_UTF16(string) u ## string
787#elif U_SIZEOF_WCHAR_T == 2 \
788 && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__)))
789# define U_DECLARE_UTF16(string) L ## string
790#else
791 /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */
792#endif
793
796/*===========================================================================*/
798/*===========================================================================*/
799
800#ifdef U_EXPORT
801 /* Use the predefined value. */
802#elif defined(U_STATIC_IMPLEMENTATION)
803# define U_EXPORT
804#elif defined(__GNUC__)
805# define U_EXPORT __attribute__((visibility("default")))
806#elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
807 || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550)
808# define U_EXPORT __global
809/*#elif defined(__HP_aCC) || defined(__HP_cc)
810# define U_EXPORT __declspec(dllexport)*/
811#elif defined(_MSC_VER)
812# define U_EXPORT __declspec(dllexport)
813#else
814# define U_EXPORT
815#endif
816
817/* U_CALLCONV is releated to U_EXPORT2 */
818#ifdef U_EXPORT2
819 /* Use the predefined value. */
820#elif defined(_MSC_VER)
821# define U_EXPORT2 __cdecl
822#else
823# define U_EXPORT2
824#endif
825
826#ifdef U_IMPORT
827 /* Use the predefined value. */
828#elif defined(_MSC_VER)
829 /* Windows needs to export/import data. */
830# define U_IMPORT __declspec(dllimport)
831#else
832# define U_IMPORT
833#endif
834
846#if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
847# define U_CALLCONV __cdecl
848#else
849# define U_CALLCONV U_EXPORT2
850#endif
851
852/* @} */
853
854#endif
User-configurable settings.
C API: definitions of ICU version numbers.