From: Sven M. Hallberg Subject: Re: mail(1) set Date and User-Agent [was: Re: Back to rfc2045] To: Omar Polo , Walter Alejandro Iglesias Cc: tech@openbsd.org Date: Fri, 02 Aug 2024 12:21:43 +0200 Unfortunate frustrations in this thread aside... out of pure interest: Omar Polo on Thu, Aug 01 2024: > Then, we can't use strftime() since it depends on the locale. Why not strftime_l, then? > + now = time(NULL); > + lt = localtime(&now); You take the local time... > + offset = lt->tm_gmtoff; > + tz = lt->tm_zone; extract the time zone info... > + r = snprintf(buf, sizeof(buf), > + "%s, %d %s %d %02d:%02d:%02d %c%02d%02d (%s)", > + day[lt->tm_wday], lt->tm_mday, month[lt->tm_mon], > + lt->tm_year + 1900, > + lt->tm_hour, lt->tm_min, lt->tm_sec, > + offset >= 0 ? '+' : '-', > + abs((int)offset / 3600), > + abs((int)offset % 3600) / 60, > + tz); and print it using the english month and weekday names. Seems to me something like the following should do the trick. NB: Calling date() twice in puthead() seems wrong and is useless anyway, since it never returns NULL. char * date(void) { static locale_t cloc; static char buf[40]; struct tm *lt; time_t now; size_t n; if (cloc == (locale_t)0) { cloc = newlocale(LC_ALL, "C", 0); if (cloc == (locale_t)0) errx(1, "newlocale"); } now = time(NULL); lt = localtime(&now); if (lt == NULL) errx(1, "localtime"); n = strftime_l(buf, sizeof buf, "%a, %d %b %Y %T %z (%Z)", lt, cloc); if (n == 0) errx(1, "strftime_l"); return buf; }