| OLD | NEW |
| (Empty) | |
| 1 diff --git a/source/common/putil.cpp b/source/common/putil.cpp |
| 2 index c87b60e..9b8e184 100644 |
| 3 --- a/source/common/putil.cpp |
| 4 +++ b/source/common/putil.cpp |
| 5 @@ -832,7 +832,6 @@ static const char* remapShortTimeZone(const char *stdID, con
st char *dstID, int3 |
| 6 #endif |
| 7 |
| 8 #ifdef SEARCH_TZFILE |
| 9 -#define MAX_PATH_SIZE PATH_MAX /* Set the limit for the size of the path. */ |
| 10 #define MAX_READ_SIZE 512 |
| 11 |
| 12 typedef struct DefaultTZInfo { |
| 13 @@ -908,15 +907,19 @@ static UBool compareBinaryFiles(const char* defaultTZFileN
ame, const char* TZFil |
| 14 |
| 15 return result; |
| 16 } |
| 17 -/* |
| 18 - * This method recursively traverses the directory given for a matching TZ file
and returns the first match. |
| 19 - */ |
| 20 + |
| 21 + |
| 22 /* dirent also lists two entries: "." and ".." that we can safely ignore. */ |
| 23 #define SKIP1 "." |
| 24 #define SKIP2 ".." |
| 25 -static char SEARCH_TZFILE_RESULT[MAX_PATH_SIZE] = ""; |
| 26 +static UBool U_CALLCONV putil_cleanup(void); |
| 27 +static CharString *gSearchTZFileResult = NULL; |
| 28 + |
| 29 +/* |
| 30 + * This method recursively traverses the directory given for a matching TZ file
and returns the first match. |
| 31 + * This function is not thread safe - it uses a global, gSearchTZFileResult, to
hold its results. |
| 32 + */ |
| 33 static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) { |
| 34 - char curpath[MAX_PATH_SIZE]; |
| 35 DIR* dirp = opendir(path); |
| 36 DIR* subDirp = NULL; |
| 37 struct dirent* dirEntry = NULL; |
| 38 @@ -926,24 +929,40 @@ static char* searchForTZFile(const char* path, DefaultTZIn
fo* tzInfo) { |
| 39 return result; |
| 40 } |
| 41 |
| 42 + if (gSearchTZFileResult == NULL) { |
| 43 + gSearchTZFileResult = new CharString; |
| 44 + if (gSearchTZFileResult == NULL) { |
| 45 + return NULL; |
| 46 + } |
| 47 + ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup); |
| 48 + } |
| 49 + |
| 50 /* Save the current path */ |
| 51 - uprv_memset(curpath, 0, MAX_PATH_SIZE); |
| 52 - uprv_strcpy(curpath, path); |
| 53 + UErrorCode status = U_ZERO_ERROR; |
| 54 + CharString curpath(path, -1, status); |
| 55 + if (U_FAILURE(status)) { |
| 56 + return NULL; |
| 57 + } |
| 58 |
| 59 /* Check each entry in the directory. */ |
| 60 while((dirEntry = readdir(dirp)) != NULL) { |
| 61 const char* dirName = dirEntry->d_name; |
| 62 if (uprv_strcmp(dirName, SKIP1) != 0 && uprv_strcmp(dirName, SKIP2) !=
0) { |
| 63 /* Create a newpath with the new entry to test each entry in the di
rectory. */ |
| 64 - char newpath[MAX_PATH_SIZE]; |
| 65 - uprv_strcpy(newpath, curpath); |
| 66 - uprv_strcat(newpath, dirName); |
| 67 + CharString newpath(curpath, status); |
| 68 + newpath.append(dirName, -1, status); |
| 69 + if (U_FAILURE(status)) { |
| 70 + return NULL; |
| 71 + } |
| 72 |
| 73 - if ((subDirp = opendir(newpath)) != NULL) { |
| 74 + if ((subDirp = opendir(newpath.data())) != NULL) { |
| 75 /* If this new path is a directory, make a recursive call with
the newpath. */ |
| 76 closedir(subDirp); |
| 77 - uprv_strcat(newpath, "/"); |
| 78 - result = searchForTZFile(newpath, tzInfo); |
| 79 + newpath.append('/', status); |
| 80 + if (U_FAILURE(status)) { |
| 81 + return NULL; |
| 82 + } |
| 83 + result = searchForTZFile(newpath.data(), tzInfo); |
| 84 /* |
| 85 Have to get out here. Otherwise, we'd keep looking |
| 86 and return the first match in the top-level directory |
| 87 @@ -955,11 +974,19 @@ static char* searchForTZFile(const char* path, DefaultTZIn
fo* tzInfo) { |
| 88 if (result != NULL) |
| 89 break; |
| 90 } else if (uprv_strcmp(TZFILE_SKIP, dirName) != 0 && uprv_strcmp(TZ
FILE_SKIP2, dirName) != 0) { |
| 91 - if(compareBinaryFiles(TZDEFAULT, newpath, tzInfo)) { |
| 92 - const char* zoneid = newpath + (sizeof(TZZONEINFO)) - 1; |
| 93 + if(compareBinaryFiles(TZDEFAULT, newpath.data(), tzInfo)) { |
| 94 + int32_t amountToSkip = sizeof(TZZONEINFO) - 1; |
| 95 + if (amountToSkip > newpath.length()) { |
| 96 + amountToSkip = newpath.length(); |
| 97 + } |
| 98 + const char* zoneid = newpath.data() + amountToSkip; |
| 99 skipZoneIDPrefix(&zoneid); |
| 100 - uprv_strcpy(SEARCH_TZFILE_RESULT, zoneid); |
| 101 - result = SEARCH_TZFILE_RESULT; |
| 102 + gSearchTZFileResult->clear(); |
| 103 + gSearchTZFileResult->append(zoneid, -1, status); |
| 104 + if (U_FAILURE(status)) { |
| 105 + return NULL; |
| 106 + } |
| 107 + result = gSearchTZFileResult->data(); |
| 108 /* Get out after the first one found. */ |
| 109 break; |
| 110 } |
| 111 @@ -1144,6 +1171,11 @@ static UBool U_CALLCONV putil_cleanup(void) |
| 112 gTimeZoneFilesDirectory = NULL; |
| 113 gTimeZoneFilesInitOnce.reset(); |
| 114 |
| 115 +#ifdef SEARCH_TZFILE |
| 116 + delete gSearchTZFileResult; |
| 117 + gSearchTZFileResult = NULL; |
| 118 +#endif |
| 119 + |
| 120 #if U_POSIX_LOCALE || U_PLATFORM_USES_ONLY_WIN32_API |
| 121 if (gCorrectedPOSIXLocale) { |
| 122 uprv_free(gCorrectedPOSIXLocale); |
| 123 diff --git a/source/tools/toolutil/filetools.cpp b/source/tools/toolutil/filetoo
ls.cpp |
| 124 index 238ef7b..9b61c87 100644 |
| 125 --- a/source/tools/toolutil/filetools.cpp |
| 126 +++ b/source/tools/toolutil/filetools.cpp |
| 127 @@ -4,6 +4,7 @@ |
| 128 ******************************************************************************
* |
| 129 */ |
| 130 |
| 131 +#include "unicode/platform.h" |
| 132 #if U_PLATFORM == U_PF_MINGW |
| 133 // *cough* - for struct stat |
| 134 #ifdef __STRICT_ANSI__ |
| 135 @@ -13,6 +14,7 @@ |
| 136 |
| 137 #include "filetools.h" |
| 138 #include "filestrm.h" |
| 139 +#include "charstr.h" |
| 140 #include "cstring.h" |
| 141 #include "unicode/putil.h" |
| 142 #include "putilimp.h" |
| 143 @@ -27,8 +29,6 @@ |
| 144 #include <dirent.h> |
| 145 typedef struct dirent DIRENT; |
| 146 |
| 147 -#define MAX_PATH_SIZE 4096 /* Set the limit for the size of the path. */ |
| 148 - |
| 149 #define SKIP1 "." |
| 150 #define SKIP2 ".." |
| 151 #endif |
| 152 @@ -56,20 +56,24 @@ isFileModTimeLater(const char *filePath, const char *checkAg
ainst, UBool isDir) |
| 153 |
| 154 while ((dirEntry = readdir(pDir)) != NULL) { |
| 155 if (uprv_strcmp(dirEntry->d_name, SKIP1) != 0 && uprv_strcmp(di
rEntry->d_name, SKIP2) != 0) { |
| 156 - char newpath[MAX_PATH_SIZE] = ""; |
| 157 - uprv_strcpy(newpath, checkAgainst); |
| 158 - uprv_strcat(newpath, U_FILE_SEP_STRING); |
| 159 - uprv_strcat(newpath, dirEntry->d_name); |
| 160 - |
| 161 - if ((subDirp = opendir(newpath)) != NULL) { |
| 162 + UErrorCode status = U_ZERO_ERROR; |
| 163 + icu::CharString newpath(checkAgainst, -1, status); |
| 164 + newpath.append(U_FILE_SEP_STRING, -1, status); |
| 165 + newpath.append(dirEntry->d_name, -1, status); |
| 166 + if (U_FAILURE(status)) { |
| 167 + fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, u_er
rorName(status)); |
| 168 + return FALSE; |
| 169 + }; |
| 170 + |
| 171 + if ((subDirp = opendir(newpath.data())) != NULL) { |
| 172 /* If this new path is a directory, make a recursive ca
ll with the newpath. */ |
| 173 closedir(subDirp); |
| 174 - isLatest = isFileModTimeLater(filePath, newpath, isDir)
; |
| 175 + isLatest = isFileModTimeLater(filePath, newpath.data(),
isDir); |
| 176 if (!isLatest) { |
| 177 break; |
| 178 } |
| 179 } else { |
| 180 - int32_t latest = whichFileModTimeIsLater(filePath, newp
ath); |
| 181 + int32_t latest = whichFileModTimeIsLater(filePath, newp
ath.data()); |
| 182 if (latest < 0 || latest == 2) { |
| 183 isLatest = FALSE; |
| 184 break; |
| OLD | NEW |