| OLD | NEW |
| 1 /* | 1 /* |
| 2 ****************************************************************************** | 2 ****************************************************************************** |
| 3 * | 3 * |
| 4 * Copyright (C) 1997-2013, International Business Machines | 4 * Copyright (C) 1997-2014, International Business Machines |
| 5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
| 6 * | 6 * |
| 7 ****************************************************************************** | 7 ****************************************************************************** |
| 8 * | 8 * |
| 9 * FILE NAME : putil.c (previously putil.cpp and ptypes.cpp) | 9 * FILE NAME : putil.c (previously putil.cpp and ptypes.cpp) |
| 10 * | 10 * |
| 11 * Date Name Description | 11 * Date Name Description |
| 12 * 04/14/97 aliu Creation. | 12 * 04/14/97 aliu Creation. |
| 13 * 04/24/97 aliu Added getDefaultDataDirectory() and | 13 * 04/24/97 aliu Added getDefaultDataDirectory() and |
| 14 * getDefaultLocaleID(). | 14 * getDefaultLocaleID(). |
| (...skipping 30 matching lines...) Expand all Loading... |
| 45 #include "unicode/utypes.h" | 45 #include "unicode/utypes.h" |
| 46 #include "unicode/putil.h" | 46 #include "unicode/putil.h" |
| 47 #include "unicode/ustring.h" | 47 #include "unicode/ustring.h" |
| 48 #include "putilimp.h" | 48 #include "putilimp.h" |
| 49 #include "uassert.h" | 49 #include "uassert.h" |
| 50 #include "umutex.h" | 50 #include "umutex.h" |
| 51 #include "cmemory.h" | 51 #include "cmemory.h" |
| 52 #include "cstring.h" | 52 #include "cstring.h" |
| 53 #include "locmap.h" | 53 #include "locmap.h" |
| 54 #include "ucln_cmn.h" | 54 #include "ucln_cmn.h" |
| 55 #include "charstr.h" |
| 55 | 56 |
| 56 /* Include standard headers. */ | 57 /* Include standard headers. */ |
| 57 #include <stdio.h> | 58 #include <stdio.h> |
| 58 #include <stdlib.h> | 59 #include <stdlib.h> |
| 59 #include <string.h> | 60 #include <string.h> |
| 60 #include <math.h> | 61 #include <math.h> |
| 61 #include <locale.h> | 62 #include <locale.h> |
| 62 #include <float.h> | 63 #include <float.h> |
| 63 | 64 |
| 64 #ifndef U_COMMON_IMPLEMENTATION | 65 #ifndef U_COMMON_IMPLEMENTATION |
| (...skipping 15 matching lines...) Expand all Loading... |
| 80 # define NOIME | 81 # define NOIME |
| 81 # define NOMCX | 82 # define NOMCX |
| 82 # include <windows.h> | 83 # include <windows.h> |
| 83 # include "wintz.h" | 84 # include "wintz.h" |
| 84 #elif U_PLATFORM == U_PF_OS400 | 85 #elif U_PLATFORM == U_PF_OS400 |
| 85 # include <float.h> | 86 # include <float.h> |
| 86 # include <qusec.h> /* error code structure */ | 87 # include <qusec.h> /* error code structure */ |
| 87 # include <qusrjobi.h> | 88 # include <qusrjobi.h> |
| 88 # include <qliept.h> /* EPT_CALL macro - this include must be after all
other "QSYSINCs" */ | 89 # include <qliept.h> /* EPT_CALL macro - this include must be after all
other "QSYSINCs" */ |
| 89 # include <mih/testptr.h> /* For uprv_maximumPtr */ | 90 # include <mih/testptr.h> /* For uprv_maximumPtr */ |
| 90 #elif U_PLATFORM == U_PF_CLASSIC_MACOS | |
| 91 # include <Files.h> | |
| 92 # include <IntlResources.h> | |
| 93 # include <Script.h> | |
| 94 # include <Folders.h> | |
| 95 # include <MacTypes.h> | |
| 96 # include <TextUtils.h> | |
| 97 # define ICU_NO_USER_DATA_OVERRIDE 1 | |
| 98 #elif U_PLATFORM == U_PF_OS390 | 91 #elif U_PLATFORM == U_PF_OS390 |
| 99 # include "unicode/ucnv.h" /* Needed for UCNV_SWAP_LFNL_OPTION_STRING */ | 92 # include "unicode/ucnv.h" /* Needed for UCNV_SWAP_LFNL_OPTION_STRING */ |
| 100 #elif U_PLATFORM_IS_DARWIN_BASED || U_PLATFORM_IS_LINUX_BASED || U_PLATFORM == U
_PF_BSD || U_PLATFORM == U_PF_SOLARIS | 93 #elif U_PLATFORM_IS_DARWIN_BASED || U_PLATFORM_IS_LINUX_BASED || U_PLATFORM == U
_PF_BSD || U_PLATFORM == U_PF_SOLARIS |
| 101 # include <limits.h> | 94 # include <limits.h> |
| 102 # include <unistd.h> | 95 # include <unistd.h> |
| 103 # if U_PLATFORM == U_PF_SOLARIS | 96 # if U_PLATFORM == U_PF_SOLARIS |
| 104 # ifndef _XPG4_2 | 97 # ifndef _XPG4_2 |
| 105 # define _XPG4_2 | 98 # define _XPG4_2 |
| 106 # endif | 99 # endif |
| 107 # endif | 100 # endif |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 # endif | 144 # endif |
| 152 # ifndef HAVE_GETTIMEOFDAY | 145 # ifndef HAVE_GETTIMEOFDAY |
| 153 # define HAVE_GETTIMEOFDAY 1 | 146 # define HAVE_GETTIMEOFDAY 1 |
| 154 # endif | 147 # endif |
| 155 #else | 148 #else |
| 156 # define HAVE_DLFCN_H 0 | 149 # define HAVE_DLFCN_H 0 |
| 157 # define HAVE_DLOPEN 0 | 150 # define HAVE_DLOPEN 0 |
| 158 # define HAVE_GETTIMEOFDAY 0 | 151 # define HAVE_GETTIMEOFDAY 0 |
| 159 #endif | 152 #endif |
| 160 | 153 |
| 161 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) | 154 U_NAMESPACE_USE |
| 162 | 155 |
| 163 /* Define the extension for data files, again... */ | 156 /* Define the extension for data files, again... */ |
| 164 #define DATA_TYPE "dat" | 157 #define DATA_TYPE "dat" |
| 165 | 158 |
| 166 /* Leave this copyright notice here! */ | 159 /* Leave this copyright notice here! */ |
| 167 static const char copyright[] = U_COPYRIGHT_STRING; | 160 static const char copyright[] = U_COPYRIGHT_STRING; |
| 168 | 161 |
| 169 /* floating point implementations ------------------------------------------- */ | 162 /* floating point implementations ------------------------------------------- */ |
| 170 | 163 |
| 171 /* We return QNAN rather than SNAN*/ | 164 /* We return QNAN rather than SNAN*/ |
| 172 #define SIGN 0x80000000U | 165 #define SIGN 0x80000000U |
| 173 | 166 |
| 174 /* Make it easy to define certain types of constants */ | 167 /* Make it easy to define certain types of constants */ |
| 175 typedef union { | 168 typedef union { |
| 176 int64_t i64; /* This must be defined first in order to allow the initializat
ion to work. This is a C89 feature. */ | 169 int64_t i64; /* This must be defined first in order to allow the initializat
ion to work. This is a C89 feature. */ |
| 177 double d64; | 170 double d64; |
| 178 } BitPatternConversion; | 171 } BitPatternConversion; |
| 179 static const BitPatternConversion gNan = { (int64_t) INT64_C(0x7FF8000000000000)
}; | 172 static const BitPatternConversion gNan = { (int64_t) INT64_C(0x7FF8000000000000)
}; |
| 180 static const BitPatternConversion gInf = { (int64_t) INT64_C(0x7FF0000000000000)
}; | 173 static const BitPatternConversion gInf = { (int64_t) INT64_C(0x7FF0000000000000)
}; |
| 181 | 174 |
| 182 /*--------------------------------------------------------------------------- | 175 /*--------------------------------------------------------------------------- |
| 183 Platform utilities | 176 Platform utilities |
| 184 Our general strategy is to assume we're on a POSIX platform. Platforms which | 177 Our general strategy is to assume we're on a POSIX platform. Platforms which |
| 185 are non-POSIX must declare themselves so. The default POSIX implementation | 178 are non-POSIX must declare themselves so. The default POSIX implementation |
| 186 will sometimes work for non-POSIX platforms as well (e.g., the NaN-related | 179 will sometimes work for non-POSIX platforms as well (e.g., the NaN-related |
| 187 functions). | 180 functions). |
| 188 ---------------------------------------------------------------------------*/ | 181 ---------------------------------------------------------------------------*/ |
| 189 | 182 |
| 190 #if U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM == U_PF_CLASSIC_MACOS || U_PLAT
FORM == U_PF_OS400 | 183 #if U_PLATFORM_USES_ONLY_WIN32_API || U_PLATFORM == U_PF_OS400 |
| 191 # undef U_POSIX_LOCALE | 184 # undef U_POSIX_LOCALE |
| 192 #else | 185 #else |
| 193 # define U_POSIX_LOCALE 1 | 186 # define U_POSIX_LOCALE 1 |
| 194 #endif | 187 #endif |
| 195 | 188 |
| 196 /* | 189 /* |
| 197 WARNING! u_topNBytesOfDouble and u_bottomNBytesOfDouble | 190 WARNING! u_topNBytesOfDouble and u_bottomNBytesOfDouble |
| 198 can't be properly optimized by the gcc compiler sometimes (i.e. gcc 3.2). | 191 can't be properly optimized by the gcc compiler sometimes (i.e. gcc 3.2). |
| 199 */ | 192 */ |
| 200 #if !IEEE_754 | 193 #if !IEEE_754 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 return getUTCtime_fake(); /* Hook for overriding the clock */ | 292 return getUTCtime_fake(); /* Hook for overriding the clock */ |
| 300 #else | 293 #else |
| 301 return uprv_getRawUTCtime(); | 294 return uprv_getRawUTCtime(); |
| 302 #endif | 295 #endif |
| 303 } | 296 } |
| 304 | 297 |
| 305 /* Return UTC (GMT) time measured in milliseconds since 0:00 on 1/1/70.*/ | 298 /* Return UTC (GMT) time measured in milliseconds since 0:00 on 1/1/70.*/ |
| 306 U_CAPI UDate U_EXPORT2 | 299 U_CAPI UDate U_EXPORT2 |
| 307 uprv_getRawUTCtime() | 300 uprv_getRawUTCtime() |
| 308 { | 301 { |
| 309 #if U_PLATFORM == U_PF_CLASSIC_MACOS | 302 #if U_PLATFORM_USES_ONLY_WIN32_API |
| 310 time_t t, t1, t2; | |
| 311 struct tm tmrec; | |
| 312 | |
| 313 uprv_memset( &tmrec, 0, sizeof(tmrec) ); | |
| 314 tmrec.tm_year = 70; | |
| 315 tmrec.tm_mon = 0; | |
| 316 tmrec.tm_mday = 1; | |
| 317 t1 = mktime(&tmrec); /* seconds of 1/1/1970*/ | |
| 318 | |
| 319 time(&t); | |
| 320 uprv_memcpy( &tmrec, gmtime(&t), sizeof(tmrec) ); | |
| 321 t2 = mktime(&tmrec); /* seconds of current GMT*/ | |
| 322 return (UDate)(t2 - t1) * U_MILLIS_PER_SECOND; /* GMT (or UTC) in se
conds since 1970*/ | |
| 323 #elif U_PLATFORM_USES_ONLY_WIN32_API | |
| 324 | 303 |
| 325 FileTimeConversion winTime; | 304 FileTimeConversion winTime; |
| 326 GetSystemTimeAsFileTime(&winTime.fileTime); | 305 GetSystemTimeAsFileTime(&winTime.fileTime); |
| 327 return (UDate)((winTime.int64 - EPOCH_BIAS) / HECTONANOSECOND_PER_MILLISECON
D); | 306 return (UDate)((winTime.int64 - EPOCH_BIAS) / HECTONANOSECOND_PER_MILLISECON
D); |
| 328 #else | 307 #else |
| 329 | 308 |
| 330 #if HAVE_GETTIMEOFDAY | 309 #if HAVE_GETTIMEOFDAY |
| 331 struct timeval posixTime; | 310 struct timeval posixTime; |
| 332 gettimeofday(&posixTime, NULL); | 311 gettimeofday(&posixTime, NULL); |
| 333 return (UDate)(((int64_t)posixTime.tv_sec * U_MILLIS_PER_SECOND) + (posixTim
e.tv_usec/1000)); | 312 return (UDate)(((int64_t)posixTime.tv_sec * U_MILLIS_PER_SECOND) + (posixTim
e.tv_usec/1000)); |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 }; | 810 }; |
| 832 | 811 |
| 833 /*#define DEBUG_TZNAME*/ | 812 /*#define DEBUG_TZNAME*/ |
| 834 | 813 |
| 835 static const char* remapShortTimeZone(const char *stdID, const char *dstID, int3
2_t daylightType, int32_t offset) | 814 static const char* remapShortTimeZone(const char *stdID, const char *dstID, int3
2_t daylightType, int32_t offset) |
| 836 { | 815 { |
| 837 int32_t idx; | 816 int32_t idx; |
| 838 #ifdef DEBUG_TZNAME | 817 #ifdef DEBUG_TZNAME |
| 839 fprintf(stderr, "TZ=%s std=%s dst=%s daylight=%d offset=%d\n", getenv("TZ"),
stdID, dstID, daylightType, offset); | 818 fprintf(stderr, "TZ=%s std=%s dst=%s daylight=%d offset=%d\n", getenv("TZ"),
stdID, dstID, daylightType, offset); |
| 840 #endif | 819 #endif |
| 841 for (idx = 0; idx < LENGTHOF(OFFSET_ZONE_MAPPINGS); idx++) | 820 for (idx = 0; idx < UPRV_LENGTHOF(OFFSET_ZONE_MAPPINGS); idx++) |
| 842 { | 821 { |
| 843 if (offset == OFFSET_ZONE_MAPPINGS[idx].offsetSeconds | 822 if (offset == OFFSET_ZONE_MAPPINGS[idx].offsetSeconds |
| 844 && daylightType == OFFSET_ZONE_MAPPINGS[idx].daylightType | 823 && daylightType == OFFSET_ZONE_MAPPINGS[idx].daylightType |
| 845 && strcmp(OFFSET_ZONE_MAPPINGS[idx].stdID, stdID) == 0 | 824 && strcmp(OFFSET_ZONE_MAPPINGS[idx].stdID, stdID) == 0 |
| 846 && strcmp(OFFSET_ZONE_MAPPINGS[idx].dstID, dstID) == 0) | 825 && strcmp(OFFSET_ZONE_MAPPINGS[idx].dstID, dstID) == 0) |
| 847 { | 826 { |
| 848 return OFFSET_ZONE_MAPPINGS[idx].olsonID; | 827 return OFFSET_ZONE_MAPPINGS[idx].olsonID; |
| 849 } | 828 } |
| 850 } | 829 } |
| 851 return NULL; | 830 return NULL; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 | 875 |
| 897 if (sizeFile != tzInfo->defaultTZFileSize) { | 876 if (sizeFile != tzInfo->defaultTZFileSize) { |
| 898 result = FALSE; | 877 result = FALSE; |
| 899 } else { | 878 } else { |
| 900 /* Store the data from the files in seperate buffers and | 879 /* Store the data from the files in seperate buffers and |
| 901 * compare each byte to determine equality. | 880 * compare each byte to determine equality. |
| 902 */ | 881 */ |
| 903 if (tzInfo->defaultTZBuffer == NULL) { | 882 if (tzInfo->defaultTZBuffer == NULL) { |
| 904 rewind(tzInfo->defaultTZFilePtr); | 883 rewind(tzInfo->defaultTZFilePtr); |
| 905 tzInfo->defaultTZBuffer = (char*)uprv_malloc(sizeof(char) * tzIn
fo->defaultTZFileSize); | 884 tzInfo->defaultTZBuffer = (char*)uprv_malloc(sizeof(char) * tzIn
fo->defaultTZFileSize); |
| 906 sizeFileRead = fread(tzInfo->defaultTZBuffer, 1, tzInfo->default
TZFileSize, tzInfo->defaultTZFilePtr); | 885 fread(tzInfo->defaultTZBuffer, 1, tzInfo->defaultTZFileSize, tzI
nfo->defaultTZFilePtr); |
| 907 } | 886 } |
| 908 rewind(file); | 887 rewind(file); |
| 909 while(sizeFileLeft > 0) { | 888 while(sizeFileLeft > 0) { |
| 910 uprv_memset(bufferFile, 0, MAX_READ_SIZE); | 889 uprv_memset(bufferFile, 0, MAX_READ_SIZE); |
| 911 sizeFileToRead = sizeFileLeft < MAX_READ_SIZE ? sizeFileLeft : M
AX_READ_SIZE; | 890 sizeFileToRead = sizeFileLeft < MAX_READ_SIZE ? sizeFileLeft : M
AX_READ_SIZE; |
| 912 | 891 |
| 913 sizeFileRead = fread(bufferFile, 1, sizeFileToRead, file); | 892 sizeFileRead = fread(bufferFile, 1, sizeFileToRead, file); |
| 914 if (memcmp(tzInfo->defaultTZBuffer + tzInfo->defaultTZPosition,
bufferFile, sizeFileRead) != 0) { | 893 if (memcmp(tzInfo->defaultTZBuffer + tzInfo->defaultTZPosition,
bufferFile, sizeFileRead) != 0) { |
| 915 result = FALSE; | 894 result = FALSE; |
| 916 break; | 895 break; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 } | 1106 } |
| 1128 return U_TZNAME[n]; | 1107 return U_TZNAME[n]; |
| 1129 #endif | 1108 #endif |
| 1130 #else | 1109 #else |
| 1131 return ""; | 1110 return ""; |
| 1132 #endif | 1111 #endif |
| 1133 } | 1112 } |
| 1134 | 1113 |
| 1135 /* Get and set the ICU data directory --------------------------------------- */ | 1114 /* Get and set the ICU data directory --------------------------------------- */ |
| 1136 | 1115 |
| 1116 static icu::UInitOnce gDataDirInitOnce = U_INITONCE_INITIALIZER; |
| 1137 static char *gDataDirectory = NULL; | 1117 static char *gDataDirectory = NULL; |
| 1118 |
| 1119 UInitOnce gTimeZoneFilesInitOnce = U_INITONCE_INITIALIZER; |
| 1120 static CharString *gTimeZoneFilesDirectory = NULL; |
| 1121 |
| 1138 #if U_POSIX_LOCALE || U_PLATFORM_USES_ONLY_WIN32_API | 1122 #if U_POSIX_LOCALE || U_PLATFORM_USES_ONLY_WIN32_API |
| 1139 static char *gCorrectedPOSIXLocale = NULL; /* Heap allocated */ | 1123 static char *gCorrectedPOSIXLocale = NULL; /* Heap allocated */ |
| 1140 #endif | 1124 #endif |
| 1141 | 1125 |
| 1142 static UBool U_CALLCONV putil_cleanup(void) | 1126 static UBool U_CALLCONV putil_cleanup(void) |
| 1143 { | 1127 { |
| 1144 if (gDataDirectory && *gDataDirectory) { | 1128 if (gDataDirectory && *gDataDirectory) { |
| 1145 uprv_free(gDataDirectory); | 1129 uprv_free(gDataDirectory); |
| 1146 } | 1130 } |
| 1147 gDataDirectory = NULL; | 1131 gDataDirectory = NULL; |
| 1132 gDataDirInitOnce.reset(); |
| 1133 |
| 1134 delete gTimeZoneFilesDirectory; |
| 1135 gTimeZoneFilesDirectory = NULL; |
| 1136 gTimeZoneFilesInitOnce.reset(); |
| 1137 |
| 1148 #if U_POSIX_LOCALE || U_PLATFORM_USES_ONLY_WIN32_API | 1138 #if U_POSIX_LOCALE || U_PLATFORM_USES_ONLY_WIN32_API |
| 1149 if (gCorrectedPOSIXLocale) { | 1139 if (gCorrectedPOSIXLocale) { |
| 1150 uprv_free(gCorrectedPOSIXLocale); | 1140 uprv_free(gCorrectedPOSIXLocale); |
| 1151 gCorrectedPOSIXLocale = NULL; | 1141 gCorrectedPOSIXLocale = NULL; |
| 1152 } | 1142 } |
| 1153 #endif | 1143 #endif |
| 1154 return TRUE; | 1144 return TRUE; |
| 1155 } | 1145 } |
| 1156 | 1146 |
| 1157 /* | 1147 /* |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1225 } | 1215 } |
| 1226 | 1216 |
| 1227 /* Temporary backup setting of ICU_DATA_DIR_PREFIX_ENV_VAR | 1217 /* Temporary backup setting of ICU_DATA_DIR_PREFIX_ENV_VAR |
| 1228 until some client wrapper makefiles are updated */ | 1218 until some client wrapper makefiles are updated */ |
| 1229 #if U_PLATFORM_IS_DARWIN_BASED && TARGET_IPHONE_SIMULATOR | 1219 #if U_PLATFORM_IS_DARWIN_BASED && TARGET_IPHONE_SIMULATOR |
| 1230 # if !defined(ICU_DATA_DIR_PREFIX_ENV_VAR) | 1220 # if !defined(ICU_DATA_DIR_PREFIX_ENV_VAR) |
| 1231 # define ICU_DATA_DIR_PREFIX_ENV_VAR "IPHONE_SIMULATOR_ROOT" | 1221 # define ICU_DATA_DIR_PREFIX_ENV_VAR "IPHONE_SIMULATOR_ROOT" |
| 1232 # endif | 1222 # endif |
| 1233 #endif | 1223 #endif |
| 1234 | 1224 |
| 1235 U_CAPI const char * U_EXPORT2 | 1225 static void U_CALLCONV dataDirectoryInitFn() { |
| 1236 u_getDataDirectory(void) { | 1226 /* If we already have the directory, then return immediately. Will happen if
user called |
| 1227 * u_setDataDirectory(). |
| 1228 */ |
| 1229 if (gDataDirectory) { |
| 1230 return; |
| 1231 } |
| 1232 |
| 1237 const char *path = NULL; | 1233 const char *path = NULL; |
| 1238 #if defined(ICU_DATA_DIR_PREFIX_ENV_VAR) | 1234 #if defined(ICU_DATA_DIR_PREFIX_ENV_VAR) |
| 1239 char datadir_path_buffer[PATH_MAX]; | 1235 char datadir_path_buffer[PATH_MAX]; |
| 1240 #endif | 1236 #endif |
| 1241 | 1237 |
| 1242 /* if we have the directory, then return it immediately */ | |
| 1243 if(gDataDirectory) { | |
| 1244 return gDataDirectory; | |
| 1245 } | |
| 1246 | |
| 1247 /* | 1238 /* |
| 1248 When ICU_NO_USER_DATA_OVERRIDE is defined, users aren't allowed to | 1239 When ICU_NO_USER_DATA_OVERRIDE is defined, users aren't allowed to |
| 1249 override ICU's data with the ICU_DATA environment variable. This prevents | 1240 override ICU's data with the ICU_DATA environment variable. This prevents |
| 1250 problems where multiple custom copies of ICU's specific version of data | 1241 problems where multiple custom copies of ICU's specific version of data |
| 1251 are installed on a system. Either the application must define the data | 1242 are installed on a system. Either the application must define the data |
| 1252 directory with u_setDataDirectory, define ICU_DATA_DIR when compiling | 1243 directory with u_setDataDirectory, define ICU_DATA_DIR when compiling |
| 1253 ICU, set the data with udata_setCommonData or trust that all of the | 1244 ICU, set the data with udata_setCommonData or trust that all of the |
| 1254 required data is contained in ICU's data library that contains | 1245 required data is contained in ICU's data library that contains |
| 1255 the entry point defined by U_ICUDATA_ENTRY_POINT. | 1246 the entry point defined by U_ICUDATA_ENTRY_POINT. |
| 1256 | 1247 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1287 # endif | 1278 # endif |
| 1288 } | 1279 } |
| 1289 #endif | 1280 #endif |
| 1290 | 1281 |
| 1291 if(path==NULL) { | 1282 if(path==NULL) { |
| 1292 /* It looks really bad, set it to something. */ | 1283 /* It looks really bad, set it to something. */ |
| 1293 path = ""; | 1284 path = ""; |
| 1294 } | 1285 } |
| 1295 | 1286 |
| 1296 u_setDataDirectory(path); | 1287 u_setDataDirectory(path); |
| 1288 return; |
| 1289 } |
| 1290 |
| 1291 U_CAPI const char * U_EXPORT2 |
| 1292 u_getDataDirectory(void) { |
| 1293 umtx_initOnce(gDataDirInitOnce, &dataDirectoryInitFn); |
| 1297 return gDataDirectory; | 1294 return gDataDirectory; |
| 1298 } | 1295 } |
| 1299 | 1296 |
| 1297 static void setTimeZoneFilesDir(const char *path, UErrorCode &status) { |
| 1298 if (U_FAILURE(status)) { |
| 1299 return; |
| 1300 } |
| 1301 gTimeZoneFilesDirectory->clear(); |
| 1302 gTimeZoneFilesDirectory->append(path, status); |
| 1303 #if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR) |
| 1304 char *p = gTimeZoneFilesDirectory->data(); |
| 1305 while (p = uprv_strchr(p, U_FILE_ALT_SEP_CHAR)) { |
| 1306 *p = U_FILE_SEP_CHAR; |
| 1307 } |
| 1308 #endif |
| 1309 } |
| 1310 |
| 1311 #define TO_STRING(x) TO_STRING_2(x) |
| 1312 #define TO_STRING_2(x) #x |
| 1313 |
| 1314 static void U_CALLCONV TimeZoneDataDirInitFn(UErrorCode &status) { |
| 1315 U_ASSERT(gTimeZoneFilesDirectory == NULL); |
| 1316 ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup); |
| 1317 gTimeZoneFilesDirectory = new CharString(); |
| 1318 if (gTimeZoneFilesDirectory == NULL) { |
| 1319 status = U_MEMORY_ALLOCATION_ERROR; |
| 1320 return; |
| 1321 } |
| 1322 const char *dir = getenv("ICU_TIMEZONE_FILES_DIR"); |
| 1323 #if defined(U_TIMEZONE_FILES_DIR) |
| 1324 if (dir == NULL) { |
| 1325 dir = TO_STRING(U_TIMEZONE_FILES_DIR); |
| 1326 } |
| 1327 #endif |
| 1328 if (dir == NULL) { |
| 1329 dir = ""; |
| 1330 } |
| 1331 setTimeZoneFilesDir(dir, status); |
| 1332 } |
| 1300 | 1333 |
| 1301 | 1334 |
| 1335 U_CAPI const char * U_EXPORT2 |
| 1336 u_getTimeZoneFilesDirectory(UErrorCode *status) { |
| 1337 umtx_initOnce(gTimeZoneFilesInitOnce, &TimeZoneDataDirInitFn, *status); |
| 1338 return U_SUCCESS(*status) ? gTimeZoneFilesDirectory->data() : ""; |
| 1339 } |
| 1302 | 1340 |
| 1341 U_CAPI void U_EXPORT2 |
| 1342 u_setTimeZoneFilesDirectory(const char *path, UErrorCode *status) { |
| 1343 umtx_initOnce(gTimeZoneFilesInitOnce, &TimeZoneDataDirInitFn, *status); |
| 1344 setTimeZoneFilesDir(path, *status); |
| 1303 | 1345 |
| 1304 /* Macintosh-specific locale information ------------------------------------ */ | 1346 // Note: this function does some extra churn, first setting based on the |
| 1305 #if U_PLATFORM == U_PF_CLASSIC_MACOS | 1347 // environment, then immediately replacing with the value passed in. |
| 1348 // The logic is simpler that way, and performance shouldn't be an issu
e. |
| 1349 } |
| 1306 | 1350 |
| 1307 typedef struct { | |
| 1308 int32_t script; | |
| 1309 int32_t region; | |
| 1310 int32_t lang; | |
| 1311 int32_t date_region; | |
| 1312 const char* posixID; | |
| 1313 } mac_lc_rec; | |
| 1314 | |
| 1315 /* Todo: This will be updated with a newer version from www.unicode.org web | |
| 1316 page when it's available.*/ | |
| 1317 #define MAC_LC_MAGIC_NUMBER -5 | |
| 1318 #define MAC_LC_INIT_NUMBER -9 | |
| 1319 | |
| 1320 static const mac_lc_rec mac_lc_recs[] = { | |
| 1321 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 0, "en_US", | |
| 1322 /* United States*/ | |
| 1323 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 1, "fr_FR", | |
| 1324 /* France*/ | |
| 1325 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 2, "en_GB", | |
| 1326 /* Great Britain*/ | |
| 1327 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 3, "de_DE", | |
| 1328 /* Germany*/ | |
| 1329 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 4, "it_IT", | |
| 1330 /* Italy*/ | |
| 1331 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 5, "nl_NL", | |
| 1332 /* Metherlands*/ | |
| 1333 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 6, "fr_BE", | |
| 1334 /* French for Belgium or Lxembourg*/ | |
| 1335 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 7, "sv_SE", | |
| 1336 /* Sweden*/ | |
| 1337 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 9, "da_DK", | |
| 1338 /* Denmark*/ | |
| 1339 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 10, "pt_PT", | |
| 1340 /* Portugal*/ | |
| 1341 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 11, "fr_CA", | |
| 1342 /* French Canada*/ | |
| 1343 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 13, "is_IS", | |
| 1344 /* Israel*/ | |
| 1345 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 14, "ja_JP", | |
| 1346 /* Japan*/ | |
| 1347 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 15, "en_AU", | |
| 1348 /* Australia*/ | |
| 1349 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 16, "ar_AE", | |
| 1350 /* the Arabic world (?)*/ | |
| 1351 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 17, "fi_FI", | |
| 1352 /* Finland*/ | |
| 1353 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 18, "fr_CH", | |
| 1354 /* French for Switzerland*/ | |
| 1355 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 19, "de_CH", | |
| 1356 /* German for Switzerland*/ | |
| 1357 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 20, "el_GR", | |
| 1358 /* Greece*/ | |
| 1359 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 21, "is_IS", | |
| 1360 /* Iceland ===*/ | |
| 1361 /*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 22, "",*/ | |
| 1362 /* Malta ===*/ | |
| 1363 /*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 23, "",*/ | |
| 1364 /* Cyprus ===*/ | |
| 1365 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 24, "tr_TR", | |
| 1366 /* Turkey ===*/ | |
| 1367 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 25, "sh_YU", | |
| 1368 /* Croatian system for Yugoslavia*/ | |
| 1369 /*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 33, "",*/ | |
| 1370 /* Hindi system for India*/ | |
| 1371 /*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 34, "",*/ | |
| 1372 /* Pakistan*/ | |
| 1373 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 41, "lt_LT", | |
| 1374 /* Lithuania*/ | |
| 1375 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 42, "pl_PL", | |
| 1376 /* Poland*/ | |
| 1377 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 43, "hu_HU", | |
| 1378 /* Hungary*/ | |
| 1379 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 44, "et_EE", | |
| 1380 /* Estonia*/ | |
| 1381 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 45, "lv_LV", | |
| 1382 /* Latvia*/ | |
| 1383 /*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 46, "",*/ | |
| 1384 /* Lapland [Ask Rich for the data. HS]*/ | |
| 1385 /*MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 47, "",*/ | |
| 1386 /* Faeroe Islands*/ | |
| 1387 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 48, "fa_IR", | |
| 1388 /* Iran*/ | |
| 1389 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 49, "ru_RU", | |
| 1390 /* Russia*/ | |
| 1391 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 50, "en_IE", | |
| 1392 /* Ireland*/ | |
| 1393 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 51, "ko_KR", | |
| 1394 /* Korea*/ | |
| 1395 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 52, "zh_CN", | |
| 1396 /* People's Republic of China*/ | |
| 1397 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 53, "zh_TW", | |
| 1398 /* Taiwan*/ | |
| 1399 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, 54, "th_TH", | |
| 1400 /* Thailand*/ | |
| 1401 | |
| 1402 /* fallback is en_US*/ | |
| 1403 MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, MAC_LC_MAGIC_NUMBER, | |
| 1404 MAC_LC_MAGIC_NUMBER, "en_US" | |
| 1405 }; | |
| 1406 | |
| 1407 #endif | |
| 1408 | 1351 |
| 1409 #if U_POSIX_LOCALE | 1352 #if U_POSIX_LOCALE |
| 1410 /* A helper function used by uprv_getPOSIXIDForDefaultLocale and | 1353 /* A helper function used by uprv_getPOSIXIDForDefaultLocale and |
| 1411 * uprv_getPOSIXIDForDefaultCodepage. Returns the posix locale id for | 1354 * uprv_getPOSIXIDForDefaultCodepage. Returns the posix locale id for |
| 1412 * LC_CTYPE and LC_MESSAGES. It doesn't support other locale categories. | 1355 * LC_CTYPE and LC_MESSAGES. It doesn't support other locale categories. |
| 1413 */ | 1356 */ |
| 1414 static const char *uprv_getPOSIXIDForCategory(int category) | 1357 static const char *uprv_getPOSIXIDForCategory(int category) |
| 1415 { | 1358 { |
| 1416 const char* posixID = NULL; | 1359 const char* posixID = NULL; |
| 1417 if (category == LC_MESSAGES || category == LC_CTYPE) { | 1360 if (category == LC_MESSAGES || category == LC_CTYPE) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 } else { | 1577 } else { |
| 1635 uprv_free(correctedPOSIXLocale); | 1578 uprv_free(correctedPOSIXLocale); |
| 1636 } | 1579 } |
| 1637 } | 1580 } |
| 1638 | 1581 |
| 1639 if (gCorrectedPOSIXLocale == NULL) { | 1582 if (gCorrectedPOSIXLocale == NULL) { |
| 1640 return "en_US"; | 1583 return "en_US"; |
| 1641 } | 1584 } |
| 1642 return gCorrectedPOSIXLocale; | 1585 return gCorrectedPOSIXLocale; |
| 1643 | 1586 |
| 1644 #elif U_PLATFORM == U_PF_CLASSIC_MACOS | |
| 1645 int32_t script = MAC_LC_INIT_NUMBER; | |
| 1646 /* = IntlScript(); or GetScriptManagerVariable(smSysScript);*/ | |
| 1647 int32_t region = MAC_LC_INIT_NUMBER; | |
| 1648 /* = GetScriptManagerVariable(smRegionCode);*/ | |
| 1649 int32_t lang = MAC_LC_INIT_NUMBER; | |
| 1650 /* = GetScriptManagerVariable(smScriptLang);*/ | |
| 1651 int32_t date_region = MAC_LC_INIT_NUMBER; | |
| 1652 const char* posixID = 0; | |
| 1653 int32_t count = sizeof(mac_lc_recs) / sizeof(mac_lc_rec); | |
| 1654 int32_t i; | |
| 1655 Intl1Hndl ih; | |
| 1656 | |
| 1657 ih = (Intl1Hndl) GetIntlResource(1); | |
| 1658 if (ih) | |
| 1659 date_region = ((uint16_t)(*ih)->intl1Vers) >> 8; | |
| 1660 | |
| 1661 for (i = 0; i < count; i++) { | |
| 1662 if ( ((mac_lc_recs[i].script == MAC_LC_MAGIC_NUMBER) | |
| 1663 || (mac_lc_recs[i].script == script)) | |
| 1664 && ((mac_lc_recs[i].region == MAC_LC_MAGIC_NUMBER) | |
| 1665 || (mac_lc_recs[i].region == region)) | |
| 1666 && ((mac_lc_recs[i].lang == MAC_LC_MAGIC_NUMBER) | |
| 1667 || (mac_lc_recs[i].lang == lang)) | |
| 1668 && ((mac_lc_recs[i].date_region == MAC_LC_MAGIC_NUMBER) | |
| 1669 || (mac_lc_recs[i].date_region == date_region)) | |
| 1670 ) | |
| 1671 { | |
| 1672 posixID = mac_lc_recs[i].posixID; | |
| 1673 break; | |
| 1674 } | |
| 1675 } | |
| 1676 | |
| 1677 return posixID; | |
| 1678 | |
| 1679 #elif U_PLATFORM == U_PF_OS400 | 1587 #elif U_PLATFORM == U_PF_OS400 |
| 1680 /* locales are process scoped and are by definition thread safe */ | 1588 /* locales are process scoped and are by definition thread safe */ |
| 1681 static char correctedLocale[64]; | 1589 static char correctedLocale[64]; |
| 1682 const char *localeID = getenv("LC_ALL"); | 1590 const char *localeID = getenv("LC_ALL"); |
| 1683 char *p; | 1591 char *p; |
| 1684 | 1592 |
| 1685 if (localeID == NULL) | 1593 if (localeID == NULL) |
| 1686 localeID = getenv("LANG"); | 1594 localeID = getenv("LANG"); |
| 1687 if (localeID == NULL) | 1595 if (localeID == NULL) |
| 1688 localeID = setlocale(LC_ALL, NULL); | 1596 localeID = setlocale(LC_ALL, NULL); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1950 | 1858 |
| 1951 #elif U_PLATFORM == U_PF_OS390 | 1859 #elif U_PLATFORM == U_PF_OS390 |
| 1952 static char codepage[64]; | 1860 static char codepage[64]; |
| 1953 | 1861 |
| 1954 strncpy(codepage, nl_langinfo(CODESET),63-strlen(UCNV_SWAP_LFNL_OPTION_STRIN
G)); | 1862 strncpy(codepage, nl_langinfo(CODESET),63-strlen(UCNV_SWAP_LFNL_OPTION_STRIN
G)); |
| 1955 strcat(codepage,UCNV_SWAP_LFNL_OPTION_STRING); | 1863 strcat(codepage,UCNV_SWAP_LFNL_OPTION_STRING); |
| 1956 codepage[63] = 0; /* NULL terminate */ | 1864 codepage[63] = 0; /* NULL terminate */ |
| 1957 | 1865 |
| 1958 return codepage; | 1866 return codepage; |
| 1959 | 1867 |
| 1960 #elif U_PLATFORM == U_PF_CLASSIC_MACOS | |
| 1961 return "macintosh"; /* TODO: Macintosh Roman. There must be a better way. fi
xme! */ | |
| 1962 | |
| 1963 #elif U_PLATFORM_USES_ONLY_WIN32_API | 1868 #elif U_PLATFORM_USES_ONLY_WIN32_API |
| 1964 static char codepage[64]; | 1869 static char codepage[64]; |
| 1965 sprintf(codepage, "windows-%d", GetACP()); | 1870 sprintf(codepage, "windows-%d", GetACP()); |
| 1966 return codepage; | 1871 return codepage; |
| 1967 | 1872 |
| 1968 #elif U_POSIX_LOCALE | 1873 #elif U_POSIX_LOCALE |
| 1969 static char codesetName[100]; | 1874 static char codesetName[100]; |
| 1970 const char *localeName = NULL; | 1875 const char *localeName = NULL; |
| 1971 const char *name = NULL; | 1876 const char *name = NULL; |
| 1972 | 1877 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 } | 2034 } |
| 2130 *versionString++=(char)('0'+field); | 2035 *versionString++=(char)('0'+field); |
| 2131 } | 2036 } |
| 2132 | 2037 |
| 2133 /* NUL-terminate */ | 2038 /* NUL-terminate */ |
| 2134 *versionString=0; | 2039 *versionString=0; |
| 2135 } | 2040 } |
| 2136 | 2041 |
| 2137 U_CAPI void U_EXPORT2 | 2042 U_CAPI void U_EXPORT2 |
| 2138 u_getVersion(UVersionInfo versionArray) { | 2043 u_getVersion(UVersionInfo versionArray) { |
| 2044 (void)copyright; // Suppress unused variable warning from clang. |
| 2139 u_versionFromString(versionArray, U_ICU_VERSION); | 2045 u_versionFromString(versionArray, U_ICU_VERSION); |
| 2140 } | 2046 } |
| 2141 | 2047 |
| 2142 /** | 2048 /** |
| 2143 * icucfg.h dependent code | 2049 * icucfg.h dependent code |
| 2144 */ | 2050 */ |
| 2145 | 2051 |
| 2146 #if U_ENABLE_DYLOAD | 2052 #if U_ENABLE_DYLOAD |
| 2147 | 2053 |
| 2148 #if HAVE_DLOPEN && !U_PLATFORM_USES_ONLY_WIN32_API | 2054 #if HAVE_DLOPEN && !U_PLATFORM_USES_ONLY_WIN32_API |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2306 #endif /* U_ENABLE_DYLOAD */ | 2212 #endif /* U_ENABLE_DYLOAD */ |
| 2307 | 2213 |
| 2308 /* | 2214 /* |
| 2309 * Hey, Emacs, please set the following: | 2215 * Hey, Emacs, please set the following: |
| 2310 * | 2216 * |
| 2311 * Local Variables: | 2217 * Local Variables: |
| 2312 * indent-tabs-mode: nil | 2218 * indent-tabs-mode: nil |
| 2313 * End: | 2219 * End: |
| 2314 * | 2220 * |
| 2315 */ | 2221 */ |
| OLD | NEW |