xref: /aosp_15_r20/external/icu/libicu/cts_headers/putilimp.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker *
6*0e209d39SAndroid Build Coastguard Worker *   Copyright (C) 1997-2016, International Business Machines
7*0e209d39SAndroid Build Coastguard Worker *   Corporation and others.  All Rights Reserved.
8*0e209d39SAndroid Build Coastguard Worker *
9*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
10*0e209d39SAndroid Build Coastguard Worker *
11*0e209d39SAndroid Build Coastguard Worker *  FILE NAME : putilimp.h
12*0e209d39SAndroid Build Coastguard Worker *
13*0e209d39SAndroid Build Coastguard Worker *   Date        Name        Description
14*0e209d39SAndroid Build Coastguard Worker *   10/17/04    grhoten     Move internal functions from putil.h to this file.
15*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
16*0e209d39SAndroid Build Coastguard Worker */
17*0e209d39SAndroid Build Coastguard Worker 
18*0e209d39SAndroid Build Coastguard Worker #ifndef PUTILIMP_H
19*0e209d39SAndroid Build Coastguard Worker #define PUTILIMP_H
20*0e209d39SAndroid Build Coastguard Worker 
21*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
22*0e209d39SAndroid Build Coastguard Worker #include "unicode/putil.h"
23*0e209d39SAndroid Build Coastguard Worker 
24*0e209d39SAndroid Build Coastguard Worker /**
25*0e209d39SAndroid Build Coastguard Worker  * \def U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC
26*0e209d39SAndroid Build Coastguard Worker  * Nearly all CPUs and compilers implement a right-shift of a signed integer
27*0e209d39SAndroid Build Coastguard Worker  * as an Arithmetic Shift Right which copies the sign bit (the Most Significant Bit (MSB))
28*0e209d39SAndroid Build Coastguard Worker  * into the vacated bits (sign extension).
29*0e209d39SAndroid Build Coastguard Worker  * For example, (int32_t)0xfff5fff3>>4 becomes 0xffff5fff and -1>>1=-1.
30*0e209d39SAndroid Build Coastguard Worker  *
31*0e209d39SAndroid Build Coastguard Worker  * This can be useful for storing a signed value in the upper bits
32*0e209d39SAndroid Build Coastguard Worker  * and another bit field in the lower bits.
33*0e209d39SAndroid Build Coastguard Worker  * The signed value can be retrieved by simple right-shifting.
34*0e209d39SAndroid Build Coastguard Worker  *
35*0e209d39SAndroid Build Coastguard Worker  * This is consistent with the Java language.
36*0e209d39SAndroid Build Coastguard Worker  *
37*0e209d39SAndroid Build Coastguard Worker  * However, the C standard allows compilers to implement a right-shift of a signed integer
38*0e209d39SAndroid Build Coastguard Worker  * as a Logical Shift Right which copies a 0 into the vacated bits.
39*0e209d39SAndroid Build Coastguard Worker  * For example, (int32_t)0xfff5fff3>>4 becomes 0x0fff5fff and -1>>1=0x7fffffff.
40*0e209d39SAndroid Build Coastguard Worker  *
41*0e209d39SAndroid Build Coastguard Worker  * Code that depends on the natural behavior should be guarded with this macro,
42*0e209d39SAndroid Build Coastguard Worker  * with an alternate path for unusual platforms.
43*0e209d39SAndroid Build Coastguard Worker  * @internal
44*0e209d39SAndroid Build Coastguard Worker  */
45*0e209d39SAndroid Build Coastguard Worker #ifdef U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC
46*0e209d39SAndroid Build Coastguard Worker     /* Use the predefined value. */
47*0e209d39SAndroid Build Coastguard Worker #else
48*0e209d39SAndroid Build Coastguard Worker     /*
49*0e209d39SAndroid Build Coastguard Worker      * Nearly all CPUs & compilers implement a right-shift of a signed integer
50*0e209d39SAndroid Build Coastguard Worker      * as an Arithmetic Shift Right (with sign extension).
51*0e209d39SAndroid Build Coastguard Worker      */
52*0e209d39SAndroid Build Coastguard Worker #   define U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC 1
53*0e209d39SAndroid Build Coastguard Worker #endif
54*0e209d39SAndroid Build Coastguard Worker 
55*0e209d39SAndroid Build Coastguard Worker /** Define this to 1 if your platform supports IEEE 754 floating point,
56*0e209d39SAndroid Build Coastguard Worker    to 0 if it does not. */
57*0e209d39SAndroid Build Coastguard Worker #ifndef IEEE_754
58*0e209d39SAndroid Build Coastguard Worker #   define IEEE_754 1
59*0e209d39SAndroid Build Coastguard Worker #endif
60*0e209d39SAndroid Build Coastguard Worker 
61*0e209d39SAndroid Build Coastguard Worker /**
62*0e209d39SAndroid Build Coastguard Worker  * uintptr_t is an optional part of the standard definitions in stdint.h.
63*0e209d39SAndroid Build Coastguard Worker  * The opengroup.org documentation for stdint.h says
64*0e209d39SAndroid Build Coastguard Worker  * "On XSI-conformant systems, the intptr_t and uintptr_t types are required;
65*0e209d39SAndroid Build Coastguard Worker  * otherwise, they are optional."
66*0e209d39SAndroid Build Coastguard Worker  * We assume that when uintptr_t is defined, UINTPTR_MAX is defined as well.
67*0e209d39SAndroid Build Coastguard Worker  *
68*0e209d39SAndroid Build Coastguard Worker  * Do not use ptrdiff_t since it is signed. size_t is unsigned.
69*0e209d39SAndroid Build Coastguard Worker  */
70*0e209d39SAndroid Build Coastguard Worker /* TODO: This check fails on some z environments. Filed a ticket #9357 for this. */
71*0e209d39SAndroid Build Coastguard Worker #if !defined(__intptr_t_defined) && !defined(UINTPTR_MAX) && (U_PLATFORM != U_PF_OS390)
72*0e209d39SAndroid Build Coastguard Worker typedef size_t uintptr_t;
73*0e209d39SAndroid Build Coastguard Worker #endif
74*0e209d39SAndroid Build Coastguard Worker 
75*0e209d39SAndroid Build Coastguard Worker /*===========================================================================*/
76*0e209d39SAndroid Build Coastguard Worker /** @{ Information about POSIX support                                       */
77*0e209d39SAndroid Build Coastguard Worker /*===========================================================================*/
78*0e209d39SAndroid Build Coastguard Worker 
79*0e209d39SAndroid Build Coastguard Worker #ifdef U_HAVE_NL_LANGINFO_CODESET
80*0e209d39SAndroid Build Coastguard Worker     /* Use the predefined value. */
81*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM == U_PF_ANDROID || U_PLATFORM == U_PF_QNX
82*0e209d39SAndroid Build Coastguard Worker #   define U_HAVE_NL_LANGINFO_CODESET 0
83*0e209d39SAndroid Build Coastguard Worker #else
84*0e209d39SAndroid Build Coastguard Worker #   define U_HAVE_NL_LANGINFO_CODESET 1
85*0e209d39SAndroid Build Coastguard Worker #endif
86*0e209d39SAndroid Build Coastguard Worker 
87*0e209d39SAndroid Build Coastguard Worker #ifdef U_NL_LANGINFO_CODESET
88*0e209d39SAndroid Build Coastguard Worker     /* Use the predefined value. */
89*0e209d39SAndroid Build Coastguard Worker #elif !U_HAVE_NL_LANGINFO_CODESET
90*0e209d39SAndroid Build Coastguard Worker #   define U_NL_LANGINFO_CODESET -1
91*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM == U_PF_OS400
92*0e209d39SAndroid Build Coastguard Worker    /* not defined */
93*0e209d39SAndroid Build Coastguard Worker #else
94*0e209d39SAndroid Build Coastguard Worker #   define U_NL_LANGINFO_CODESET CODESET
95*0e209d39SAndroid Build Coastguard Worker #endif
96*0e209d39SAndroid Build Coastguard Worker 
97*0e209d39SAndroid Build Coastguard Worker #if defined(U_TZSET) || defined(U_HAVE_TZSET)
98*0e209d39SAndroid Build Coastguard Worker     /* Use the predefined value. */
99*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM_USES_ONLY_WIN32_API
100*0e209d39SAndroid Build Coastguard Worker     // UWP doesn't support tzset or environment variables for tz
101*0e209d39SAndroid Build Coastguard Worker #if U_PLATFORM_HAS_WINUWP_API == 0
102*0e209d39SAndroid Build Coastguard Worker #   define U_TZSET _tzset
103*0e209d39SAndroid Build Coastguard Worker #endif
104*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM == U_PF_OS400
105*0e209d39SAndroid Build Coastguard Worker    /* not defined */
106*0e209d39SAndroid Build Coastguard Worker #else
107*0e209d39SAndroid Build Coastguard Worker #   define U_TZSET tzset
108*0e209d39SAndroid Build Coastguard Worker #endif
109*0e209d39SAndroid Build Coastguard Worker 
110*0e209d39SAndroid Build Coastguard Worker #if defined(U_TIMEZONE) || defined(U_HAVE_TIMEZONE)
111*0e209d39SAndroid Build Coastguard Worker     /* Use the predefined value. */
112*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM == U_PF_ANDROID
113*0e209d39SAndroid Build Coastguard Worker #   define U_TIMEZONE timezone
114*0e209d39SAndroid Build Coastguard Worker #elif defined(__UCLIBC__)
115*0e209d39SAndroid Build Coastguard Worker     // uClibc does not have __timezone or _timezone.
116*0e209d39SAndroid Build Coastguard Worker #elif defined(_NEWLIB_VERSION)
117*0e209d39SAndroid Build Coastguard Worker #   define U_TIMEZONE _timezone
118*0e209d39SAndroid Build Coastguard Worker #elif defined(__GLIBC__)
119*0e209d39SAndroid Build Coastguard Worker     // glibc
120*0e209d39SAndroid Build Coastguard Worker #   define U_TIMEZONE __timezone
121*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM_IS_LINUX_BASED
122*0e209d39SAndroid Build Coastguard Worker     // not defined
123*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM_USES_ONLY_WIN32_API
124*0e209d39SAndroid Build Coastguard Worker #   define U_TIMEZONE _timezone
125*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM == U_PF_BSD && !defined(__NetBSD__)
126*0e209d39SAndroid Build Coastguard Worker    /* not defined */
127*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM == U_PF_OS400
128*0e209d39SAndroid Build Coastguard Worker    /* not defined */
129*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM == U_PF_IPHONE
130*0e209d39SAndroid Build Coastguard Worker    /* not defined */
131*0e209d39SAndroid Build Coastguard Worker #else
132*0e209d39SAndroid Build Coastguard Worker #   define U_TIMEZONE timezone
133*0e209d39SAndroid Build Coastguard Worker #endif
134*0e209d39SAndroid Build Coastguard Worker 
135*0e209d39SAndroid Build Coastguard Worker #if defined(U_TZNAME) || defined(U_HAVE_TZNAME)
136*0e209d39SAndroid Build Coastguard Worker     /* Use the predefined value. */
137*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM_USES_ONLY_WIN32_API
138*0e209d39SAndroid Build Coastguard Worker     /* not usable on all windows platforms */
139*0e209d39SAndroid Build Coastguard Worker #if U_PLATFORM_HAS_WINUWP_API == 0
140*0e209d39SAndroid Build Coastguard Worker #   define U_TZNAME _tzname
141*0e209d39SAndroid Build Coastguard Worker #endif
142*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM == U_PF_OS400
143*0e209d39SAndroid Build Coastguard Worker    /* not defined */
144*0e209d39SAndroid Build Coastguard Worker #else
145*0e209d39SAndroid Build Coastguard Worker #   define U_TZNAME tzname
146*0e209d39SAndroid Build Coastguard Worker #endif
147*0e209d39SAndroid Build Coastguard Worker 
148*0e209d39SAndroid Build Coastguard Worker #ifdef U_HAVE_MMAP
149*0e209d39SAndroid Build Coastguard Worker     /* Use the predefined value. */
150*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM_USES_ONLY_WIN32_API
151*0e209d39SAndroid Build Coastguard Worker #   define U_HAVE_MMAP 0
152*0e209d39SAndroid Build Coastguard Worker #else
153*0e209d39SAndroid Build Coastguard Worker #   define U_HAVE_MMAP 1
154*0e209d39SAndroid Build Coastguard Worker #endif
155*0e209d39SAndroid Build Coastguard Worker 
156*0e209d39SAndroid Build Coastguard Worker #ifdef U_HAVE_POPEN
157*0e209d39SAndroid Build Coastguard Worker     /* Use the predefined value. */
158*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM_USES_ONLY_WIN32_API
159*0e209d39SAndroid Build Coastguard Worker #   define U_HAVE_POPEN 0
160*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM == U_PF_OS400
161*0e209d39SAndroid Build Coastguard Worker #   define U_HAVE_POPEN 0
162*0e209d39SAndroid Build Coastguard Worker #else
163*0e209d39SAndroid Build Coastguard Worker #   define U_HAVE_POPEN 1
164*0e209d39SAndroid Build Coastguard Worker #endif
165*0e209d39SAndroid Build Coastguard Worker 
166*0e209d39SAndroid Build Coastguard Worker /**
167*0e209d39SAndroid Build Coastguard Worker  * \def U_HAVE_DIRENT_H
168*0e209d39SAndroid Build Coastguard Worker  * Defines whether dirent.h is available.
169*0e209d39SAndroid Build Coastguard Worker  * @internal
170*0e209d39SAndroid Build Coastguard Worker  */
171*0e209d39SAndroid Build Coastguard Worker #ifdef U_HAVE_DIRENT_H
172*0e209d39SAndroid Build Coastguard Worker     /* Use the predefined value. */
173*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM_USES_ONLY_WIN32_API
174*0e209d39SAndroid Build Coastguard Worker #   define U_HAVE_DIRENT_H 0
175*0e209d39SAndroid Build Coastguard Worker #else
176*0e209d39SAndroid Build Coastguard Worker #   define U_HAVE_DIRENT_H 1
177*0e209d39SAndroid Build Coastguard Worker #endif
178*0e209d39SAndroid Build Coastguard Worker 
179*0e209d39SAndroid Build Coastguard Worker /** @} */
180*0e209d39SAndroid Build Coastguard Worker 
181*0e209d39SAndroid Build Coastguard Worker /*===========================================================================*/
182*0e209d39SAndroid Build Coastguard Worker /** @{ Programs used by ICU code                                             */
183*0e209d39SAndroid Build Coastguard Worker /*===========================================================================*/
184*0e209d39SAndroid Build Coastguard Worker 
185*0e209d39SAndroid Build Coastguard Worker /**
186*0e209d39SAndroid Build Coastguard Worker  * \def U_MAKE_IS_NMAKE
187*0e209d39SAndroid Build Coastguard Worker  * Defines whether the "make" program is Windows nmake.
188*0e209d39SAndroid Build Coastguard Worker  */
189*0e209d39SAndroid Build Coastguard Worker #ifdef U_MAKE_IS_NMAKE
190*0e209d39SAndroid Build Coastguard Worker     /* Use the predefined value. */
191*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM == U_PF_WINDOWS
192*0e209d39SAndroid Build Coastguard Worker #   define U_MAKE_IS_NMAKE 1
193*0e209d39SAndroid Build Coastguard Worker #else
194*0e209d39SAndroid Build Coastguard Worker #   define U_MAKE_IS_NMAKE 0
195*0e209d39SAndroid Build Coastguard Worker #endif
196*0e209d39SAndroid Build Coastguard Worker 
197*0e209d39SAndroid Build Coastguard Worker /** @} */
198*0e209d39SAndroid Build Coastguard Worker 
199*0e209d39SAndroid Build Coastguard Worker /*==========================================================================*/
200*0e209d39SAndroid Build Coastguard Worker /* Platform utilities                                                       */
201*0e209d39SAndroid Build Coastguard Worker /*==========================================================================*/
202*0e209d39SAndroid Build Coastguard Worker 
203*0e209d39SAndroid Build Coastguard Worker /**
204*0e209d39SAndroid Build Coastguard Worker  * Platform utilities isolates the platform dependencies of the
205*0e209d39SAndroid Build Coastguard Worker  * library.  For each platform which this code is ported to, these
206*0e209d39SAndroid Build Coastguard Worker  * functions may have to be re-implemented.
207*0e209d39SAndroid Build Coastguard Worker  */
208*0e209d39SAndroid Build Coastguard Worker 
209*0e209d39SAndroid Build Coastguard Worker /**
210*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to determine if a double is Not a Number (NaN).
211*0e209d39SAndroid Build Coastguard Worker  * @internal
212*0e209d39SAndroid Build Coastguard Worker  */
213*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool   U_EXPORT2 uprv_isNaN(double d);
214*0e209d39SAndroid Build Coastguard Worker /**
215*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to determine if a double has an infinite value.
216*0e209d39SAndroid Build Coastguard Worker  * @internal
217*0e209d39SAndroid Build Coastguard Worker  */
218*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool   U_EXPORT2 uprv_isInfinite(double d);
219*0e209d39SAndroid Build Coastguard Worker /**
220*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to determine if a double has a positive infinite value.
221*0e209d39SAndroid Build Coastguard Worker  * @internal
222*0e209d39SAndroid Build Coastguard Worker  */
223*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool   U_EXPORT2 uprv_isPositiveInfinity(double d);
224*0e209d39SAndroid Build Coastguard Worker /**
225*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to determine if a double has a negative infinite value.
226*0e209d39SAndroid Build Coastguard Worker  * @internal
227*0e209d39SAndroid Build Coastguard Worker  */
228*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool   U_EXPORT2 uprv_isNegativeInfinity(double d);
229*0e209d39SAndroid Build Coastguard Worker /**
230*0e209d39SAndroid Build Coastguard Worker  * Floating point utility that returns a Not a Number (NaN) value.
231*0e209d39SAndroid Build Coastguard Worker  * @internal
232*0e209d39SAndroid Build Coastguard Worker  */
233*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_getNaN(void);
234*0e209d39SAndroid Build Coastguard Worker /**
235*0e209d39SAndroid Build Coastguard Worker  * Floating point utility that returns an infinite value.
236*0e209d39SAndroid Build Coastguard Worker  * @internal
237*0e209d39SAndroid Build Coastguard Worker  */
238*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_getInfinity(void);
239*0e209d39SAndroid Build Coastguard Worker 
240*0e209d39SAndroid Build Coastguard Worker /**
241*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to truncate a double.
242*0e209d39SAndroid Build Coastguard Worker  * @internal
243*0e209d39SAndroid Build Coastguard Worker  */
244*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_trunc(double d);
245*0e209d39SAndroid Build Coastguard Worker /**
246*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to calculate the floor of a double.
247*0e209d39SAndroid Build Coastguard Worker  * @internal
248*0e209d39SAndroid Build Coastguard Worker  */
249*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_floor(double d);
250*0e209d39SAndroid Build Coastguard Worker /**
251*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to calculate the ceiling of a double.
252*0e209d39SAndroid Build Coastguard Worker  * @internal
253*0e209d39SAndroid Build Coastguard Worker  */
254*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_ceil(double d);
255*0e209d39SAndroid Build Coastguard Worker /**
256*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to calculate the absolute value of a double.
257*0e209d39SAndroid Build Coastguard Worker  * @internal
258*0e209d39SAndroid Build Coastguard Worker  */
259*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_fabs(double d);
260*0e209d39SAndroid Build Coastguard Worker /**
261*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to calculate the fractional and integer parts of a double.
262*0e209d39SAndroid Build Coastguard Worker  * @internal
263*0e209d39SAndroid Build Coastguard Worker  */
264*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_modf(double d, double* pinteger);
265*0e209d39SAndroid Build Coastguard Worker /**
266*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to calculate the remainder of a double divided by another double.
267*0e209d39SAndroid Build Coastguard Worker  * @internal
268*0e209d39SAndroid Build Coastguard Worker  */
269*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_fmod(double d, double y);
270*0e209d39SAndroid Build Coastguard Worker /**
271*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to calculate d to the power of exponent (d^exponent).
272*0e209d39SAndroid Build Coastguard Worker  * @internal
273*0e209d39SAndroid Build Coastguard Worker  */
274*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_pow(double d, double exponent);
275*0e209d39SAndroid Build Coastguard Worker /**
276*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to calculate 10 to the power of exponent (10^exponent).
277*0e209d39SAndroid Build Coastguard Worker  * @internal
278*0e209d39SAndroid Build Coastguard Worker  */
279*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_pow10(int32_t exponent);
280*0e209d39SAndroid Build Coastguard Worker /**
281*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to calculate the maximum value of two doubles.
282*0e209d39SAndroid Build Coastguard Worker  * @internal
283*0e209d39SAndroid Build Coastguard Worker  */
284*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_fmax(double d, double y);
285*0e209d39SAndroid Build Coastguard Worker /**
286*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to calculate the minimum value of two doubles.
287*0e209d39SAndroid Build Coastguard Worker  * @internal
288*0e209d39SAndroid Build Coastguard Worker  */
289*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_fmin(double d, double y);
290*0e209d39SAndroid Build Coastguard Worker /**
291*0e209d39SAndroid Build Coastguard Worker  * Private utility to calculate the maximum value of two integers.
292*0e209d39SAndroid Build Coastguard Worker  * @internal
293*0e209d39SAndroid Build Coastguard Worker  */
294*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2 uprv_max(int32_t d, int32_t y);
295*0e209d39SAndroid Build Coastguard Worker /**
296*0e209d39SAndroid Build Coastguard Worker  * Private utility to calculate the minimum value of two integers.
297*0e209d39SAndroid Build Coastguard Worker  * @internal
298*0e209d39SAndroid Build Coastguard Worker  */
299*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2 uprv_min(int32_t d, int32_t y);
300*0e209d39SAndroid Build Coastguard Worker 
301*0e209d39SAndroid Build Coastguard Worker #if U_IS_BIG_ENDIAN
302*0e209d39SAndroid Build Coastguard Worker #   define uprv_isNegative(number) (*((signed char *)&(number))<0)
303*0e209d39SAndroid Build Coastguard Worker #else
304*0e209d39SAndroid Build Coastguard Worker #   define uprv_isNegative(number) (*((signed char *)&(number)+sizeof(number)-1)<0)
305*0e209d39SAndroid Build Coastguard Worker #endif
306*0e209d39SAndroid Build Coastguard Worker 
307*0e209d39SAndroid Build Coastguard Worker /**
308*0e209d39SAndroid Build Coastguard Worker  * Return the largest positive number that can be represented by an integer
309*0e209d39SAndroid Build Coastguard Worker  * type of arbitrary bit length.
310*0e209d39SAndroid Build Coastguard Worker  * @internal
311*0e209d39SAndroid Build Coastguard Worker  */
312*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_maxMantissa(void);
313*0e209d39SAndroid Build Coastguard Worker 
314*0e209d39SAndroid Build Coastguard Worker /**
315*0e209d39SAndroid Build Coastguard Worker  * Floating point utility to calculate the logarithm of a double.
316*0e209d39SAndroid Build Coastguard Worker  * @internal
317*0e209d39SAndroid Build Coastguard Worker  */
318*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_log(double d);
319*0e209d39SAndroid Build Coastguard Worker 
320*0e209d39SAndroid Build Coastguard Worker /**
321*0e209d39SAndroid Build Coastguard Worker  * Does common notion of rounding e.g. uprv_floor(x + 0.5);
322*0e209d39SAndroid Build Coastguard Worker  * @param x the double number
323*0e209d39SAndroid Build Coastguard Worker  * @return the rounded double
324*0e209d39SAndroid Build Coastguard Worker  * @internal
325*0e209d39SAndroid Build Coastguard Worker  */
326*0e209d39SAndroid Build Coastguard Worker U_CAPI double  U_EXPORT2 uprv_round(double x);
327*0e209d39SAndroid Build Coastguard Worker 
328*0e209d39SAndroid Build Coastguard Worker /**
329*0e209d39SAndroid Build Coastguard Worker  * Adds the signed integers a and b, storing the result in res.
330*0e209d39SAndroid Build Coastguard Worker  * Checks for signed integer overflow.
331*0e209d39SAndroid Build Coastguard Worker  * Similar to the GCC/Clang extension __builtin_add_overflow
332*0e209d39SAndroid Build Coastguard Worker  *
333*0e209d39SAndroid Build Coastguard Worker  * @param a The first operand.
334*0e209d39SAndroid Build Coastguard Worker  * @param b The second operand.
335*0e209d39SAndroid Build Coastguard Worker  * @param res a + b
336*0e209d39SAndroid Build Coastguard Worker  * @return true if overflow occurred; false if no overflow occurred.
337*0e209d39SAndroid Build Coastguard Worker  * @internal
338*0e209d39SAndroid Build Coastguard Worker  */
339*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2 uprv_add32_overflow(int32_t a, int32_t b, int32_t* res);
340*0e209d39SAndroid Build Coastguard Worker 
341*0e209d39SAndroid Build Coastguard Worker /**
342*0e209d39SAndroid Build Coastguard Worker  * Multiplies the signed integers a and b, storing the result in res.
343*0e209d39SAndroid Build Coastguard Worker  * Checks for signed integer overflow.
344*0e209d39SAndroid Build Coastguard Worker  * Similar to the GCC/Clang extension __builtin_mul_overflow
345*0e209d39SAndroid Build Coastguard Worker  *
346*0e209d39SAndroid Build Coastguard Worker  * @param a The first multiplicand.
347*0e209d39SAndroid Build Coastguard Worker  * @param b The second multiplicand.
348*0e209d39SAndroid Build Coastguard Worker  * @param res a * b
349*0e209d39SAndroid Build Coastguard Worker  * @return true if overflow occurred; false if no overflow occurred.
350*0e209d39SAndroid Build Coastguard Worker  * @internal
351*0e209d39SAndroid Build Coastguard Worker  */
352*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2 uprv_mul32_overflow(int32_t a, int32_t b, int32_t* res);
353*0e209d39SAndroid Build Coastguard Worker 
354*0e209d39SAndroid Build Coastguard Worker #if 0
355*0e209d39SAndroid Build Coastguard Worker /**
356*0e209d39SAndroid Build Coastguard Worker  * Returns the number of digits after the decimal point in a double number x.
357*0e209d39SAndroid Build Coastguard Worker  *
358*0e209d39SAndroid Build Coastguard Worker  * @param x the double number
359*0e209d39SAndroid Build Coastguard Worker  * @return the number of digits after the decimal point in a double number x.
360*0e209d39SAndroid Build Coastguard Worker  * @internal
361*0e209d39SAndroid Build Coastguard Worker  */
362*0e209d39SAndroid Build Coastguard Worker /*U_CAPI int32_t  U_EXPORT2 uprv_digitsAfterDecimal(double x);*/
363*0e209d39SAndroid Build Coastguard Worker #endif
364*0e209d39SAndroid Build Coastguard Worker 
365*0e209d39SAndroid Build Coastguard Worker #if !U_CHARSET_IS_UTF8
366*0e209d39SAndroid Build Coastguard Worker /**
367*0e209d39SAndroid Build Coastguard Worker  * Please use ucnv_getDefaultName() instead.
368*0e209d39SAndroid Build Coastguard Worker  * Return the default codepage for this platform and locale.
369*0e209d39SAndroid Build Coastguard Worker  * This function can call setlocale() on Unix platforms. Please read the
370*0e209d39SAndroid Build Coastguard Worker  * platform documentation on setlocale() before calling this function.
371*0e209d39SAndroid Build Coastguard Worker  * @return the default codepage for this platform
372*0e209d39SAndroid Build Coastguard Worker  * @internal
373*0e209d39SAndroid Build Coastguard Worker  */
374*0e209d39SAndroid Build Coastguard Worker U_CAPI const char*  U_EXPORT2 uprv_getDefaultCodepage(void);
375*0e209d39SAndroid Build Coastguard Worker #endif
376*0e209d39SAndroid Build Coastguard Worker 
377*0e209d39SAndroid Build Coastguard Worker /**
378*0e209d39SAndroid Build Coastguard Worker  * Please use uloc_getDefault() instead.
379*0e209d39SAndroid Build Coastguard Worker  * Return the default locale ID string by querying the system, or
380*0e209d39SAndroid Build Coastguard Worker  *     zero if one cannot be found.
381*0e209d39SAndroid Build Coastguard Worker  * This function can call setlocale() on Unix platforms. Please read the
382*0e209d39SAndroid Build Coastguard Worker  * platform documentation on setlocale() before calling this function.
383*0e209d39SAndroid Build Coastguard Worker  * @return the default locale ID string
384*0e209d39SAndroid Build Coastguard Worker  * @internal
385*0e209d39SAndroid Build Coastguard Worker  */
386*0e209d39SAndroid Build Coastguard Worker U_CAPI const char*  U_EXPORT2 uprv_getDefaultLocaleID(void);
387*0e209d39SAndroid Build Coastguard Worker 
388*0e209d39SAndroid Build Coastguard Worker /**
389*0e209d39SAndroid Build Coastguard Worker  * Time zone utilities
390*0e209d39SAndroid Build Coastguard Worker  *
391*0e209d39SAndroid Build Coastguard Worker  * Wrappers for C runtime library functions relating to timezones.
392*0e209d39SAndroid Build Coastguard Worker  * The t_tzset() function (similar to tzset) uses the current setting
393*0e209d39SAndroid Build Coastguard Worker  * of the environment variable TZ to assign values to three global
394*0e209d39SAndroid Build Coastguard Worker  * variables: daylight, timezone, and tzname. These variables have the
395*0e209d39SAndroid Build Coastguard Worker  * following meanings, and are declared in &lt;time.h&gt;.
396*0e209d39SAndroid Build Coastguard Worker  *
397*0e209d39SAndroid Build Coastguard Worker  *   daylight   Nonzero if daylight-saving-time zone (DST) is specified
398*0e209d39SAndroid Build Coastguard Worker  *              in TZ; otherwise, 0. Default value is 1.
399*0e209d39SAndroid Build Coastguard Worker  *   timezone   Difference in seconds between coordinated universal
400*0e209d39SAndroid Build Coastguard Worker  *              time and local time. E.g., -28,800 for PST (GMT-8hrs)
401*0e209d39SAndroid Build Coastguard Worker  *   tzname(0)  Three-letter time-zone name derived from TZ environment
402*0e209d39SAndroid Build Coastguard Worker  *              variable. E.g., "PST".
403*0e209d39SAndroid Build Coastguard Worker  *   tzname(1)  Three-letter DST zone name derived from TZ environment
404*0e209d39SAndroid Build Coastguard Worker  *              variable.  E.g., "PDT". If DST zone is omitted from TZ,
405*0e209d39SAndroid Build Coastguard Worker  *              tzname(1) is an empty string.
406*0e209d39SAndroid Build Coastguard Worker  *
407*0e209d39SAndroid Build Coastguard Worker  * Notes: For example, to set the TZ environment variable to correspond
408*0e209d39SAndroid Build Coastguard Worker  * to the current time zone in Germany, you can use one of the
409*0e209d39SAndroid Build Coastguard Worker  * following statements:
410*0e209d39SAndroid Build Coastguard Worker  *
411*0e209d39SAndroid Build Coastguard Worker  *   set TZ=GST1GDT
412*0e209d39SAndroid Build Coastguard Worker  *   set TZ=GST+1GDT
413*0e209d39SAndroid Build Coastguard Worker  *
414*0e209d39SAndroid Build Coastguard Worker  * If the TZ value is not set, t_tzset() attempts to use the time zone
415*0e209d39SAndroid Build Coastguard Worker  * information specified by the operating system. Under Windows NT
416*0e209d39SAndroid Build Coastguard Worker  * and Windows 95, this information is specified in the Control Panel's
417*0e209d39SAndroid Build Coastguard Worker  * Date/Time application.
418*0e209d39SAndroid Build Coastguard Worker  * @internal
419*0e209d39SAndroid Build Coastguard Worker  */
420*0e209d39SAndroid Build Coastguard Worker U_CAPI void     U_EXPORT2 uprv_tzset(void);
421*0e209d39SAndroid Build Coastguard Worker 
422*0e209d39SAndroid Build Coastguard Worker /**
423*0e209d39SAndroid Build Coastguard Worker  * Difference in seconds between coordinated universal
424*0e209d39SAndroid Build Coastguard Worker  * time and local time. E.g., -28,800 for PST (GMT-8hrs)
425*0e209d39SAndroid Build Coastguard Worker  * @return the difference in seconds between coordinated universal time and local time.
426*0e209d39SAndroid Build Coastguard Worker  * @internal
427*0e209d39SAndroid Build Coastguard Worker  */
428*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t  U_EXPORT2 uprv_timezone(void);
429*0e209d39SAndroid Build Coastguard Worker 
430*0e209d39SAndroid Build Coastguard Worker /**
431*0e209d39SAndroid Build Coastguard Worker  *   tzname(0)  Three-letter time-zone name derived from TZ environment
432*0e209d39SAndroid Build Coastguard Worker  *              variable. E.g., "PST".
433*0e209d39SAndroid Build Coastguard Worker  *   tzname(1)  Three-letter DST zone name derived from TZ environment
434*0e209d39SAndroid Build Coastguard Worker  *              variable.  E.g., "PDT". If DST zone is omitted from TZ,
435*0e209d39SAndroid Build Coastguard Worker  *              tzname(1) is an empty string.
436*0e209d39SAndroid Build Coastguard Worker  * @internal
437*0e209d39SAndroid Build Coastguard Worker  */
438*0e209d39SAndroid Build Coastguard Worker U_CAPI const char* U_EXPORT2 uprv_tzname(int n);
439*0e209d39SAndroid Build Coastguard Worker 
440*0e209d39SAndroid Build Coastguard Worker /**
441*0e209d39SAndroid Build Coastguard Worker  * Reset the global tzname cache.
442*0e209d39SAndroid Build Coastguard Worker  * @internal
443*0e209d39SAndroid Build Coastguard Worker  */
444*0e209d39SAndroid Build Coastguard Worker U_CAPI void uprv_tzname_clear_cache(void);
445*0e209d39SAndroid Build Coastguard Worker 
446*0e209d39SAndroid Build Coastguard Worker /**
447*0e209d39SAndroid Build Coastguard Worker  * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970.
448*0e209d39SAndroid Build Coastguard Worker  * This function is affected by 'faketime' and should be the bottleneck for all user-visible ICU time functions.
449*0e209d39SAndroid Build Coastguard Worker  * @return the UTC time measured in milliseconds
450*0e209d39SAndroid Build Coastguard Worker  * @internal
451*0e209d39SAndroid Build Coastguard Worker  */
452*0e209d39SAndroid Build Coastguard Worker U_CAPI UDate U_EXPORT2 uprv_getUTCtime(void);
453*0e209d39SAndroid Build Coastguard Worker 
454*0e209d39SAndroid Build Coastguard Worker /**
455*0e209d39SAndroid Build Coastguard Worker  * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970.
456*0e209d39SAndroid Build Coastguard Worker  * This function is not affected by 'faketime', so it should only be used by low level test functions- not by anything that
457*0e209d39SAndroid Build Coastguard Worker  * exposes time to the end user.
458*0e209d39SAndroid Build Coastguard Worker  * @return the UTC time measured in milliseconds
459*0e209d39SAndroid Build Coastguard Worker  * @internal
460*0e209d39SAndroid Build Coastguard Worker  */
461*0e209d39SAndroid Build Coastguard Worker U_CAPI UDate U_EXPORT2 uprv_getRawUTCtime(void);
462*0e209d39SAndroid Build Coastguard Worker 
463*0e209d39SAndroid Build Coastguard Worker /**
464*0e209d39SAndroid Build Coastguard Worker  * Determine whether a pathname is absolute or not, as defined by the platform.
465*0e209d39SAndroid Build Coastguard Worker  * @param path Pathname to test
466*0e209d39SAndroid Build Coastguard Worker  * @return true if the path is absolute
467*0e209d39SAndroid Build Coastguard Worker  * @internal (ICU 3.0)
468*0e209d39SAndroid Build Coastguard Worker  */
469*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2 uprv_pathIsAbsolute(const char *path);
470*0e209d39SAndroid Build Coastguard Worker 
471*0e209d39SAndroid Build Coastguard Worker /**
472*0e209d39SAndroid Build Coastguard Worker  * Use U_MAX_PTR instead of this function.
473*0e209d39SAndroid Build Coastguard Worker  * @param void pointer to test
474*0e209d39SAndroid Build Coastguard Worker  * @return the largest possible pointer greater than the base
475*0e209d39SAndroid Build Coastguard Worker  * @internal (ICU 3.8)
476*0e209d39SAndroid Build Coastguard Worker  */
477*0e209d39SAndroid Build Coastguard Worker U_CAPI void * U_EXPORT2 uprv_maximumPtr(void *base);
478*0e209d39SAndroid Build Coastguard Worker 
479*0e209d39SAndroid Build Coastguard Worker /**
480*0e209d39SAndroid Build Coastguard Worker  * Maximum value of a (void*) - use to indicate the limit of an 'infinite' buffer.
481*0e209d39SAndroid Build Coastguard Worker  * In fact, buffer sizes must not exceed 2GB so that the difference between
482*0e209d39SAndroid Build Coastguard Worker  * the buffer limit and the buffer start can be expressed in an int32_t.
483*0e209d39SAndroid Build Coastguard Worker  *
484*0e209d39SAndroid Build Coastguard Worker  * The definition of U_MAX_PTR must fulfill the following conditions:
485*0e209d39SAndroid Build Coastguard Worker  * - return the largest possible pointer greater than base
486*0e209d39SAndroid Build Coastguard Worker  * - return a valid pointer according to the machine architecture (AS/400, 64-bit, etc.)
487*0e209d39SAndroid Build Coastguard Worker  * - avoid wrapping around at high addresses
488*0e209d39SAndroid Build Coastguard Worker  * - make sure that the returned pointer is not farther from base than 0x7fffffff bytes
489*0e209d39SAndroid Build Coastguard Worker  *
490*0e209d39SAndroid Build Coastguard Worker  * @param base The beginning of a buffer to find the maximum offset from
491*0e209d39SAndroid Build Coastguard Worker  * @internal
492*0e209d39SAndroid Build Coastguard Worker  */
493*0e209d39SAndroid Build Coastguard Worker #ifndef U_MAX_PTR
494*0e209d39SAndroid Build Coastguard Worker #  if U_PLATFORM == U_PF_OS390 && !defined(_LP64)
495*0e209d39SAndroid Build Coastguard Worker     /* We have 31-bit pointers. */
496*0e209d39SAndroid Build Coastguard Worker #    define U_MAX_PTR(base) ((void *)0x7fffffff)
497*0e209d39SAndroid Build Coastguard Worker #  elif U_PLATFORM == U_PF_OS400
498*0e209d39SAndroid Build Coastguard Worker #    define U_MAX_PTR(base) uprv_maximumPtr((void *)base)
499*0e209d39SAndroid Build Coastguard Worker #  elif 0
500*0e209d39SAndroid Build Coastguard Worker     /*
501*0e209d39SAndroid Build Coastguard Worker      * For platforms where pointers are scalar values (which is normal, but unlike i5/OS)
502*0e209d39SAndroid Build Coastguard Worker      * but that do not define uintptr_t.
503*0e209d39SAndroid Build Coastguard Worker      *
504*0e209d39SAndroid Build Coastguard Worker      * However, this does not work on modern compilers:
505*0e209d39SAndroid Build Coastguard Worker      * The C++ standard does not define pointer overflow, and allows compilers to
506*0e209d39SAndroid Build Coastguard Worker      * assume that p+u>p for any pointer p and any integer u>0.
507*0e209d39SAndroid Build Coastguard Worker      * Thus, modern compilers optimize away the ">" comparison.
508*0e209d39SAndroid Build Coastguard Worker      * (See ICU tickets #7187 and #8096.)
509*0e209d39SAndroid Build Coastguard Worker      */
510*0e209d39SAndroid Build Coastguard Worker #    define U_MAX_PTR(base) \
511*0e209d39SAndroid Build Coastguard Worker     ((void *)(((char *)(base)+0x7fffffffu) > (char *)(base) \
512*0e209d39SAndroid Build Coastguard Worker         ? ((char *)(base)+0x7fffffffu) \
513*0e209d39SAndroid Build Coastguard Worker         : (char *)-1))
514*0e209d39SAndroid Build Coastguard Worker #  else
515*0e209d39SAndroid Build Coastguard Worker     /* Default version. C++ standard compliant for scalar pointers. */
516*0e209d39SAndroid Build Coastguard Worker #    define U_MAX_PTR(base) \
517*0e209d39SAndroid Build Coastguard Worker     ((void *)(((uintptr_t)(base)+0x7fffffffu) > (uintptr_t)(base) \
518*0e209d39SAndroid Build Coastguard Worker         ? ((uintptr_t)(base)+0x7fffffffu) \
519*0e209d39SAndroid Build Coastguard Worker         : (uintptr_t)-1))
520*0e209d39SAndroid Build Coastguard Worker #  endif
521*0e209d39SAndroid Build Coastguard Worker #endif
522*0e209d39SAndroid Build Coastguard Worker 
523*0e209d39SAndroid Build Coastguard Worker 
524*0e209d39SAndroid Build Coastguard Worker #ifdef __cplusplus
525*0e209d39SAndroid Build Coastguard Worker /**
526*0e209d39SAndroid Build Coastguard Worker  * Pin a buffer capacity such that doing pointer arithmetic
527*0e209d39SAndroid Build Coastguard Worker  * on the destination pointer and capacity cannot overflow.
528*0e209d39SAndroid Build Coastguard Worker  *
529*0e209d39SAndroid Build Coastguard Worker  * The pinned capacity must fulfill the following conditions (for positive capacities):
530*0e209d39SAndroid Build Coastguard Worker  *   - dest + capacity is a valid pointer according to the machine architecture (AS/400, 64-bit, etc.)
531*0e209d39SAndroid Build Coastguard Worker  *   - (dest + capacity) >= dest
532*0e209d39SAndroid Build Coastguard Worker  *   - The size (in bytes) of T[capacity] does not exceed 0x7fffffff
533*0e209d39SAndroid Build Coastguard Worker  *
534*0e209d39SAndroid Build Coastguard Worker  * @param dest the destination buffer pointer.
535*0e209d39SAndroid Build Coastguard Worker  * @param capacity the requested buffer capacity, in units of type T.
536*0e209d39SAndroid Build Coastguard Worker  * @return the pinned capacity.
537*0e209d39SAndroid Build Coastguard Worker  * @internal
538*0e209d39SAndroid Build Coastguard Worker  */
539*0e209d39SAndroid Build Coastguard Worker template <typename T>
pinCapacity(T * dest,int32_t capacity)540*0e209d39SAndroid Build Coastguard Worker inline int32_t pinCapacity(T *dest, int32_t capacity) {
541*0e209d39SAndroid Build Coastguard Worker     if (capacity <= 0) { return capacity; }
542*0e209d39SAndroid Build Coastguard Worker 
543*0e209d39SAndroid Build Coastguard Worker     uintptr_t destInt = (uintptr_t)dest;
544*0e209d39SAndroid Build Coastguard Worker     uintptr_t maxInt;
545*0e209d39SAndroid Build Coastguard Worker 
546*0e209d39SAndroid Build Coastguard Worker #  if U_PLATFORM == U_PF_OS390 && !defined(_LP64)
547*0e209d39SAndroid Build Coastguard Worker     // We have 31-bit pointers.
548*0e209d39SAndroid Build Coastguard Worker     maxInt = 0x7fffffff;
549*0e209d39SAndroid Build Coastguard Worker #  elif U_PLATFORM == U_PF_OS400
550*0e209d39SAndroid Build Coastguard Worker     maxInt = (uintptr_t)uprv_maximumPtr((void *)dest);
551*0e209d39SAndroid Build Coastguard Worker #  else
552*0e209d39SAndroid Build Coastguard Worker     maxInt = destInt + 0x7fffffffu;
553*0e209d39SAndroid Build Coastguard Worker     if (maxInt < destInt) {
554*0e209d39SAndroid Build Coastguard Worker         // Less than 2GB to the end of the address space.
555*0e209d39SAndroid Build Coastguard Worker         // Pin to that to prevent address overflow.
556*0e209d39SAndroid Build Coastguard Worker         maxInt = (uintptr_t)-1;
557*0e209d39SAndroid Build Coastguard Worker     }
558*0e209d39SAndroid Build Coastguard Worker #  endif
559*0e209d39SAndroid Build Coastguard Worker 
560*0e209d39SAndroid Build Coastguard Worker     uintptr_t maxBytes = maxInt - destInt;  // max. 2GB
561*0e209d39SAndroid Build Coastguard Worker     int32_t maxCapacity = (int32_t)(maxBytes / sizeof(T));
562*0e209d39SAndroid Build Coastguard Worker     return capacity <= maxCapacity ? capacity : maxCapacity;
563*0e209d39SAndroid Build Coastguard Worker }
564*0e209d39SAndroid Build Coastguard Worker #endif   // __cplusplus
565*0e209d39SAndroid Build Coastguard Worker 
566*0e209d39SAndroid Build Coastguard Worker /*  Dynamic Library Functions */
567*0e209d39SAndroid Build Coastguard Worker 
568*0e209d39SAndroid Build Coastguard Worker typedef void (UVoidFunction)(void);
569*0e209d39SAndroid Build Coastguard Worker 
570*0e209d39SAndroid Build Coastguard Worker #if U_ENABLE_DYLOAD
571*0e209d39SAndroid Build Coastguard Worker /**
572*0e209d39SAndroid Build Coastguard Worker  * Load a library
573*0e209d39SAndroid Build Coastguard Worker  * @internal (ICU 4.4)
574*0e209d39SAndroid Build Coastguard Worker  */
575*0e209d39SAndroid Build Coastguard Worker U_CAPI void * U_EXPORT2 uprv_dl_open(const char *libName, UErrorCode *status);
576*0e209d39SAndroid Build Coastguard Worker 
577*0e209d39SAndroid Build Coastguard Worker /**
578*0e209d39SAndroid Build Coastguard Worker  * Close a library
579*0e209d39SAndroid Build Coastguard Worker  * @internal (ICU 4.4)
580*0e209d39SAndroid Build Coastguard Worker  */
581*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 uprv_dl_close( void *lib, UErrorCode *status);
582*0e209d39SAndroid Build Coastguard Worker 
583*0e209d39SAndroid Build Coastguard Worker /**
584*0e209d39SAndroid Build Coastguard Worker  * Extract a symbol from a library (function)
585*0e209d39SAndroid Build Coastguard Worker  * @internal (ICU 4.8)
586*0e209d39SAndroid Build Coastguard Worker  */
587*0e209d39SAndroid Build Coastguard Worker U_CAPI UVoidFunction* U_EXPORT2 uprv_dlsym_func( void *lib, const char *symbolName, UErrorCode *status);
588*0e209d39SAndroid Build Coastguard Worker 
589*0e209d39SAndroid Build Coastguard Worker /**
590*0e209d39SAndroid Build Coastguard Worker  * Extract a symbol from a library (function)
591*0e209d39SAndroid Build Coastguard Worker  * Not implemented, no clients.
592*0e209d39SAndroid Build Coastguard Worker  * @internal
593*0e209d39SAndroid Build Coastguard Worker  */
594*0e209d39SAndroid Build Coastguard Worker /* U_CAPI void * U_EXPORT2 uprv_dlsym_data( void *lib, const char *symbolName, UErrorCode *status); */
595*0e209d39SAndroid Build Coastguard Worker 
596*0e209d39SAndroid Build Coastguard Worker #endif
597*0e209d39SAndroid Build Coastguard Worker 
598*0e209d39SAndroid Build Coastguard Worker /**
599*0e209d39SAndroid Build Coastguard Worker  * Define malloc and related functions
600*0e209d39SAndroid Build Coastguard Worker  * @internal
601*0e209d39SAndroid Build Coastguard Worker  */
602*0e209d39SAndroid Build Coastguard Worker #if U_PLATFORM == U_PF_OS400
603*0e209d39SAndroid Build Coastguard Worker # define uprv_default_malloc(x) _C_TS_malloc(x)
604*0e209d39SAndroid Build Coastguard Worker # define uprv_default_realloc(x,y) _C_TS_realloc(x,y)
605*0e209d39SAndroid Build Coastguard Worker # define uprv_default_free(x) _C_TS_free(x)
606*0e209d39SAndroid Build Coastguard Worker /* also _C_TS_calloc(x) */
607*0e209d39SAndroid Build Coastguard Worker #else
608*0e209d39SAndroid Build Coastguard Worker /* C defaults */
609*0e209d39SAndroid Build Coastguard Worker # define uprv_default_malloc(x) malloc(x)
610*0e209d39SAndroid Build Coastguard Worker # define uprv_default_realloc(x,y) realloc(x,y)
611*0e209d39SAndroid Build Coastguard Worker # define uprv_default_free(x) free(x)
612*0e209d39SAndroid Build Coastguard Worker #endif
613*0e209d39SAndroid Build Coastguard Worker 
614*0e209d39SAndroid Build Coastguard Worker 
615*0e209d39SAndroid Build Coastguard Worker #endif
616