Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Fix strftime (prompts) before 5.2?
On Sun, 22 Nov 2015 09:27:11 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> Do we want to try to fix users/20859 ? It shouldn't be that hard for
> someone in an environment where it fails (I'm having trouble creating
> one).
Putting it all together, the reported failing case is:
% (LC_ALL=de_CH.UTF-8; print -P "%D{%a %b %d} %D{%I:%M:%S%P}")
Son Nov 22
5:36% (LC_ALL=de_CH.UTF-8; print -P "%D{%a %b %d} %D{%I:%M:%S}")
Son Nov 22 05:37:02
and that's indeed the feature --- no time if %P is present.
The date component is irrelevant (except that it shosw strftime isn't
completely screwed), so it just reduces to the second %D substitution in
that locale. Not specific to Switzerland or in fact to German; happens
in de_DE.UTF-8 and fr_CH.UTF-8, too. Suspected metafication, but it
wasn't.
This suggests the test for a successful expansion isn't safe after all,
but probably there aren't too many expansions like %p and %P.
pws
diff --git a/Src/utils.c b/Src/utils.c
index 0afa8c9..4640970 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3143,6 +3143,7 @@ strftimehandling:
* in the accounting in bufsize (but nowhere else).
*/
{
+ char origchar = fmt[-1];
int size = fmt - fmtstart;
char *tmp, *last;
tmp = zhalloc(size + 1);
@@ -3163,11 +3164,17 @@ strftimehandling:
*buf = '\1';
if (!strftime(buf, bufsize + 2, tmp, tm))
{
- if (*buf) {
- buf[0] = '\0';
- return -1;
+ /*
+ * Some locales don't have strings for
+ * AM/PM, so empty output is valid.
+ */
+ if (*buf || (origchar != 'p' && origchar != 'P')) {
+ if (*buf) {
+ buf[0] = '\0';
+ return -1;
+ }
+ return 0;
}
- return 0;
}
decr = strlen(buf);
buf += decr;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author