1999-08-16 21:50:52 +00:00
|
|
|
/*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2000-01-13 23:54:23 +00:00
|
|
|
*
|
2014-01-10 02:24:54 +00:00
|
|
|
* Copyright (C) 1997-2014, International Business Machines
|
2000-01-13 23:54:23 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* FILE NAME : putil.c (previously putil.cpp and ptypes.cpp)
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 04/14/97 aliu Creation.
|
|
|
|
* 04/24/97 aliu Added getDefaultDataDirectory() and
|
|
|
|
* getDefaultLocaleID().
|
2001-08-17 21:34:07 +00:00
|
|
|
* 04/28/97 aliu Rewritten to assume Unix and apply general methods
|
1999-08-16 21:50:52 +00:00
|
|
|
* for assumed case. Non-UNIX platforms must be
|
|
|
|
* special-cased. Rewrote numeric methods dealing
|
|
|
|
* with NaN and Infinity to be platform independent
|
|
|
|
* over all IEEE 754 platforms.
|
2001-08-17 21:34:07 +00:00
|
|
|
* 05/13/97 aliu Restored sign of timezone
|
1999-08-16 21:50:52 +00:00
|
|
|
* (semantics are hours West of GMT)
|
|
|
|
* 06/16/98 erm Added IEEE_754 stuff, cleaned up isInfinite, isNan,
|
|
|
|
* nextDouble..
|
|
|
|
* 07/22/98 stephen Added remainder, max, min, trunc
|
|
|
|
* 08/13/98 stephen Added isNegativeInfinity, isPositiveInfinity
|
|
|
|
* 08/24/98 stephen Added longBitsFromDouble
|
|
|
|
* 09/08/98 stephen Minor changes for Mac Port
|
2001-08-17 21:34:07 +00:00
|
|
|
* 03/02/99 stephen Removed openFile(). Added AS400 support.
|
1999-08-16 21:50:52 +00:00
|
|
|
* Fixed EBCDIC tables
|
|
|
|
* 04/15/99 stephen Converted to C.
|
|
|
|
* 06/28/99 stephen Removed mutex locking in u_isBigEndian().
|
|
|
|
* 08/04/99 jeffrey R. Added OS/2 changes
|
1999-11-16 01:05:10 +00:00
|
|
|
* 11/15/99 helena Integrated S/390 IEEE support.
|
2002-06-25 17:23:07 +00:00
|
|
|
* 04/26/01 Barry N. OS/400 support for uprv_getDefaultLocaleID
|
2001-08-16 16:20:56 +00:00
|
|
|
* 08/15/01 Steven H. OS/400 support for uprv_getDefaultCodepage
|
2008-01-04 01:05:15 +00:00
|
|
|
* 01/03/08 Steven L. Fake Time Support
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-25 21:02:32 +00:00
|
|
|
// Defines _XOPEN_SOURCE for access to POSIX functions.
|
|
|
|
// Must be before any other #includes.
|
|
|
|
#include "uposixdefs.h"
|
2006-10-23 21:38:22 +00:00
|
|
|
|
1999-11-23 05:34:05 +00:00
|
|
|
/* include ICU headers */
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/utypes.h"
|
2001-01-03 00:18:57 +00:00
|
|
|
#include "unicode/putil.h"
|
2003-08-08 23:39:34 +00:00
|
|
|
#include "unicode/ustring.h"
|
2004-10-27 22:55:57 +00:00
|
|
|
#include "putilimp.h"
|
2003-07-02 17:17:37 +00:00
|
|
|
#include "uassert.h"
|
1999-11-23 05:34:05 +00:00
|
|
|
#include "umutex.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
2001-08-29 21:37:09 +00:00
|
|
|
#include "locmap.h"
|
2001-08-31 02:14:47 +00:00
|
|
|
#include "ucln_cmn.h"
|
2005-01-14 00:51:03 +00:00
|
|
|
|
|
|
|
/* Include standard headers. */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <float.h>
|
1999-11-23 05:34:05 +00:00
|
|
|
|
2011-10-26 23:02:14 +00:00
|
|
|
#ifndef U_COMMON_IMPLEMENTATION
|
|
|
|
#error U_COMMON_IMPLEMENTATION not set - must be set for all ICU source files in common/ - see http://userguide.icu-project.org/howtouseicu
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-11-18 22:48:30 +00:00
|
|
|
/* include system headers */
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM_USES_ONLY_WIN32_API
|
|
|
|
/*
|
|
|
|
* TODO: U_PLATFORM_USES_ONLY_WIN32_API includes MinGW.
|
|
|
|
* Should Cygwin be included as well (U_PLATFORM_HAS_WIN32_API)
|
|
|
|
* to use native APIs as much as possible?
|
|
|
|
*/
|
2001-06-27 16:25:02 +00:00
|
|
|
# define WIN32_LEAN_AND_MEAN
|
2004-10-21 06:40:36 +00:00
|
|
|
# define VC_EXTRALEAN
|
2001-06-27 16:25:02 +00:00
|
|
|
# define NOUSER
|
|
|
|
# define NOSERVICE
|
|
|
|
# define NOIME
|
|
|
|
# define NOMCX
|
|
|
|
# include <windows.h>
|
2006-01-12 19:53:58 +00:00
|
|
|
# include "wintz.h"
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_OS400
|
1999-11-18 22:48:30 +00:00
|
|
|
# include <float.h>
|
2001-08-16 16:20:56 +00:00
|
|
|
# include <qusec.h> /* error code structure */
|
|
|
|
# include <qusrjobi.h>
|
|
|
|
# include <qliept.h> /* EPT_CALL macro - this include must be after all other "QSYSINCs" */
|
2007-08-30 22:17:58 +00:00
|
|
|
# include <mih/testptr.h> /* For uprv_maximumPtr */
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_CLASSIC_MACOS
|
1999-11-18 22:48:30 +00:00
|
|
|
# include <Files.h>
|
|
|
|
# include <IntlResources.h>
|
|
|
|
# include <Script.h>
|
2000-08-28 21:27:18 +00:00
|
|
|
# include <Folders.h>
|
2001-05-15 22:11:59 +00:00
|
|
|
# include <MacTypes.h>
|
2000-08-28 21:27:18 +00:00
|
|
|
# include <TextUtils.h>
|
2005-06-30 20:02:38 +00:00
|
|
|
# define ICU_NO_USER_DATA_OVERRIDE 1
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_OS390
|
2011-06-28 23:34:49 +00:00
|
|
|
# include "unicode/ucnv.h" /* Needed for UCNV_SWAP_LFNL_OPTION_STRING */
|
2013-02-06 23:39:05 +00:00
|
|
|
#elif U_PLATFORM_IS_DARWIN_BASED || U_PLATFORM_IS_LINUX_BASED || U_PLATFORM == U_PF_BSD || U_PLATFORM == U_PF_SOLARIS
|
2011-06-28 23:34:49 +00:00
|
|
|
# include <limits.h>
|
|
|
|
# include <unistd.h>
|
2013-02-14 06:53:53 +00:00
|
|
|
# if U_PLATFORM == U_PF_SOLARIS
|
|
|
|
# ifndef _XPG4_2
|
|
|
|
# define _XPG4_2
|
|
|
|
# endif
|
|
|
|
# endif
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_QNX
|
2011-06-28 23:34:49 +00:00
|
|
|
# include <sys/neutrino.h>
|
|
|
|
#endif
|
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#if (U_PF_MINGW <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(__STRICT_ANSI__)
|
2011-06-29 19:49:05 +00:00
|
|
|
/* tzset isn't defined in strict ANSI on Cygwin and MinGW. */
|
2011-06-28 23:34:49 +00:00
|
|
|
#undef __STRICT_ANSI__
|
2003-12-14 18:06:34 +00:00
|
|
|
#endif
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2011-06-09 21:32:19 +00:00
|
|
|
/*
|
2011-06-28 23:36:17 +00:00
|
|
|
* Cygwin with GCC requires inclusion of time.h after the above disabling strict asci mode statement.
|
2011-06-09 21:32:19 +00:00
|
|
|
*/
|
|
|
|
#include <time.h>
|
2010-01-12 00:14:07 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#if !U_PLATFORM_USES_ONLY_WIN32_API
|
2008-08-26 20:32:18 +00:00
|
|
|
#include <sys/time.h>
|
2005-01-14 00:51:03 +00:00
|
|
|
#endif
|
2004-06-18 18:23:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Only include langinfo.h if we have a way to get the codeset. If we later
|
|
|
|
* depend on more feature, we can test on U_HAVE_NL_LANGINFO.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if U_HAVE_NL_LANGINFO_CODESET
|
|
|
|
#include <langinfo.h>
|
|
|
|
#endif
|
|
|
|
|
2010-01-12 19:18:58 +00:00
|
|
|
/**
|
|
|
|
* Simple things (presence of functions, etc) should just go in configure.in and be added to
|
|
|
|
* icucfg.h via autoheader.
|
|
|
|
*/
|
2011-09-29 19:22:56 +00:00
|
|
|
#if U_PLATFORM_IMPLEMENTS_POSIX
|
2011-09-16 01:59:56 +00:00
|
|
|
# if U_PLATFORM == U_PF_OS400
|
2011-09-29 19:22:56 +00:00
|
|
|
# define HAVE_DLFCN_H 0
|
|
|
|
# define HAVE_DLOPEN 0
|
2011-09-16 01:59:56 +00:00
|
|
|
# else
|
2011-09-29 19:22:56 +00:00
|
|
|
# ifndef HAVE_DLFCN_H
|
2011-09-16 01:59:56 +00:00
|
|
|
# define HAVE_DLFCN_H 1
|
2011-09-29 19:22:56 +00:00
|
|
|
# endif
|
|
|
|
# ifndef HAVE_DLOPEN
|
2011-09-16 01:59:56 +00:00
|
|
|
# define HAVE_DLOPEN 1
|
|
|
|
# endif
|
2011-09-29 19:22:56 +00:00
|
|
|
# endif
|
|
|
|
# ifndef HAVE_GETTIMEOFDAY
|
|
|
|
# define HAVE_GETTIMEOFDAY 1
|
|
|
|
# endif
|
2011-07-23 00:10:30 +00:00
|
|
|
#else
|
2011-09-29 19:22:56 +00:00
|
|
|
# define HAVE_DLFCN_H 0
|
|
|
|
# define HAVE_DLOPEN 0
|
|
|
|
# define HAVE_GETTIMEOFDAY 0
|
2010-01-12 19:18:58 +00:00
|
|
|
#endif
|
|
|
|
|
2011-05-26 20:05:39 +00:00
|
|
|
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
|
|
|
|
2001-06-22 16:10:38 +00:00
|
|
|
/* Define the extension for data files, again... */
|
|
|
|
#define DATA_TYPE "dat"
|
|
|
|
|
2003-06-02 18:40:09 +00:00
|
|
|
/* Leave this copyright notice here! */
|
|
|
|
static const char copyright[] = U_COPYRIGHT_STRING;
|
|
|
|
|
1999-11-18 22:48:30 +00:00
|
|
|
/* floating point implementations ------------------------------------------- */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* We return QNAN rather than SNAN*/
|
2003-02-11 22:42:18 +00:00
|
|
|
#define SIGN 0x80000000U
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2006-03-22 07:40:47 +00:00
|
|
|
/* Make it easy to define certain types of constants */
|
|
|
|
typedef union {
|
|
|
|
int64_t i64; /* This must be defined first in order to allow the initialization to work. This is a C89 feature. */
|
|
|
|
double d64;
|
|
|
|
} BitPatternConversion;
|
|
|
|
static const BitPatternConversion gNan = { (int64_t) INT64_C(0x7FF8000000000000) };
|
|
|
|
static const BitPatternConversion gInf = { (int64_t) INT64_C(0x7FF0000000000000) };
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
Platform utilities
|
|
|
|
Our general strategy is to assume we're on a POSIX platform. Platforms which
|
|
|
|
are non-POSIX must declare themselves so. The default POSIX implementation
|
|
|
|
will sometimes work for non-POSIX platforms as well (e.g., the NaN-related
|
|
|
|
functions).
|
|
|
|
---------------------------------------------------------------------------*/
|
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM == U_PF_CLASSIC_MACOS || U_PLATFORM == U_PF_OS400
|
2000-10-05 19:33:35 +00:00
|
|
|
# undef U_POSIX_LOCALE
|
1999-10-22 00:38:39 +00:00
|
|
|
#else
|
2001-03-15 00:31:08 +00:00
|
|
|
# define U_POSIX_LOCALE 1
|
2000-07-20 04:43:47 +00:00
|
|
|
#endif
|
|
|
|
|
2006-03-22 07:40:47 +00:00
|
|
|
/*
|
|
|
|
WARNING! u_topNBytesOfDouble and u_bottomNBytesOfDouble
|
|
|
|
can't be properly optimized by the gcc compiler sometimes (i.e. gcc 3.2).
|
|
|
|
*/
|
|
|
|
#if !IEEE_754
|
2003-05-09 20:46:41 +00:00
|
|
|
static char*
|
|
|
|
u_topNBytesOfDouble(double* d, int n)
|
|
|
|
{
|
|
|
|
#if U_IS_BIG_ENDIAN
|
|
|
|
return (char*)d;
|
|
|
|
#else
|
|
|
|
return (char*)(d + 1) - n;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
|
|
|
u_bottomNBytesOfDouble(double* d, int n)
|
|
|
|
{
|
|
|
|
#if U_IS_BIG_ENDIAN
|
|
|
|
return (char*)(d + 1) - n;
|
|
|
|
#else
|
|
|
|
return (char*)d;
|
|
|
|
#endif
|
|
|
|
}
|
2010-07-12 18:03:29 +00:00
|
|
|
#endif /* !IEEE_754 */
|
|
|
|
|
|
|
|
#if IEEE_754
|
|
|
|
static UBool
|
|
|
|
u_signBit(double d) {
|
|
|
|
uint8_t hiByte;
|
|
|
|
#if U_IS_BIG_ENDIAN
|
|
|
|
hiByte = *(uint8_t *)&d;
|
|
|
|
#else
|
|
|
|
hiByte = *(((uint8_t *)&d) + sizeof(double) - 1);
|
|
|
|
#endif
|
|
|
|
return (hiByte & 0x80) != 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-05-09 20:46:41 +00:00
|
|
|
|
2008-01-04 01:05:15 +00:00
|
|
|
#if defined (U_DEBUG_FAKETIME)
|
2008-08-26 20:32:18 +00:00
|
|
|
/* Override the clock to test things without having to move the system clock.
|
2008-01-04 01:05:15 +00:00
|
|
|
* Assumes POSIX gettimeofday() will function
|
|
|
|
*/
|
|
|
|
UDate fakeClock_t0 = 0; /** Time to start the clock from **/
|
|
|
|
UDate fakeClock_dt = 0; /** Offset (fake time - real time) **/
|
|
|
|
UBool fakeClock_set = FALSE; /** True if fake clock has spun up **/
|
2012-10-05 21:22:02 +00:00
|
|
|
static UMutex fakeClockMutex = U_MUTEX_INTIALIZER;
|
2008-01-04 01:05:15 +00:00
|
|
|
|
|
|
|
static UDate getUTCtime_real() {
|
|
|
|
struct timeval posixTime;
|
|
|
|
gettimeofday(&posixTime, NULL);
|
|
|
|
return (UDate)(((int64_t)posixTime.tv_sec * U_MILLIS_PER_SECOND) + (posixTime.tv_usec/1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
static UDate getUTCtime_fake() {
|
|
|
|
umtx_lock(&fakeClockMutex);
|
|
|
|
if(!fakeClock_set) {
|
|
|
|
UDate real = getUTCtime_real();
|
|
|
|
const char *fake_start = getenv("U_FAKETIME_START");
|
2010-08-17 01:27:18 +00:00
|
|
|
if((fake_start!=NULL) && (fake_start[0]!=0)) {
|
2008-01-04 01:05:15 +00:00
|
|
|
sscanf(fake_start,"%lf",&fakeClock_t0);
|
2010-08-17 01:27:18 +00:00
|
|
|
fakeClock_dt = fakeClock_t0 - real;
|
|
|
|
fprintf(stderr,"U_DEBUG_FAKETIME was set at compile time, so the ICU clock will start at a preset value\n"
|
|
|
|
"env variable U_FAKETIME_START=%.0f (%s) for an offset of %.0f ms from the current time %.0f\n",
|
|
|
|
fakeClock_t0, fake_start, fakeClock_dt, real);
|
|
|
|
} else {
|
|
|
|
fakeClock_dt = 0;
|
|
|
|
fprintf(stderr,"U_DEBUG_FAKETIME was set at compile time, but U_FAKETIME_START was not set.\n"
|
|
|
|
"Set U_FAKETIME_START to the number of milliseconds since 1/1/1970 to set the ICU clock.\n");
|
2008-01-04 01:05:15 +00:00
|
|
|
}
|
|
|
|
fakeClock_set = TRUE;
|
|
|
|
}
|
|
|
|
umtx_unlock(&fakeClockMutex);
|
2008-08-26 20:32:18 +00:00
|
|
|
|
2008-01-04 01:05:15 +00:00
|
|
|
return getUTCtime_real() + fakeClock_dt;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM_USES_ONLY_WIN32_API
|
2005-01-14 00:51:03 +00:00
|
|
|
typedef union {
|
2005-03-15 22:59:22 +00:00
|
|
|
int64_t int64;
|
2005-01-14 00:51:03 +00:00
|
|
|
FILETIME fileTime;
|
|
|
|
} FileTimeConversion; /* This is like a ULARGE_INTEGER */
|
|
|
|
|
|
|
|
/* Number of 100 nanoseconds from 1/1/1601 to 1/1/1970 */
|
2005-03-15 22:59:22 +00:00
|
|
|
#define EPOCH_BIAS INT64_C(116444736000000000)
|
2005-01-14 00:51:03 +00:00
|
|
|
#define HECTONANOSECOND_PER_MILLISECOND 10000
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
Universal Implementations
|
2005-01-14 00:51:03 +00:00
|
|
|
These are designed to work on all platforms. Try these, and if they
|
|
|
|
don't work on your platform, then special case your platform with new
|
1999-08-16 21:50:52 +00:00
|
|
|
implementations.
|
2005-01-14 00:51:03 +00:00
|
|
|
---------------------------------------------------------------------------*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-08-13 01:20:26 +00:00
|
|
|
U_CAPI UDate U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_getUTCtime()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2008-01-04 01:05:15 +00:00
|
|
|
#if defined(U_DEBUG_FAKETIME)
|
|
|
|
return getUTCtime_fake(); /* Hook for overriding the clock */
|
2010-05-25 19:55:05 +00:00
|
|
|
#else
|
|
|
|
return uprv_getRawUTCtime();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return UTC (GMT) time measured in milliseconds since 0:00 on 1/1/70.*/
|
|
|
|
U_CAPI UDate U_EXPORT2
|
|
|
|
uprv_getRawUTCtime()
|
|
|
|
{
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM == U_PF_CLASSIC_MACOS
|
2000-10-13 02:00:26 +00:00
|
|
|
time_t t, t1, t2;
|
|
|
|
struct tm tmrec;
|
|
|
|
|
2003-11-14 23:01:06 +00:00
|
|
|
uprv_memset( &tmrec, 0, sizeof(tmrec) );
|
2000-10-13 02:00:26 +00:00
|
|
|
tmrec.tm_year = 70;
|
|
|
|
tmrec.tm_mon = 0;
|
|
|
|
tmrec.tm_mday = 1;
|
|
|
|
t1 = mktime(&tmrec); /* seconds of 1/1/1970*/
|
|
|
|
|
|
|
|
time(&t);
|
2003-11-14 23:01:06 +00:00
|
|
|
uprv_memcpy( &tmrec, gmtime(&t), sizeof(tmrec) );
|
2000-10-13 02:00:26 +00:00
|
|
|
t2 = mktime(&tmrec); /* seconds of current GMT*/
|
2004-08-13 01:20:26 +00:00
|
|
|
return (UDate)(t2 - t1) * U_MILLIS_PER_SECOND; /* GMT (or UTC) in seconds since 1970*/
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM_USES_ONLY_WIN32_API
|
2005-01-14 00:51:03 +00:00
|
|
|
|
|
|
|
FileTimeConversion winTime;
|
|
|
|
GetSystemTimeAsFileTime(&winTime.fileTime);
|
2005-03-15 00:25:04 +00:00
|
|
|
return (UDate)((winTime.int64 - EPOCH_BIAS) / HECTONANOSECOND_PER_MILLISECOND);
|
1999-08-16 21:50:52 +00:00
|
|
|
#else
|
2010-01-11 21:58:15 +00:00
|
|
|
|
2011-09-29 19:22:56 +00:00
|
|
|
#if HAVE_GETTIMEOFDAY
|
2005-01-14 00:51:03 +00:00
|
|
|
struct timeval posixTime;
|
|
|
|
gettimeofday(&posixTime, NULL);
|
2005-03-23 07:45:55 +00:00
|
|
|
return (UDate)(((int64_t)posixTime.tv_sec * U_MILLIS_PER_SECOND) + (posixTime.tv_usec/1000));
|
2010-01-11 21:58:15 +00:00
|
|
|
#else
|
2000-10-13 02:00:26 +00:00
|
|
|
time_t epochtime;
|
|
|
|
time(&epochtime);
|
2004-08-13 01:20:26 +00:00
|
|
|
return (UDate)epochtime * U_MILLIS_PER_SECOND;
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
2010-01-11 21:58:15 +00:00
|
|
|
|
|
|
|
#endif
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
IEEE 754
|
|
|
|
These methods detect and return NaN and infinity values for doubles
|
|
|
|
conforming to IEEE 754. Platforms which support this standard include X86,
|
|
|
|
Mac 680x0, Mac PowerPC, AIX RS/6000, and most others.
|
|
|
|
If this doesn't work on your platform, you have non-IEEE floating-point, and
|
|
|
|
will need to code your own versions. A naive implementation is to return 0.0
|
|
|
|
for getNaN and getInfinity, and false for isNaN and isInfinite.
|
|
|
|
---------------------------------------------------------------------------*/
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_isNaN(double number)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-04-06 16:45:03 +00:00
|
|
|
#if IEEE_754
|
2006-03-22 07:40:47 +00:00
|
|
|
BitPatternConversion convertedNumber;
|
|
|
|
convertedNumber.d64 = number;
|
2003-02-14 18:35:32 +00:00
|
|
|
/* Infinity is 0x7FF0000000000000U. Anything greater than that is a NaN */
|
2006-03-22 07:40:47 +00:00
|
|
|
return (UBool)((convertedNumber.i64 & U_INT64_MAX) > gInf.i64);
|
2003-02-11 22:42:18 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_OS390
|
2000-10-13 02:00:26 +00:00
|
|
|
uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
|
|
|
|
sizeof(uint32_t));
|
|
|
|
uint32_t lowBits = *(uint32_t*)u_bottomNBytesOfDouble(&number,
|
|
|
|
sizeof(uint32_t));
|
|
|
|
|
|
|
|
return ((highBits & 0x7F080000L) == 0x7F080000L) &&
|
|
|
|
(lowBits == 0x00000000L);
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* If your platform doesn't support IEEE 754 but *does* have an NaN value,*/
|
|
|
|
/* you'll need to replace this default implementation with what's correct*/
|
|
|
|
/* for your platform.*/
|
|
|
|
return number != number;
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_isInfinite(double number)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-04-06 16:45:03 +00:00
|
|
|
#if IEEE_754
|
2006-03-22 07:40:47 +00:00
|
|
|
BitPatternConversion convertedNumber;
|
|
|
|
convertedNumber.d64 = number;
|
|
|
|
/* Infinity is exactly 0x7FF0000000000000U. */
|
|
|
|
return (UBool)((convertedNumber.i64 & U_INT64_MAX) == gInf.i64);
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_OS390
|
2000-10-13 02:00:26 +00:00
|
|
|
uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
|
|
|
|
sizeof(uint32_t));
|
|
|
|
uint32_t lowBits = *(uint32_t*)u_bottomNBytesOfDouble(&number,
|
|
|
|
sizeof(uint32_t));
|
|
|
|
|
|
|
|
return ((highBits & ~SIGN) == 0x70FF0000L) && (lowBits == 0x00000000L);
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* If your platform doesn't support IEEE 754 but *does* have an infinity*/
|
|
|
|
/* value, you'll need to replace this default implementation with what's*/
|
|
|
|
/* correct for your platform.*/
|
|
|
|
return number == (2.0 * number);
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_isPositiveInfinity(double number)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2011-07-23 00:10:30 +00:00
|
|
|
#if IEEE_754 || U_PLATFORM == U_PF_OS390
|
2000-10-13 02:00:26 +00:00
|
|
|
return (UBool)(number > 0 && uprv_isInfinite(number));
|
1999-08-16 21:50:52 +00:00
|
|
|
#else
|
2000-10-13 02:00:26 +00:00
|
|
|
return uprv_isInfinite(number);
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_isNegativeInfinity(double number)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2011-07-23 00:10:30 +00:00
|
|
|
#if IEEE_754 || U_PLATFORM == U_PF_OS390
|
2000-10-13 02:00:26 +00:00
|
|
|
return (UBool)(number < 0 && uprv_isInfinite(number));
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#else
|
2000-10-13 02:00:26 +00:00
|
|
|
uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
|
|
|
|
sizeof(uint32_t));
|
|
|
|
return((highBits & SIGN) && uprv_isInfinite(number));
|
1999-12-30 00:41:40 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_getNaN()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2011-07-23 00:10:30 +00:00
|
|
|
#if IEEE_754 || U_PLATFORM == U_PF_OS390
|
2006-03-22 07:40:47 +00:00
|
|
|
return gNan.d64;
|
1999-08-16 21:50:52 +00:00
|
|
|
#else
|
2000-10-13 02:00:26 +00:00
|
|
|
/* If your platform doesn't support IEEE 754 but *does* have an NaN value,*/
|
|
|
|
/* you'll need to replace this default implementation with what's correct*/
|
|
|
|
/* for your platform.*/
|
|
|
|
return 0.0;
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_getInfinity()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2011-07-23 00:10:30 +00:00
|
|
|
#if IEEE_754 || U_PLATFORM == U_PF_OS390
|
2006-03-22 07:40:47 +00:00
|
|
|
return gInf.d64;
|
1999-08-16 21:50:52 +00:00
|
|
|
#else
|
2000-10-13 02:00:26 +00:00
|
|
|
/* If your platform doesn't support IEEE 754 but *does* have an infinity*/
|
|
|
|
/* value, you'll need to replace this default implementation with what's*/
|
|
|
|
/* correct for your platform.*/
|
|
|
|
return 0.0;
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_floor(double x)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-10-13 02:00:26 +00:00
|
|
|
return floor(x);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_ceil(double x)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-10-13 02:00:26 +00:00
|
|
|
return ceil(x);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
2001-10-11 21:41:11 +00:00
|
|
|
uprv_round(double x)
|
|
|
|
{
|
|
|
|
return uprv_floor(x + 0.5);
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_fabs(double x)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-10-13 02:00:26 +00:00
|
|
|
return fabs(x);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_modf(double x, double* y)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-10-13 02:00:26 +00:00
|
|
|
return modf(x, y);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_fmod(double x, double y)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-10-13 02:00:26 +00:00
|
|
|
return fmod(x, y);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
2001-10-11 21:41:11 +00:00
|
|
|
uprv_pow(double x, double y)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-10-13 02:00:26 +00:00
|
|
|
/* This is declared as "double pow(double x, double y)" */
|
2001-10-11 21:41:11 +00:00
|
|
|
return pow(x, y);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
2001-10-11 21:41:11 +00:00
|
|
|
uprv_pow10(int32_t x)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-10-11 21:41:11 +00:00
|
|
|
return pow(10.0, (double)x);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_fmax(double x, double y)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-04-06 16:45:03 +00:00
|
|
|
#if IEEE_754
|
2000-10-13 02:00:26 +00:00
|
|
|
/* first handle NaN*/
|
|
|
|
if(uprv_isNaN(x) || uprv_isNaN(y))
|
|
|
|
return uprv_getNaN();
|
2000-08-11 20:36:51 +00:00
|
|
|
|
2000-10-13 02:00:26 +00:00
|
|
|
/* check for -0 and 0*/
|
2010-07-12 18:03:29 +00:00
|
|
|
if(x == 0.0 && y == 0.0 && u_signBit(x))
|
2001-08-17 21:34:07 +00:00
|
|
|
return y;
|
2000-08-11 20:36:51 +00:00
|
|
|
|
2001-10-11 21:41:11 +00:00
|
|
|
#endif
|
2000-10-13 02:00:26 +00:00
|
|
|
|
2010-07-12 18:03:29 +00:00
|
|
|
/* this should work for all flt point w/o NaN and Inf special cases */
|
2000-10-13 02:00:26 +00:00
|
|
|
return (x > y ? x : y);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_fmin(double x, double y)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-04-06 16:45:03 +00:00
|
|
|
#if IEEE_754
|
2000-10-13 02:00:26 +00:00
|
|
|
/* first handle NaN*/
|
|
|
|
if(uprv_isNaN(x) || uprv_isNaN(y))
|
|
|
|
return uprv_getNaN();
|
2000-08-11 20:36:51 +00:00
|
|
|
|
2000-10-13 02:00:26 +00:00
|
|
|
/* check for -0 and 0*/
|
2010-07-12 18:03:29 +00:00
|
|
|
if(x == 0.0 && y == 0.0 && u_signBit(y))
|
2001-08-17 21:34:07 +00:00
|
|
|
return y;
|
2000-08-11 20:36:51 +00:00
|
|
|
|
2001-10-11 21:41:11 +00:00
|
|
|
#endif
|
1999-11-16 01:05:10 +00:00
|
|
|
|
2000-10-13 02:00:26 +00:00
|
|
|
/* this should work for all flt point w/o NaN and Inf special cases */
|
|
|
|
return (x > y ? y : x);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Truncates the given double.
|
|
|
|
* trunc(3.3) = 3.0, trunc (-3.3) = -3.0
|
|
|
|
* This is different than calling floor() or ceil():
|
|
|
|
* floor(3.3) = 3, floor(-3.3) = -4
|
|
|
|
* ceil(3.3) = 4, ceil(-3.3) = -3
|
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_trunc(double d)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-04-06 16:45:03 +00:00
|
|
|
#if IEEE_754
|
2000-10-13 02:00:26 +00:00
|
|
|
/* handle error cases*/
|
|
|
|
if(uprv_isNaN(d))
|
|
|
|
return uprv_getNaN();
|
|
|
|
if(uprv_isInfinite(d))
|
|
|
|
return uprv_getInfinity();
|
|
|
|
|
2010-07-12 18:03:29 +00:00
|
|
|
if(u_signBit(d)) /* Signbit() picks up -0.0; d<0 does not. */
|
2000-10-13 02:00:26 +00:00
|
|
|
return ceil(d);
|
|
|
|
else
|
|
|
|
return floor(d);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#else
|
2001-10-11 21:41:11 +00:00
|
|
|
return d >= 0 ? floor(d) : ceil(d);
|
2000-10-13 02:00:26 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-10-11 21:41:11 +00:00
|
|
|
/**
|
|
|
|
* Return the largest positive number that can be represented by an integer
|
|
|
|
* type of arbitrary bit length.
|
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
2001-10-11 21:41:11 +00:00
|
|
|
uprv_maxMantissa(void)
|
|
|
|
{
|
|
|
|
return pow(2.0, DBL_MANT_DIG + 1.0) - 1.0;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI double U_EXPORT2
|
2001-10-11 21:41:11 +00:00
|
|
|
uprv_log(double d)
|
|
|
|
{
|
|
|
|
return log(d);
|
|
|
|
}
|
|
|
|
|
2007-08-30 22:17:58 +00:00
|
|
|
U_CAPI void * U_EXPORT2
|
|
|
|
uprv_maximumPtr(void * base)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM == U_PF_OS400
|
2007-08-30 22:17:58 +00:00
|
|
|
/*
|
2008-08-26 20:32:18 +00:00
|
|
|
* With the provided function we should never be out of range of a given segment
|
2007-08-30 22:17:58 +00:00
|
|
|
* (a traditional/typical segment that is). Our segments have 5 bytes for the
|
|
|
|
* id and 3 bytes for the offset. The key is that the casting takes care of
|
|
|
|
* only retrieving the offset portion minus x1000. Hence, the smallest offset
|
|
|
|
* seen in a program is x001000 and when casted to an int would be 0.
|
|
|
|
* That's why we can only add 0xffefff. Otherwise, we would exceed the segment.
|
|
|
|
*
|
2008-08-26 20:32:18 +00:00
|
|
|
* Currently, 16MB is the current addressing limitation on i5/OS if the activation is
|
2007-08-30 22:17:58 +00:00
|
|
|
* non-TERASPACE. If it is TERASPACE it is 2GB - 4k(header information).
|
2008-08-26 20:32:18 +00:00
|
|
|
* This function determines the activation based on the pointer that is passed in and
|
|
|
|
* calculates the appropriate maximum available size for
|
2007-08-30 22:17:58 +00:00
|
|
|
* each pointer type (TERASPACE and non-TERASPACE)
|
|
|
|
*
|
|
|
|
* Unlike other operating systems, the pointer model isn't determined at
|
|
|
|
* compile time on i5/OS.
|
|
|
|
*/
|
|
|
|
if ((base != NULL) && (_TESTPTR(base, _C_TERASPACE_CHECK))) {
|
|
|
|
/* if it is a TERASPACE pointer the max is 2GB - 4k */
|
|
|
|
return ((void *)(((char *)base)-((uint32_t)(base))+((uint32_t)0x7fffefff)));
|
2000-10-13 02:00:26 +00:00
|
|
|
}
|
2007-08-30 22:17:58 +00:00
|
|
|
/* otherwise 16MB since NULL ptr is not checkable or the ptr is not TERASPACE */
|
|
|
|
return ((void *)(((char *)base)-((uint32_t)(base))+((uint32_t)0xffefff)));
|
2000-08-11 20:36:51 +00:00
|
|
|
|
2007-08-30 22:17:58 +00:00
|
|
|
#else
|
2008-08-26 20:32:18 +00:00
|
|
|
return U_MAX_PTR(base);
|
2004-05-10 19:27:09 +00:00
|
|
|
#endif
|
2007-08-30 22:17:58 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
Platform-specific Implementations
|
|
|
|
Try these, and if they don't work on your platform, then special case your
|
|
|
|
platform with new implementations.
|
|
|
|
---------------------------------------------------------------------------*/
|
|
|
|
|
2003-05-02 00:07:35 +00:00
|
|
|
/* Generic time zone layer -------------------------------------------------- */
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* Time zone utilities */
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_tzset()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2011-06-28 23:34:49 +00:00
|
|
|
#if defined(U_TZSET)
|
2000-10-05 23:41:59 +00:00
|
|
|
U_TZSET();
|
|
|
|
#else
|
2000-10-13 02:00:26 +00:00
|
|
|
/* no initialization*/
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_timezone()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-06-18 18:23:05 +00:00
|
|
|
#ifdef U_TIMEZONE
|
2000-10-05 23:41:59 +00:00
|
|
|
return U_TIMEZONE;
|
|
|
|
#else
|
2000-10-13 02:00:26 +00:00
|
|
|
time_t t, t1, t2;
|
|
|
|
struct tm tmrec;
|
|
|
|
int32_t tdiff = 0;
|
|
|
|
|
|
|
|
time(&t);
|
2003-11-14 23:01:06 +00:00
|
|
|
uprv_memcpy( &tmrec, localtime(&t), sizeof(tmrec) );
|
2013-09-09 17:58:59 +00:00
|
|
|
#if U_PLATFORM != U_PF_IPHONE
|
|
|
|
UBool dst_checked = (tmrec.tm_isdst != 0); /* daylight savings time is checked*/
|
|
|
|
#endif
|
2000-10-13 02:00:26 +00:00
|
|
|
t1 = mktime(&tmrec); /* local time in seconds*/
|
2003-11-14 23:01:06 +00:00
|
|
|
uprv_memcpy( &tmrec, gmtime(&t), sizeof(tmrec) );
|
2000-10-13 02:00:26 +00:00
|
|
|
t2 = mktime(&tmrec); /* GMT (or UTC) in seconds*/
|
|
|
|
tdiff = t2 - t1;
|
2013-09-09 17:58:59 +00:00
|
|
|
|
|
|
|
#if U_PLATFORM != U_PF_IPHONE
|
2001-08-17 21:34:07 +00:00
|
|
|
/* imitate NT behaviour, which returns same timezone offset to GMT for
|
2012-06-28 23:01:26 +00:00
|
|
|
winter and summer.
|
|
|
|
This does not work on all platforms. For instance, on glibc on Linux
|
|
|
|
and on Mac OS 10.5, tdiff calculated above remains the same
|
2013-09-09 17:58:59 +00:00
|
|
|
regardless of whether DST is in effect or not. iOS is another
|
|
|
|
platform where this does not work. Linux + glibc and Mac OS 10.5
|
|
|
|
have U_TIMEZONE defined so that this code is not reached.
|
|
|
|
*/
|
2000-10-13 02:00:26 +00:00
|
|
|
if (dst_checked)
|
|
|
|
tdiff += 3600;
|
2013-09-09 17:58:59 +00:00
|
|
|
#endif
|
2000-10-13 02:00:26 +00:00
|
|
|
return tdiff;
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-08-15 20:06:22 +00:00
|
|
|
/* Note that U_TZNAME does *not* have to be tzname, but if it is,
|
2008-08-26 20:32:18 +00:00
|
|
|
some platforms need to have it declared here. */
|
2002-01-31 06:44:59 +00:00
|
|
|
|
2011-08-18 18:47:16 +00:00
|
|
|
#if defined(U_TZNAME) && (U_PLATFORM == U_PF_IRIX || U_PLATFORM_IS_DARWIN_BASED || (U_PLATFORM == U_PF_CYGWIN && !U_PLATFORM_USES_ONLY_WIN32_API))
|
2004-06-18 18:23:05 +00:00
|
|
|
/* RS6000 and others reject char **tzname. */
|
|
|
|
extern U_IMPORT char *U_TZNAME[];
|
2002-01-31 06:44:59 +00:00
|
|
|
#endif
|
|
|
|
|
2013-09-20 18:11:24 +00:00
|
|
|
#if !UCONFIG_NO_FILE_IO && ((U_PLATFORM_IS_DARWIN_BASED && (U_PLATFORM != U_PF_IPHONE || defined(U_TIMEZONE))) || U_PLATFORM_IS_LINUX_BASED || U_PLATFORM == U_PF_BSD || U_PLATFORM == U_PF_SOLARIS)
|
2006-03-03 06:47:40 +00:00
|
|
|
/* These platforms are likely to use Olson timezone IDs. */
|
|
|
|
#define CHECK_LOCALTIME_LINK 1
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM_IS_DARWIN_BASED
|
2007-06-06 22:11:45 +00:00
|
|
|
#include <tzfile.h>
|
|
|
|
#define TZZONEINFO (TZDIR "/")
|
2013-02-06 23:39:05 +00:00
|
|
|
#elif U_PLATFORM == U_PF_SOLARIS
|
|
|
|
#define TZDEFAULT "/etc/localtime"
|
|
|
|
#define TZZONEINFO "/usr/share/lib/zoneinfo/"
|
2013-05-08 17:00:30 +00:00
|
|
|
#define TZZONEINFO2 "../usr/share/lib/zoneinfo/"
|
2013-02-06 23:39:05 +00:00
|
|
|
#define TZ_ENV_CHECK "localtime"
|
2008-02-23 19:15:18 +00:00
|
|
|
#else
|
|
|
|
#define TZDEFAULT "/etc/localtime"
|
|
|
|
#define TZZONEINFO "/usr/share/zoneinfo/"
|
2007-06-06 22:11:45 +00:00
|
|
|
#endif
|
2008-09-03 22:15:18 +00:00
|
|
|
#if U_HAVE_DIRENT_H
|
2009-10-28 21:10:31 +00:00
|
|
|
#define TZFILE_SKIP "posixrules" /* tz file to skip when searching. */
|
2010-06-28 17:44:29 +00:00
|
|
|
/* Some Linux distributions have 'localtime' in /usr/share/zoneinfo
|
|
|
|
symlinked to /etc/localtime, which makes searchForTZFile return
|
|
|
|
'localtime' when it's the first match. */
|
|
|
|
#define TZFILE_SKIP2 "localtime"
|
2008-09-03 22:15:18 +00:00
|
|
|
#define SEARCH_TZFILE
|
|
|
|
#include <dirent.h> /* Needed to search through system timezone files */
|
|
|
|
#endif
|
2008-09-16 16:49:33 +00:00
|
|
|
static char gTimeZoneBuffer[PATH_MAX];
|
|
|
|
static char *gTimeZoneBufferPtr = NULL;
|
|
|
|
#endif
|
2003-08-15 20:06:22 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#if !U_PLATFORM_USES_ONLY_WIN32_API
|
2006-03-23 23:38:53 +00:00
|
|
|
#define isNonDigit(ch) (ch < '0' || '9' < ch)
|
2006-03-03 06:47:40 +00:00
|
|
|
static UBool isValidOlsonID(const char *id) {
|
2006-03-24 03:22:11 +00:00
|
|
|
int32_t idx = 0;
|
2006-03-23 23:38:53 +00:00
|
|
|
|
|
|
|
/* Determine if this is something like Iceland (Olson ID)
|
|
|
|
or AST4ADT (non-Olson ID) */
|
|
|
|
while (id[idx] && isNonDigit(id[idx]) && id[idx] != ',') {
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we went through the whole string, then it might be okay.
|
|
|
|
The timezone is sometimes set to "CST-7CDT", "CST6CDT5,J129,J131/19:30",
|
|
|
|
"GRNLNDST3GRNLNDDT" or similar, so we cannot use it.
|
2006-03-03 06:47:40 +00:00
|
|
|
The rest of the time it could be an Olson ID. George */
|
2006-03-23 23:38:53 +00:00
|
|
|
return (UBool)(id[idx] == 0
|
|
|
|
|| uprv_strcmp(id, "PST8PDT") == 0
|
|
|
|
|| uprv_strcmp(id, "MST7MDT") == 0
|
|
|
|
|| uprv_strcmp(id, "CST6CDT") == 0
|
|
|
|
|| uprv_strcmp(id, "EST5EDT") == 0);
|
2006-03-03 06:47:40 +00:00
|
|
|
}
|
2010-10-07 18:07:05 +00:00
|
|
|
|
|
|
|
/* On some Unix-like OS, 'posix' subdirectory in
|
|
|
|
/usr/share/zoneinfo replicates the top-level contents. 'right'
|
|
|
|
subdirectory has the same set of files, but individual files
|
|
|
|
are different from those in the top-level directory or 'posix'
|
|
|
|
because 'right' has files for TAI (Int'l Atomic Time) while 'posix'
|
|
|
|
has files for UTC.
|
|
|
|
When the first match for /etc/localtime is in either of them
|
|
|
|
(usually in posix because 'right' has different file contents),
|
|
|
|
or TZ environment variable points to one of them, createTimeZone
|
|
|
|
fails because, say, 'posix/America/New_York' is not an Olson
|
2010-10-09 00:54:20 +00:00
|
|
|
timezone id ('America/New_York' is). So, we have to skip
|
2010-10-07 18:07:05 +00:00
|
|
|
'posix/' and 'right/' at the beginning. */
|
2010-10-09 00:54:20 +00:00
|
|
|
static void skipZoneIDPrefix(const char** id) {
|
2010-10-07 18:07:05 +00:00
|
|
|
if (uprv_strncmp(*id, "posix/", 6) == 0
|
|
|
|
|| uprv_strncmp(*id, "right/", 6) == 0)
|
|
|
|
{
|
|
|
|
*id += 6;
|
|
|
|
}
|
|
|
|
}
|
2006-03-03 06:47:40 +00:00
|
|
|
#endif
|
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#if defined(U_TZNAME) && !U_PLATFORM_USES_ONLY_WIN32_API
|
2006-11-15 19:01:21 +00:00
|
|
|
|
2006-11-01 09:04:57 +00:00
|
|
|
#define CONVERT_HOURS_TO_SECONDS(offset) (int32_t)(offset*3600)
|
|
|
|
typedef struct OffsetZoneMapping {
|
|
|
|
int32_t offsetSeconds;
|
2011-11-14 19:32:51 +00:00
|
|
|
int32_t daylightType; /* 0=U_DAYLIGHT_NONE, 1=daylight in June-U_DAYLIGHT_JUNE, 2=daylight in December=U_DAYLIGHT_DECEMBER*/
|
2006-11-01 09:04:57 +00:00
|
|
|
const char *stdID;
|
|
|
|
const char *dstID;
|
|
|
|
const char *olsonID;
|
|
|
|
} OffsetZoneMapping;
|
|
|
|
|
2011-11-14 19:32:51 +00:00
|
|
|
enum { U_DAYLIGHT_NONE=0,U_DAYLIGHT_JUNE=1,U_DAYLIGHT_DECEMBER=2 };
|
|
|
|
|
2006-11-01 09:04:57 +00:00
|
|
|
/*
|
|
|
|
This list tries to disambiguate a set of abbreviated timezone IDs and offsets
|
|
|
|
and maps it to an Olson ID.
|
|
|
|
Before adding anything to this list, take a look at
|
|
|
|
icu/source/tools/tzcode/tz.alias
|
2007-06-28 16:39:09 +00:00
|
|
|
Sometimes no daylight savings (0) is important to define due to aliases.
|
|
|
|
This list can be tested with icu/source/test/compat/tzone.pl
|
|
|
|
More values could be added to daylightType to increase precision.
|
2011-11-14 20:01:43 +00:00
|
|
|
*/
|
2006-11-01 09:04:57 +00:00
|
|
|
static const struct OffsetZoneMapping OFFSET_ZONE_MAPPINGS[] = {
|
2007-06-28 07:33:44 +00:00
|
|
|
{-45900, 2, "CHAST", "CHADT", "Pacific/Chatham"},
|
2006-11-01 09:04:57 +00:00
|
|
|
{-43200, 1, "PETT", "PETST", "Asia/Kamchatka"},
|
2007-06-28 07:33:44 +00:00
|
|
|
{-43200, 2, "NZST", "NZDT", "Pacific/Auckland"},
|
2006-11-01 09:04:57 +00:00
|
|
|
{-43200, 1, "ANAT", "ANAST", "Asia/Anadyr"},
|
|
|
|
{-39600, 1, "MAGT", "MAGST", "Asia/Magadan"},
|
2007-06-28 07:33:44 +00:00
|
|
|
{-37800, 2, "LHST", "LHST", "Australia/Lord_Howe"},
|
2007-06-28 16:39:09 +00:00
|
|
|
{-36000, 2, "EST", "EST", "Australia/Sydney"},
|
2006-11-01 09:04:57 +00:00
|
|
|
{-36000, 1, "SAKT", "SAKST", "Asia/Sakhalin"},
|
|
|
|
{-36000, 1, "VLAT", "VLAST", "Asia/Vladivostok"},
|
2007-06-28 07:33:44 +00:00
|
|
|
{-34200, 2, "CST", "CST", "Australia/South"},
|
2006-11-01 09:04:57 +00:00
|
|
|
{-32400, 1, "YAKT", "YAKST", "Asia/Yakutsk"},
|
|
|
|
{-32400, 1, "CHOT", "CHOST", "Asia/Choibalsan"},
|
2007-06-28 07:33:44 +00:00
|
|
|
{-31500, 2, "CWST", "CWST", "Australia/Eucla"},
|
2006-11-01 09:04:57 +00:00
|
|
|
{-28800, 1, "IRKT", "IRKST", "Asia/Irkutsk"},
|
|
|
|
{-28800, 1, "ULAT", "ULAST", "Asia/Ulaanbaatar"},
|
2007-06-28 07:33:44 +00:00
|
|
|
{-28800, 2, "WST", "WST", "Australia/West"},
|
2006-11-01 09:04:57 +00:00
|
|
|
{-25200, 1, "HOVT", "HOVST", "Asia/Hovd"},
|
|
|
|
{-25200, 1, "KRAT", "KRAST", "Asia/Krasnoyarsk"},
|
|
|
|
{-21600, 1, "NOVT", "NOVST", "Asia/Novosibirsk"},
|
|
|
|
{-21600, 1, "OMST", "OMSST", "Asia/Omsk"},
|
|
|
|
{-18000, 1, "YEKT", "YEKST", "Asia/Yekaterinburg"},
|
|
|
|
{-14400, 1, "SAMT", "SAMST", "Europe/Samara"},
|
|
|
|
{-14400, 1, "AMT", "AMST", "Asia/Yerevan"},
|
|
|
|
{-14400, 1, "AZT", "AZST", "Asia/Baku"},
|
|
|
|
{-10800, 1, "AST", "ADT", "Asia/Baghdad"},
|
|
|
|
{-10800, 1, "MSK", "MSD", "Europe/Moscow"},
|
2007-06-28 07:33:44 +00:00
|
|
|
{-10800, 1, "VOLT", "VOLST", "Europe/Volgograd"},
|
2006-11-01 09:04:57 +00:00
|
|
|
{-7200, 0, "EET", "CEST", "Africa/Tripoli"},
|
2007-06-28 16:39:09 +00:00
|
|
|
{-7200, 1, "EET", "EEST", "Europe/Athens"}, /* Conflicts with Africa/Cairo */
|
2006-11-01 09:04:57 +00:00
|
|
|
{-7200, 1, "IST", "IDT", "Asia/Jerusalem"},
|
|
|
|
{-3600, 0, "CET", "WEST", "Africa/Algiers"},
|
2007-06-28 07:33:44 +00:00
|
|
|
{-3600, 2, "WAT", "WAST", "Africa/Windhoek"},
|
2006-11-01 09:04:57 +00:00
|
|
|
{0, 1, "GMT", "IST", "Europe/Dublin"},
|
|
|
|
{0, 1, "GMT", "BST", "Europe/London"},
|
2007-06-28 07:33:44 +00:00
|
|
|
{0, 0, "WET", "WEST", "Africa/Casablanca"},
|
2006-11-01 09:04:57 +00:00
|
|
|
{0, 0, "WET", "WET", "Africa/El_Aaiun"},
|
|
|
|
{3600, 1, "AZOT", "AZOST", "Atlantic/Azores"},
|
|
|
|
{3600, 1, "EGT", "EGST", "America/Scoresbysund"},
|
|
|
|
{10800, 1, "PMST", "PMDT", "America/Miquelon"},
|
2007-06-28 07:33:44 +00:00
|
|
|
{10800, 2, "UYT", "UYST", "America/Montevideo"},
|
2006-11-01 09:04:57 +00:00
|
|
|
{10800, 1, "WGT", "WGST", "America/Godthab"},
|
2007-06-28 07:33:44 +00:00
|
|
|
{10800, 2, "BRT", "BRST", "Brazil/East"},
|
2006-11-01 09:04:57 +00:00
|
|
|
{12600, 1, "NST", "NDT", "America/St_Johns"},
|
2007-06-28 16:39:09 +00:00
|
|
|
{14400, 1, "AST", "ADT", "Canada/Atlantic"},
|
2007-06-28 07:33:44 +00:00
|
|
|
{14400, 2, "AMT", "AMST", "America/Cuiaba"},
|
|
|
|
{14400, 2, "CLT", "CLST", "Chile/Continental"},
|
|
|
|
{14400, 2, "FKT", "FKST", "Atlantic/Stanley"},
|
|
|
|
{14400, 2, "PYT", "PYST", "America/Asuncion"},
|
2007-06-28 16:39:09 +00:00
|
|
|
{18000, 1, "CST", "CDT", "America/Havana"},
|
2007-06-28 07:33:44 +00:00
|
|
|
{18000, 1, "EST", "EDT", "US/Eastern"}, /* Conflicts with America/Grand_Turk */
|
|
|
|
{21600, 2, "EAST", "EASST", "Chile/EasterIsland"},
|
|
|
|
{21600, 0, "CST", "MDT", "Canada/Saskatchewan"},
|
|
|
|
{21600, 0, "CST", "CDT", "America/Guatemala"},
|
|
|
|
{21600, 1, "CST", "CDT", "US/Central"}, /* Conflicts with Mexico/General */
|
|
|
|
{25200, 1, "MST", "MDT", "US/Mountain"}, /* Conflicts with Mexico/BajaSur */
|
2006-11-01 09:04:57 +00:00
|
|
|
{28800, 0, "PST", "PST", "Pacific/Pitcairn"},
|
2007-06-28 16:39:09 +00:00
|
|
|
{28800, 1, "PST", "PDT", "US/Pacific"}, /* Conflicts with Mexico/BajaNorte */
|
|
|
|
{32400, 1, "AKST", "AKDT", "US/Alaska"},
|
|
|
|
{36000, 1, "HAST", "HADT", "US/Aleutian"}
|
2006-11-01 09:04:57 +00:00
|
|
|
};
|
|
|
|
|
2007-06-28 16:39:09 +00:00
|
|
|
/*#define DEBUG_TZNAME*/
|
|
|
|
|
2007-06-28 07:33:44 +00:00
|
|
|
static const char* remapShortTimeZone(const char *stdID, const char *dstID, int32_t daylightType, int32_t offset)
|
2006-11-01 09:04:57 +00:00
|
|
|
{
|
|
|
|
int32_t idx;
|
2007-06-28 16:39:09 +00:00
|
|
|
#ifdef DEBUG_TZNAME
|
|
|
|
fprintf(stderr, "TZ=%s std=%s dst=%s daylight=%d offset=%d\n", getenv("TZ"), stdID, dstID, daylightType, offset);
|
|
|
|
#endif
|
2011-05-26 20:05:39 +00:00
|
|
|
for (idx = 0; idx < LENGTHOF(OFFSET_ZONE_MAPPINGS); idx++)
|
2006-11-01 09:04:57 +00:00
|
|
|
{
|
|
|
|
if (offset == OFFSET_ZONE_MAPPINGS[idx].offsetSeconds
|
2007-06-28 07:33:44 +00:00
|
|
|
&& daylightType == OFFSET_ZONE_MAPPINGS[idx].daylightType
|
2006-11-01 09:04:57 +00:00
|
|
|
&& strcmp(OFFSET_ZONE_MAPPINGS[idx].stdID, stdID) == 0
|
|
|
|
&& strcmp(OFFSET_ZONE_MAPPINGS[idx].dstID, dstID) == 0)
|
|
|
|
{
|
|
|
|
return OFFSET_ZONE_MAPPINGS[idx].olsonID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-09-03 22:15:18 +00:00
|
|
|
#ifdef SEARCH_TZFILE
|
|
|
|
#define MAX_PATH_SIZE PATH_MAX /* Set the limit for the size of the path. */
|
2008-10-06 17:38:07 +00:00
|
|
|
#define MAX_READ_SIZE 512
|
2008-10-14 21:46:58 +00:00
|
|
|
|
|
|
|
typedef struct DefaultTZInfo {
|
|
|
|
char* defaultTZBuffer;
|
|
|
|
int64_t defaultTZFileSize;
|
|
|
|
FILE* defaultTZFilePtr;
|
|
|
|
UBool defaultTZstatus;
|
|
|
|
int32_t defaultTZPosition;
|
|
|
|
} DefaultTZInfo;
|
|
|
|
|
2008-09-03 22:15:18 +00:00
|
|
|
/*
|
|
|
|
* This method compares the two files given to see if they are a match.
|
|
|
|
* It is currently use to compare two TZ files.
|
|
|
|
*/
|
2008-10-14 21:46:58 +00:00
|
|
|
static UBool compareBinaryFiles(const char* defaultTZFileName, const char* TZFileName, DefaultTZInfo* tzInfo) {
|
2009-03-27 17:08:12 +00:00
|
|
|
FILE* file;
|
2008-10-01 14:11:08 +00:00
|
|
|
int64_t sizeFile;
|
2008-10-06 17:38:07 +00:00
|
|
|
int64_t sizeFileLeft;
|
|
|
|
int32_t sizeFileRead;
|
|
|
|
int32_t sizeFileToRead;
|
|
|
|
char bufferFile[MAX_READ_SIZE];
|
2008-09-03 22:15:18 +00:00
|
|
|
UBool result = TRUE;
|
|
|
|
|
2009-03-27 17:08:12 +00:00
|
|
|
if (tzInfo->defaultTZFilePtr == NULL) {
|
|
|
|
tzInfo->defaultTZFilePtr = fopen(defaultTZFileName, "r");
|
|
|
|
}
|
|
|
|
file = fopen(TZFileName, "r");
|
|
|
|
|
|
|
|
tzInfo->defaultTZPosition = 0; /* reset position to begin search */
|
|
|
|
|
2008-10-14 21:46:58 +00:00
|
|
|
if (file != NULL && tzInfo->defaultTZFilePtr != NULL) {
|
2008-09-03 22:15:18 +00:00
|
|
|
/* First check that the file size are equal. */
|
2008-10-14 21:46:58 +00:00
|
|
|
if (tzInfo->defaultTZFileSize == 0) {
|
|
|
|
fseek(tzInfo->defaultTZFilePtr, 0, SEEK_END);
|
|
|
|
tzInfo->defaultTZFileSize = ftell(tzInfo->defaultTZFilePtr);
|
2008-10-01 14:11:08 +00:00
|
|
|
}
|
|
|
|
fseek(file, 0, SEEK_END);
|
|
|
|
sizeFile = ftell(file);
|
2008-10-06 17:38:07 +00:00
|
|
|
sizeFileLeft = sizeFile;
|
2008-09-03 22:15:18 +00:00
|
|
|
|
2008-10-14 21:46:58 +00:00
|
|
|
if (sizeFile != tzInfo->defaultTZFileSize) {
|
2008-09-03 22:15:18 +00:00
|
|
|
result = FALSE;
|
|
|
|
} else {
|
|
|
|
/* Store the data from the files in seperate buffers and
|
|
|
|
* compare each byte to determine equality.
|
|
|
|
*/
|
2008-10-14 21:46:58 +00:00
|
|
|
if (tzInfo->defaultTZBuffer == NULL) {
|
|
|
|
rewind(tzInfo->defaultTZFilePtr);
|
|
|
|
tzInfo->defaultTZBuffer = (char*)uprv_malloc(sizeof(char) * tzInfo->defaultTZFileSize);
|
2011-06-09 22:28:40 +00:00
|
|
|
sizeFileRead = fread(tzInfo->defaultTZBuffer, 1, tzInfo->defaultTZFileSize, tzInfo->defaultTZFilePtr);
|
2008-10-01 14:11:08 +00:00
|
|
|
}
|
|
|
|
rewind(file);
|
2008-10-06 17:38:07 +00:00
|
|
|
while(sizeFileLeft > 0) {
|
|
|
|
uprv_memset(bufferFile, 0, MAX_READ_SIZE);
|
|
|
|
sizeFileToRead = sizeFileLeft < MAX_READ_SIZE ? sizeFileLeft : MAX_READ_SIZE;
|
|
|
|
|
|
|
|
sizeFileRead = fread(bufferFile, 1, sizeFileToRead, file);
|
2008-10-14 21:46:58 +00:00
|
|
|
if (memcmp(tzInfo->defaultTZBuffer + tzInfo->defaultTZPosition, bufferFile, sizeFileRead) != 0) {
|
2008-10-06 17:38:07 +00:00
|
|
|
result = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sizeFileLeft -= sizeFileRead;
|
2008-10-14 21:46:58 +00:00
|
|
|
tzInfo->defaultTZPosition += sizeFileRead;
|
2008-09-03 22:15:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = FALSE;
|
|
|
|
}
|
|
|
|
|
2008-10-01 14:11:08 +00:00
|
|
|
if (file != NULL) {
|
|
|
|
fclose(file);
|
2008-09-03 22:15:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* This method recursively traverses the directory given for a matching TZ file and returns the first match.
|
|
|
|
*/
|
|
|
|
/* dirent also lists two entries: "." and ".." that we can safely ignore. */
|
|
|
|
#define SKIP1 "."
|
|
|
|
#define SKIP2 ".."
|
2009-04-16 20:56:04 +00:00
|
|
|
static char SEARCH_TZFILE_RESULT[MAX_PATH_SIZE] = "";
|
2008-10-14 21:46:58 +00:00
|
|
|
static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) {
|
2009-10-28 19:59:29 +00:00
|
|
|
char curpath[MAX_PATH_SIZE];
|
2008-09-03 22:15:18 +00:00
|
|
|
DIR* dirp = opendir(path);
|
|
|
|
DIR* subDirp = NULL;
|
|
|
|
struct dirent* dirEntry = NULL;
|
|
|
|
|
|
|
|
char* result = NULL;
|
2009-09-30 21:21:02 +00:00
|
|
|
if (dirp == NULL) {
|
|
|
|
return result;
|
|
|
|
}
|
2008-09-03 22:15:18 +00:00
|
|
|
|
2008-10-14 21:46:58 +00:00
|
|
|
/* Save the current path */
|
2008-09-03 22:15:18 +00:00
|
|
|
uprv_memset(curpath, 0, MAX_PATH_SIZE);
|
|
|
|
uprv_strcpy(curpath, path);
|
|
|
|
|
|
|
|
/* Check each entry in the directory. */
|
2008-10-14 21:46:58 +00:00
|
|
|
while((dirEntry = readdir(dirp)) != NULL) {
|
2010-10-07 18:07:05 +00:00
|
|
|
const char* dirName = dirEntry->d_name;
|
|
|
|
if (uprv_strcmp(dirName, SKIP1) != 0 && uprv_strcmp(dirName, SKIP2) != 0) {
|
2008-09-03 22:15:18 +00:00
|
|
|
/* Create a newpath with the new entry to test each entry in the directory. */
|
2008-10-01 14:11:08 +00:00
|
|
|
char newpath[MAX_PATH_SIZE];
|
2008-09-03 22:15:18 +00:00
|
|
|
uprv_strcpy(newpath, curpath);
|
2010-10-07 18:07:05 +00:00
|
|
|
uprv_strcat(newpath, dirName);
|
2008-09-03 22:15:18 +00:00
|
|
|
|
2008-10-14 21:46:58 +00:00
|
|
|
if ((subDirp = opendir(newpath)) != NULL) {
|
2008-09-03 22:15:18 +00:00
|
|
|
/* If this new path is a directory, make a recursive call with the newpath. */
|
|
|
|
closedir(subDirp);
|
|
|
|
uprv_strcat(newpath, "/");
|
2008-10-14 21:46:58 +00:00
|
|
|
result = searchForTZFile(newpath, tzInfo);
|
2010-06-28 17:44:29 +00:00
|
|
|
/*
|
|
|
|
Have to get out here. Otherwise, we'd keep looking
|
|
|
|
and return the first match in the top-level directory
|
|
|
|
if there's a match in the top-level. If not, this function
|
|
|
|
would return NULL and set gTimeZoneBufferPtr to NULL in initDefault().
|
|
|
|
It worked without this in most cases because we have a fallback of calling
|
|
|
|
localtime_r to figure out the default timezone.
|
|
|
|
*/
|
|
|
|
if (result != NULL)
|
|
|
|
break;
|
2010-10-07 18:07:05 +00:00
|
|
|
} else if (uprv_strcmp(TZFILE_SKIP, dirName) != 0 && uprv_strcmp(TZFILE_SKIP2, dirName) != 0) {
|
2008-10-14 21:46:58 +00:00
|
|
|
if(compareBinaryFiles(TZDEFAULT, newpath, tzInfo)) {
|
2010-10-07 18:07:05 +00:00
|
|
|
const char* zoneid = newpath + (sizeof(TZZONEINFO)) - 1;
|
2010-10-09 00:54:20 +00:00
|
|
|
skipZoneIDPrefix(&zoneid);
|
2010-10-07 18:07:05 +00:00
|
|
|
uprv_strcpy(SEARCH_TZFILE_RESULT, zoneid);
|
2009-04-16 20:56:04 +00:00
|
|
|
result = SEARCH_TZFILE_RESULT;
|
2008-10-14 21:46:58 +00:00
|
|
|
/* Get out after the first one found. */
|
2008-09-03 22:15:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dirp);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
2004-06-18 18:23:05 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
2000-04-14 05:22:29 +00:00
|
|
|
uprv_tzname(int n)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2006-11-01 19:09:59 +00:00
|
|
|
const char *tzid = NULL;
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM_USES_ONLY_WIN32_API
|
2006-11-01 19:09:59 +00:00
|
|
|
tzid = uprv_detectWindowsTimeZone();
|
2006-01-12 19:53:58 +00:00
|
|
|
|
2006-11-01 19:09:59 +00:00
|
|
|
if (tzid != NULL) {
|
|
|
|
return tzid;
|
2003-05-02 00:07:35 +00:00
|
|
|
}
|
2006-03-03 01:00:54 +00:00
|
|
|
#else
|
2006-03-03 01:05:05 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
/*#if U_PLATFORM_IS_DARWIN_BASED
|
2003-08-15 20:06:22 +00:00
|
|
|
int ret;
|
|
|
|
|
2006-11-01 19:09:59 +00:00
|
|
|
tzid = getenv("TZFILE");
|
|
|
|
if (tzid != NULL) {
|
|
|
|
return tzid;
|
2003-08-15 20:06:22 +00:00
|
|
|
}
|
2006-03-03 06:47:40 +00:00
|
|
|
#endif*/
|
2003-08-15 20:06:22 +00:00
|
|
|
|
2007-06-28 16:39:09 +00:00
|
|
|
/* This code can be temporarily disabled to test tzname resolution later on. */
|
|
|
|
#ifndef DEBUG_TZNAME
|
2006-11-01 19:09:59 +00:00
|
|
|
tzid = getenv("TZ");
|
2013-02-06 23:39:05 +00:00
|
|
|
if (tzid != NULL && isValidOlsonID(tzid)
|
|
|
|
#if U_PLATFORM == U_PF_SOLARIS
|
|
|
|
/* When TZ equals localtime on Solaris, check the /etc/localtime file. */
|
|
|
|
&& uprv_strcmp(tzid, TZ_ENV_CHECK) != 0
|
|
|
|
#endif
|
|
|
|
) {
|
2006-03-03 01:00:54 +00:00
|
|
|
/* This might be a good Olson ID. */
|
2010-10-09 00:54:20 +00:00
|
|
|
skipZoneIDPrefix(&tzid);
|
2006-11-01 19:09:59 +00:00
|
|
|
return tzid;
|
2005-11-04 19:19:45 +00:00
|
|
|
}
|
2006-03-03 01:00:54 +00:00
|
|
|
/* else U_TZNAME will give a better result. */
|
2007-06-28 07:33:44 +00:00
|
|
|
#endif
|
2006-03-03 01:05:05 +00:00
|
|
|
|
2011-11-14 19:32:51 +00:00
|
|
|
#if defined(CHECK_LOCALTIME_LINK) && !defined(DEBUG_SKIP_LOCALTIME_LINK)
|
2006-03-03 01:05:05 +00:00
|
|
|
/* Caller must handle threading issues */
|
|
|
|
if (gTimeZoneBufferPtr == NULL) {
|
2006-03-03 06:47:40 +00:00
|
|
|
/*
|
|
|
|
This is a trick to look at the name of the link to get the Olson ID
|
|
|
|
because the tzfile contents is underspecified.
|
|
|
|
This isn't guaranteed to work because it may not be a symlink.
|
|
|
|
*/
|
2007-06-06 22:11:45 +00:00
|
|
|
int32_t ret = (int32_t)readlink(TZDEFAULT, gTimeZoneBuffer, sizeof(gTimeZoneBuffer));
|
2006-03-03 01:05:05 +00:00
|
|
|
if (0 < ret) {
|
2006-03-03 06:47:40 +00:00
|
|
|
int32_t tzZoneInfoLen = uprv_strlen(TZZONEINFO);
|
2006-03-03 01:05:05 +00:00
|
|
|
gTimeZoneBuffer[ret] = 0;
|
2006-03-03 06:47:40 +00:00
|
|
|
if (uprv_strncmp(gTimeZoneBuffer, TZZONEINFO, tzZoneInfoLen) == 0
|
|
|
|
&& isValidOlsonID(gTimeZoneBuffer + tzZoneInfoLen))
|
|
|
|
{
|
|
|
|
return (gTimeZoneBufferPtr = gTimeZoneBuffer + tzZoneInfoLen);
|
2006-03-03 01:05:05 +00:00
|
|
|
}
|
2013-05-08 17:00:30 +00:00
|
|
|
#if U_PLATFORM == U_PF_SOLARIS
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tzZoneInfoLen = uprv_strlen(TZZONEINFO2);
|
|
|
|
if (uprv_strncmp(gTimeZoneBuffer, TZZONEINFO2, tzZoneInfoLen) == 0
|
|
|
|
&& isValidOlsonID(gTimeZoneBuffer + tzZoneInfoLen))
|
|
|
|
{
|
|
|
|
return (gTimeZoneBufferPtr = gTimeZoneBuffer + tzZoneInfoLen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2008-09-03 22:15:18 +00:00
|
|
|
} else {
|
|
|
|
#if defined(SEARCH_TZFILE)
|
2008-10-14 21:46:58 +00:00
|
|
|
DefaultTZInfo* tzInfo = (DefaultTZInfo*)uprv_malloc(sizeof(DefaultTZInfo));
|
|
|
|
if (tzInfo != NULL) {
|
|
|
|
tzInfo->defaultTZBuffer = NULL;
|
|
|
|
tzInfo->defaultTZFileSize = 0;
|
|
|
|
tzInfo->defaultTZFilePtr = NULL;
|
|
|
|
tzInfo->defaultTZstatus = FALSE;
|
|
|
|
tzInfo->defaultTZPosition = 0;
|
|
|
|
|
|
|
|
gTimeZoneBufferPtr = searchForTZFile(TZZONEINFO, tzInfo);
|
|
|
|
|
|
|
|
/* Free previously allocated memory */
|
|
|
|
if (tzInfo->defaultTZBuffer != NULL) {
|
|
|
|
uprv_free(tzInfo->defaultTZBuffer);
|
|
|
|
}
|
|
|
|
if (tzInfo->defaultTZFilePtr != NULL) {
|
|
|
|
fclose(tzInfo->defaultTZFilePtr);
|
|
|
|
}
|
|
|
|
uprv_free(tzInfo);
|
2008-10-01 14:11:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-03 22:15:18 +00:00
|
|
|
if (gTimeZoneBufferPtr != NULL && isValidOlsonID(gTimeZoneBufferPtr)) {
|
|
|
|
return gTimeZoneBufferPtr;
|
|
|
|
}
|
|
|
|
#endif
|
2006-03-03 01:05:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return gTimeZoneBufferPtr;
|
|
|
|
}
|
2005-11-04 19:19:45 +00:00
|
|
|
#endif
|
2006-03-03 01:00:54 +00:00
|
|
|
#endif
|
|
|
|
|
2000-10-05 23:41:59 +00:00
|
|
|
#ifdef U_TZNAME
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM_USES_ONLY_WIN32_API
|
2009-10-06 16:58:50 +00:00
|
|
|
/* The return value is free'd in timezone.cpp on Windows because
|
|
|
|
* the other code path returns a pointer to a heap location. */
|
|
|
|
return uprv_strdup(U_TZNAME[n]);
|
|
|
|
#else
|
2006-03-03 01:00:54 +00:00
|
|
|
/*
|
2006-11-15 19:01:21 +00:00
|
|
|
U_TZNAME is usually a non-unique abbreviation, which isn't normally usable.
|
|
|
|
So we remap the abbreviation to an olson ID.
|
|
|
|
|
|
|
|
Since Windows exposes a little more timezone information,
|
2007-06-28 07:33:44 +00:00
|
|
|
we normally don't use this code on Windows because
|
|
|
|
uprv_detectWindowsTimeZone should have already given the correct answer.
|
2006-03-03 01:00:54 +00:00
|
|
|
*/
|
2007-06-28 07:33:44 +00:00
|
|
|
{
|
|
|
|
struct tm juneSol, decemberSol;
|
|
|
|
int daylightType;
|
|
|
|
static const time_t juneSolstice=1182478260; /*2007-06-21 18:11 UT*/
|
|
|
|
static const time_t decemberSolstice=1198332540; /*2007-12-22 06:09 UT*/
|
|
|
|
|
|
|
|
/* This probing will tell us when daylight savings occurs. */
|
|
|
|
localtime_r(&juneSolstice, &juneSol);
|
|
|
|
localtime_r(&decemberSolstice, &decemberSol);
|
2011-11-14 19:32:51 +00:00
|
|
|
if(decemberSol.tm_isdst > 0) {
|
|
|
|
daylightType = U_DAYLIGHT_DECEMBER;
|
|
|
|
} else if(juneSol.tm_isdst > 0) {
|
|
|
|
daylightType = U_DAYLIGHT_JUNE;
|
|
|
|
} else {
|
|
|
|
daylightType = U_DAYLIGHT_NONE;
|
|
|
|
}
|
2007-06-28 07:33:44 +00:00
|
|
|
tzid = remapShortTimeZone(U_TZNAME[0], U_TZNAME[1], daylightType, uprv_timezone());
|
|
|
|
if (tzid != NULL) {
|
|
|
|
return tzid;
|
|
|
|
}
|
2006-11-01 09:04:57 +00:00
|
|
|
}
|
2000-10-05 23:41:59 +00:00
|
|
|
return U_TZNAME[n];
|
2009-10-06 16:58:50 +00:00
|
|
|
#endif
|
2000-10-05 23:41:59 +00:00
|
|
|
#else
|
2000-10-13 02:00:26 +00:00
|
|
|
return "";
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-11-18 22:48:30 +00:00
|
|
|
/* Get and set the ICU data directory --------------------------------------- */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-08-31 02:14:47 +00:00
|
|
|
static char *gDataDirectory = NULL;
|
2013-05-03 21:36:03 +00:00
|
|
|
#if U_POSIX_LOCALE || U_PLATFORM_USES_ONLY_WIN32_API
|
2001-11-13 21:50:01 +00:00
|
|
|
static char *gCorrectedPOSIXLocale = NULL; /* Heap allocated */
|
|
|
|
#endif
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-10-06 23:10:53 +00:00
|
|
|
static UBool U_CALLCONV putil_cleanup(void)
|
2001-08-31 02:14:47 +00:00
|
|
|
{
|
2005-03-10 00:11:51 +00:00
|
|
|
if (gDataDirectory && *gDataDirectory) {
|
2001-08-31 02:14:47 +00:00
|
|
|
uprv_free(gDataDirectory);
|
|
|
|
}
|
2005-03-10 00:11:51 +00:00
|
|
|
gDataDirectory = NULL;
|
2013-05-03 21:36:03 +00:00
|
|
|
#if U_POSIX_LOCALE || U_PLATFORM_USES_ONLY_WIN32_API
|
2001-11-13 21:50:01 +00:00
|
|
|
if (gCorrectedPOSIXLocale) {
|
|
|
|
uprv_free(gCorrectedPOSIXLocale);
|
|
|
|
gCorrectedPOSIXLocale = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2001-08-31 02:14:47 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-11-18 22:48:30 +00:00
|
|
|
/*
|
2001-08-17 21:34:07 +00:00
|
|
|
* Set the data directory.
|
|
|
|
* Make a copy of the passed string, and set the global data dir to point to it.
|
1999-11-18 22:48:30 +00:00
|
|
|
*/
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
u_setDataDirectory(const char *directory) {
|
2001-08-17 21:34:07 +00:00
|
|
|
char *newDataDir;
|
2003-12-12 06:59:38 +00:00
|
|
|
int32_t length;
|
2001-08-16 16:20:56 +00:00
|
|
|
|
2005-03-10 00:11:51 +00:00
|
|
|
if(directory==NULL || *directory==0) {
|
|
|
|
/* A small optimization to prevent the malloc and copy when the
|
|
|
|
shared library is used, and this is a way to make sure that NULL
|
|
|
|
is never returned.
|
|
|
|
*/
|
2005-03-16 01:18:06 +00:00
|
|
|
newDataDir = (char *)"";
|
2002-07-17 03:01:45 +00:00
|
|
|
}
|
2005-03-10 00:11:51 +00:00
|
|
|
else {
|
|
|
|
length=(int32_t)uprv_strlen(directory);
|
|
|
|
newDataDir = (char *)uprv_malloc(length + 2);
|
2008-01-14 18:27:21 +00:00
|
|
|
/* Exit out if newDataDir could not be created. */
|
|
|
|
if (newDataDir == NULL) {
|
2008-02-23 19:15:18 +00:00
|
|
|
return;
|
2008-01-14 18:27:21 +00:00
|
|
|
}
|
2005-03-10 00:11:51 +00:00
|
|
|
uprv_strcpy(newDataDir, directory);
|
2000-10-13 02:00:26 +00:00
|
|
|
|
2004-04-22 23:27:20 +00:00
|
|
|
#if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR)
|
2005-03-10 00:11:51 +00:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
while(p = uprv_strchr(newDataDir, U_FILE_ALT_SEP_CHAR)) {
|
|
|
|
*p = U_FILE_SEP_CHAR;
|
|
|
|
}
|
|
|
|
}
|
2004-04-22 23:27:20 +00:00
|
|
|
#endif
|
2005-03-10 00:11:51 +00:00
|
|
|
}
|
2004-04-22 23:27:20 +00:00
|
|
|
|
2005-03-10 00:11:51 +00:00
|
|
|
if (gDataDirectory && *gDataDirectory) {
|
2002-07-17 03:01:45 +00:00
|
|
|
uprv_free(gDataDirectory);
|
2000-10-13 02:00:26 +00:00
|
|
|
}
|
2002-07-17 03:01:45 +00:00
|
|
|
gDataDirectory = newDataDir;
|
2004-10-06 23:10:53 +00:00
|
|
|
ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup);
|
1999-11-18 22:48:30 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-04-14 19:58:08 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2008-08-26 20:32:18 +00:00
|
|
|
uprv_pathIsAbsolute(const char *path)
|
2004-04-14 19:58:08 +00:00
|
|
|
{
|
2008-08-26 20:32:18 +00:00
|
|
|
if(!path || !*path) {
|
|
|
|
return FALSE;
|
2004-04-14 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(*path == U_FILE_SEP_CHAR) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-04-22 23:27:20 +00:00
|
|
|
|
|
|
|
#if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR)
|
|
|
|
if(*path == U_FILE_ALT_SEP_CHAR) {
|
2004-04-14 19:58:08 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2004-04-22 23:27:20 +00:00
|
|
|
#endif
|
2004-04-14 19:58:08 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM_USES_ONLY_WIN32_API
|
2004-04-14 19:58:08 +00:00
|
|
|
if( (((path[0] >= 'A') && (path[0] <= 'Z')) ||
|
|
|
|
((path[0] >= 'a') && (path[0] <= 'z'))) &&
|
|
|
|
path[1] == ':' ) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-10-26 22:02:14 +00:00
|
|
|
/* Temporary backup setting of ICU_DATA_DIR_PREFIX_ENV_VAR
|
|
|
|
until some client wrapper makefiles are updated */
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM_IS_DARWIN_BASED && TARGET_IPHONE_SIMULATOR
|
2010-10-26 22:02:14 +00:00
|
|
|
# if !defined(ICU_DATA_DIR_PREFIX_ENV_VAR)
|
|
|
|
# define ICU_DATA_DIR_PREFIX_ENV_VAR "IPHONE_SIMULATOR_ROOT"
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
1999-11-18 22:48:30 +00:00
|
|
|
U_CAPI const char * U_EXPORT2
|
|
|
|
u_getDataDirectory(void) {
|
2001-08-17 21:34:07 +00:00
|
|
|
const char *path = NULL;
|
2010-10-26 22:02:14 +00:00
|
|
|
#if defined(ICU_DATA_DIR_PREFIX_ENV_VAR)
|
2009-11-30 19:04:21 +00:00
|
|
|
char datadir_path_buffer[PATH_MAX];
|
|
|
|
#endif
|
2001-08-17 21:34:07 +00:00
|
|
|
|
1999-11-18 22:48:30 +00:00
|
|
|
/* if we have the directory, then return it immediately */
|
2013-03-28 18:25:12 +00:00
|
|
|
if(gDataDirectory) {
|
|
|
|
return gDataDirectory;
|
2001-08-17 21:34:07 +00:00
|
|
|
}
|
|
|
|
|
2005-02-16 07:53:01 +00:00
|
|
|
/*
|
2005-06-30 20:02:38 +00:00
|
|
|
When ICU_NO_USER_DATA_OVERRIDE is defined, users aren't allowed to
|
2005-02-16 07:53:01 +00:00
|
|
|
override ICU's data with the ICU_DATA environment variable. This prevents
|
|
|
|
problems where multiple custom copies of ICU's specific version of data
|
|
|
|
are installed on a system. Either the application must define the data
|
|
|
|
directory with u_setDataDirectory, define ICU_DATA_DIR when compiling
|
|
|
|
ICU, set the data with udata_setCommonData or trust that all of the
|
|
|
|
required data is contained in ICU's data library that contains
|
|
|
|
the entry point defined by U_ICUDATA_ENTRY_POINT.
|
|
|
|
|
|
|
|
There may also be some platforms where environment variables
|
|
|
|
are not allowed.
|
|
|
|
*/
|
2005-09-29 23:06:12 +00:00
|
|
|
# if !defined(ICU_NO_USER_DATA_OVERRIDE) && !UCONFIG_NO_FILE_IO
|
2005-02-16 07:53:01 +00:00
|
|
|
/* First try to get the environment variable */
|
2001-08-17 21:34:07 +00:00
|
|
|
path=getenv("ICU_DATA");
|
2005-02-16 07:53:01 +00:00
|
|
|
# endif
|
1999-11-18 22:48:30 +00:00
|
|
|
|
2010-07-29 23:37:19 +00:00
|
|
|
/* ICU_DATA_DIR may be set as a compile option.
|
|
|
|
* U_ICU_DATA_DEFAULT_DIR is provided and is set by ICU at compile time
|
|
|
|
* and is used only when data is built in archive mode eliminating the need
|
|
|
|
* for ICU_DATA_DIR to be set. U_ICU_DATA_DEFAULT_DIR is set to the installation
|
|
|
|
* directory of the data dat file. Users should use ICU_DATA_DIR if they want to
|
|
|
|
* set their own path.
|
|
|
|
*/
|
|
|
|
#if defined(ICU_DATA_DIR) || defined(U_ICU_DATA_DEFAULT_DIR)
|
2001-08-17 21:34:07 +00:00
|
|
|
if(path==NULL || *path==0) {
|
2010-10-26 22:02:14 +00:00
|
|
|
# if defined(ICU_DATA_DIR_PREFIX_ENV_VAR)
|
|
|
|
const char *prefix = getenv(ICU_DATA_DIR_PREFIX_ENV_VAR);
|
|
|
|
# endif
|
|
|
|
# ifdef ICU_DATA_DIR
|
2001-08-17 21:34:07 +00:00
|
|
|
path=ICU_DATA_DIR;
|
2010-10-26 22:02:14 +00:00
|
|
|
# else
|
2010-07-29 23:37:19 +00:00
|
|
|
path=U_ICU_DATA_DEFAULT_DIR;
|
2010-10-26 22:02:14 +00:00
|
|
|
# endif
|
|
|
|
# if defined(ICU_DATA_DIR_PREFIX_ENV_VAR)
|
|
|
|
if (prefix != NULL) {
|
|
|
|
snprintf(datadir_path_buffer, PATH_MAX, "%s%s", prefix, path);
|
2009-11-30 19:04:21 +00:00
|
|
|
path=datadir_path_buffer;
|
|
|
|
}
|
2010-10-26 22:02:14 +00:00
|
|
|
# endif
|
1999-11-18 22:48:30 +00:00
|
|
|
}
|
2010-10-26 22:02:14 +00:00
|
|
|
#endif
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-08-31 02:14:47 +00:00
|
|
|
if(path==NULL) {
|
|
|
|
/* It looks really bad, set it to something. */
|
|
|
|
path = "";
|
|
|
|
}
|
|
|
|
|
2001-08-17 21:34:07 +00:00
|
|
|
u_setDataDirectory(path);
|
1999-11-18 22:48:30 +00:00
|
|
|
return gDataDirectory;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-08-17 21:34:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-11-18 22:48:30 +00:00
|
|
|
/* Macintosh-specific locale information ------------------------------------ */
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM == U_PF_CLASSIC_MACOS
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-05-03 00:13:10 +00:00
|
|
|
typedef struct {
|
|
|
|
int32_t script;
|
|
|
|
int32_t region;
|
|
|
|
int32_t lang;
|
|
|
|
int32_t date_region;
|
2001-08-24 00:22:07 +00:00
|
|
|
const char* posixID;
|
2001-05-03 00:13:10 +00:00
|
|
|
} mac_lc_rec;
|
|
|
|
|
|
|
|
/* Todo: This will be updated with a newer version from www.unicode.org web
|
1999-08-16 21:50:52 +00:00
|
|
|
page when it's available.*/
|
|
|
|
#define MAC_LC_MAGIC_NUMBER -5
|
|
|
|
#define MAC_LC_INIT_NUMBER -9
|
|
|
|
|
2001-08-24 00:22:07 +00:00
|
|
|
static const mac_lc_rec mac_lc_recs[] = {
|
2001-05-03 00:13:10 +00:00
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 0, "en_US",
|
|
|
|
/* United States*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 1, "fr_FR",
|
|
|
|
/* France*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 2, "en_GB",
|
|
|
|
/* Great Britain*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 3, "de_DE",
|
|
|
|
/* Germany*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 4, "it_IT",
|
|
|
|
/* Italy*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 5, "nl_NL",
|
|
|
|
/* Metherlands*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 6, "fr_BE",
|
|
|
|
/* French for Belgium or Lxembourg*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 7, "sv_SE",
|
|
|
|
/* Sweden*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 9, "da_DK",
|
|
|
|
/* Denmark*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 10, "pt_PT",
|
|
|
|
/* Portugal*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 11, "fr_CA",
|
|
|
|
/* French Canada*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 13, "is_IS",
|
|
|
|
/* Israel*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 14, "ja_JP",
|
|
|
|
/* Japan*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 15, "en_AU",
|
|
|
|
/* Australia*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 16, "ar_AE",
|
|
|
|
/* the Arabic world (?)*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 17, "fi_FI",
|
|
|
|
/* Finland*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 18, "fr_CH",
|
|
|
|
/* French for Switzerland*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 19, "de_CH",
|
|
|
|
/* German for Switzerland*/
|
2001-08-16 16:20:56 +00:00
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 20, "el_GR",
|
2001-05-03 00:13:10 +00:00
|
|
|
/* Greece*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 21, "is_IS",
|
|
|
|
/* Iceland ===*/
|
|
|
|
/*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 22, "",*/
|
|
|
|
/* Malta ===*/
|
|
|
|
/*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 23, "",*/
|
|
|
|
/* Cyprus ===*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 24, "tr_TR",
|
|
|
|
/* Turkey ===*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 25, "sh_YU",
|
|
|
|
/* Croatian system for Yugoslavia*/
|
|
|
|
/*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 33, "",*/
|
|
|
|
/* Hindi system for India*/
|
|
|
|
/*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 34, "",*/
|
|
|
|
/* Pakistan*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 41, "lt_LT",
|
|
|
|
/* Lithuania*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 42, "pl_PL",
|
|
|
|
/* Poland*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 43, "hu_HU",
|
|
|
|
/* Hungary*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 44, "et_EE",
|
|
|
|
/* Estonia*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 45, "lv_LV",
|
|
|
|
/* Latvia*/
|
|
|
|
/*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 46, "",*/
|
|
|
|
/* Lapland [Ask Rich for the data. HS]*/
|
|
|
|
/*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 47, "",*/
|
|
|
|
/* Faeroe Islands*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 48, "fa_IR",
|
|
|
|
/* Iran*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 49, "ru_RU",
|
|
|
|
/* Russia*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 50, "en_IE",
|
|
|
|
/* Ireland*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 51, "ko_KR",
|
|
|
|
/* Korea*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 52, "zh_CN",
|
|
|
|
/* People's Republic of China*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 53, "zh_TW",
|
|
|
|
/* Taiwan*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 54, "th_TH",
|
|
|
|
/* Thailand*/
|
|
|
|
|
|
|
|
/* fallback is en_US*/
|
|
|
|
MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER,
|
|
|
|
MAC_LC_MAGIC_NUMBER, "en_US"
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2001-05-04 23:41:15 +00:00
|
|
|
#if U_POSIX_LOCALE
|
2010-09-03 21:44:58 +00:00
|
|
|
/* A helper function used by uprv_getPOSIXIDForDefaultLocale and
|
|
|
|
* uprv_getPOSIXIDForDefaultCodepage. Returns the posix locale id for
|
|
|
|
* LC_CTYPE and LC_MESSAGES. It doesn't support other locale categories.
|
|
|
|
*/
|
|
|
|
static const char *uprv_getPOSIXIDForCategory(int category)
|
2000-07-07 06:12:00 +00:00
|
|
|
{
|
2010-09-03 21:44:58 +00:00
|
|
|
const char* posixID = NULL;
|
|
|
|
if (category == LC_MESSAGES || category == LC_CTYPE) {
|
2006-01-05 01:21:54 +00:00
|
|
|
/*
|
2008-08-26 20:32:18 +00:00
|
|
|
* On Solaris two different calls to setlocale can result in
|
2006-01-05 01:21:54 +00:00
|
|
|
* different values. Only get this value once.
|
|
|
|
*
|
|
|
|
* We must check this first because an application can set this.
|
|
|
|
*
|
|
|
|
* LC_ALL can't be used because it's platform dependent. The LANG
|
|
|
|
* environment variable seems to affect LC_CTYPE variable by default.
|
|
|
|
* Here is what setlocale(LC_ALL, NULL) can return.
|
|
|
|
* HPUX can return 'C C C C C C C'
|
|
|
|
* Solaris can return /en_US/C/C/C/C/C on the second try.
|
|
|
|
* Linux can return LC_CTYPE=C;LC_NUMERIC=C;...
|
|
|
|
*
|
|
|
|
* The default codepage detection also needs to use LC_CTYPE.
|
2008-08-26 20:32:18 +00:00
|
|
|
*
|
2006-01-05 01:21:54 +00:00
|
|
|
* Do not call setlocale(LC_*, "")! Using an empty string instead
|
|
|
|
* of NULL, will modify the libc behavior.
|
|
|
|
*/
|
2010-09-03 21:44:58 +00:00
|
|
|
posixID = setlocale(category, NULL);
|
2006-01-05 01:21:54 +00:00
|
|
|
if ((posixID == 0)
|
|
|
|
|| (uprv_strcmp("C", posixID) == 0)
|
|
|
|
|| (uprv_strcmp("POSIX", posixID) == 0))
|
|
|
|
{
|
|
|
|
/* Maybe we got some garbage. Try something more reasonable */
|
|
|
|
posixID = getenv("LC_ALL");
|
2001-10-05 02:10:46 +00:00
|
|
|
if (posixID == 0) {
|
2010-09-03 21:44:58 +00:00
|
|
|
posixID = getenv(category == LC_MESSAGES ? "LC_MESSAGES" : "LC_CTYPE");
|
2006-01-05 01:21:54 +00:00
|
|
|
if (posixID == 0) {
|
|
|
|
posixID = getenv("LANG");
|
|
|
|
}
|
2001-10-05 02:10:46 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-03 21:44:58 +00:00
|
|
|
}
|
|
|
|
if ((posixID==0)
|
|
|
|
|| (uprv_strcmp("C", posixID) == 0)
|
|
|
|
|| (uprv_strcmp("POSIX", posixID) == 0))
|
|
|
|
{
|
|
|
|
/* Nothing worked. Give it a nice POSIX default value. */
|
|
|
|
posixID = "en_US_POSIX";
|
|
|
|
}
|
|
|
|
return posixID;
|
|
|
|
}
|
2001-08-17 21:34:07 +00:00
|
|
|
|
2010-09-03 21:44:58 +00:00
|
|
|
/* Return just the POSIX id for the default locale, whatever happens to be in
|
|
|
|
* it. It gets the value from LC_MESSAGES and indirectly from LC_ALL and LANG.
|
|
|
|
*/
|
|
|
|
static const char *uprv_getPOSIXIDForDefaultLocale(void)
|
|
|
|
{
|
|
|
|
static const char* posixID = NULL;
|
|
|
|
if (posixID == 0) {
|
|
|
|
posixID = uprv_getPOSIXIDForCategory(LC_MESSAGES);
|
2001-08-16 16:20:56 +00:00
|
|
|
}
|
2010-09-03 21:44:58 +00:00
|
|
|
return posixID;
|
|
|
|
}
|
2006-01-05 01:21:54 +00:00
|
|
|
|
2012-05-11 17:54:07 +00:00
|
|
|
#if !U_CHARSET_IS_UTF8
|
2010-09-03 21:44:58 +00:00
|
|
|
/* Return just the POSIX id for the default codepage, whatever happens to be in
|
|
|
|
* it. It gets the value from LC_CTYPE and indirectly from LC_ALL and LANG.
|
|
|
|
*/
|
|
|
|
static const char *uprv_getPOSIXIDForDefaultCodepage(void)
|
|
|
|
{
|
|
|
|
static const char* posixID = NULL;
|
|
|
|
if (posixID == 0) {
|
|
|
|
posixID = uprv_getPOSIXIDForCategory(LC_CTYPE);
|
|
|
|
}
|
2001-08-16 16:20:56 +00:00
|
|
|
return posixID;
|
2000-07-07 06:12:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-05-11 17:54:07 +00:00
|
|
|
#endif
|
2000-07-07 06:12:00 +00:00
|
|
|
|
2003-05-29 20:22:13 +00:00
|
|
|
/* NOTE: The caller should handle thread safety */
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
2000-07-07 06:12:00 +00:00
|
|
|
uprv_getDefaultLocaleID()
|
|
|
|
{
|
2000-07-20 04:43:47 +00:00
|
|
|
#if U_POSIX_LOCALE
|
2001-11-10 22:41:51 +00:00
|
|
|
/*
|
|
|
|
Note that: (a '!' means the ID is improper somehow)
|
|
|
|
LC_ALL ----> default_loc codepage
|
|
|
|
--------------------------------------------------------
|
|
|
|
ab.CD ab CD
|
|
|
|
ab@CD ab__CD -
|
|
|
|
ab@CD.EF ab__CD EF
|
|
|
|
|
|
|
|
ab_CD.EF@GH ab_CD_GH EF
|
|
|
|
|
|
|
|
Some 'improper' ways to do the same as above:
|
|
|
|
! ab_CD@GH.EF ab_CD_GH EF
|
|
|
|
! ab_CD.EF@GH.IJ ab_CD_GH EF
|
|
|
|
! ab_CD@ZZ.EF@GH.IJ ab_CD_GH EF
|
|
|
|
|
|
|
|
_CD@GH _CD_GH -
|
|
|
|
_CD.EF@GH _CD_GH EF
|
|
|
|
|
|
|
|
The variant cannot have dots in it.
|
|
|
|
The 'rightmost' variant (@xxx) wins.
|
|
|
|
The leftmost codepage (.xxx) wins.
|
|
|
|
*/
|
2001-05-04 00:47:16 +00:00
|
|
|
char *correctedPOSIXLocale = 0;
|
2010-09-03 21:44:58 +00:00
|
|
|
const char* posixID = uprv_getPOSIXIDForDefaultLocale();
|
2001-05-04 00:47:16 +00:00
|
|
|
const char *p;
|
2001-11-10 22:41:51 +00:00
|
|
|
const char *q;
|
|
|
|
int32_t len;
|
2001-08-17 21:34:07 +00:00
|
|
|
|
2001-05-04 00:47:16 +00:00
|
|
|
/* Format: (no spaces)
|
|
|
|
ll [ _CC ] [ . MM ] [ @ VV]
|
2001-08-17 21:34:07 +00:00
|
|
|
|
2001-05-04 00:47:16 +00:00
|
|
|
l = lang, C = ctry, M = charmap, V = variant
|
|
|
|
*/
|
2000-07-07 06:12:00 +00:00
|
|
|
|
2002-10-24 20:52:54 +00:00
|
|
|
if (gCorrectedPOSIXLocale != NULL) {
|
2008-08-26 20:32:18 +00:00
|
|
|
return gCorrectedPOSIXLocale;
|
2001-11-13 21:50:01 +00:00
|
|
|
}
|
|
|
|
|
2002-10-24 20:52:54 +00:00
|
|
|
if ((p = uprv_strchr(posixID, '.')) != NULL) {
|
2001-05-04 00:47:16 +00:00
|
|
|
/* assume new locale can't be larger than old one? */
|
2012-08-08 00:50:16 +00:00
|
|
|
correctedPOSIXLocale = static_cast<char *>(uprv_malloc(uprv_strlen(posixID)+1));
|
2008-01-14 18:27:21 +00:00
|
|
|
/* Exit on memory allocation error. */
|
|
|
|
if (correctedPOSIXLocale == NULL) {
|
2008-02-23 19:15:18 +00:00
|
|
|
return NULL;
|
2008-01-14 18:27:21 +00:00
|
|
|
}
|
2001-05-04 00:47:16 +00:00
|
|
|
uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
|
|
|
|
correctedPOSIXLocale[p-posixID] = 0;
|
2001-08-17 21:34:07 +00:00
|
|
|
|
2001-11-10 22:41:51 +00:00
|
|
|
/* do not copy after the @ */
|
2002-10-24 20:52:54 +00:00
|
|
|
if ((p = uprv_strchr(correctedPOSIXLocale, '@')) != NULL) {
|
2001-11-13 04:17:17 +00:00
|
|
|
correctedPOSIXLocale[p-correctedPOSIXLocale] = 0;
|
2001-11-10 22:41:51 +00:00
|
|
|
}
|
2001-05-04 00:47:16 +00:00
|
|
|
}
|
2000-07-07 06:12:00 +00:00
|
|
|
|
2001-11-10 22:41:51 +00:00
|
|
|
/* Note that we scan the *uncorrected* ID. */
|
2002-10-24 20:52:54 +00:00
|
|
|
if ((p = uprv_strrchr(posixID, '@')) != NULL) {
|
|
|
|
if (correctedPOSIXLocale == NULL) {
|
2012-08-08 00:50:16 +00:00
|
|
|
correctedPOSIXLocale = static_cast<char *>(uprv_malloc(uprv_strlen(posixID)+1));
|
2008-01-14 18:27:21 +00:00
|
|
|
/* Exit on memory allocation error. */
|
|
|
|
if (correctedPOSIXLocale == NULL) {
|
2008-02-23 19:15:18 +00:00
|
|
|
return NULL;
|
2008-01-14 18:27:21 +00:00
|
|
|
}
|
2001-05-04 00:47:16 +00:00
|
|
|
uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
|
|
|
|
correctedPOSIXLocale[p-posixID] = 0;
|
|
|
|
}
|
|
|
|
p++;
|
2000-07-07 06:12:00 +00:00
|
|
|
|
2001-05-04 00:47:16 +00:00
|
|
|
/* Take care of any special cases here.. */
|
2002-10-24 20:52:54 +00:00
|
|
|
if (!uprv_strcmp(p, "nynorsk")) {
|
2001-05-04 00:47:16 +00:00
|
|
|
p = "NY";
|
2006-06-06 16:26:06 +00:00
|
|
|
/* Don't worry about no__NY. In practice, it won't appear. */
|
2001-05-04 00:47:16 +00:00
|
|
|
}
|
2000-07-07 06:12:00 +00:00
|
|
|
|
2002-10-24 20:52:54 +00:00
|
|
|
if (uprv_strchr(correctedPOSIXLocale,'_') == NULL) {
|
2001-05-04 00:47:16 +00:00
|
|
|
uprv_strcat(correctedPOSIXLocale, "__"); /* aa@b -> aa__b */
|
2001-11-13 04:17:17 +00:00
|
|
|
}
|
2002-10-24 20:52:54 +00:00
|
|
|
else {
|
2001-05-04 00:47:16 +00:00
|
|
|
uprv_strcat(correctedPOSIXLocale, "_"); /* aa_CC@b -> aa_CC_b */
|
2001-11-13 04:17:17 +00:00
|
|
|
}
|
2001-11-10 22:41:51 +00:00
|
|
|
|
2002-10-24 20:52:54 +00:00
|
|
|
if ((q = uprv_strchr(p, '.')) != NULL) {
|
2001-11-13 04:17:17 +00:00
|
|
|
/* How big will the resulting string be? */
|
2004-04-02 01:04:37 +00:00
|
|
|
len = (int32_t)(uprv_strlen(correctedPOSIXLocale) + (q-p));
|
2001-11-13 04:17:17 +00:00
|
|
|
uprv_strncat(correctedPOSIXLocale, p, q-p);
|
|
|
|
correctedPOSIXLocale[len] = 0;
|
2001-11-10 22:41:51 +00:00
|
|
|
}
|
2002-10-24 20:52:54 +00:00
|
|
|
else {
|
|
|
|
/* Anything following the @ sign */
|
|
|
|
uprv_strcat(correctedPOSIXLocale, p);
|
2001-11-10 22:41:51 +00:00
|
|
|
}
|
2000-07-07 06:12:00 +00:00
|
|
|
|
2001-05-04 00:47:16 +00:00
|
|
|
/* Should there be a map from 'no@nynorsk' -> no_NO_NY here?
|
2002-10-24 20:52:54 +00:00
|
|
|
* How about 'russian' -> 'ru'?
|
2006-06-06 16:26:06 +00:00
|
|
|
* Many of the other locales using ISO codes will be handled by the
|
|
|
|
* canonicalization functions in uloc_getDefault.
|
2002-10-24 20:52:54 +00:00
|
|
|
*/
|
2001-11-10 22:41:51 +00:00
|
|
|
}
|
2000-07-07 06:12:00 +00:00
|
|
|
|
2001-11-10 22:41:51 +00:00
|
|
|
/* Was a correction made? */
|
2002-10-24 20:52:54 +00:00
|
|
|
if (correctedPOSIXLocale != NULL) {
|
2001-11-13 04:17:17 +00:00
|
|
|
posixID = correctedPOSIXLocale;
|
2001-05-04 00:47:16 +00:00
|
|
|
}
|
2002-10-24 20:52:54 +00:00
|
|
|
else {
|
|
|
|
/* copy it, just in case the original pointer goes away. See j2395 */
|
|
|
|
correctedPOSIXLocale = (char *)uprv_malloc(uprv_strlen(posixID) + 1);
|
2008-01-14 18:27:21 +00:00
|
|
|
/* Exit on memory allocation error. */
|
|
|
|
if (correctedPOSIXLocale == NULL) {
|
2008-02-23 19:15:18 +00:00
|
|
|
return NULL;
|
2008-01-14 18:27:21 +00:00
|
|
|
}
|
2002-10-24 20:52:54 +00:00
|
|
|
posixID = uprv_strcpy(correctedPOSIXLocale, posixID);
|
|
|
|
}
|
2000-07-07 06:12:00 +00:00
|
|
|
|
2002-10-24 20:52:54 +00:00
|
|
|
if (gCorrectedPOSIXLocale == NULL) {
|
2001-11-13 21:50:01 +00:00
|
|
|
gCorrectedPOSIXLocale = correctedPOSIXLocale;
|
2004-10-06 23:10:53 +00:00
|
|
|
ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup);
|
2001-11-13 21:50:01 +00:00
|
|
|
correctedPOSIXLocale = NULL;
|
2002-10-24 20:52:54 +00:00
|
|
|
}
|
2001-11-13 21:50:01 +00:00
|
|
|
|
2002-10-24 20:52:54 +00:00
|
|
|
if (correctedPOSIXLocale != NULL) { /* Was already set - clean up. */
|
2008-08-26 20:32:18 +00:00
|
|
|
uprv_free(correctedPOSIXLocale);
|
2001-11-13 21:50:01 +00:00
|
|
|
}
|
|
|
|
|
2001-05-04 00:47:16 +00:00
|
|
|
return posixID;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM_USES_ONLY_WIN32_API
|
2013-05-03 21:36:03 +00:00
|
|
|
#define POSIX_LOCALE_CAPACITY 64
|
2000-10-13 02:00:26 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2013-05-03 21:36:03 +00:00
|
|
|
char *correctedPOSIXLocale = 0;
|
|
|
|
|
|
|
|
if (gCorrectedPOSIXLocale != NULL) {
|
|
|
|
return gCorrectedPOSIXLocale;
|
|
|
|
}
|
|
|
|
|
2000-10-13 02:00:26 +00:00
|
|
|
LCID id = GetThreadLocale();
|
2013-05-03 21:36:03 +00:00
|
|
|
correctedPOSIXLocale = static_cast<char *>(uprv_malloc(POSIX_LOCALE_CAPACITY + 1));
|
|
|
|
if (correctedPOSIXLocale) {
|
|
|
|
int32_t posixLen = uprv_convertToPosix(id, correctedPOSIXLocale, POSIX_LOCALE_CAPACITY, &status);
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
*(correctedPOSIXLocale + posixLen) = 0;
|
|
|
|
gCorrectedPOSIXLocale = correctedPOSIXLocale;
|
|
|
|
ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup);
|
|
|
|
} else {
|
|
|
|
uprv_free(correctedPOSIXLocale);
|
|
|
|
}
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2013-05-03 21:36:03 +00:00
|
|
|
if (gCorrectedPOSIXLocale == NULL) {
|
|
|
|
return "en_US";
|
2000-10-13 02:00:26 +00:00
|
|
|
}
|
2013-05-03 21:36:03 +00:00
|
|
|
return gCorrectedPOSIXLocale;
|
2000-10-13 02:00:26 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_CLASSIC_MACOS
|
2001-08-17 21:34:07 +00:00
|
|
|
int32_t script = MAC_LC_INIT_NUMBER;
|
2001-05-04 00:47:16 +00:00
|
|
|
/* = IntlScript(); or GetScriptManagerVariable(smSysScript);*/
|
2001-08-17 21:34:07 +00:00
|
|
|
int32_t region = MAC_LC_INIT_NUMBER;
|
2001-05-04 00:47:16 +00:00
|
|
|
/* = GetScriptManagerVariable(smRegionCode);*/
|
2001-08-17 21:34:07 +00:00
|
|
|
int32_t lang = MAC_LC_INIT_NUMBER;
|
2001-05-04 00:47:16 +00:00
|
|
|
/* = GetScriptManagerVariable(smScriptLang);*/
|
|
|
|
int32_t date_region = MAC_LC_INIT_NUMBER;
|
2003-10-06 15:55:31 +00:00
|
|
|
const char* posixID = 0;
|
2001-05-04 00:47:16 +00:00
|
|
|
int32_t count = sizeof(mac_lc_recs) / sizeof(mac_lc_rec);
|
|
|
|
int32_t i;
|
|
|
|
Intl1Hndl ih;
|
|
|
|
|
|
|
|
ih = (Intl1Hndl) GetIntlResource(1);
|
|
|
|
if (ih)
|
|
|
|
date_region = ((uint16_t)(*ih)->intl1Vers) >> 8;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2001-08-17 21:34:07 +00:00
|
|
|
if ( ((mac_lc_recs[i].script == MAC_LC_MAGIC_NUMBER)
|
2001-05-04 00:47:16 +00:00
|
|
|
|| (mac_lc_recs[i].script == script))
|
|
|
|
&& ((mac_lc_recs[i].region == MAC_LC_MAGIC_NUMBER)
|
|
|
|
|| (mac_lc_recs[i].region == region))
|
|
|
|
&& ((mac_lc_recs[i].lang == MAC_LC_MAGIC_NUMBER)
|
|
|
|
|| (mac_lc_recs[i].lang == lang))
|
2001-08-17 21:34:07 +00:00
|
|
|
&& ((mac_lc_recs[i].date_region == MAC_LC_MAGIC_NUMBER)
|
2001-05-04 00:47:16 +00:00
|
|
|
|| (mac_lc_recs[i].date_region == date_region))
|
|
|
|
)
|
|
|
|
{
|
|
|
|
posixID = mac_lc_recs[i].posixID;
|
|
|
|
break;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-05-04 00:47:16 +00:00
|
|
|
|
|
|
|
return posixID;
|
2000-09-19 18:02:53 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_OS400
|
2001-05-04 00:47:16 +00:00
|
|
|
/* locales are process scoped and are by definition thread safe */
|
|
|
|
static char correctedLocale[64];
|
2001-05-04 23:41:15 +00:00
|
|
|
const char *localeID = getenv("LC_ALL");
|
2001-05-04 00:47:16 +00:00
|
|
|
char *p;
|
2000-10-13 02:00:26 +00:00
|
|
|
|
2001-05-04 23:41:15 +00:00
|
|
|
if (localeID == NULL)
|
|
|
|
localeID = getenv("LANG");
|
|
|
|
if (localeID == NULL)
|
|
|
|
localeID = setlocale(LC_ALL, NULL);
|
2001-05-04 00:47:16 +00:00
|
|
|
/* Make sure we have something... */
|
|
|
|
if (localeID == NULL)
|
|
|
|
return "en_US_POSIX";
|
|
|
|
|
|
|
|
/* Extract the locale name from the path. */
|
|
|
|
if((p = uprv_strrchr(localeID, '/')) != NULL)
|
|
|
|
{
|
|
|
|
/* Increment p to start of locale name. */
|
|
|
|
p++;
|
|
|
|
localeID = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy to work location. */
|
|
|
|
uprv_strcpy(correctedLocale, localeID);
|
|
|
|
|
|
|
|
/* Strip off the '.locale' extension. */
|
|
|
|
if((p = uprv_strchr(correctedLocale, '.')) != NULL) {
|
|
|
|
*p = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Upper case the locale name. */
|
|
|
|
T_CString_toUpperCase(correctedLocale);
|
|
|
|
|
|
|
|
/* See if we are using the POSIX locale. Any of the
|
|
|
|
* following are equivalent and use the same QLGPGCMA
|
|
|
|
* (POSIX) locale.
|
2005-03-29 21:58:43 +00:00
|
|
|
* QLGPGCMA2 means UCS2
|
|
|
|
* QLGPGCMA_4 means UTF-32
|
|
|
|
* QLGPGCMA_8 means UTF-8
|
2001-05-04 00:47:16 +00:00
|
|
|
*/
|
|
|
|
if ((uprv_strcmp("C", correctedLocale) == 0) ||
|
|
|
|
(uprv_strcmp("POSIX", correctedLocale) == 0) ||
|
2005-03-29 21:58:43 +00:00
|
|
|
(uprv_strncmp("QLGPGCMA", correctedLocale, 8) == 0))
|
2001-05-04 00:47:16 +00:00
|
|
|
{
|
|
|
|
uprv_strcpy(correctedLocale, "en_US_POSIX");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int16_t LocaleLen;
|
|
|
|
|
|
|
|
/* Lower case the lang portion. */
|
|
|
|
for(p = correctedLocale; *p != 0 && *p != '_'; p++)
|
|
|
|
{
|
|
|
|
*p = uprv_tolower(*p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust for Euro. After '_E' add 'URO'. */
|
|
|
|
LocaleLen = uprv_strlen(correctedLocale);
|
|
|
|
if (correctedLocale[LocaleLen - 2] == '_' &&
|
|
|
|
correctedLocale[LocaleLen - 1] == 'E')
|
|
|
|
{
|
|
|
|
uprv_strcat(correctedLocale, "URO");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If using Lotus-based locale then convert to
|
|
|
|
* equivalent non Lotus.
|
|
|
|
*/
|
|
|
|
else if (correctedLocale[LocaleLen - 2] == '_' &&
|
|
|
|
correctedLocale[LocaleLen - 1] == 'L')
|
|
|
|
{
|
|
|
|
correctedLocale[LocaleLen - 2] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There are separate simplified and traditional
|
|
|
|
* locales called zh_HK_S and zh_HK_T.
|
|
|
|
*/
|
|
|
|
else if (uprv_strncmp(correctedLocale, "zh_HK", 5) == 0)
|
|
|
|
{
|
|
|
|
uprv_strcpy(correctedLocale, "zh_HK");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A special zh_CN_GBK locale...
|
|
|
|
*/
|
|
|
|
else if (uprv_strcmp(correctedLocale, "zh_CN_GBK") == 0)
|
|
|
|
{
|
|
|
|
uprv_strcpy(correctedLocale, "zh_CN");
|
|
|
|
}
|
2001-08-17 21:34:07 +00:00
|
|
|
|
2001-05-04 00:47:16 +00:00
|
|
|
}
|
2001-08-17 21:34:07 +00:00
|
|
|
|
2001-05-04 00:47:16 +00:00
|
|
|
return correctedLocale;
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
2003-05-23 00:56:21 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2009-03-11 03:16:35 +00:00
|
|
|
#if !U_CHARSET_IS_UTF8
|
2005-08-04 17:44:15 +00:00
|
|
|
#if U_POSIX_LOCALE
|
2005-08-04 20:39:34 +00:00
|
|
|
/*
|
|
|
|
Due to various platform differences, one platform may specify a charset,
|
|
|
|
when they really mean a different charset. Remap the names so that they are
|
2007-12-04 16:44:36 +00:00
|
|
|
compatible with ICU. Only conflicting/ambiguous aliases should be resolved
|
|
|
|
here. Before adding anything to this function, please consider adding unique
|
|
|
|
names to the ICU alias table in the data directory.
|
2005-08-04 20:39:34 +00:00
|
|
|
*/
|
|
|
|
static const char*
|
|
|
|
remapPlatformDependentCodepage(const char *locale, const char *name) {
|
2005-08-05 17:29:57 +00:00
|
|
|
if (locale != NULL && *locale == 0) {
|
2005-08-04 20:39:34 +00:00
|
|
|
/* Make sure that an empty locale is handled the same way. */
|
|
|
|
locale = NULL;
|
|
|
|
}
|
2005-08-05 20:35:01 +00:00
|
|
|
if (name == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM == U_PF_AIX
|
2005-08-04 20:39:34 +00:00
|
|
|
if (uprv_strcmp(name, "IBM-943") == 0) {
|
|
|
|
/* Use the ASCII compatible ibm-943 */
|
|
|
|
name = "Shift-JIS";
|
|
|
|
}
|
|
|
|
else if (uprv_strcmp(name, "IBM-1252") == 0) {
|
|
|
|
/* Use the windows-1252 that contains the Euro */
|
|
|
|
name = "IBM-5348";
|
|
|
|
}
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_SOLARIS
|
2007-08-27 08:16:06 +00:00
|
|
|
if (locale != NULL && uprv_strcmp(name, "EUC") == 0) {
|
|
|
|
/* Solaris underspecifies the "EUC" name. */
|
|
|
|
if (uprv_strcmp(locale, "zh_CN") == 0) {
|
|
|
|
name = "EUC-CN";
|
|
|
|
}
|
|
|
|
else if (uprv_strcmp(locale, "zh_TW") == 0) {
|
|
|
|
name = "EUC-TW";
|
2005-08-04 20:39:34 +00:00
|
|
|
}
|
2007-08-27 08:16:06 +00:00
|
|
|
else if (uprv_strcmp(locale, "ko_KR") == 0) {
|
|
|
|
name = "EUC-KR";
|
2005-08-04 20:39:34 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-06 21:42:33 +00:00
|
|
|
else if (uprv_strcmp(name, "eucJP") == 0) {
|
|
|
|
/*
|
|
|
|
ibm-954 is the best match.
|
|
|
|
ibm-33722 is the default for eucJP (similar to Windows).
|
|
|
|
*/
|
|
|
|
name = "eucjis";
|
|
|
|
}
|
2008-04-15 22:32:28 +00:00
|
|
|
else if (uprv_strcmp(name, "646") == 0) {
|
|
|
|
/*
|
2008-08-26 20:32:18 +00:00
|
|
|
* The default codepage given by Solaris is 646 but the C library routines treat it as if it was
|
2008-04-15 22:32:28 +00:00
|
|
|
* ISO-8859-1 instead of US-ASCII(646).
|
|
|
|
*/
|
|
|
|
name = "ISO-8859-1";
|
|
|
|
}
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM_IS_DARWIN_BASED
|
2005-08-09 23:36:28 +00:00
|
|
|
if (locale == NULL && *name == 0) {
|
|
|
|
/*
|
|
|
|
No locale was specified, and an empty name was passed in.
|
|
|
|
This usually indicates that nl_langinfo didn't return valid information.
|
|
|
|
Mac OS X uses UTF-8 by default (especially the locale data and console).
|
|
|
|
*/
|
|
|
|
name = "UTF-8";
|
|
|
|
}
|
2008-08-27 19:21:22 +00:00
|
|
|
else if (uprv_strcmp(name, "CP949") == 0) {
|
|
|
|
/* Remap CP949 to a similar codepage to avoid issues with backslash and won symbol. */
|
|
|
|
name = "EUC-KR";
|
|
|
|
}
|
2009-09-11 20:41:32 +00:00
|
|
|
else if (locale != NULL && uprv_strcmp(locale, "en_US_POSIX") != 0 && uprv_strcmp(name, "US-ASCII") == 0) {
|
|
|
|
/*
|
|
|
|
* For non C/POSIX locale, default the code page to UTF-8 instead of US-ASCII.
|
|
|
|
*/
|
|
|
|
name = "UTF-8";
|
|
|
|
}
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_BSD
|
2008-08-27 19:21:22 +00:00
|
|
|
if (uprv_strcmp(name, "CP949") == 0) {
|
|
|
|
/* Remap CP949 to a similar codepage to avoid issues with backslash and won symbol. */
|
|
|
|
name = "EUC-KR";
|
|
|
|
}
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_HPUX
|
2008-01-04 17:34:02 +00:00
|
|
|
if (locale != NULL && uprv_strcmp(locale, "zh_HK") == 0 && uprv_strcmp(name, "big5") == 0) {
|
|
|
|
/* HP decided to extend big5 as hkbig5 even though it's not compatible :-( */
|
|
|
|
/* zh_TW.big5 is not the same charset as zh_HK.big5! */
|
|
|
|
name = "hkbig5";
|
|
|
|
}
|
|
|
|
else if (uprv_strcmp(name, "eucJP") == 0) {
|
2007-06-06 21:42:33 +00:00
|
|
|
/*
|
|
|
|
ibm-1350 is the best match, but unavailable.
|
|
|
|
ibm-954 is mostly a superset of ibm-1350.
|
|
|
|
ibm-33722 is the default for eucJP (similar to Windows).
|
|
|
|
*/
|
|
|
|
name = "eucjis";
|
|
|
|
}
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_LINUX
|
2007-12-04 16:36:03 +00:00
|
|
|
if (locale != NULL && uprv_strcmp(name, "euc") == 0) {
|
|
|
|
/* Linux underspecifies the "EUC" name. */
|
|
|
|
if (uprv_strcmp(locale, "korean") == 0) {
|
|
|
|
name = "EUC-KR";
|
|
|
|
}
|
|
|
|
else if (uprv_strcmp(locale, "japanese") == 0) {
|
|
|
|
/* See comment below about eucJP */
|
|
|
|
name = "eucjis";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (uprv_strcmp(name, "eucjp") == 0) {
|
2007-06-06 21:42:33 +00:00
|
|
|
/*
|
|
|
|
ibm-1350 is the best match, but unavailable.
|
|
|
|
ibm-954 is mostly a superset of ibm-1350.
|
|
|
|
ibm-33722 is the default for eucJP (similar to Windows).
|
|
|
|
*/
|
|
|
|
name = "eucjis";
|
|
|
|
}
|
2009-09-11 20:41:32 +00:00
|
|
|
else if (locale != NULL && uprv_strcmp(locale, "en_US_POSIX") != 0 &&
|
|
|
|
(uprv_strcmp(name, "ANSI_X3.4-1968") == 0 || uprv_strcmp(name, "US-ASCII") == 0)) {
|
|
|
|
/*
|
|
|
|
* For non C/POSIX locale, default the code page to UTF-8 instead of US-ASCII.
|
|
|
|
*/
|
|
|
|
name = "UTF-8";
|
|
|
|
}
|
2010-09-03 21:44:58 +00:00
|
|
|
/*
|
|
|
|
* Linux returns ANSI_X3.4-1968 for C/POSIX, but the call site takes care of
|
|
|
|
* it by falling back to 'US-ASCII' when NULL is returned from this
|
|
|
|
* function. So, we don't have to worry about it here.
|
|
|
|
*/
|
2005-08-04 20:39:34 +00:00
|
|
|
#endif
|
|
|
|
/* return NULL when "" is passed in */
|
|
|
|
if (*name == 0) {
|
|
|
|
name = NULL;
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2008-08-26 20:32:18 +00:00
|
|
|
static const char*
|
2005-08-04 20:39:34 +00:00
|
|
|
getCodepageFromPOSIXID(const char *localeName, char * buffer, int32_t buffCapacity)
|
|
|
|
{
|
|
|
|
char localeBuf[100];
|
|
|
|
const char *name = NULL;
|
2005-08-04 17:44:15 +00:00
|
|
|
char *variant = NULL;
|
|
|
|
|
|
|
|
if (localeName != NULL && (name = (uprv_strchr(localeName, '.'))) != NULL) {
|
2005-08-06 00:13:14 +00:00
|
|
|
size_t localeCapacity = uprv_min(sizeof(localeBuf), (name-localeName)+1);
|
|
|
|
uprv_strncpy(localeBuf, localeName, localeCapacity);
|
|
|
|
localeBuf[localeCapacity-1] = 0; /* ensure NULL termination */
|
2005-08-04 17:44:15 +00:00
|
|
|
name = uprv_strncpy(buffer, name+1, buffCapacity);
|
2005-08-04 20:39:34 +00:00
|
|
|
buffer[buffCapacity-1] = 0; /* ensure NULL termination */
|
2011-05-26 20:05:39 +00:00
|
|
|
if ((variant = const_cast<char *>(uprv_strchr(name, '@'))) != NULL) {
|
2005-08-04 17:44:15 +00:00
|
|
|
*variant = 0;
|
|
|
|
}
|
2005-08-04 20:39:34 +00:00
|
|
|
name = remapPlatformDependentCodepage(localeBuf, name);
|
2005-08-04 17:44:15 +00:00
|
|
|
}
|
2005-08-04 20:39:34 +00:00
|
|
|
return name;
|
2005-08-04 17:44:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
2004-02-24 00:13:01 +00:00
|
|
|
|
2008-08-26 20:32:18 +00:00
|
|
|
static const char*
|
2004-02-24 00:13:01 +00:00
|
|
|
int_getDefaultCodepage()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM == U_PF_OS400
|
2001-08-16 16:20:56 +00:00
|
|
|
uint32_t ccsid = 37; /* Default to ibm-37 */
|
2003-04-05 09:50:53 +00:00
|
|
|
static char codepage[64];
|
2001-08-16 16:20:56 +00:00
|
|
|
Qwc_JOBI0400_t jobinfo;
|
|
|
|
Qus_EC_t error = { sizeof(Qus_EC_t) }; /* SPI error code */
|
|
|
|
|
|
|
|
EPT_CALL(QUSRJOBI)(&jobinfo, sizeof(jobinfo), "JOBI0400",
|
|
|
|
"* ", " ", &error);
|
|
|
|
|
|
|
|
if (error.Bytes_Available == 0) {
|
|
|
|
if (jobinfo.Coded_Char_Set_ID != 0xFFFF) {
|
|
|
|
ccsid = (uint32_t)jobinfo.Coded_Char_Set_ID;
|
|
|
|
}
|
|
|
|
else if (jobinfo.Default_Coded_Char_Set_Id != 0xFFFF) {
|
|
|
|
ccsid = (uint32_t)jobinfo.Default_Coded_Char_Set_Id;
|
|
|
|
}
|
|
|
|
/* else use the default */
|
|
|
|
}
|
|
|
|
sprintf(codepage,"ibm-%d", ccsid);
|
|
|
|
return codepage;
|
2000-10-13 02:00:26 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_OS390
|
2003-04-05 09:50:53 +00:00
|
|
|
static char codepage[64];
|
2008-09-18 23:17:37 +00:00
|
|
|
|
|
|
|
strncpy(codepage, nl_langinfo(CODESET),63-strlen(UCNV_SWAP_LFNL_OPTION_STRING));
|
|
|
|
strcat(codepage,UCNV_SWAP_LFNL_OPTION_STRING);
|
2006-11-07 08:38:52 +00:00
|
|
|
codepage[63] = 0; /* NULL terminate */
|
2008-09-18 23:17:37 +00:00
|
|
|
|
2001-08-16 16:20:56 +00:00
|
|
|
return codepage;
|
2000-10-13 02:00:26 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM == U_PF_CLASSIC_MACOS
|
2005-07-12 06:34:30 +00:00
|
|
|
return "macintosh"; /* TODO: Macintosh Roman. There must be a better way. fixme! */
|
2000-10-13 02:00:26 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#elif U_PLATFORM_USES_ONLY_WIN32_API
|
2003-04-05 09:50:53 +00:00
|
|
|
static char codepage[64];
|
|
|
|
sprintf(codepage, "windows-%d", GetACP());
|
2001-08-16 16:20:56 +00:00
|
|
|
return codepage;
|
2000-10-13 02:00:26 +00:00
|
|
|
|
2000-07-20 04:43:47 +00:00
|
|
|
#elif U_POSIX_LOCALE
|
2000-05-02 23:25:45 +00:00
|
|
|
static char codesetName[100];
|
2000-07-11 22:44:35 +00:00
|
|
|
const char *localeName = NULL;
|
2005-08-04 17:44:15 +00:00
|
|
|
const char *name = NULL;
|
2001-08-17 21:34:07 +00:00
|
|
|
|
2010-09-04 01:01:45 +00:00
|
|
|
localeName = uprv_getPOSIXIDForDefaultCodepage();
|
2002-07-02 23:31:32 +00:00
|
|
|
uprv_memset(codesetName, 0, sizeof(codesetName));
|
2004-08-26 19:07:59 +00:00
|
|
|
#if U_HAVE_NL_LANGINFO_CODESET
|
2010-09-03 21:44:58 +00:00
|
|
|
/* When available, check nl_langinfo first because it usually gives more
|
|
|
|
useful names. It depends on LC_CTYPE.
|
2005-08-04 17:44:15 +00:00
|
|
|
nl_langinfo may use the same buffer as setlocale. */
|
2002-07-02 23:31:32 +00:00
|
|
|
{
|
2000-10-16 17:26:31 +00:00
|
|
|
const char *codeset = nl_langinfo(U_NL_LANGINFO_CODESET);
|
2011-07-23 00:10:30 +00:00
|
|
|
#if U_PLATFORM_IS_DARWIN_BASED || U_PLATFORM_IS_LINUX_BASED
|
2009-09-11 20:41:32 +00:00
|
|
|
/*
|
|
|
|
* On Linux and MacOSX, ensure that default codepage for non C/POSIX locale is UTF-8
|
|
|
|
* instead of ASCII.
|
|
|
|
*/
|
|
|
|
if (uprv_strcmp(localeName, "en_US_POSIX") != 0) {
|
|
|
|
codeset = remapPlatformDependentCodepage(localeName, codeset);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
codeset = remapPlatformDependentCodepage(NULL, codeset);
|
|
|
|
}
|
|
|
|
|
2000-10-05 19:33:35 +00:00
|
|
|
if (codeset != NULL) {
|
2002-07-02 23:31:32 +00:00
|
|
|
uprv_strncpy(codesetName, codeset, sizeof(codesetName));
|
|
|
|
codesetName[sizeof(codesetName)-1] = 0;
|
2004-08-26 19:07:59 +00:00
|
|
|
return codesetName;
|
2000-10-05 19:33:35 +00:00
|
|
|
}
|
|
|
|
}
|
2000-07-20 04:43:47 +00:00
|
|
|
#endif
|
2004-08-26 19:07:59 +00:00
|
|
|
|
2010-09-03 21:44:58 +00:00
|
|
|
/* Use setlocale in a nice way, and then check some environment variables.
|
|
|
|
Maybe the application used setlocale already.
|
|
|
|
*/
|
|
|
|
uprv_memset(codesetName, 0, sizeof(codesetName));
|
|
|
|
name = getCodepageFromPOSIXID(localeName, codesetName, sizeof(codesetName));
|
|
|
|
if (name) {
|
|
|
|
/* if we can find the codeset name from setlocale, return that. */
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2002-07-02 23:31:32 +00:00
|
|
|
if (*codesetName == 0)
|
2000-05-02 23:25:45 +00:00
|
|
|
{
|
2005-08-04 17:44:15 +00:00
|
|
|
/* Everything failed. Return US ASCII (ISO 646). */
|
2007-06-11 18:44:06 +00:00
|
|
|
(void)uprv_strcpy(codesetName, "US-ASCII");
|
2000-05-19 17:19:07 +00:00
|
|
|
}
|
2000-05-02 23:25:45 +00:00
|
|
|
return codesetName;
|
1999-12-04 00:55:54 +00:00
|
|
|
#else
|
2001-11-12 20:58:22 +00:00
|
|
|
return "US-ASCII";
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
}
|
1999-11-30 23:25:49 +00:00
|
|
|
|
2004-02-24 00:13:01 +00:00
|
|
|
|
|
|
|
U_CAPI const char* U_EXPORT2
|
|
|
|
uprv_getDefaultCodepage()
|
|
|
|
{
|
|
|
|
static char const *name = NULL;
|
|
|
|
umtx_lock(NULL);
|
|
|
|
if (name == NULL) {
|
|
|
|
name = int_getDefaultCodepage();
|
|
|
|
}
|
|
|
|
umtx_unlock(NULL);
|
|
|
|
return name;
|
|
|
|
}
|
2009-03-11 03:16:35 +00:00
|
|
|
#endif /* !U_CHARSET_IS_UTF8 */
|
2004-02-24 00:13:01 +00:00
|
|
|
|
|
|
|
|
2003-08-08 23:39:34 +00:00
|
|
|
/* end of platform-specific implementation -------------- */
|
|
|
|
|
|
|
|
/* version handling --------------------------------------------------------- */
|
2001-08-16 16:20:56 +00:00
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2000-01-14 23:56:15 +00:00
|
|
|
u_versionFromString(UVersionInfo versionArray, const char *versionString) {
|
|
|
|
char *end;
|
|
|
|
uint16_t part=0;
|
|
|
|
|
|
|
|
if(versionArray==NULL) {
|
2000-01-12 19:50:27 +00:00
|
|
|
return;
|
2000-01-11 23:20:26 +00:00
|
|
|
}
|
2000-01-14 23:56:15 +00:00
|
|
|
|
|
|
|
if(versionString!=NULL) {
|
|
|
|
for(;;) {
|
|
|
|
versionArray[part]=(uint8_t)uprv_strtoul(versionString, &end, 10);
|
2000-04-19 22:13:30 +00:00
|
|
|
if(end==versionString || ++part==U_MAX_VERSION_LENGTH || *end!=U_VERSION_DELIMITER) {
|
2000-01-14 23:56:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
versionString=end+1;
|
2000-01-11 23:20:26 +00:00
|
|
|
}
|
|
|
|
}
|
2000-01-14 23:56:15 +00:00
|
|
|
|
|
|
|
while(part<U_MAX_VERSION_LENGTH) {
|
|
|
|
versionArray[part++]=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-29 00:17:44 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
u_versionFromUString(UVersionInfo versionArray, const UChar *versionString) {
|
|
|
|
if(versionArray!=NULL && versionString!=NULL) {
|
|
|
|
char versionChars[U_MAX_VERSION_STRING_LENGTH+1];
|
|
|
|
int32_t len = u_strlen(versionString);
|
2009-02-04 19:59:43 +00:00
|
|
|
if(len>U_MAX_VERSION_STRING_LENGTH) {
|
2009-01-29 00:17:44 +00:00
|
|
|
len = U_MAX_VERSION_STRING_LENGTH;
|
|
|
|
}
|
2009-02-04 19:59:43 +00:00
|
|
|
u_UCharsToChars(versionString, versionChars, len);
|
2010-01-04 22:30:29 +00:00
|
|
|
versionChars[len]=0;
|
2009-01-29 00:17:44 +00:00
|
|
|
u_versionFromString(versionArray, versionChars);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-14 23:56:15 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2011-12-16 06:43:44 +00:00
|
|
|
u_versionToString(const UVersionInfo versionArray, char *versionString) {
|
2000-05-22 22:24:51 +00:00
|
|
|
uint16_t count, part;
|
|
|
|
uint8_t field;
|
|
|
|
|
|
|
|
if(versionString==NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(versionArray==NULL) {
|
|
|
|
versionString[0]=0;
|
2000-06-02 18:37:54 +00:00
|
|
|
return;
|
2000-05-22 22:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* count how many fields need to be written */
|
2001-10-18 22:10:59 +00:00
|
|
|
for(count=4; count>0 && versionArray[count-1]==0; --count) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if(count <= 1) {
|
|
|
|
count = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write the first part */
|
|
|
|
/* write the decimal field value */
|
|
|
|
field=versionArray[0];
|
|
|
|
if(field>=100) {
|
|
|
|
*versionString++=(char)('0'+field/100);
|
|
|
|
field%=100;
|
|
|
|
}
|
|
|
|
if(field>=10) {
|
|
|
|
*versionString++=(char)('0'+field/10);
|
|
|
|
field%=10;
|
|
|
|
}
|
|
|
|
*versionString++=(char)('0'+field);
|
|
|
|
|
|
|
|
/* write the following parts */
|
|
|
|
for(part=1; part<count; ++part) {
|
|
|
|
/* write a dot first */
|
|
|
|
*versionString++=U_VERSION_DELIMITER;
|
2000-05-22 22:24:51 +00:00
|
|
|
|
|
|
|
/* write the decimal field value */
|
2001-10-18 22:10:59 +00:00
|
|
|
field=versionArray[part];
|
2000-05-22 22:24:51 +00:00
|
|
|
if(field>=100) {
|
2000-08-10 21:45:43 +00:00
|
|
|
*versionString++=(char)('0'+field/100);
|
2000-05-22 22:24:51 +00:00
|
|
|
field%=100;
|
|
|
|
}
|
|
|
|
if(field>=10) {
|
2000-08-10 21:45:43 +00:00
|
|
|
*versionString++=(char)('0'+field/10);
|
2000-05-22 22:24:51 +00:00
|
|
|
field%=10;
|
|
|
|
}
|
2000-08-10 21:45:43 +00:00
|
|
|
*versionString++=(char)('0'+field);
|
2000-05-22 22:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NUL-terminate */
|
|
|
|
*versionString=0;
|
2000-01-14 23:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
u_getVersion(UVersionInfo versionArray) {
|
2014-01-10 02:24:54 +00:00
|
|
|
(void)copyright; // Suppress unused variable warning from clang.
|
2000-01-14 23:56:15 +00:00
|
|
|
u_versionFromString(versionArray, U_ICU_VERSION);
|
2000-01-11 23:20:26 +00:00
|
|
|
}
|
2010-01-09 02:15:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* icucfg.h dependent code
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if U_ENABLE_DYLOAD
|
|
|
|
|
2012-08-08 19:54:20 +00:00
|
|
|
#if HAVE_DLOPEN && !U_PLATFORM_USES_ONLY_WIN32_API
|
2010-01-09 02:15:20 +00:00
|
|
|
|
2011-09-29 19:22:56 +00:00
|
|
|
#if HAVE_DLFCN_H
|
2011-07-23 00:10:30 +00:00
|
|
|
|
2010-03-02 22:00:40 +00:00
|
|
|
#ifdef __MVS__
|
|
|
|
#ifndef __SUSV3
|
|
|
|
#define __SUSV3 1
|
|
|
|
#endif
|
|
|
|
#endif
|
2010-01-09 02:15:20 +00:00
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
U_INTERNAL void * U_EXPORT2
|
|
|
|
uprv_dl_open(const char *libName, UErrorCode *status) {
|
2010-10-04 23:20:15 +00:00
|
|
|
void *ret = NULL;
|
|
|
|
if(U_FAILURE(*status)) return ret;
|
|
|
|
ret = dlopen(libName, RTLD_NOW|RTLD_GLOBAL);
|
|
|
|
if(ret==NULL) {
|
2012-02-18 23:10:51 +00:00
|
|
|
#ifdef U_TRACE_DYLOAD
|
|
|
|
printf("dlerror on dlopen(%s): %s\n", libName, dlerror());
|
2010-10-04 23:20:15 +00:00
|
|
|
#endif
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
|
|
|
return ret;
|
2010-01-09 02:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_INTERNAL void U_EXPORT2
|
|
|
|
uprv_dl_close(void *lib, UErrorCode *status) {
|
2010-10-04 23:20:15 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
|
|
|
dlclose(lib);
|
2010-01-09 02:15:20 +00:00
|
|
|
}
|
|
|
|
|
2011-05-04 04:07:45 +00:00
|
|
|
U_INTERNAL UVoidFunction* U_EXPORT2
|
|
|
|
uprv_dlsym_func(void *lib, const char* sym, UErrorCode *status) {
|
2011-06-09 22:28:40 +00:00
|
|
|
union {
|
|
|
|
UVoidFunction *fp;
|
|
|
|
void *vp;
|
|
|
|
} uret;
|
|
|
|
uret.fp = NULL;
|
|
|
|
if(U_FAILURE(*status)) return uret.fp;
|
|
|
|
uret.vp = dlsym(lib, sym);
|
|
|
|
if(uret.vp == NULL) {
|
2012-02-18 23:10:51 +00:00
|
|
|
#ifdef U_TRACE_DYLOAD
|
|
|
|
printf("dlerror on dlsym(%p,%s): %s\n", lib,sym, dlerror());
|
|
|
|
#endif
|
2010-10-04 23:20:15 +00:00
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2011-06-09 22:28:40 +00:00
|
|
|
return uret.fp;
|
2010-01-09 02:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* null (nonexistent) implementation. */
|
|
|
|
|
|
|
|
U_INTERNAL void * U_EXPORT2
|
|
|
|
uprv_dl_open(const char *libName, UErrorCode *status) {
|
2010-10-04 23:20:15 +00:00
|
|
|
if(U_FAILURE(*status)) return NULL;
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return NULL;
|
2010-01-09 02:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_INTERNAL void U_EXPORT2
|
|
|
|
uprv_dl_close(void *lib, UErrorCode *status) {
|
2010-10-04 23:20:15 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return;
|
2010-01-09 02:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-04 04:07:45 +00:00
|
|
|
U_INTERNAL UVoidFunction* U_EXPORT2
|
|
|
|
uprv_dlsym_func(void *lib, const char* sym, UErrorCode *status) {
|
|
|
|
if(U_SUCCESS(*status)) {
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
}
|
|
|
|
return (UVoidFunction*)NULL;
|
2010-01-09 02:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-08-08 19:54:20 +00:00
|
|
|
#elif U_PLATFORM_USES_ONLY_WIN32_API
|
2010-01-09 02:15:20 +00:00
|
|
|
|
|
|
|
U_INTERNAL void * U_EXPORT2
|
|
|
|
uprv_dl_open(const char *libName, UErrorCode *status) {
|
2010-10-04 23:20:15 +00:00
|
|
|
HMODULE lib = NULL;
|
|
|
|
|
|
|
|
if(U_FAILURE(*status)) return NULL;
|
|
|
|
|
2011-02-17 01:03:37 +00:00
|
|
|
lib = LoadLibraryA(libName);
|
2010-10-04 23:20:15 +00:00
|
|
|
|
|
|
|
if(lib==NULL) {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (void*)lib;
|
2010-01-09 02:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_INTERNAL void U_EXPORT2
|
|
|
|
uprv_dl_close(void *lib, UErrorCode *status) {
|
2010-10-04 23:20:15 +00:00
|
|
|
HMODULE handle = (HMODULE)lib;
|
|
|
|
if(U_FAILURE(*status)) return;
|
|
|
|
|
|
|
|
FreeLibrary(handle);
|
|
|
|
|
|
|
|
return;
|
2010-01-09 02:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-04 04:07:45 +00:00
|
|
|
U_INTERNAL UVoidFunction* U_EXPORT2
|
|
|
|
uprv_dlsym_func(void *lib, const char* sym, UErrorCode *status) {
|
2010-10-04 23:20:15 +00:00
|
|
|
HMODULE handle = (HMODULE)lib;
|
2011-05-04 04:07:45 +00:00
|
|
|
UVoidFunction* addr = NULL;
|
2010-10-04 23:20:15 +00:00
|
|
|
|
|
|
|
if(U_FAILURE(*status) || lib==NULL) return NULL;
|
|
|
|
|
2011-05-04 04:07:45 +00:00
|
|
|
addr = (UVoidFunction*)GetProcAddress(handle, sym);
|
2010-10-04 23:20:15 +00:00
|
|
|
|
|
|
|
if(addr==NULL) {
|
|
|
|
DWORD lastError = GetLastError();
|
|
|
|
if(lastError == ERROR_PROC_NOT_FOUND) {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
} else {
|
|
|
|
*status = U_UNSUPPORTED_ERROR; /* other unknown error. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return addr;
|
2010-01-09 02:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* No dynamic loading set. */
|
|
|
|
|
|
|
|
U_INTERNAL void * U_EXPORT2
|
|
|
|
uprv_dl_open(const char *libName, UErrorCode *status) {
|
|
|
|
if(U_FAILURE(*status)) return NULL;
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_INTERNAL void U_EXPORT2
|
|
|
|
uprv_dl_close(void *lib, UErrorCode *status) {
|
|
|
|
if(U_FAILURE(*status)) return;
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-04 04:07:45 +00:00
|
|
|
U_INTERNAL UVoidFunction* U_EXPORT2
|
|
|
|
uprv_dlsym_func(void *lib, const char* sym, UErrorCode *status) {
|
|
|
|
if(U_SUCCESS(*status)) {
|
2010-01-09 02:15:20 +00:00
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
2011-05-04 04:07:45 +00:00
|
|
|
}
|
|
|
|
return (UVoidFunction*)NULL;
|
2010-01-09 02:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* U_ENABLE_DYLOAD */
|
|
|
|
|
2001-06-06 23:32:41 +00:00
|
|
|
/*
|
|
|
|
* Hey, Emacs, please set the following:
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
*/
|