1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
From: Christian Kastner <ckk@kvr.at>
Date: Tue, 22 Dec 2015 23:21:27 +0100
Subject: Use strftime to print time
Fix provided by Steve Greenland <stevegr@debian.org>, possibly with OpenBSD as
the original source (the subversion history is ambiguous).
Forwarded: no
Last-Update: 2015-12-22
---
misc.c | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/misc.c b/misc.c
index edf4ee6..cf4a74c 100644
--- a/misc.c
+++ b/misc.c
@@ -659,26 +659,36 @@ mkprints(src, len)
#ifdef MAIL_DATE
-/* Sat, 27 Feb 93 11:44:51 CST
- * 123456789012345678901234567
+/* Sat, 27 Feb 1993 11:44:51 -0800 (CST)
+ * 1234567890123456789012345678901234567
*/
char *
arpadate(clock)
time_t *clock;
{
- time_t t = clock ?*clock :time(0L);
+ static char ret[64]; /* zone name might be >3 chars */
+ time_t t = clock ? *clock : time(NULL);
struct tm *tm = localtime(&t);
- static char ret[30]; /* zone name might be >3 chars */
-
- (void) snprintf(ret, 30, "%s, %2d %s %2d %02d:%02d:%02d %s",
- DowNames[tm->tm_wday],
- tm->tm_mday,
- MonthNames[tm->tm_mon],
- tm->tm_year,
- tm->tm_hour,
- tm->tm_min,
- tm->tm_sec,
- TZONE(*tm));
+ char *qmark;
+ size_t len;
+ int hours = tm->tm_gmtoff / 3600;
+ int minutes = (tm->tm_gmtoff - (hours * 3600)) / 60;
+
+ if (minutes < 0)
+ minutes = -minutes;
+
+ /* Defensive coding (almost) never hurts... */
+ len = strftime(ret, sizeof(ret), "%a, %e %b %Y %T ????? (%Z)", tm);
+ if (len == 0) {
+ ret[0] = '?';
+ ret[1] = '\0';
+ return ret;
+ }
+ qmark = strchr(ret, '?');
+ if (qmark && len - (qmark - ret) >= 6) {
+ snprintf(qmark, 6, "% .2d%.2d", hours, minutes);
+ qmark[5] = ' ';
+ }
return ret;
}
#endif /*MAIL_DATE*/
|