summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2007-01-30 13:18:51 +0100
committerKarel Zak2007-01-30 13:52:48 +0100
commite9ce5ccc90c63cb1c499ad01800e638ece23f8b0 (patch)
tree251163add0f5966824a79409005502cb1c70e328
parentbuild-sys: fix ifdef ENABLE_WIDECHAR usage (diff)
downloadkernel-qcow2-util-linux-e9ce5ccc90c63cb1c499ad01800e638ece23f8b0.tar.gz
kernel-qcow2-util-linux-e9ce5ccc90c63cb1c499ad01800e638ece23f8b0.tar.xz
kernel-qcow2-util-linux-e9ce5ccc90c63cb1c499ad01800e638ece23f8b0.zip
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 <kzak@redhat.com>
-rw-r--r--tests/commands.sh.in2
-rw-r--r--tests/expected/ts-col-multibyte1
-rw-r--r--tests/functions.sh5
-rw-r--r--tests/input/ts-col-multibyte1
-rwxr-xr-xtests/ts-col-multibyte17
-rw-r--r--text-utils/col.c15
6 files changed, 37 insertions, 4 deletions
diff --git a/tests/commands.sh.in b/tests/commands.sh.in
index 4345a28f5..92deda21d 100644
--- a/tests/commands.sh.in
+++ b/tests/commands.sh.in
@@ -11,3 +11,5 @@ TS_CMD_SWAPON=${TS_CMD_MOUNT:-"$TOPDIR/mount/swapon"}
TS_CMD_SWAPOFF=${TS_CMD_MOUNT:-"$TOPDIR/mount/swapoff"}
TS_CMD_IPCS=${TS_CMD_IPCS:-"$TOPDIR/sys-utils/ipcs"}
+
+TS_CMD_COL=${TS_CMD_COL:-"$TOPDIR/text-utils/col"}
diff --git a/tests/expected/ts-col-multibyte b/tests/expected/ts-col-multibyte
new file mode 100644
index 000000000..c6d36cce3
--- /dev/null
+++ b/tests/expected/ts-col-multibyte
@@ -0,0 +1 @@
+col: Invalid or incomplete multibyte or wide character
diff --git a/tests/functions.sh b/tests/functions.sh
index 81168fc32..8e8b34f74 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -2,6 +2,7 @@
TS_OUTDIR="$TS_TOPDIR/output"
TS_DIFFDIR="$TS_TOPDIR/diff"
TS_EXPECTEDDIR="$TS_TOPDIR/expected"
+TS_INPUTDIR="$TS_TOPDIR/input"
function ts_skip {
echo " IGNORE ($1)"
@@ -9,6 +10,7 @@ function ts_skip {
}
function ts_init {
+ export LANG="en_US.UTF-8":
TS_NAME=$(basename $0)
if [ ! -d $TS_OUTDIR ]; then
mkdir -p $TS_OUTDIR
@@ -19,6 +21,7 @@ function ts_init {
TS_OUTPUT="$TS_OUTDIR/$TS_NAME"
TS_DIFF="$TS_DIFFDIR/$TS_NAME"
TS_EXPECTED="$TS_EXPECTEDDIR/$TS_NAME"
+ TS_INPUT="$TS_INPUTDIR/$TS_NAME"
rm -f $TS_OUTPUT
@@ -35,7 +38,7 @@ function ts_finalize {
res=1
fi
else
- res=0
+ res=1
fi
else
echo " IGNORE (expected output undefined)"
diff --git a/tests/input/ts-col-multibyte b/tests/input/ts-col-multibyte
new file mode 100644
index 000000000..b203afd0a
--- /dev/null
+++ b/tests/input/ts-col-multibyte
@@ -0,0 +1 @@
+Dateiname der Versandhülle
diff --git a/tests/ts-col-multibyte b/tests/ts-col-multibyte
new file mode 100755
index 000000000..125e396c7
--- /dev/null
+++ b/tests/ts-col-multibyte
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+. commands.sh
+. functions.sh
+
+TS_COMPONENT="col"
+TS_DESC="multibyte"
+
+ts_init
+
+cat $TS_INPUT | $TS_CMD_COL > /dev/null 2> $TS_OUTPUT
+
+
+
+
+ts_finalize
+
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)