From 065e2add9fd443ffaabc4ce66298714fec9756fb Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 29 Apr 2015 10:41:42 +0200 Subject: strftime: comment on %0xY %+nY %-nY Would fix: date -u +%4Y%2m%2d%2H%2M%2S Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/time/time.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libc/misc/time/time.c b/libc/misc/time/time.c index a3fccb251..03635d86d 100644 --- a/libc/misc/time/time.c +++ b/libc/misc/time/time.c @@ -1084,7 +1084,25 @@ LOOP: o_count = 1; if ((*(o = (CHAR_T *)p) == '%') && (*++p != '%')) { +#if 0 /* TODO, same for strptime */ + /* POSIX.1-2008 allows %0xY %+nY %-nY etc. for certain formats. + * Just accept these for all (for now) */ + const int plus = *p == '+'; + CHAR_T *q = (CHAR_T *)p; + long int o_width = __XL_NPP(strtol)(p, &q, 0 __LOCALE_ARG); + if (o_width > 0 && o_width < 256) { /* arbitrary upper limit */ + o_count = o_width; + if (plus) { + *s++ = '+'; + --count; + } + p = q; + } else { + o_count = 2; + } +#else o_count = 2; +#endif mod = ILLEGAL_SPEC; if ((*p == 'O') || (*p == 'E')) { /* modifier */ mod |= ((*p == 'O') ? NO_O_MOD : NO_E_MOD); @@ -1317,7 +1335,13 @@ ISO_LOOP: ccp = __XL_NPP(nl_langinfo)(_NL_ITEM(LC_TIME, field_val) __LOCALE_ARG); fmt_to_wc(o, ccp); } else { +#if 0 /* TODO, same for strptime */ + size_t min_count = ((i >> 1) & 3) + 1; + if (o_count < min_count) + o_count = min_count; +#else o_count = ((i >> 1) & 3) + 1; +#endif ccp = buf + o_count; do { *(char *)(--ccp) = '0' + (field_val % 10); -- cgit v1.2.3