diff --git a/fdbclient/BackupContainer.actor.cpp b/fdbclient/BackupContainer.actor.cpp index a9976e8c27..7620fee40e 100644 --- a/fdbclient/BackupContainer.actor.cpp +++ b/fdbclient/BackupContainer.actor.cpp @@ -33,12 +33,6 @@ #include #include -#ifdef _WIN32 - #define localtime_safe(t, out) if(localtime_s(out, t) != 0) throw platform_error; -#else - #define localtime_safe(t, out) localtime_r(t, out) -#endif - namespace IBackupFile_impl { ACTOR Future appendStringRefWithLen(Reference file, Standalone s) { @@ -85,7 +79,7 @@ std::string formatTime(int64_t t) { time_t curTime = (time_t)t; char buffer[128]; struct tm timeinfo; - localtime_safe(&curTime, &timeinfo); + getLocalTime(&curTime, &timeinfo); strftime(buffer, 128, "%Y-%m-%d %H:%M:%S", &timeinfo); return buffer; } @@ -809,7 +803,7 @@ public: static std::string getURLFormat() { return "file://"; } - BackupContainerLocalDirectory(std::string url) { + BackupContainerLocalDirectory(std::string url) { std::string path; if(url.find("file://") != 0) { TraceEvent(SevWarn, "BackupContainerLocalDirectory").detail("Description", "Invalid URL for BackupContainerLocalDirectory").detail("URL", url); diff --git a/flow/Platform.cpp b/flow/Platform.cpp index 37bb428f18..5eeb7ecaf1 100644 --- a/flow/Platform.cpp +++ b/flow/Platform.cpp @@ -1345,6 +1345,22 @@ uint64_t timer_int() { #endif }; +void getLocalTime(const time_t *timep, struct tm *result) { +#ifdef _WIN32 + if(localtime_s(result, timep) != 0) { + TraceEvent(SevError, "GetLocalTimeError").GetLastError(); + throw platform_error; + } +#elif defined(__unixish__) + if(localtime_r(timep, result) == NULL) { + TraceEvent(SevError, "GetLocalTimeError").GetLastError(); + throw platform_error; + } +#else +#error Port me! +#endif +} + void setMemoryQuota( size_t limit ) { INJECT_FAULT( platform_error, "setMemoryQuota" ); #if defined(_WIN32) diff --git a/flow/Platform.h b/flow/Platform.h index f0d3231e1a..938384bffc 100644 --- a/flow/Platform.h +++ b/flow/Platform.h @@ -270,6 +270,8 @@ double timer(); // Returns the system real time clock with high precision. May double timer_monotonic(); // Returns a high precision monotonic clock which is adjusted to be kind of similar to timer() at startup, but might not be a globally accurate time. uint64_t timer_int(); // Return timer as uint64_t +void getLocalTime(const time_t *timep, struct tm *result); + void setMemoryQuota(size_t limit); void *allocate(size_t length, bool allowLargePages);