From 590f4062ab5733f517fcbfac63cbfee1659f5239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20P=C3=B6ttker?= <25299532+hpoettker@users.noreply.github.com> Date: Sun, 20 Sep 2026 20:41:16 +0200 Subject: [PATCH] Fix build in Windows C Runtime In the Windows C Runtime, the POSIX function `localtime_r`, which is a thread-safe alternative to `localtime`, is not available. It offers the function `localtime_s` instead, which differs from the C11 function of that name in both parameter order and return value. --- src/stata/readstat_dta_write.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/stata/readstat_dta_write.c b/src/stata/readstat_dta_write.c index e30a96c3..4a3a84ef 100644 --- a/src/stata/readstat_dta_write.c +++ b/src/stata/readstat_dta_write.c @@ -155,7 +155,12 @@ static readstat_error_t dta_emit_header_time_stamp(readstat_writer_t *writer, dt if (writer->timestamp != 0) { time_t now = writer->timestamp; struct tm time_buf; +#if !defined _MSC_VER struct tm *time_s = localtime_r(&now, &time_buf); +#else + errno_t time_err = localtime_s(&time_buf, &now); + struct tm *time_s = (time_err == 0) ? &time_buf : NULL; +#endif if (!time_s || time_s->tm_mon < 0 || time_s->tm_mon > 11) { error = READSTAT_ERROR_BAD_TIMESTAMP_VALUE;