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