Author: yuripv
Date: Sun Jun  7 08:21:19 2020
New Revision: 361887
URL: https://svnweb.freebsd.org/changeset/base/361887

Log:
  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

Modified:
  head/bin/ps/keyword.c
  head/bin/ps/print.c
  head/bin/ps/ps.c

Modified: head/bin/ps/keyword.c
==============================================================================
--- head/bin/ps/keyword.c       Sun Jun  7 05:08:44 2020        (r361886)
+++ head/bin/ps/keyword.c       Sun Jun  7 08:21:19 2020        (r361887)
@@ -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");

Modified: head/bin/ps/print.c
==============================================================================
--- head/bin/ps/print.c Sun Jun  7 05:08:44 2020        (r361886)
+++ head/bin/ps/print.c Sun Jun  7 08:21:19 2020        (r361887)
@@ -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: }");
        }

Modified: head/bin/ps/ps.c
==============================================================================
--- head/bin/ps/ps.c    Sun Jun  7 05:08:44 2020        (r361886)
+++ head/bin/ps/ps.c    Sun Jun  7 08:21:19 2020        (r361887)
@@ -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);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to