Extract getLocalTime to platform.cpp
This commit is contained in:
parent
a6fc30209e
commit
4bfbdbf454
|
@ -33,12 +33,6 @@
|
|||
#include <algorithm>
|
||||
#include <time.h>
|
||||
|
||||
#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<Void> appendStringRefWithLen(Reference<IBackupFile> file, Standalone<StringRef> 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://</path/to/base/dir/>"; }
|
||||
|
||||
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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue