chiark / gitweb /
Switch from asctime() to strftime()
authorBen Harris <bjh21@bjh21.me.uk>
Tue, 25 Mar 2025 11:09:54 +0000 (11:09 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 25 Mar 2025 11:09:54 +0000 (11:09 +0000)
C23 marks asctime() as deprecated and it seems polite to keep up with
that.  Using strftime() isn't noticeably more complicated: the "%c"
specifier does what we want and we don't get a spurious newline that
we have to remove again.

bedstead.c

index d524564f6052c145a9c6d6d2546dc6b1d867d1d9..704ed407871881579ec049c05826ecca3a682326 100644 (file)
@@ -3145,9 +3145,11 @@ fullname_to_fontname(char const *fullname)
 static char *
 time_for_ttx(void)
 {
+       static char timestr[25];
+       size_t timestrlen;
        struct tm *timeptr, tm;
        unsigned long long epochull;
-       char *epochstr, *endptr, *timestr;
+       char *epochstr, *endptr;
 
        /* Work out what timestamp to use. */
        if ((epochstr = getenv("SOURCE_DATE_EPOCH")) != NULL) {
@@ -3201,9 +3203,8 @@ time_for_ttx(void)
                        return NULL;
                }
        }
-       timestr = asctime(timeptr);
-       assert(strlen(timestr) == 25);
-       timestr[24] = '\0'; /* Remove newline. */
+       timestrlen = strftime(timestr, lenof(timestr), "%c", timeptr);
+       assert(timestrlen == 24);
        return timestr;
 }