From ec7db090855b26969333e1e22316d85f2ce1f74a Mon Sep 17 00:00:00 2001 From: Jaak Ristioja Date: Fri, 28 Apr 2017 16:10:50 +0300 Subject: [PATCH] Use system_error instead of strerror_r: * Addresses portability issues. --- tz.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tz.cpp b/tz.cpp index 1fb4ae4..7162041 100644 --- a/tz.cpp +++ b/tz.cpp @@ -2939,23 +2939,17 @@ current_zone() CONSTDATA auto timezone = "/etc/localtime"; if (lstat(timezone, &sb) == 0 && S_ISLNK(sb.st_mode) && sb.st_size > 0) { - std::string result; + using namespace std; + string result; char rp[PATH_MAX]; if (realpath(timezone, rp)) - result = std::string(rp); + result = string(rp); else - { - std::ostringstream os; - char message[128]; - if (strerror_r(errno, message, sizeof(message)) != 0) - message[0] = '\0'; - os << "realpath failure: errno = " << errno << "; " << message; - throw std::runtime_error(os.str()); - } + throw system_error(errno, system_category(), "realpath() failed"); const char zonepath[] = "/usr/share/zoneinfo/"; - const std::size_t zonepath_len = sizeof(zonepath)/sizeof(zonepath[0])-1; - const std::size_t pos = result.find(zonepath); + const size_t zonepath_len = sizeof(zonepath)/sizeof(zonepath[0])-1; + const size_t pos = result.find(zonepath); if (pos != result.npos) result.erase(0, zonepath_len+pos); return locate_zone(result);