--- coreutils-8.4/src/expand.c.orig 2010-01-03 18:06:20.000000000 +0100 +++ coreutils-8.4/src/expand.c 2010-03-09 13:42:53.112823153 +0100 @@ -36,6 +36,8 @@ #include #include +#include +#include #include #include #include "system.h" @@ -272,8 +274,8 @@ for (;;) { - /* Input character, or EOF. */ - int c; + /* Input character, or WEOF. */ + wchar_t c; /* If true, perform translations. */ bool convert = true; @@ -293,12 +295,13 @@ do { - while ((c = getc (fp)) < 0 && (fp = next_file (fp))) + /* skip to next readable character */ + while ((c = fgetwc (fp)) == WEOF && (fp = next_file (fp))) continue; if (convert) { - if (c == '\t') + if (c == L'\t') { /* Column the next input tab stop is on. */ uintmax_t next_tab_column; @@ -326,12 +329,12 @@ error (EXIT_FAILURE, 0, _("input line is too long")); while (++column < next_tab_column) - if (putchar (' ') < 0) + if (putwchar (L' ') == WEOF) error (EXIT_FAILURE, errno, _("write error")); - c = ' '; + c = L' '; } - else if (c == '\b') + else if (c == L'\b') { /* Go back one column, and force recalculation of the next tab stop. */ @@ -345,16 +348,16 @@ error (EXIT_FAILURE, 0, _("input line is too long")); } - convert &= convert_entire_line || !! isblank (c); + convert &= convert_entire_line || !! iswblank (c); } - if (c < 0) + if (c == WEOF ) return; - if (putchar (c) < 0) + if (putwchar (c) == WEOF) error (EXIT_FAILURE, errno, _("write error")); } - while (c != '\n'); + while (c != L'\n'); } }