1diff --git a/source/common/putil.cpp b/source/common/putil.cpp 2index ab25f3b9..d6dcd96c 100644 3--- a/source/common/putil.cpp 4+++ b/source/common/putil.cpp 5@@ -1171,31 +1171,16 @@ uprv_tzname(int n) 6 because the tzfile contents is underspecified. 7 This isn't guaranteed to work because it may not be a symlink. 8 */ 9- char *ret = realpath(TZDEFAULT, gTimeZoneBuffer); 10- if (ret != nullptr && uprv_strcmp(TZDEFAULT, gTimeZoneBuffer) != 0) { 11+ int32_t ret = (int32_t)readlink(TZDEFAULT, gTimeZoneBuffer, sizeof(gTimeZoneBuffer)-1); 12+ if (0 < ret) { 13 int32_t tzZoneInfoTailLen = uprv_strlen(TZZONEINFOTAIL); 14- const char *tzZoneInfoTailPtr = uprv_strstr(gTimeZoneBuffer, TZZONEINFOTAIL); 15- // MacOS14 has the realpath as something like 16- // /usr/share/zoneinfo.default/Australia/Melbourne 17- // which will not have "/zoneinfo/" in the path. 18- // Therefore if we fail, we fall back to read the link which is 19- // /var/db/timezone/zoneinfo/Australia/Melbourne 20- // We also fall back to reading the link if the realpath leads to something like 21- // /usr/share/zoneinfo/posixrules 22- if (tzZoneInfoTailPtr == nullptr || 23- uprv_strcmp(tzZoneInfoTailPtr + tzZoneInfoTailLen, "posixrules") == 0) { 24- ssize_t size = readlink(TZDEFAULT, gTimeZoneBuffer, sizeof(gTimeZoneBuffer)-1); 25- if (size > 0) { 26- gTimeZoneBuffer[size] = 0; 27- tzZoneInfoTailPtr = uprv_strstr(gTimeZoneBuffer, TZZONEINFOTAIL); 28- } 29- } 30- if (tzZoneInfoTailPtr != nullptr) { 31- tzZoneInfoTailPtr += tzZoneInfoTailLen; 32- skipZoneIDPrefix(&tzZoneInfoTailPtr); 33- if (isValidOlsonID(tzZoneInfoTailPtr)) { 34- return (gTimeZoneBufferPtr = tzZoneInfoTailPtr); 35- } 36+ gTimeZoneBuffer[ret] = 0; 37+ char * tzZoneInfoTailPtr = uprv_strstr(gTimeZoneBuffer, TZZONEINFOTAIL); 38+ 39+ if (tzZoneInfoTailPtr != NULL 40+ && isValidOlsonID(tzZoneInfoTailPtr + tzZoneInfoTailLen)) 41+ { 42+ return (gTimeZoneBufferPtr = tzZoneInfoTailPtr + tzZoneInfoTailLen); 43 } 44 } else { 45 #if defined(SEARCH_TZFILE) 46diff --git a/source/common/uposixdefs.h b/source/common/uposixdefs.h 47index 7c008fdd..3770a335 100644 48--- a/source/common/uposixdefs.h 49+++ b/source/common/uposixdefs.h 50@@ -48,7 +48,7 @@ 51 #endif 52 53 /* 54- * Make sure things like realpath and such functions work. 55+ * Make sure things like readlink and such functions work. 56 * Poorly upgraded Solaris machines can't have this defined. 57 * Cleanly installed Solaris can use this #define. 58 * 59