[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Use of strftime in movemail.ec
From: |
Eli Zaretskii |
Subject: |
Re: Use of strftime in movemail.ec |
Date: |
Sat, 05 Mar 2016 22:37:48 +0200 |
> Date: Sat, 05 Mar 2016 21:58:58 +0200
> From: Eli Zaretskii <address@hidden>
> Cc: address@hidden
>
> This change causes us have 2 slightly different format specifiers,
> which subtly depend on each other for correct operation. Wouldn't it
> be better to pass the format string to movemail_strftime, and replace
> %e and %T there? Or maybe use %H:%M:%S instead of %T (it's just a
> shorthand, right?)? I'm a little bit nervous about having the format
> duplicated.
How about the follow-up below?
diff --git a/lib-src/movemail.c b/lib-src/movemail.c
index 873d85d..93d2ee3 100644
--- a/lib-src/movemail.c
+++ b/lib-src/movemail.c
@@ -807,7 +807,28 @@ static size_t
movemail_strftime (char *s, size_t size, char const *format,
struct tm const *tm)
{
- size_t n = strftime (s, size, "From movemail %a %b %d %H:%M:%S %Y\n", tm);
+ char fmt[size + 6], *q;
+ const char *p;
+
+ for (p = format, q = &fmt[0]; *p; )
+ {
+ if (*p == '%' && p[1] == 'e')
+ {
+ strncpy (q, "%d", 2);
+ q += 2;
+ p += 2;
+ }
+ else if (*p == '%' && p[1] == 'T')
+ {
+ strncpy (q, "%H:%M:%S", 8);
+ q += 8;
+ p += 2;
+ }
+ else
+ *q++ = *p++;
+ }
+
+ size_t n = strftime (s, size, fmt, tm);
char *mday = s + sizeof "From movemail Sun Jan " - 1;
if (*mday == '0')
*mday = ' ';