How about this (or gl-ctime?): /* safer-ctime.h -- safer version of ctime(). Copyright (C) 2024 FSF Authors: Paul Eggert, Bruno Haible, Simon Josefsson License: LGPL-2+ */
#define SAFER_CTIME_BUFSIZE 35 /* Convert WHEN representing the number of seconds before/after epoch, 1970-01-01 00:00:00 +0000 (UTC) to a fixed locale-independent NUL-terminated string such as "Wed Jun 30 21:49:08 1993\n\0", relative to the user's specified timezone, using abbreviations for the days of the week as "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", and "Sat" and abbreviations for the months as "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", and "Dec". The function does not set the external variables tzname, timezone or daylight, see tzset(3). The output is copied into STR which should have room for at least SAFER_CTIME_BUFSIZE bytes. For years 1000 to 9999 inclusive the output string length will be 26 characters including the final NUL byte. The string length may be shorter for years before 1000 and larger for years after 9999. The years are not padded with whitespace or zeros, so valid outputs include strings "Wed Jun 30 21:49:08 623\n" and "Wed Jun 30 21:49:08 11147\n", and for negative years strings such as "Wed Jun 30 21:49:08 -42\n". The preloptic Gregorian calendar is used for all years, to cover years before the Gregorian calendar was adopted; and for years before 1 the ISO 8601 approach to have years 2, 1, 0, -1, and so on is used instead of having 2 BC, 1 BC, AD 1, AD 2. On systems with a 64-bit time_t type, the year value may be large as in strings looking like "Sun Sep 16 01:03:52 -292471206706\n\0", and future systems with larger time_t types may lead to even longer strings. If WHEN cannot be converted into a string, NULL is returned and errno is set to an error, otherwise on success STR is returned. The function's Thread safety attribute value is MT-Safe env locale. */ char *safer_ctime (time_t when, char *str); /Simon
signature.asc
Description: PGP signature
