diff --git a/usr.bin/rev/rev.c b/usr.bin/rev/rev.c index 6a48d5e7e35e..87c858712ff8 100644 --- a/usr.bin/rev/rev.c +++ b/usr.bin/rev/rev.c @@ -50,21 +50,26 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include #include +#include void usage(void); int main(int argc, char *argv[]) { - const char *filename, *p, *t; + const char *filename; + wchar_t *p, *t; FILE *fp; size_t len; int ch, rval; + setlocale(LC_ALL, ""); + while ((ch = getopt(argc, argv, "")) != -1) switch(ch) { case '?': @@ -88,13 +93,13 @@ main(int argc, char *argv[]) } filename = *argv++; } - while ((p = fgetln(fp, &len)) != NULL) { + while ((p = fgetwln(fp, &len)) != NULL) { if (p[len - 1] == '\n') --len; t = p + len - 1; for (t = p + len - 1; t >= p; --t) - putchar(*t); - putchar('\n'); + putwchar(*t); + putwchar('\n'); } if (ferror(fp)) { warn("%s", filename);