ps: use %hs instead of %s format specifiers

Use %hs (locale-based encoding) instead of %s (UTF-8) format for
strings that are expected to be in current locale encoding (date/time,
process names/argument list).

PR:		241491
Reviewed by:	phil
Differential Revision:	https://reviews.freebsd.org/D22160
This commit is contained in:
Yuri Pankov 2020-06-07 08:21:19 +00:00
parent 857e0646ca
commit aa8ab14697
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=361887
3 changed files with 6 additions and 5 deletions

View file

@ -254,7 +254,7 @@ showkey(void)
i = len;
sep = "\n";
}
xo_emit("{P:/%s}{l:key/%s}", sep, p);
xo_emit("{P:/%hs}{l:key/%hs}", sep, p);
sep = " ";
}
xo_emit("\n");

View file

@ -89,11 +89,11 @@ printheader(void)
v = vent->var;
if (v->flag & LJUST) {
if (STAILQ_NEXT(vent, next_ve) == NULL) /* last one */
xo_emit("{T:/%s}", vent->header);
xo_emit("{T:/%hs}", vent->header);
else
xo_emit("{T:/%-*s}", v->width, vent->header);
xo_emit("{T:/%-*hs}", v->width, vent->header);
} else
xo_emit("{T:/%*s}", v->width, vent->header);
xo_emit("{T:/%*hs}", v->width, vent->header);
if (STAILQ_NEXT(vent, next_ve) != NULL)
xo_emit("{P: }");
}

View file

@ -192,6 +192,7 @@ main(int argc, char *argv[])
char fmtbuf[_POSIX2_LINE_MAX];
(void) setlocale(LC_ALL, "");
xo_no_setlocale();
time(&now); /* Used by routines in print.c. */
/*
@ -696,7 +697,7 @@ main(int argc, char *argv[])
fwidthmin = (xo_get_style(NULL) != XO_STYLE_TEXT ||
(STAILQ_NEXT(vent, next_ve) == NULL &&
(vent->var->flag & LJUST))) ? 0 : vent->var->width;
snprintf(fmtbuf, sizeof(fmtbuf), "{:%s/%%%s%d..%ds}",
snprintf(fmtbuf, sizeof(fmtbuf), "{:%s/%%%s%d..%dhs}",
vent->var->field ? vent->var->field : vent->var->name,
(vent->var->flag & LJUST) ? "-" : "",
fwidthmin, fwidthmax);