Skip to content

Commit 287e7e7

Browse files
nehebnikias
authored andcommitted
time64: Add time_s support for WIN32
Signed-off-by: Rosen Penev <[email protected]>
1 parent 06d92b1 commit 287e7e7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/time64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ void copy_TM64_to_tm(const struct TM *src, struct tm *dest) {
443443
}
444444

445445

446-
#ifndef HAVE_LOCALTIME_R
446+
#if !defined(HAVE_LOCALTIME_R) && !defined(_WIN32)
447447
/* Simulate localtime_r() to the best of our ability */
448448
static struct tm * fake_localtime_r(const time_t *time, struct tm *result) {
449449
const struct tm *static_result = localtime(time);
@@ -462,7 +462,7 @@ static struct tm * fake_localtime_r(const time_t *time, struct tm *result) {
462462
#endif
463463

464464

465-
#ifndef HAVE_GMTIME_R
465+
#if !defined(HAVE_GMTIME_R) && !defined(_WIN32)
466466
/* Simulate gmtime_r() to the best of our ability */
467467
static struct tm * fake_gmtime_r(const time_t *time, struct tm *result) {
468468
const struct tm *static_result = gmtime(time);

src/time64.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ Time64_T timelocal64 (struct TM *);
5858
/* Not everyone has gm/localtime_r(), provide a replacement */
5959
#ifdef HAVE_LOCALTIME_R
6060
# define LOCALTIME_R(clock, result) localtime_r(clock, result)
61+
#elif defined(_WIN32)
62+
# define LOCALTIME_R(clock, result) (localtime_s(result, clock) ? NULL : result)
6163
#else
6264
# define LOCALTIME_R(clock, result) fake_localtime_r(clock, result)
6365
#endif
6466
#ifdef HAVE_GMTIME_R
6567
# define GMTIME_R(clock, result) gmtime_r(clock, result)
68+
#elif defined (_WIN32)
69+
# define GMTIME_R(clock, result) (gmtime_s(result, clock) ? NULL : result)
6670
#else
6771
# define GMTIME_R(clock, result) fake_gmtime_r(clock, result)
6872
#endif

0 commit comments

Comments
 (0)