From 869db9d756c7140dc39ff006715c0203b65005cd Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Mon, 18 Jan 2016 19:06:38 +0000 Subject: 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 , who confirmed that this version is better. Identified as a regression by tedu@. OK sthen@. --- bin/ls/utf8.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'bin/ls/utf8.c') 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 + * Copyright (c) 2015, 2016 Ingo Schwarze * * 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 #include +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) -- cgit v1.2.3