From c3677e08e06449018682bb2f7cf13cdd9db586dc Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Sat, 6 Dec 2025 19:53:05 -0500 Subject: [PATCH] WIN32: fix ctime_r and add Win32 compat for ctime_s so we can compile on Win32 again; --- src/fne/restapi/RESTAPI.cpp | 42 ++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/fne/restapi/RESTAPI.cpp b/src/fne/restapi/RESTAPI.cpp index 12d2edfb..e1b6722e 100644 --- a/src/fne/restapi/RESTAPI.cpp +++ b/src/fne/restapi/RESTAPI.cpp @@ -1693,9 +1693,12 @@ void RESTAPI::restAPI_GetStats(const HTTPPayload& request, HTTPPayload& reply, c char timeBuf[26]; ::memset(timeBuf, 0x00U, 26); +#if defined(_WIN32) + ::ctime_s(timeBuf, 26, &lastPingTime); +#else ::ctime_r(&lastPingTime, timeBuf); - - // remove newline character from ctime_r output +#endif + // remove newline character from ctime output std::string timeStr = std::string(timeBuf); timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end()); peerObj["lastPing"].set(timeStr); @@ -1729,9 +1732,12 @@ void RESTAPI::restAPI_GetStats(const HTTPPayload& request, HTTPPayload& reply, c char timeBuf[26]; ::memset(timeBuf, 0x00U, 26); +#if defined(_WIN32) + ::ctime_s(timeBuf, 26, &lastLoadTime); +#else ::ctime_r(&lastLoadTime, timeBuf); - - // remove newline character from ctime_r output +#endif + // remove newline character from ctime output std::string timeStr = std::string(timeBuf); timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end()); tableLastLoad["ridLastLoadTime"].set(timeStr); @@ -1746,9 +1752,12 @@ void RESTAPI::restAPI_GetStats(const HTTPPayload& request, HTTPPayload& reply, c char timeBuf[26]; ::memset(timeBuf, 0x00U, 26); +#if defined(_WIN32) + ::ctime_s(timeBuf, 26, &lastLoadTime); +#else ::ctime_r(&lastLoadTime, timeBuf); - - // remove newline character from ctime_r output +#endif + // remove newline character from ctime output std::string timeStr = std::string(timeBuf); timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end()); tableLastLoad["tgLastLoadTime"].set(timeStr); @@ -1763,9 +1772,12 @@ void RESTAPI::restAPI_GetStats(const HTTPPayload& request, HTTPPayload& reply, c char timeBuf[26]; ::memset(timeBuf, 0x00U, 26); +#if defined(_WIN32) + ::ctime_s(timeBuf, 26, &lastLoadTime); +#else ::ctime_r(&lastLoadTime, timeBuf); - - // remove newline character from ctime_r output +#endif + // remove newline character from ctime output std::string timeStr = std::string(timeBuf); timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end()); tableLastLoad["peerListLastLoadTime"].set(timeStr); @@ -1780,9 +1792,12 @@ void RESTAPI::restAPI_GetStats(const HTTPPayload& request, HTTPPayload& reply, c char timeBuf[26]; ::memset(timeBuf, 0x00U, 26); +#if defined(_WIN32) + ::ctime_s(timeBuf, 26, &lastLoadTime); +#else ::ctime_r(&lastLoadTime, timeBuf); - - // remove newline character from ctime_r output +#endif + // remove newline character from ctime output std::string timeStr = std::string(timeBuf); timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end()); tableLastLoad["adjSiteMapLastLoadTime"].set(timeStr); @@ -1797,9 +1812,12 @@ void RESTAPI::restAPI_GetStats(const HTTPPayload& request, HTTPPayload& reply, c char timeBuf[26]; ::memset(timeBuf, 0x00U, 26); +#if defined(_WIN32) + ::ctime_s(timeBuf, 26, &lastLoadTime); +#else ::ctime_r(&lastLoadTime, timeBuf); - - // remove newline character from ctime_r output +#endif + // remove newline character from ctime output std::string timeStr = std::string(timeBuf); timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end()); tableLastLoad["cryptoKeyLastLoadTime"].set(timeStr);