mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Samuel Holland <samuel@sholland.org>
To: musl@lists.openwall.com
Cc: Samuel Holland <samuel@sholland.org>
Subject: [PATCH] implement wcsftime padding specifier extensions
Date: Sat,  7 Apr 2018 09:47:16 -0500	[thread overview]
Message-ID: <20180407144716.17741-1-samuel@sholland.org> (raw)

Commit 8a6bd7307da3fc4d08dd6a9277b611ccb4971354 added support for
padding specifier extensions to strftime, but did not modify wcsftime.
In the process, it added a parameter to __strftime_fmt_1 in strftime.c,
but failed to update the prototype in wcsftime.c. This was found by
compiling musl with LTO:

    src/time/wcsftime.c:7:13: warning: type of '__strftime_fmt_1' does \
        not match original declaration [-Wlto-type-mismatch]

Fix the prototype of __strftime_fmt_1 in wcsftime.c, and generate the
'pad' argument the same way as it is done in strftime.
---
 src/time/wcsftime.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/time/wcsftime.c b/src/time/wcsftime.c
index 638e64f6..23500cc8 100644
--- a/src/time/wcsftime.c
+++ b/src/time/wcsftime.c
@@ -4,7 +4,7 @@
 #include "locale_impl.h"
 #include "libc.h"
 
-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);
 
 size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, const struct tm *restrict tm, locale_t loc)
 {
@@ -14,7 +14,7 @@ size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, co
 	wchar_t *p;
 	const char *t_mb;
 	const wchar_t *t;
-	int plus;
+	int pad, plus;
 	unsigned long width;
 	for (l=0; l<n; f++) {
 		if (!*f) {
@@ -26,6 +26,8 @@ size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, co
 			continue;
 		}
 		f++;
+		pad = 0;
+		if (*f == '-' || *f == '_' || *f == '0') pad = *f++;
 		if ((plus = (*f == '+'))) f++;
 		width = wcstoul(f, &p, 10);
 		if (*p == 'C' || *p == 'F' || *p == 'G' || *p == 'Y') {
@@ -35,7 +37,7 @@ size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, co
 		}
 		f = p;
 		if (*f == 'E' || *f == 'O') f++;
-		t_mb = __strftime_fmt_1(&buf, &k, *f, tm, loc);
+		t_mb = __strftime_fmt_1(&buf, &k, *f, tm, loc, pad);
 		if (!t_mb) break;
 		k = mbstowcs(wbuf, t_mb, sizeof wbuf / sizeof *wbuf);
 		if (k == (size_t)-1) return 0;
-- 
2.16.1



                 reply	other threads:[~2018-04-07 14:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180407144716.17741-1-samuel@sholland.org \
    --to=samuel@sholland.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).