diff options
author | bapt <bapt@FreeBSD.org> | 2016-01-18 20:47:04 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2016-01-18 20:47:04 +0000 |
commit | a4bbea0419ac706a7197d1db72bb3c784a075776 (patch) | |
tree | c5fd4dcae9b797f8a573ae817692cfd09f2221fb /usr.bin/finger/net.c | |
parent | c81a82d3821dcd7490df7a6a2f445ded2a2ec82f (diff) | |
download | FreeBSD-src-a4bbea0419ac706a7197d1db72bb3c784a075776.zip FreeBSD-src-a4bbea0419ac706a7197d1db72bb3c784a075776.tar.gz |
Fix printing multibyte printing when performing a networked finger(1) request
MFC after: 1 week
Diffstat (limited to 'usr.bin/finger/net.c')
-rw-r--r-- | usr.bin/finger/net.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/usr.bin/finger/net.c b/usr.bin/finger/net.c index 2b18b0f..da3a4e1 100644 --- a/usr.bin/finger/net.c +++ b/usr.bin/finger/net.c @@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/socket.h> #include <sys/uio.h> -#include <ctype.h> +#include <wctype.h> #include <db.h> #include <err.h> #include <netdb.h> @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <unistd.h> #include <utmpx.h> +#include <wchar.h> #include "finger.h" static void cleanup(int sig); @@ -108,7 +109,7 @@ do_protocol(const char *name, const struct addrinfo *ai) { int cnt, line_len, s; FILE *fp; - int c, lastc; + wint_t c, lastc; struct iovec iov[3]; struct msghdr msg; static char slash_w[] = "/W "; @@ -168,7 +169,7 @@ do_protocol(const char *name, const struct addrinfo *ai) if ((fp = fdopen(s, "r")) != NULL) { cnt = 0; line_len = 0; - while ((c = getc(fp)) != EOF) { + while ((c = getwc(fp)) != EOF) { if (++cnt > OUTPUT_MAX) { printf("\n\n Output truncated at %d bytes...\n", cnt - 1); @@ -180,7 +181,7 @@ do_protocol(const char *name, const struct addrinfo *ai) c = '\n'; lastc = '\r'; } else { - if (!isprint(c) && !isspace(c)) { + if (!iswprint(c) && !iswspace(c)) { c &= 0x7f; c |= 0x40; } @@ -191,7 +192,7 @@ do_protocol(const char *name, const struct addrinfo *ai) continue; } } - putchar(c); + putwchar(c); if (c != '\n' && ++line_len > _POSIX2_LINE_MAX) { putchar('\\'); putchar('\n'); @@ -206,7 +207,7 @@ do_protocol(const char *name, const struct addrinfo *ai) */ warn("reading from network"); } - if (lastc != '\n') + if (lastc != L'\n') putchar('\n'); fclose(fp); |