| OLD | NEW |
| 1 /* | 1 /* |
| 2 ****************************************************************************** | 2 ****************************************************************************** |
| 3 * | 3 * |
| 4 * Copyright (C) 1997-2014, 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 * |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 && strcmp(OFFSET_ZONE_MAPPINGS[idx].dstID, dstID) == 0) | 825 && strcmp(OFFSET_ZONE_MAPPINGS[idx].dstID, dstID) == 0) |
| 826 { | 826 { |
| 827 return OFFSET_ZONE_MAPPINGS[idx].olsonID; | 827 return OFFSET_ZONE_MAPPINGS[idx].olsonID; |
| 828 } | 828 } |
| 829 } | 829 } |
| 830 return NULL; | 830 return NULL; |
| 831 } | 831 } |
| 832 #endif | 832 #endif |
| 833 | 833 |
| 834 #ifdef SEARCH_TZFILE | 834 #ifdef SEARCH_TZFILE |
| 835 #define MAX_PATH_SIZE PATH_MAX /* Set the limit for the size of the path. */ | |
| 836 #define MAX_READ_SIZE 512 | 835 #define MAX_READ_SIZE 512 |
| 837 | 836 |
| 838 typedef struct DefaultTZInfo { | 837 typedef struct DefaultTZInfo { |
| 839 char* defaultTZBuffer; | 838 char* defaultTZBuffer; |
| 840 int64_t defaultTZFileSize; | 839 int64_t defaultTZFileSize; |
| 841 FILE* defaultTZFilePtr; | 840 FILE* defaultTZFilePtr; |
| 842 UBool defaultTZstatus; | 841 UBool defaultTZstatus; |
| 843 int32_t defaultTZPosition; | 842 int32_t defaultTZPosition; |
| 844 } DefaultTZInfo; | 843 } DefaultTZInfo; |
| 845 | 844 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 } else { | 900 } else { |
| 902 result = FALSE; | 901 result = FALSE; |
| 903 } | 902 } |
| 904 | 903 |
| 905 if (file != NULL) { | 904 if (file != NULL) { |
| 906 fclose(file); | 905 fclose(file); |
| 907 } | 906 } |
| 908 | 907 |
| 909 return result; | 908 return result; |
| 910 } | 909 } |
| 911 /* | 910 |
| 912 * This method recursively traverses the directory given for a matching TZ file
and returns the first match. | 911 |
| 913 */ | |
| 914 /* dirent also lists two entries: "." and ".." that we can safely ignore. */ | 912 /* dirent also lists two entries: "." and ".." that we can safely ignore. */ |
| 915 #define SKIP1 "." | 913 #define SKIP1 "." |
| 916 #define SKIP2 ".." | 914 #define SKIP2 ".." |
| 917 static char SEARCH_TZFILE_RESULT[MAX_PATH_SIZE] = ""; | 915 static UBool U_CALLCONV putil_cleanup(void); |
| 916 static CharString *gSearchTZFileResult = NULL; |
| 917 |
| 918 /* |
| 919 * This method recursively traverses the directory given for a matching TZ file
and returns the first match. |
| 920 * This function is not thread safe - it uses a global, gSearchTZFileResult, to
hold its results. |
| 921 */ |
| 918 static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) { | 922 static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) { |
| 919 char curpath[MAX_PATH_SIZE]; | |
| 920 DIR* dirp = opendir(path); | 923 DIR* dirp = opendir(path); |
| 921 DIR* subDirp = NULL; | 924 DIR* subDirp = NULL; |
| 922 struct dirent* dirEntry = NULL; | 925 struct dirent* dirEntry = NULL; |
| 923 | 926 |
| 924 char* result = NULL; | 927 char* result = NULL; |
| 925 if (dirp == NULL) { | 928 if (dirp == NULL) { |
| 926 return result; | 929 return result; |
| 927 } | 930 } |
| 928 | 931 |
| 932 if (gSearchTZFileResult == NULL) { |
| 933 gSearchTZFileResult = new CharString; |
| 934 if (gSearchTZFileResult == NULL) { |
| 935 return NULL; |
| 936 } |
| 937 ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup); |
| 938 } |
| 939 |
| 929 /* Save the current path */ | 940 /* Save the current path */ |
| 930 uprv_memset(curpath, 0, MAX_PATH_SIZE); | 941 UErrorCode status = U_ZERO_ERROR; |
| 931 uprv_strcpy(curpath, path); | 942 CharString curpath(path, -1, status); |
| 943 if (U_FAILURE(status)) { |
| 944 return NULL; |
| 945 } |
| 932 | 946 |
| 933 /* Check each entry in the directory. */ | 947 /* Check each entry in the directory. */ |
| 934 while((dirEntry = readdir(dirp)) != NULL) { | 948 while((dirEntry = readdir(dirp)) != NULL) { |
| 935 const char* dirName = dirEntry->d_name; | 949 const char* dirName = dirEntry->d_name; |
| 936 if (uprv_strcmp(dirName, SKIP1) != 0 && uprv_strcmp(dirName, SKIP2) != 0
) { | 950 if (uprv_strcmp(dirName, SKIP1) != 0 && uprv_strcmp(dirName, SKIP2) != 0
) { |
| 937 /* Create a newpath with the new entry to test each entry in the dir
ectory. */ | 951 /* Create a newpath with the new entry to test each entry in the dir
ectory. */ |
| 938 char newpath[MAX_PATH_SIZE]; | 952 CharString newpath(curpath, status); |
| 939 uprv_strcpy(newpath, curpath); | 953 newpath.append(dirName, -1, status); |
| 940 uprv_strcat(newpath, dirName); | 954 if (U_FAILURE(status)) { |
| 955 return NULL; |
| 956 } |
| 941 | 957 |
| 942 if ((subDirp = opendir(newpath)) != NULL) { | 958 if ((subDirp = opendir(newpath.data())) != NULL) { |
| 943 /* If this new path is a directory, make a recursive call with t
he newpath. */ | 959 /* If this new path is a directory, make a recursive call with t
he newpath. */ |
| 944 closedir(subDirp); | 960 closedir(subDirp); |
| 945 uprv_strcat(newpath, "/"); | 961 newpath.append('/', status); |
| 946 result = searchForTZFile(newpath, tzInfo); | 962 if (U_FAILURE(status)) { |
| 963 return NULL; |
| 964 } |
| 965 result = searchForTZFile(newpath.data(), tzInfo); |
| 947 /* | 966 /* |
| 948 Have to get out here. Otherwise, we'd keep looking | 967 Have to get out here. Otherwise, we'd keep looking |
| 949 and return the first match in the top-level directory | 968 and return the first match in the top-level directory |
| 950 if there's a match in the top-level. If not, this function | 969 if there's a match in the top-level. If not, this function |
| 951 would return NULL and set gTimeZoneBufferPtr to NULL in initDef
ault(). | 970 would return NULL and set gTimeZoneBufferPtr to NULL in initDef
ault(). |
| 952 It worked without this in most cases because we have a fallback
of calling | 971 It worked without this in most cases because we have a fallback
of calling |
| 953 localtime_r to figure out the default timezone. | 972 localtime_r to figure out the default timezone. |
| 954 */ | 973 */ |
| 955 if (result != NULL) | 974 if (result != NULL) |
| 956 break; | 975 break; |
| 957 } else if (uprv_strcmp(TZFILE_SKIP, dirName) != 0 && uprv_strcmp(TZF
ILE_SKIP2, dirName) != 0) { | 976 } else if (uprv_strcmp(TZFILE_SKIP, dirName) != 0 && uprv_strcmp(TZF
ILE_SKIP2, dirName) != 0) { |
| 958 if(compareBinaryFiles(TZDEFAULT, newpath, tzInfo)) { | 977 if(compareBinaryFiles(TZDEFAULT, newpath.data(), tzInfo)) { |
| 959 const char* zoneid = newpath + (sizeof(TZZONEINFO)) - 1; | 978 int32_t amountToSkip = sizeof(TZZONEINFO) - 1; |
| 979 if (amountToSkip > newpath.length()) { |
| 980 amountToSkip = newpath.length(); |
| 981 } |
| 982 const char* zoneid = newpath.data() + amountToSkip; |
| 960 skipZoneIDPrefix(&zoneid); | 983 skipZoneIDPrefix(&zoneid); |
| 961 uprv_strcpy(SEARCH_TZFILE_RESULT, zoneid); | 984 gSearchTZFileResult->clear(); |
| 962 result = SEARCH_TZFILE_RESULT; | 985 gSearchTZFileResult->append(zoneid, -1, status); |
| 986 if (U_FAILURE(status)) { |
| 987 return NULL; |
| 988 } |
| 989 result = gSearchTZFileResult->data(); |
| 963 /* Get out after the first one found. */ | 990 /* Get out after the first one found. */ |
| 964 break; | 991 break; |
| 965 } | 992 } |
| 966 } | 993 } |
| 967 } | 994 } |
| 968 } | 995 } |
| 969 closedir(dirp); | 996 closedir(dirp); |
| 970 return result; | 997 return result; |
| 971 } | 998 } |
| 972 #endif | 999 #endif |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 if (gDataDirectory && *gDataDirectory) { | 1164 if (gDataDirectory && *gDataDirectory) { |
| 1138 uprv_free(gDataDirectory); | 1165 uprv_free(gDataDirectory); |
| 1139 } | 1166 } |
| 1140 gDataDirectory = NULL; | 1167 gDataDirectory = NULL; |
| 1141 gDataDirInitOnce.reset(); | 1168 gDataDirInitOnce.reset(); |
| 1142 | 1169 |
| 1143 delete gTimeZoneFilesDirectory; | 1170 delete gTimeZoneFilesDirectory; |
| 1144 gTimeZoneFilesDirectory = NULL; | 1171 gTimeZoneFilesDirectory = NULL; |
| 1145 gTimeZoneFilesInitOnce.reset(); | 1172 gTimeZoneFilesInitOnce.reset(); |
| 1146 | 1173 |
| 1174 #ifdef SEARCH_TZFILE |
| 1175 delete gSearchTZFileResult; |
| 1176 gSearchTZFileResult = NULL; |
| 1177 #endif |
| 1178 |
| 1147 #if U_POSIX_LOCALE || U_PLATFORM_USES_ONLY_WIN32_API | 1179 #if U_POSIX_LOCALE || U_PLATFORM_USES_ONLY_WIN32_API |
| 1148 if (gCorrectedPOSIXLocale) { | 1180 if (gCorrectedPOSIXLocale) { |
| 1149 uprv_free(gCorrectedPOSIXLocale); | 1181 uprv_free(gCorrectedPOSIXLocale); |
| 1150 gCorrectedPOSIXLocale = NULL; | 1182 gCorrectedPOSIXLocale = NULL; |
| 1151 } | 1183 } |
| 1152 #endif | 1184 #endif |
| 1153 return TRUE; | 1185 return TRUE; |
| 1154 } | 1186 } |
| 1155 | 1187 |
| 1156 /* | 1188 /* |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2221 #endif /* U_ENABLE_DYLOAD */ | 2253 #endif /* U_ENABLE_DYLOAD */ |
| 2222 | 2254 |
| 2223 /* | 2255 /* |
| 2224 * Hey, Emacs, please set the following: | 2256 * Hey, Emacs, please set the following: |
| 2225 * | 2257 * |
| 2226 * Local Variables: | 2258 * Local Variables: |
| 2227 * indent-tabs-mode: nil | 2259 * indent-tabs-mode: nil |
| 2228 * End: | 2260 * End: |
| 2229 * | 2261 * |
| 2230 */ | 2262 */ |
| OLD | NEW |