* This function is not thread safe - it uses a global, gSearchTZFileResult, to hold its results.
*/
static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) {
- DIR* dirp = opendir(path);
- DIR* subDirp = NULL;
+ DIR* dirp = NULL;
struct dirent* dirEntry = NULL;
-
char* result = NULL;
+ UErrorCode status = U_ZERO_ERROR;
+
+ /* Save the current path */
+ CharString curpath(path, -1, status);
+ if (U_FAILURE(status)) {
+ goto cleanupAndReturn;
+ }
+
+ dirp = opendir(path);
if (dirp == NULL) {
- return result;
+ goto cleanupAndReturn;
}
if (gSearchTZFileResult == NULL) {
gSearchTZFileResult = new CharString;
if (gSearchTZFileResult == NULL) {
- return NULL;
+ goto cleanupAndReturn;
}
ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup);
}
- /* Save the current path */
- UErrorCode status = U_ZERO_ERROR;
- CharString curpath(path, -1, status);
- if (U_FAILURE(status)) {
- return NULL;
- }
-
/* Check each entry in the directory. */
while((dirEntry = readdir(dirp)) != NULL) {
const char* dirName = dirEntry->d_name;
CharString newpath(curpath, status);
newpath.append(dirName, -1, status);
if (U_FAILURE(status)) {
- return NULL;
+ break;
}
+ DIR* subDirp = NULL;
if ((subDirp = opendir(newpath.data())) != NULL) {
/* If this new path is a directory, make a recursive call with the newpath. */
closedir(subDirp);
newpath.append('/', status);
if (U_FAILURE(status)) {
- return NULL;
+ break;
}
result = searchForTZFile(newpath.data(), tzInfo);
/*
gSearchTZFileResult->clear();
gSearchTZFileResult->append(zoneid, -1, status);
if (U_FAILURE(status)) {
- return NULL;
+ break;
}
result = gSearchTZFileResult->data();
/* Get out after the first one found. */
}
}
}
- closedir(dirp);
+
+ cleanupAndReturn:
+ if (dirp) {
+ closedir(dirp);
+ }
return result;
}
#endif
}
}
} else {
- UVector *customProps = NULL;
+ UnicodeString icutzprop;
+ UVector customProps(nullptr, uhash_compareUnicodeString, status);
if (olsonzid.length() > 0 && icutzver.length() > 0) {
- customProps = new UVector(uprv_deleteUObject, uhash_compareUnicodeString, status);
- if (U_FAILURE(status)) {
- return;
- }
- UnicodeString *icutzprop = new UnicodeString(ICU_TZINFO_PROP);
- icutzprop->append(olsonzid);
- icutzprop->append((UChar)0x005B/*'['*/);
- icutzprop->append(icutzver);
- icutzprop->append((UChar)0x005D/*']'*/);
- customProps->addElement(icutzprop, status);
- if (U_FAILURE(status)) {
- delete icutzprop;
- delete customProps;
- return;
- }
+ icutzprop.append(olsonzid);
+ icutzprop.append(u'[');
+ icutzprop.append(icutzver);
+ icutzprop.append(u']');
+ customProps.addElement(&icutzprop, status);
}
- writeZone(writer, *tz, customProps, status);
- delete customProps;
+ writeZone(writer, *tz, &customProps, status);
}
}