* asctime.c (ctime): Call localtime and asctime, not localtime_r
and ctime_r.
---
 asctime.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/asctime.c b/asctime.c
index 3817182e..1bfcafe9 100644
--- a/asctime.c
+++ b/asctime.c
@@ -162,5 +162,8 @@ ctime_r(const time_t *timep, char *buf)
 char *
 ctime(const time_t *timep)
 {
-  return ctime_r(timep, buf_ctime);
+  /* Do not call localtime_r, as C23 requires ctime to initialize the
+     static storage that localtime updates.  */
+  struct tm *tmp = localtime(timep);
+  return tmp ? asctime(tmp) : NULL;
 }
-- 
2.47.1

Reply via email to