For isprint() to work correctly in a UTF-8 locale applications must
set up the LC_CTYPE locale before using isprint().

As done for hexdump and tcpdump already.

This diff covers all offenders in usr.bin.

Index: bc/bc.y
===================================================================
RCS file: /cvs/src/usr.bin/bc/bc.y,v
retrieving revision 1.34
diff -u -p -r1.34 bc.y
--- bc/bc.y     7 Mar 2011 08:11:15 -0000       1.34
+++ bc/bc.y     4 Apr 2011 21:32:29 -0000
@@ -38,6 +38,7 @@
 #include <errno.h>
 #include <histedit.h>
 #include <limits.h>
+#include <locale.h>
 #include <search.h>
 #include <signal.h>
 #include <stdarg.h>
@@ -1088,6 +1089,7 @@ main(int argc, char *argv[])
        int     p[2];
        char    *q;
 
+       setlocale(LC_CTYPE, "");
        init();
        setlinebuf(stdout);
 
Index: bgplg/bgplgsh.c
===================================================================
RCS file: /cvs/src/usr.bin/bgplg/bgplgsh.c,v
retrieving revision 1.3
diff -u -p -r1.3 bgplgsh.c
--- bgplg/bgplgsh.c     2 Apr 2010 21:20:49 -0000       1.3
+++ bgplg/bgplgsh.c     4 Apr 2011 21:41:52 -0000
@@ -20,6 +20,7 @@
 #include <sys/types.h>
 #include <sys/param.h>
 
+#include <locale.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
@@ -225,6 +226,7 @@ main(void)
        /* Ignore the whitespace character */
        rl_basic_word_break_characters = "\t\n\"\\'`@$><=;|&{(";
 
