diff options
author | Jérôme Martinez <jerome@mediaarea.net> | 2020-03-03 14:39:28 +0300 |
---|---|---|
committer | Jérôme Martinez <jerome@mediaarea.net> | 2020-03-03 14:44:23 +0300 |
commit | 70868fe21d8c58373389dd318a76695136580a4b (patch) | |
tree | 859d47b03873f025fa90fe811ae6ddec269f8bc5 /Source | |
parent | ce8a4e8908829b786b7cd88d6fdae423e701df2f (diff) |
x Ztring: some date conversion methods were not thread safe
Diffstat (limited to 'Source')
-rw-r--r-- | Source/ZenLib/Ztring.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Source/ZenLib/Ztring.cpp b/Source/ZenLib/Ztring.cpp index ed34062..7dfb720 100644 --- a/Source/ZenLib/Ztring.cpp +++ b/Source/ZenLib/Ztring.cpp @@ -1306,7 +1306,16 @@ Ztring& Ztring::Date_From_Seconds_1970 (const int32s Value) Ztring& Ztring::Date_From_Seconds_1970 (const int64s Value)
{
time_t Time=(time_t)Value;
+ #if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE || _POSIX_SOURCE
+ struct tm Gmt_Temp;
+ struct tm *Gmt=gmtime_r(&Time, &Gmt_Temp);
+ #elif defined(_WIN32)
+ struct tm Gmt_Temp;
+ errno_t gmtime_s_Result=gmtime_s(&Gmt_Temp , &Time);
+ struct tm* Gmt=gmtime_s_Result?NULL:&Gmt_Temp;
+ #else
struct tm *Gmt=gmtime(&Time);
+ #endif
if (!Gmt)
{
clear();
@@ -1337,7 +1346,16 @@ Ztring& Ztring::Date_From_Seconds_1970 (const int64s Value) Ztring& Ztring::Date_From_Seconds_1970_Local (const int32u Value)
{
time_t Time=(time_t)Value;
+ #if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE || _POSIX_SOURCE
+ struct tm Gmt_Temp;
+ struct tm *Gmt=localtime_r(&Time, &Gmt_Temp);
+ #elif defined(_WIN32)
+ struct tm Gmt_Temp;
+ errno_t localtime_s_Result=localtime_s(&Gmt_Temp , &Time);
+ struct tm* Gmt=localtime_s_Result?NULL:&Gmt_Temp;
+ #else
struct tm *Gmt=localtime(&Time);
+ #endif
Ztring DateT;
Ztring Date;
Date+=Ztring::ToZtring((Gmt->tm_year+1900));
|