diff options
author | Martin Willi <martin@revosec.ch> | 2013-10-15 16:23:44 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-06-04 15:52:58 +0200 |
commit | 95a8d53dbe1f0dcff27e170fc47902bd4006102d (patch) | |
tree | dd0c7872b7db7cffad3050169cb7574a02f0fac3 /src | |
parent | a4719c5767147bd038128b540a394a802ee0b2e0 (diff) | |
download | strongswan-95a8d53dbe1f0dcff27e170fc47902bd4006102d.tar.bz2 strongswan-95a8d53dbe1f0dcff27e170fc47902bd4006102d.tar.xz |
windows: Use localtime/gmtime to implement _r variants
The _s variants and friends do not seem to work on Windows 7 and always fail.
Diffstat (limited to 'src')
-rw-r--r-- | src/libstrongswan/utils/windows.h | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/src/libstrongswan/utils/windows.h b/src/libstrongswan/utils/windows.h index 2457cff32..d47ae9a99 100644 --- a/src/libstrongswan/utils/windows.h +++ b/src/libstrongswan/utils/windows.h @@ -111,21 +111,17 @@ static inline void timersub(struct timeval *a, struct timeval *b, */ static inline struct tm *gmtime_r(const time_t *timep, struct tm *result) { - if (sizeof(time_t) == 4) - { - if (_gmtime32_s(result, (__time32_t*)time) == 0) - { - return result; - } - } - else + struct tm *ret; + + /* gmtime_s() and friends seem not to be implemented/functioning. + * Relying on gmtime() on Windows works as well, as it uses thread + * specific buffers. */ + ret = gmtime(timep); + if (ret) { - if (_gmtime64_s(result, (__time64_t*)time) == 0) - { - return result; - } + memcpy(result, ret, sizeof(*result)); } - return NULL; + return ret; } /** @@ -133,21 +129,17 @@ static inline struct tm *gmtime_r(const time_t *timep, struct tm *result) */ static inline struct tm *localtime_r(const time_t *timep, struct tm *result) { - if (sizeof(time_t) == 4) - { - if (_localtime32_s(result, (__time32_t*)time) == 0) - { - return result; - } - } - else + struct tm *ret; + + /* localtime_s() and friends seem not to be implemented/functioning. + * Relying on localtime() on Windows works as well, as it uses thread + * specific buffers. */ + ret = localtime(timep); + if (ret) { - if (_localtime64_s(result, (__time64_t*)time) == 0) - { - return result; - } + memcpy(result, ret, sizeof(*result)); } - return NULL; + return ret; } /** |