diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-12-01 18:36:14 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-12-01 18:36:14 +0000 |
commit | 51dbee4f9cb8843e5e1afc77881fa3bd3eaa9ad9 (patch) | |
tree | b54cc4f6dcf1a92eed8a0ede2c61d16a6fdbf1c7 /bin/ls/ls.c | |
parent | 4adcc5bb8d17c4de04b10799e1f19daa3e5a4564 (diff) |
Support UTF-8: use wcwidth(3) for column adjustment and replace
non-printable Unicode codepoints and invalid bytes with ASCII
question marks. No change for the SMALL version.
Using ideas developed by tedu@, phessler@, bentley@ and feedback from many.
OK yasuoka@ czarkoff@ sthen@.
Diffstat (limited to 'bin/ls/ls.c')
-rw-r--r-- | bin/ls/ls.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/bin/ls/ls.c b/bin/ls/ls.c index da93dd91e10..6341bfc6fa2 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ls.c,v 1.43 2015/10/09 01:37:06 deraadt Exp $ */ +/* $OpenBSD: ls.c,v 1.44 2015/12/01 18:36:13 schwarze Exp $ */ /* $NetBSD: ls.c,v 1.18 1996/07/09 09:16:29 mycroft Exp $ */ /* @@ -48,6 +48,7 @@ #include <string.h> #include <unistd.h> #include <limits.h> +#include <locale.h> #include <util.h> #include "ls.h" @@ -103,6 +104,10 @@ ls_main(int argc, char *argv[]) int kflag = 0, width = 0; char *p; +#ifndef SMALL + setlocale(LC_CTYPE, ""); +#endif + /* Terminal defaults to -Cq, non-terminal defaults to -1. */ if (isatty(STDOUT_FILENO)) { if ((p = getenv("COLUMNS")) != NULL) @@ -428,6 +433,7 @@ display(FTSENT *p, FTSENT *list) ino_t maxinode; int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser; int entries, needstats; + int width; char *user, *group, buf[21]; /* 64 bits == 20 digits */ char nuser[12], ngroup[12]; char *flags = NULL; @@ -474,8 +480,8 @@ display(FTSENT *p, FTSENT *list) continue; } } - if (cur->fts_namelen > maxlen) - maxlen = cur->fts_namelen; + if ((width = mbsprint(cur->fts_name, 0)) > maxlen) + maxlen = width; if (needstats) { sp = cur->fts_statp; if (sp->st_blocks > maxblock) |