aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorEli Zaretskii2016-03-06 18:27:16 +0200
committerEli Zaretskii2016-03-06 18:27:16 +0200
commitb71c717f952d57995c54a2d276b10af87529dcd3 (patch)
tree5b5b2b54a44b84da52f732119c0ed174993395a6 /lib-src
parentcc057e43130780e566f4b901a59a88edb3f5130d (diff)
downloademacs-b71c717f952d57995c54a2d276b10af87529dcd3.tar.gz
emacs-b71c717f952d57995c54a2d276b10af87529dcd3.zip
Make the code in movemail_strftime more general
* lib-src/movemail.c (movemail_strftime): Transform the format string passed by the caller instead of using a separate format string.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/movemail.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/lib-src/movemail.c b/lib-src/movemail.c
index 873d85dfd77..fa4c0294955 100644
--- a/lib-src/movemail.c
+++ b/lib-src/movemail.c
@@ -807,7 +807,34 @@ static size_t
807movemail_strftime (char *s, size_t size, char const *format, 807movemail_strftime (char *s, size_t size, char const *format,
808 struct tm const *tm) 808 struct tm const *tm)
809{ 809{
810 size_t n = strftime (s, size, "From movemail %a %b %d %H:%M:%S %Y\n", tm); 810 char fmt[size + 6], *q;
811 const char *p;
812
813 for (p = format, q = &fmt[0]; *p; )
814 {
815 if (*p == '%' && p[1] == 'e')
816 {
817 memcpy (q, "%d", 2);
818 q += 2;
819 p += 2;
820 }
821 else if (*p == '%' && p[1] == 'T')
822 {
823 memcpy (q, "%H:%M:%S", 8);
824 q += 8;
825 p += 2;
826 }
827 else if (*p == '%' && p[1] == '%')
828 {
829 memcpy (q, p, 2);
830 q += 2;
831 p += 2;
832 }
833 else
834 *q++ = *p++;
835 }
836
837 size_t n = strftime (s, size, fmt, tm);
811 char *mday = s + sizeof "From movemail Sun Jan " - 1; 838 char *mday = s + sizeof "From movemail Sun Jan " - 1;
812 if (*mday == '0') 839 if (*mday == '0')
813 *mday = ' '; 840 *mday = ' ';