ICU 75.1 75.1
Loading...
Searching...
No Matches
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
91#define U_PF_WINDOWS 1000
93#define U_PF_MINGW 1800
99#define U_PF_CYGWIN 1900
100/* Reserve 2000 for U_PF_UNIX? */
102#define U_PF_HPUX 2100
104#define U_PF_SOLARIS 2600
106#define U_PF_BSD 3000
108#define U_PF_AIX 3100
110#define U_PF_IRIX 3200
119#define U_PF_DARWIN 3500
121#define U_PF_IPHONE 3550
123#define U_PF_QNX 3700
125#define U_PF_LINUX 4000
132#define U_PF_BROWSER_NATIVE_CLIENT 4020
134#define U_PF_ANDROID 4050
136#define U_PF_FUCHSIA 4100
137/* Maximum value for Linux-based platform is 4499 */
145#define U_PF_EMSCRIPTEN 5010
147#define U_PF_OS390 9000
149#define U_PF_OS400 9400
150
151#ifdef U_PLATFORM
152 /* Use the predefined value. */
153#elif defined(__MINGW32__)
154# define U_PLATFORM U_PF_MINGW
155#elif defined(__CYGWIN__)
156# define U_PLATFORM U_PF_CYGWIN
157#elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
158# define U_PLATFORM U_PF_WINDOWS
159#elif defined(__ANDROID__)
160# define U_PLATFORM U_PF_ANDROID
161 /* Android wchar_t support depends on the API level. */
162# include <android/api-level.h>
163#elif defined(__pnacl__) || defined(__native_client__)
164# define U_PLATFORM U_PF_BROWSER_NATIVE_CLIENT
165#elif defined(__Fuchsia__)
166# define U_PLATFORM U_PF_FUCHSIA
167#elif defined(linux) || defined(__linux__) || defined(__linux)
168# define U_PLATFORM U_PF_LINUX
169#elif defined(__APPLE__) && defined(__MACH__)
170# include <TargetConditionals.h>
171# if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && (defined(TARGET_OS_MACCATALYST) && !TARGET_OS_MACCATALYST) /* variant of TARGET_OS_MAC */
172# define U_PLATFORM U_PF_IPHONE
173# else
174# define U_PLATFORM U_PF_DARWIN
175# endif
176#elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__MirBSD__)
177# if defined(__FreeBSD__)
178# include <sys/endian.h>
179# endif
180# define U_PLATFORM U_PF_BSD
181#elif defined(sun) || defined(__sun)
182 /* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */
183# define U_PLATFORM U_PF_SOLARIS
184# if defined(__GNUC__)
185 /* Solaris/GCC needs this header file to get the proper endianness. Normally, this
186 * header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h
187 * is included which does not include this header file.
188 */
189# include <sys/isa_defs.h>
190# endif
191#elif defined(_AIX) || defined(__TOS_AIX__)
192# define U_PLATFORM U_PF_AIX
193#elif defined(_hpux) || defined(hpux) || defined(__hpux)
194# define U_PLATFORM U_PF_HPUX
195#elif defined(sgi) || defined(__sgi)
196# define U_PLATFORM U_PF_IRIX
197#elif defined(__QNX__) || defined(__QNXNTO__)
198# define U_PLATFORM U_PF_QNX
199#elif defined(__TOS_MVS__)
200# define U_PLATFORM U_PF_OS390
201#elif defined(__OS400__) || defined(__TOS_OS400__)
202# define U_PLATFORM U_PF_OS400
203#elif defined(__EMSCRIPTEN__)
204# define U_PLATFORM U_PF_EMSCRIPTEN
205#else
206# define U_PLATFORM U_PF_UNKNOWN
207#endif
208
215/* Commented out because this is already set in mh-cygwin-msvc
216#if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER)
217# define CYGWINMSVC
218#endif
219*/
220#ifdef U_IN_DOXYGEN
221# define CYGWINMSVC
222#endif
223
230#ifdef U_PLATFORM_USES_ONLY_WIN32_API
231 /* Use the predefined value. */
232#elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC)
233# define U_PLATFORM_USES_ONLY_WIN32_API 1
234#else
235 /* Cygwin implements POSIX. */
236# define U_PLATFORM_USES_ONLY_WIN32_API 0
237#endif
238
245#ifdef U_PLATFORM_HAS_WIN32_API
246 /* Use the predefined value. */
247#elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
248# define U_PLATFORM_HAS_WIN32_API 1
249#else
250# define U_PLATFORM_HAS_WIN32_API 0
251#endif
252
259#ifdef U_PLATFORM_HAS_WINUWP_API
260 /* Use the predefined value. */
261#else
262# define U_PLATFORM_HAS_WINUWP_API 0
263#endif
264
271#ifdef U_PLATFORM_IMPLEMENTS_POSIX
272 /* Use the predefined value. */
273#elif U_PLATFORM_USES_ONLY_WIN32_API
274# define U_PLATFORM_IMPLEMENTS_POSIX 0
275#else
276# define U_PLATFORM_IMPLEMENTS_POSIX 1
277#endif
278
284#ifdef U_PLATFORM_IS_LINUX_BASED
285 /* Use the predefined value. */
286#elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= 4499
287# define U_PLATFORM_IS_LINUX_BASED 1
288#else
289# define U_PLATFORM_IS_LINUX_BASED 0
290#endif
291
297#ifdef U_PLATFORM_IS_DARWIN_BASED
298 /* Use the predefined value. */
299#elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE
300# define U_PLATFORM_IS_DARWIN_BASED 1
301#else
302# define U_PLATFORM_IS_DARWIN_BASED 0
303#endif
304
305/*===========================================================================*/
307/*===========================================================================*/
308
319#ifdef __GNUC__
320# define U_GCC_MAJOR_MINOR (__GNUC__ * 100 + __GNUC_MINOR__)
321#else
322# define U_GCC_MAJOR_MINOR 0
323#endif
324
330#ifdef U_IS_BIG_ENDIAN
331 /* Use the predefined value. */
332#elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
333# define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN)
334#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
335 /* gcc */
336# define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
337#elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
338# define U_IS_BIG_ENDIAN 1
339#elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN)
340# define U_IS_BIG_ENDIAN 0
341#elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400 || defined(__s390__) || defined(__s390x__)
342 /* These platforms do not appear to predefine any endianness macros. */
343# define U_IS_BIG_ENDIAN 1
344#elif defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0)
345 /* HPPA do not appear to predefine any endianness macros. */
346# define U_IS_BIG_ENDIAN 1
347#elif defined(sparc) || defined(__sparc) || defined(__sparc__)
348 /* Some sparc based systems (e.g. Linux) do not predefine any endianness macros. */
349# define U_IS_BIG_ENDIAN 1
350#else
351# define U_IS_BIG_ENDIAN 0
352#endif
353
359#ifdef U_HAVE_PLACEMENT_NEW
360 /* Use the predefined value. */
361#elif defined(__BORLANDC__)
362# define U_HAVE_PLACEMENT_NEW 0
363#else
364# define U_HAVE_PLACEMENT_NEW 1
365#endif
366
373#ifdef U_HAVE_DEBUG_LOCATION_NEW
374 /* Use the predefined value. */
375#elif defined(_MSC_VER)
376# define U_HAVE_DEBUG_LOCATION_NEW 1
377#else
378# define U_HAVE_DEBUG_LOCATION_NEW 0
379#endif
380
381/* Compatibility with compilers other than clang: http://clang.llvm.org/docs/LanguageExtensions.html */
382#ifdef __has_attribute
383# define UPRV_HAS_ATTRIBUTE(x) __has_attribute(x)
384#else
385# define UPRV_HAS_ATTRIBUTE(x) 0
386#endif
387#ifdef __has_cpp_attribute
388# define UPRV_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
389#else
390# define UPRV_HAS_CPP_ATTRIBUTE(x) 0
391#endif
392#ifdef __has_declspec_attribute
393# define UPRV_HAS_DECLSPEC_ATTRIBUTE(x) __has_declspec_attribute(x)
394#else
395# define UPRV_HAS_DECLSPEC_ATTRIBUTE(x) 0
396#endif
397#ifdef __has_builtin
398# define UPRV_HAS_BUILTIN(x) __has_builtin(x)
399#else
400# define UPRV_HAS_BUILTIN(x) 0
401#endif
402#ifdef __has_feature
403# define UPRV_HAS_FEATURE(x) __has_feature(x)
404#else
405# define UPRV_HAS_FEATURE(x) 0
406#endif
407#ifdef __has_extension
408# define UPRV_HAS_EXTENSION(x) __has_extension(x)
409#else
410# define UPRV_HAS_EXTENSION(x) 0
411#endif
412#ifdef __has_warning
413# define UPRV_HAS_WARNING(x) __has_warning(x)
414#else
415# define UPRV_HAS_WARNING(x) 0
416#endif
417
418
419#if defined(__clang__)
420#define UPRV_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
421#else
422#define UPRV_NO_SANITIZE_UNDEFINED
423#endif
424
430#if defined(__GNUC__) && __GNUC__>=3
431# define U_MALLOC_ATTR __attribute__ ((__malloc__))
432#else
433# define U_MALLOC_ATTR
434#endif
435
441#if (defined(__GNUC__) && \
442 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || \
443 UPRV_HAS_ATTRIBUTE(alloc_size)
444# define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X)))
445# define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y)))
446#else
447# define U_ALLOC_SIZE_ATTR(X)
448# define U_ALLOC_SIZE_ATTR2(X,Y)
449#endif
450
457#ifdef U_CPLUSPLUS_VERSION
458# if U_CPLUSPLUS_VERSION != 0 && !defined(__cplusplus)
459# undef U_CPLUSPLUS_VERSION
460# define U_CPLUSPLUS_VERSION 0
461# endif
462 /* Otherwise use the predefined value. */
463#elif !defined(__cplusplus)
464# define U_CPLUSPLUS_VERSION 0
465#elif __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
466# define U_CPLUSPLUS_VERSION 17
467#elif __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
468# define U_CPLUSPLUS_VERSION 14
469#elif __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
470# define U_CPLUSPLUS_VERSION 11
471#else
472 // C++98 or C++03
473# define U_CPLUSPLUS_VERSION 1
474#endif
475
482#ifndef __cplusplus
483 // Not for C.
484#elif defined(U_FALLTHROUGH)
485 // Use the predefined value.
486#elif defined(__clang__)
487 // Test for compiler vs. feature separately.
488 // Other compilers might choke on the feature test.
489# if UPRV_HAS_CPP_ATTRIBUTE(clang::fallthrough) || \
490 (UPRV_HAS_FEATURE(cxx_attributes) && \
491 UPRV_HAS_WARNING("-Wimplicit-fallthrough"))
492# define U_FALLTHROUGH [[clang::fallthrough]]
493# endif
494#elif defined(__GNUC__) && (__GNUC__ >= 7)
495# define U_FALLTHROUGH __attribute__((fallthrough))
496#endif
497
498#ifndef U_FALLTHROUGH
499# define U_FALLTHROUGH
500#endif
501
504/*===========================================================================*/
506/*===========================================================================*/
507
512#define U_ASCII_FAMILY 0
513
518#define U_EBCDIC_FAMILY 1
519
562#ifdef U_CHARSET_FAMILY
563 /* Use the predefined value. */
564#elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB)
565# define U_CHARSET_FAMILY U_EBCDIC_FAMILY
566#elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__)
567# define U_CHARSET_FAMILY U_EBCDIC_FAMILY
568#else
569# define U_CHARSET_FAMILY U_ASCII_FAMILY
570#endif
571
592#ifdef U_CHARSET_IS_UTF8
593 /* Use the predefined value. */
594#elif U_PLATFORM_IS_LINUX_BASED || U_PLATFORM_IS_DARWIN_BASED || \
595 U_PLATFORM == U_PF_EMSCRIPTEN
596# define U_CHARSET_IS_UTF8 1
597#else
598# define U_CHARSET_IS_UTF8 0
599#endif
600
603/*===========================================================================*/
605/*===========================================================================*/
606
613#ifdef U_HAVE_WCHAR_H
614 /* Use the predefined value. */
615#elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9
616 /*
617 * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t.
618 * The type and header existed, but the library functions did not work as expected.
619 * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway.
620 */
621# define U_HAVE_WCHAR_H 0
622#else
623# define U_HAVE_WCHAR_H 1
624#endif
625
632#ifdef U_SIZEOF_WCHAR_T
633 /* Use the predefined value. */
634#elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9)
635 /*
636 * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring.
637 * Newer Mac OS X has size 4.
638 */
639# define U_SIZEOF_WCHAR_T 1
640#elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN
641# define U_SIZEOF_WCHAR_T 2
642#elif U_PLATFORM == U_PF_AIX
643 /*
644 * AIX 6.1 information, section "Wide character data representation":
645 * "... the wchar_t datatype is 32-bit in the 64-bit environment and
646 * 16-bit in the 32-bit environment."
647 * and
648 * "All locales use Unicode for their wide character code values (process code),
649 * except the IBM-eucTW codeset."
650 */
651# ifdef __64BIT__
652# define U_SIZEOF_WCHAR_T 4
653# else
654# define U_SIZEOF_WCHAR_T 2
655# endif
656#elif U_PLATFORM == U_PF_OS390
657 /*
658 * z/OS V1R11 information center, section "LP64 | ILP32":
659 * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes.
660 * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes."
661 */
662# ifdef _LP64
663# define U_SIZEOF_WCHAR_T 4
664# else
665# define U_SIZEOF_WCHAR_T 2
666# endif
667#elif U_PLATFORM == U_PF_OS400
668# if defined(__UTF32__)
669 /*
670 * LOCALETYPE(*LOCALEUTF) is specified.
671 * Wide-character strings are in UTF-32,
672 * narrow-character strings are in UTF-8.
673 */
674# define U_SIZEOF_WCHAR_T 4
675# elif defined(__UCS2__)
676 /*
677 * LOCALETYPE(*LOCALEUCS2) is specified.
678 * Wide-character strings are in UCS-2,
679 * narrow-character strings are in EBCDIC.
680 */
681# define U_SIZEOF_WCHAR_T 2
682# else
683 /*
684 * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified.
685 * Wide-character strings are in 16-bit EBCDIC,
686 * narrow-character strings are in EBCDIC.
687 */
688# define U_SIZEOF_WCHAR_T 2
689# endif
690#else
691# define U_SIZEOF_WCHAR_T 4
692#endif
693
694#ifndef U_HAVE_WCSCPY
695#define U_HAVE_WCSCPY U_HAVE_WCHAR_H
696#endif
697
708#ifdef U_HAVE_CHAR16_T
709 /* Use the predefined value. */
710#else
711 /*
712 * Notes:
713 * C++11 and C11 require support for UTF-16 literals
714 * Doesn't work on Mac C11 (see workaround in ptypes.h).
715 */
716# if defined(__cplusplus) || !U_PLATFORM_IS_DARWIN_BASED
717# define U_HAVE_CHAR16_T 1
718# else
719# define U_HAVE_CHAR16_T 0
720# endif
721#endif
722
730#ifdef U_DECLARE_UTF16
731 /* Use the predefined value. */
732#elif U_HAVE_CHAR16_T \
733 || (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \
734 || (defined(__HP_aCC) && __HP_aCC >= 035000) \
735 || (defined(__HP_cc) && __HP_cc >= 111106) \
736 || (defined(U_IN_DOXYGEN))
737# define U_DECLARE_UTF16(string) u ## string
738#elif U_SIZEOF_WCHAR_T == 2 \
739 && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__)))
740# define U_DECLARE_UTF16(string) L ## string
741#else
742 /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */
743#endif
744
747/*===========================================================================*/
749/*===========================================================================*/
750
751#ifdef U_EXPORT
752 /* Use the predefined value. */
753#elif defined(U_STATIC_IMPLEMENTATION)
754# define U_EXPORT
755#elif defined(_MSC_VER) || (UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllexport__) && \
756 UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllimport__))
757# define U_EXPORT __declspec(dllexport)
758#elif defined(__GNUC__)
759# define U_EXPORT __attribute__((visibility("default")))
760#elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
761 || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550)
762# define U_EXPORT __global
763/*#elif defined(__HP_aCC) || defined(__HP_cc)
764# define U_EXPORT __declspec(dllexport)*/
765#else
766# define U_EXPORT
767#endif
768
769/* U_CALLCONV is related to U_EXPORT2 */
770#ifdef U_EXPORT2
771 /* Use the predefined value. */
772#elif defined(_MSC_VER)
773# define U_EXPORT2 __cdecl
774#else
775# define U_EXPORT2
776#endif
777
778#ifdef U_IMPORT
779 /* Use the predefined value. */
780#elif defined(_MSC_VER) || (UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllexport__) && \
781 UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllimport__))
782 /* Windows needs to export/import data. */
783# define U_IMPORT __declspec(dllimport)
784#else
785# define U_IMPORT
786#endif
787
795#ifdef U_HIDDEN
796 /* Use the predefined value. */
797#elif defined(__GNUC__)
798# define U_HIDDEN __attribute__((visibility("hidden")))
799#else
800# define U_HIDDEN
801#endif
802
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
831#if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
832# define U_CALLCONV_FPTR U_CALLCONV
833#else
834# define U_CALLCONV_FPTR
835#endif
838#endif // _PLATFORM_H
User-configurable settings.
C API: definitions of ICU version numbers.