+       setlocale(LC_CTYPE, "");
        while (!quit) {
                v = -1;
                gethostname(prompt, sizeof(prompt) - 2);
Index: chpass/chpass.c
===================================================================
RCS file: /cvs/src/usr.bin/chpass/chpass.c,v
retrieving revision 1.37
diff -u -p -r1.37 chpass.c
--- chpass/chpass.c     27 Oct 2009 23:59:36 -0000      1.37
+++ chpass/chpass.c     4 Apr 2011 21:34:44 -0000
@@ -45,6 +45,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <locale.h>
 #include <unistd.h>
 #include <util.h>
 
@@ -74,6 +75,9 @@ main(int argc, char *argv[])
 #ifdef YP
        use_yp = _yp_check(NULL);
 #endif
+
+       setlocale(LC_CTYPE, "");
+
        /* We need to use the system timezone for date conversions. */
        if ((tz = getenv("TZ")) != NULL) {
            unsetenv("TZ");
Index: cvs/cvs.c
===================================================================
RCS file: /cvs/src/usr.bin/cvs/cvs.c,v
retrieving revision 1.151
diff -u -p -r1.151 cvs.c
--- cvs/cvs.c   23 Jul 2010 08:31:19 -0000      1.151
+++ cvs/cvs.c   4 Apr 2011 21:36:04 -0000
@@ -30,6 +30,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <pwd.h>
+#include <locale.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
@@ -188,6 +189,7 @@ main(int argc, char **argv)
        char fpath[MAXPATHLEN];
 
        tzset();
+       setlocale(LC_CTYPE, "");
 
        TAILQ_INIT(&cvs_variables);
        SLIST_INIT(&repo_locks);
Index: diff/diff.c
===================================================================
RCS file: /cvs/src/usr.bin/diff/diff.c,v
retrieving revision 1.57
diff -u -p -r1.57 diff.c
--- diff/diff.c 16 Jul 2010 23:27:58 -0000      1.57
+++ diff/diff.c 4 Apr 2011 21:38:23 -0000
@@ -27,6 +27,7 @@
 #include <err.h>
 #include <errno.h>
 #include <getopt.h>
+#include <locale.h>
 #include <signal.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -87,6 +88,7 @@ main(int argc, char **argv)
        long  l;
        int   ch, dflags, lastch, gotstdin, prevoptind, newarg;
 
+       setlocale(LC_CTYPE, "");
        oargv = argv;
        gotstdin = 0;
        dflags = 0;
Index: finger/finger.c
===================================================================
RCS file: /cvs/src/usr.bin/finger/finger.c,v
retrieving revision 1.18
diff -u -p -r1.18 finger.c
--- finger/finger.c     12 Nov 2009 15:33:21 -0000      1.18
+++ finger/finger.c     4 Apr 2011 21:41:09 -0000
@@ -59,6 +59,7 @@
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/stat.h>
+#include <locale.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -84,6 +85,8 @@ main(int argc, char *argv[])
        struct stat sb;
 
        oflag = 1;              /* default to old "office" behavior */
+
+       setlocale(LC_CTYPE, "");
 
        while ((ch = getopt(argc, argv, "lmMpsho")) != -1)
                switch(ch) {
Index: grep/grep.c
===================================================================
RCS file: /cvs/src/usr.bin/grep/grep.c,v
retrieving revision 1.43
diff -u -p -r1.43 grep.c
--- grep/grep.c 4 Mar 2011 03:11:23 -0000       1.43
+++ grep/grep.c 4 Apr 2011 21:44:00 -0000
@@ -35,6 +35,7 @@
 #include <err.h>
 #include <errno.h>
 #include <getopt.h>
+#include <locale.h>
 #include <regex.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -236,6 +237,8 @@ main(int argc, char *argv[])
        struct patfile *patfile, *pf_next;
        long l;
        char *ep, **expr;
+
+       setlocale(LC_CTYPE, "");
 
        SLIST_INIT(&patfilelh);
        switch (__progname[0]) {
Index: infocmp/infocmp.c
===================================================================
RCS file: /cvs/src/usr.bin/infocmp/infocmp.c,v
retrieving revision 1.20
diff -u -p -r1.20 infocmp.c
--- infocmp/infocmp.c   12 Jan 2010 23:22:13 -0000      1.20
+++ infocmp/infocmp.c   4 Apr 2011 21:46:04 -0000
@@ -1291,6 +1291,8 @@ main(int argc, char *argv[])
 
     _nc_progname = _nc_rootname(argv[0]);
 
+    setlocale(LC_CTYPE, "");
+
     /* make sure we have enough space to add two terminal entries */
     myargv = typeCalloc(char *, (size_t) (argc + 3));
     memcpy(myargv, argv, (sizeof(char *) * (size_t) argc));
Index: kdump/kdump.c
===================================================================
RCS file: /cvs/src/usr.bin/kdump/kdump.c,v
retrieving revision 1.47
diff -u -p -r1.47 kdump.c
--- kdump/kdump.c       6 Jul 2010 00:31:02 -0000       1.47
+++ kdump/kdump.c       4 Apr 2011 21:48:48 -0000
@@ -42,6 +42,7 @@
 
 #include <ctype.h>
 #include <err.h>
+#include <locale.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -134,6 +135,8 @@ main(int argc, char *argv[])
        void *m;
 
        current = &emulations[0];       /* native */
+
+       setlocale(LC_CTYPE, "");
 
        while ((ch = getopt(argc, argv, "e:f:dlm:nRp:Tt:xX")) != -1)
                switch (ch) {
Index: lastcomm/lastcomm.c
===================================================================
RCS file: /cvs/src/usr.bin/lastcomm/lastcomm.c,v
retrieving revision 1.17
diff -u -p -r1.17 lastcomm.c
--- lastcomm/lastcomm.c 27 Oct 2009 23:59:39 -0000      1.17
+++ lastcomm/lastcomm.c 4 Apr 2011 21:49:59 -0000
@@ -37,6 +37,7 @@
 #include <ctype.h>
 #include <err.h>
 #include <fcntl.h>
+#include <locale.h>
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -66,6 +67,8 @@ main(int argc, char *argv[])
        double delta;
        int ch;
        char *acctfile;
+
+       setlocale(LC_CTYPE, "");
 
        acctfile = _PATH_ACCT;
        while ((ch = getopt(argc, argv, "f:")) != -1)
Index: lex/libmain.c
===================================================================
RCS file: /cvs/src/usr.bin/lex/libmain.c,v
retrieving revision 1.6
diff -u -p -r1.6 libmain.c
--- lex/libmain.c       28 Jul 2003 20:38:31 -0000      1.6
+++ lex/libmain.c       4 Apr 2011 21:52:07 -0000
@@ -5,6 +5,7 @@
 /* $Header: /cvs/src/usr.bin/lex/libmain.c,v 1.6 2003/07/28 20:38:31 deraadt 
Exp $ */
 
 #include <sys/cdefs.h>
+#include <locale.h>
 
 int yylex(void);
 int main(int, char **);
@@ -13,6 +14,8 @@ int main(int, char **);
 int
 main(int argc, char *argv[])
 {
+       setlocale(LC_CTYPE, "");
+
        while (yylex() != 0)
                ;
 
Index: mail/main.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/main.c,v
retrieving revision 1.23
diff -u -p -r1.23 main.c
--- mail/main.c 27 Oct 2009 23:59:40 -0000      1.23
+++ mail/main.c 4 Apr 2011 21:54:58 -0000
@@ -33,6 +33,7 @@
 #include "rcv.h"
 #include <fcntl.h>
 #include <sys/ioctl.h>
+#include <locale.h>
 #include "extern.h"
 
 __dead void    usage(void);
@@ -60,6 +61,7 @@ main(int argc, char **argv)
         * Figure out whether we are being run interactively,
         * start the SIGCHLD catcher, and so forth.
         */
+       setlocale(LC_CTYPE, "");
        (void)signal(SIGCHLD, sigchild);
        (void)signal(SIGPIPE, SIG_IGN);
        if (isatty(0))
Index: mg/main.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/main.c,v
retrieving revision 1.61
diff -u -p -r1.61 main.c
--- mg/main.c   4 Jun 2009 02:23:37 -0000       1.61
+++ mg/main.c   4 Apr 2011 21:56:21 -0000
@@ -48,6 +48,8 @@ main(int argc, char **argv)
        int      nobackups = 0;
        struct buffer *bp;
 
+       setlocale(LC_CTYPE, "");
+
        while ((o = getopt(argc, argv, "nf:")) != -1)
                switch (o) {
                case 'n':
Index: mg/sysdef.h
===================================================================
RCS file: /cvs/src/usr.bin/mg/sysdef.h,v
retrieving revision 1.16
diff -u -p -r1.16 sysdef.h
--- mg/sysdef.h 15 Sep 2008 16:11:35 -0000      1.16
+++ mg/sysdef.h 4 Apr 2011 21:56:03 -0000
@@ -13,6 +13,7 @@
 #include <string.h>
 #include <errno.h>
 #include <signal.h>
+#include <locale.h>
 
 #define        KBLOCK          8192    /* Kill grow.                    */
 #define        GOOD            0       /* Good exit status.             */
Index: mklocale/yacc.y
===================================================================
RCS file: /cvs/src/usr.bin/mklocale/yacc.y,v
retrieving revision 1.4
diff -u -p -r1.4 yacc.y
--- mklocale/yacc.y     14 Jan 2011 23:15:40 -0000      1.4
+++ mklocale/yacc.y     4 Apr 2011 21:57:21 -0000
@@ -42,6 +42,7 @@
 
 #include <err.h>
 #include "locale/runetype.h"
+#include <locale.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -249,6 +250,8 @@ main(int ac, char *av[])
 
     extern char *optarg;
     extern int optind;
+
+    setlocale(LC_CTYPE, "");
 
     while ((x = getopt(ac, av, "do:")) != -1) {
        switch(x) {
Index: rcs/rcsprog.c
===================================================================
RCS file: /cvs/src/usr.bin/rcs/rcsprog.c,v
retrieving revision 1.150
diff -u -p -r1.150 rcsprog.c
--- rcs/rcsprog.c       6 Dec 2010 22:47:56 -0000       1.150
+++ rcs/rcsprog.c       4 Apr 2011 21:59:20 -0000
@@ -27,6 +27,7 @@
 #include <sys/stat.h>
 
 #include <err.h>
+#include <locale.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -127,6 +128,8 @@ main(int argc, char **argv)
        u_int i;
        char **cmd_argv;
        int ret, cmd_argc;
+
+       setlocale(LC_CTYPE, "");
 
        ret = -1;
        rcs_optind = 1;
Index: rpcgen/rpc_main.c
===================================================================
RCS file: /cvs/src/usr.bin/rpcgen/rpc_main.c,v
retrieving revision 1.25
diff -u -p -r1.25 rpc_main.c
--- rpcgen/rpc_main.c   1 Sep 2010 14:43:34 -0000       1.25
+++ rpcgen/rpc_main.c   4 Apr 2011 22:00:17 -0000
@@ -46,6 +46,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <locale.h>
 #include <ctype.h>
 #include <sys/stat.h>
 #include "rpc_parse.h"
@@ -140,6 +141,8 @@ int
 main(int argc, char *argv[])
 {
        struct commandline cmd;
+
+       setlocale(LC_CTYPE, "");
 
        (void) memset((char *) &cmd, 0, sizeof(struct commandline));
        clear_args();
Index: sed/main.c
===================================================================
RCS file: /cvs/src/usr.bin/sed/main.c,v
retrieving revision 1.17
diff -u -p -r1.17 main.c
--- sed/main.c  27 Oct 2009 23:59:43 -0000      1.17
+++ sed/main.c  4 Apr 2011 22:01:01 -0000
@@ -39,6 +39,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <locale.h>
 #include <regex.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -95,6 +96,8 @@ int
 main(int argc, char *argv[])
 {
        int c, fflag;
+
+       setlocale(LC_CTYPE, "");
 
        fflag = 0;
        while ((c = getopt(argc, argv, "Eae:f:nru")) != -1)
Index: systat/main.c
===================================================================
RCS file: /cvs/src/usr.bin/systat/main.c,v
retrieving revision 1.57
diff -u -p -r1.57 main.c
--- systat/main.c       16 Jul 2010 05:22:48 -0000      1.57
+++ systat/main.c       4 Apr 2011 22:02:26 -0000
@@ -41,6 +41,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <locale.h>
 #include <netdb.h>
 #include <signal.h>
 #include <stdio.h>
@@ -375,6 +376,8 @@ main(int argc, char *argv[])
        int maxlines = 0;
 
        int ch;
+
+       setlocale(LC_CTYPE, "");
 
        ut = open(_PATH_UTMP, O_RDONLY);
        if (ut < 0) {
Index: talk/talk.c
===================================================================
RCS file: /cvs/src/usr.bin/talk/talk.c,v
retrieving revision 1.9
diff -u -p -r1.9 talk.c
--- talk/talk.c 27 Oct 2009 23:59:44 -0000      1.9
+++ talk/talk.c 4 Apr 2011 22:03:17 -0000
@@ -49,6 +49,7 @@
 int
 main(int argc, char *argv[])
 {
+       setlocale(LC_CTYPE, "");
        get_names(argc, argv);
        init_display();
        open_ctl();
Index: talk/talk.h
===================================================================
RCS file: /cvs/src/usr.bin/talk/talk.h,v
retrieving revision 1.11
diff -u -p -r1.11 talk.h
--- talk/talk.h 9 May 2009 11:05:01 -0000       1.11
+++ talk/talk.h 4 Apr 2011 22:03:06 -0000
@@ -37,6 +37,7 @@
 #include <netinet/in.h>
 #include <protocols/talkd.h>
 #include <curses.h>
+#include <locale.h>
 #include <signal.h>
 #include <string.h>
 #include <err.h>
Index: telnet/main.c
===================================================================
RCS file: /cvs/src/usr.bin/telnet/main.c,v
retrieving revision 1.20
diff -u -p -r1.20 main.c
--- telnet/main.c       3 Jul 2010 04:44:51 -0000       1.20
+++ telnet/main.c       4 Apr 2011 22:04:12 -0000
@@ -150,6 +150,8 @@ main(argc, argv)
        extern int forward_flags;
 #endif /* FORWARD */
 
+       setlocale(LC_CTYPE, "");
+
 #ifdef KRB5
        krb5_init();
 #endif
Index: telnet/telnet_locl.h
===================================================================
RCS file: /cvs/src/usr.bin/telnet/telnet_locl.h,v
retrieving revision 1.3
diff -u -p -r1.3 telnet_locl.h
--- telnet/telnet_locl.h        14 May 2003 01:46:51 -0000      1.3
+++ telnet/telnet_locl.h        4 Apr 2011 22:04:01 -0000
@@ -45,6 +45,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <ctype.h>
+#include <locale.h>
 #include <signal.h>
 #include <errno.h>
 #include <setjmp.h>
Index: tic/progs.priv.h
===================================================================
RCS file: /cvs/src/usr.bin/tic/progs.priv.h,v
retrieving revision 1.9
diff -u -p -r1.9 progs.priv.h
--- tic/progs.priv.h    12 Jan 2010 23:22:14 -0000      1.9
+++ tic/progs.priv.h    4 Apr 2011 21:46:49 -0000
@@ -66,6 +66,8 @@
 # include <sys/param.h>
 #endif
 
+#include <locale.h>
+
 #if HAVE_DIRENT_H
 # include <dirent.h>
 # define NAMLEN(dirent) strlen((dirent)->d_name)
Index: tic/tic.c
===================================================================
RCS file: /cvs/src/usr.bin/tic/tic.c,v
retrieving revision 1.30
diff -u -p -r1.30 tic.c
--- tic/tic.c   12 Jan 2010 23:22:14 -0000      1.30
+++ tic/tic.c   4 Apr 2011 21:47:12 -0000
@@ -501,6 +501,8 @@ main(int argc, char *argv[])
 
     log_fp = stderr;
 
+    setlocale(LC_CTYPE, "");
+
     _nc_progname = _nc_rootname(argv[0]);
 
     if ((infodump = (strcmp(_nc_progname, PROG_CAPTOINFO) == 0)) != FALSE) {
Index: top/top.c
===================================================================
RCS file: /cvs/src/usr.bin/top/top.c,v
retrieving revision 1.75
diff -u -p -r1.75 top.c
--- top/top.c   24 Apr 2010 22:02:14 -0000      1.75
+++ top/top.c   4 Apr 2011 22:05:58 -0000
@@ -32,6 +32,7 @@
 #include <curses.h>
 #include <err.h>
 #include <errno.h>
+#include <locale.h>
 #include <stdio.h>
 #include <signal.h>
 #include <string.h>
@@ -269,6 +270,8 @@ main(int argc, char *argv[])
        sigset_t mask, oldmask;
        time_t curr_time;
        caddr_t processes;
+
+       setlocale(LC_CTYPE, "");
 
        /* set the buffer for stdout */
 #ifdef DEBUG
Index: tr/tr.c
===================================================================
RCS file: /cvs/src/usr.bin/tr/tr.c,v
retrieving revision 1.15
diff -u -p -r1.15 tr.c
--- tr/tr.c     27 Oct 2009 23:59:46 -0000      1.15
+++ tr/tr.c     4 Apr 2011 22:08:54 -0000
@@ -32,6 +32,7 @@
 
 #include <sys/types.h>
 
+#include <locale.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -86,6 +87,8 @@ main(int argc, char *argv[])
 {
        int ch, cnt, lastch, *p;
        int cflag, dflag, sflag, isstring2;
+
+       setlocale(LC_CTYPE, "");
 
        cflag = dflag = sflag = 0;
        while ((ch = getopt(argc, argv, "cds")) != -1)
Index: what/what.c
===================================================================
RCS file: /cvs/src/usr.bin/what/what.c,v
retrieving revision 1.12
diff -u -p -r1.12 what.c
--- what/what.c 27 Oct 2009 23:59:50 -0000      1.12
+++ what/what.c 4 Apr 2011 22:10:37 -0000
@@ -35,6 +35,7 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <err.h>
+#include <locale.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -57,6 +58,8 @@ main(int argc, char *argv[])
        struct utsname utsn;
        char match[256];
        int c;
+
+       setlocale(LC_CTYPE, "");
 
        matches = sflag = 0;
        while ((c = getopt(argc, argv, "s")) != -1) {
Index: yacc/main.c
===================================================================
RCS file: /cvs/src/usr.bin/yacc/main.c,v
retrieving revision 1.23
diff -u -p -r1.23 main.c
--- yacc/main.c 27 Oct 2009 23:59:50 -0000      1.23
+++ yacc/main.c 4 Apr 2011 22:11:55 -0000
@@ -36,6 +36,7 @@
 #include <sys/types.h>
 #include <fcntl.h>
 #include <paths.h>
+#include <locale.h>
 #include <signal.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -366,6 +367,7 @@ open_files(void)
 int
 main(int argc, char *argv[])
 {
+    setlocale(LC_CTYPE, "");
     set_signals();
     getargs(argc, argv);
     open_files();

Reply via email to