From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10894 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH v2] implement strftime GNU extension padding specifiers '_', '-' and '0' Date: Fri, 6 Jan 2017 08:59:59 +0200 Message-ID: <20170106065959.2161-1-timo.teras@iki.fi> References: <20161221032000.GM1555@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1483686030 17684 195.159.176.226 (6 Jan 2017 07:00:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 6 Jan 2017 07:00:30 +0000 (UTC) Cc: =?UTF-8?q?Timo=20Ter=C3=A4s?= To: musl@lists.openwall.com Original-X-From: musl-return-10907-gllmg-musl=m.gmane.org@lists.openwall.com Fri Jan 06 08:00:27 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1cPOVd-00030u-4z for gllmg-musl@m.gmane.org; Fri, 06 Jan 2017 08:00:17 +0100 Original-Received: (qmail 17455 invoked by uid 550); 6 Jan 2017 07:00:18 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 17423 invoked from network); 6 Jan 2017 07:00:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=eP9ZT5nhJQmqKowUOyN1t+ZznmU8UFuv81qBu7Nr3Wc=; b=b3MiRH7mVwSet6IXhzK8VuVF2/aTUJrWBG64oQfWZbr9gqwHZp719xCBOS+Ejadglj NiG/Da/3J/Nx5MOIrQqAmuCZTUmxrszFDyXsgTGoIND53Kg211PMBaSTXOM6yih8iRpF fAnmEcJDmZw1llrsTzkgUb4qJS8OVmMxHbkR+qJLzM6vLzgmYzp7WdbkbGOvRHY4VSEo VLVVBC/DVtsaP4HVEO/KshG47npvky98uGaVRuRsS8l1TLuuV2fEoVXxsUzkVnJFEBjG yJmiV0/Drl8J8X8YL8WAx5MntsuKCzzvQNnP2LJdmjHE+tBdvz0/bo02UyNGq7BP+8Su UscQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=eP9ZT5nhJQmqKowUOyN1t+ZznmU8UFuv81qBu7Nr3Wc=; b=qb0SbBDBdm88gaWPyX9uY7fJzqt3dTz78FNdEaAP7uH3c7VGdiU6lJu028EeAu39GX dyKKofpHIaB2Ly/5lytkFjgsLauWPAvAvHn+PctLzoeQg2GGk2RuEvgnIqK0k6mk9/Hl sfWNn+WvmMta6M09/wS2ps4NTuKX2fpG+lck98z7UT6kOpK6+0FGSJJcgAlK0Rf5o6PQ gb19HKIcemqVdLn2yiOW1yyai4kbx600nFV8/X8TL9uOp42tMy7kDjUutc6CZIs/EGbM w4g2UIXDEhJJTHWYaHYPd6GkGidvaFBLuFf2+WkloriDyEC6mhTcE0KK0E+HBBczP3MU 4wEA== X-Gm-Message-State: AIkVDXLKPjlGeifikvP+hvtxwMI9osthhG9h4VOqM1L+I4IsZc8AJ9Wd01Mywyb9j5XM8Q== X-Received: by 10.46.20.25 with SMTP id u25mr2053630ljd.61.1483686005489; Thu, 05 Jan 2017 23:00:05 -0800 (PST) Original-Sender: =?UTF-8?Q?Timo_Ter=C3=A4s?= X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161221032000.GM1555@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:10894 Archived-At: --- v2: support these specifiers for recursive built format strings such as '%F' src/time/strftime.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/time/strftime.c b/src/time/strftime.c index a3039204..733e4e28 100644 --- a/src/time/strftime.c +++ b/src/time/strftime.c @@ -46,9 +46,9 @@ static int week_num(const struct tm *tm) } const char *__tm_to_tzname(const struct tm *); -size_t __strftime_l(char *restrict, size_t, const char *restrict, const struct tm *restrict, locale_t); +static size_t __strftime_impl(char *restrict, size_t, const char *restrict, const struct tm *restrict, locale_t, int); -const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc) +const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc, int pad) { nl_item item; long long val; @@ -79,15 +79,14 @@ const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm * case 'C': val = (1900LL+tm->tm_year) / 100; goto number; + case 'e': + pad = '_'; case 'd': val = tm->tm_mday; goto number; case 'D': fmt = "%m/%d/%y"; goto recu_strftime; - case 'e': - *l = snprintf(*s, sizeof *s, "%2d", tm->tm_mday); - return *s; case 'F': fmt = "%Y-%m-%d"; goto recu_strftime; @@ -200,7 +199,12 @@ const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm * return 0; } number: - *l = snprintf(*s, sizeof *s, "%0*lld", width, val); + switch (pad) { + case '-': *l = snprintf(*s, sizeof *s, "%lld", val); break; + case '_': *l = snprintf(*s, sizeof *s, "%*lld", width, val); break; + case '0': + default: *l = snprintf(*s, sizeof *s, "%0*lld", width, val); break; + } return *s; nl_strcat: fmt = __nl_langinfo_l(item, loc); @@ -210,18 +214,18 @@ string: nl_strftime: fmt = __nl_langinfo_l(item, loc); recu_strftime: - *l = __strftime_l(*s, sizeof *s, fmt, tm, loc); + *l = __strftime_impl(*s, sizeof *s, fmt, tm, loc, pad); if (!*l) return 0; return *s; } -size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm, locale_t loc) +static size_t __strftime_impl(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm, locale_t loc, int def_pad) { size_t l, k; char buf[100]; char *p; const char *t; - int plus; + int plus, pad; unsigned long width; for (l=0; l