diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-01-18 19:06:38 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-01-18 19:06:38 +0000 |
commit | 869db9d756c7140dc39ff006715c0203b65005cd (patch) | |
tree | ce7a692c204a2a0debc9371fe74c932e53bd7ae1 | |
parent | 083f445638de2c0ed9da94565e10323bead7ba3d (diff) |
Fix a regression (and POSIX violation) introduced with UTF-8 support:
When neither running on a terminal nor with -q, names must be passed
through as they are, nothing must be replaced with question marks.
Effectively, -q was always in effect. SMALL was not affected.
Triggered by a different patch from Martijn van Duren <openbsd plus tech
at list dot imperialat dot at>, who confirmed that this version is better.
Identified as a regression by tedu@.
OK sthen@.
-rw-r--r-- | bin/ls/utf8.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/bin/ls/utf8.c b/bin/ls/utf8.c index 3825c531f16..08511f4158a 100644 --- a/bin/ls/utf8.c +++ b/bin/ls/utf8.c @@ -1,7 +1,7 @@ -/* $OpenBSD: utf8.c,v 1.1 2015/12/01 18:36:13 schwarze Exp $ */ +/* $OpenBSD: utf8.c,v 1.2 2016/01/18 19:06:37 schwarze Exp $ */ /* - * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2015, 2016 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -21,6 +21,8 @@ #include <stdlib.h> #include <wchar.h> +extern int f_nonprint; + int mbsprint(const char *mbs, int print) { @@ -33,12 +35,16 @@ mbsprint(const char *mbs, int print) if ((len = mbtowc(&wc, mbs, MB_CUR_MAX)) == -1) { (void)mbtowc(NULL, NULL, MB_CUR_MAX); if (print) - putchar('?'); + putchar(f_nonprint ? '?' : *mbs); total_width++; len = 1; } else if ((width = wcwidth(wc)) == -1) { - if (print) - putchar('?'); + if (print) { + if (f_nonprint) + putchar('?'); + else + fwrite(mbs, 1, len, stdout); + } total_width++; } else { if (print) |