Hi,

A backwards-incompatible change was made to Gnulib yesterday:


Date        Modules         Changes

2025-10-31  nstrftime       The return type changed from size_t to ptrdiff_t.
                            The return value in case of failure changed from 0
                            to -1.


Guile needs an update accordingly. Find attached a proposed patch (untested).

Bruno

>From d71f0eb0e186305f854efde35e7241e0473d6c24 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sat, 1 Nov 2025 09:38:54 +0100
Subject: [PATCH] libguile: Update after gnulib changed.

* libguile/stime.c (scm_strftime): Adapt to new calling convention of
nstrftime. Remove previous ugly hack.
---
 libguile/stime.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/libguile/stime.c b/libguile/stime.c
index 18af71350..0a2e02a5e 100644
--- a/libguile/stime.c
+++ b/libguile/stime.c
@@ -1,4 +1,4 @@
-/* Copyright 1995-2001,2003-2009,2011,2013-2014,2016-2020
+/* Copyright 1995-2001,2003-2009,2011,2013-2014,2016-2020,2025
      Free Software Foundation, Inc.
 
    This file is part of Guile.
@@ -658,28 +658,18 @@ SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0,
   char *tbuf;
   int size = 50;
   char *fmt;
-  char *myfmt;
   size_t len;
+  ptrdiff_t ret;
   SCM result;
 
   SCM_VALIDATE_STRING (1, format);
   bdtime2c (stime, &t, SCM_ARG2, FUNC_NAME);
 
   /* Convert the format string to the locale encoding, as the underlying
-     'strftime' C function expects.  */
+     'nstrftime' C function expects.  */
   fmt = scm_to_locale_stringn (format, &len);
 
-  /* Ugly hack: strftime can return 0 if its buffer is too small,
-     but some valid time strings (e.g. "%p") can sometimes produce
-     a zero-byte output string!  Workaround is to prepend a junk
-     character to the format string, so that valid returns are always
-     nonzero. */
-  myfmt = scm_malloc (len+2);
-  *myfmt = (uint8_t) 'x';
-  strncpy (myfmt + 1, fmt, len);
-  myfmt[len + 1] = 0;
   scm_remember_upto_here_1 (format);
-  free (fmt);
 
   tbuf = scm_malloc (size);
   {
@@ -714,12 +704,16 @@ SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0,
 
     /* Use `nstrftime ()' from Gnulib, which supports all GNU extensions
        supported by glibc.  */
-    while ((len = nstrftime (tbuf, size, myfmt, &t, 0, 0)) == 0)
+    while ((ret = nstrftime (tbuf, size, fmt, &t, 0, 0)) == -1
+	   && errno == ERANGE)
       {
 	free (tbuf);
 	size *= 2;
 	tbuf = scm_malloc (size);
       }
+    if (ret < 0)
+      /* nstrftime failed.  */
+      strcpy (tbuf, "???");
 
 #if !defined (HAVE_STRUCT_TM_TM_ZONE)
     if (have_zone)
@@ -730,9 +724,9 @@ SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0,
 #endif
     }
 
-  result = scm_from_locale_string (tbuf + 1);
+  result = scm_from_locale_string (tbuf);
   free (tbuf);
-  free (myfmt);
+  free (fmt);
 #if HAVE_STRUCT_TM_TM_ZONE
   free ((char *) t.tm_zone);
 #endif
-- 
2.51.0

Reply via email to