From e9ce5ccc90c63cb1c499ad01800e638ece23f8b0 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 30 Jan 2007 13:18:51 +0100 Subject: col: getwchar() errors shouldn't be hidden The col truncates output when multibyte errors is detected, but the problem is not reported to stderr and return code is still same like for successful exit. This stupid behaviour is fixed by this patch. Signed-off-by: Karel Zak --- text-utils/col.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'text-utils/col.c') diff --git a/text-utils/col.c b/text-utils/col.c index 052d91e7a..3b81a891a 100644 --- a/text-utils/col.c +++ b/text-utils/col.c @@ -128,6 +128,7 @@ int main(int argc, char **argv) int this_line; /* line l points to */ int nflushd_lines; /* number of lines that were flushed */ int adjust, opt, warned; + int ret = 0; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -175,8 +176,16 @@ int main(int argc, char **argv) cur_line = max_line = nflushd_lines = this_line = 0; cur_set = last_set = CS_NORMAL; lines = l = alloc_line(); - - while ((ch = getwchar()) != WEOF) { + + while (feof(stdin)==0) { + errno = 0; + if ((ch = getwchar()) == WEOF) { + if (errno==EILSEQ) { + perror("col"); + ret = 1; + } + break; + } if (!iswgraph(ch)) { switch (ch) { case BS: /* can't go back further */ @@ -332,7 +341,7 @@ int main(int argc, char **argv) flush_blanks(); if (ferror(stdout) || fclose(stdout)) return 1; - return 0; + return ret; } void flush_lines(int nflush) -- cgit v1.2.3-55-g7522