On Sun, Jun 19, 2011 at 02:21:10PM +0200, Stefan Sperling wrote:
> [[[
> Make tools in usr.bin which use isprint() call setlocale() so that
> the ctype map is initialised correctly. Prevents printing of invalid
> UTF-8 if the UTF-8 locale is active.
> ]]]
I am still looking for OKs for this one.
>
> Index: bc/bc.y
> ===================================================================
> RCS file: /cvs/src/usr.bin/bc/bc.y,v
> retrieving revision 1.37
> diff -u -p -r1.37 bc.y
> --- bc/bc.y 3 Jun 2011 06:52:37 -0000 1.37
> +++ bc/bc.y 5 Jun 2011 09:14:35 -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>
> @@ -1089,6 +1090,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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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.50
> diff -u -p -r1.50 kdump.c
> --- kdump/kdump.c 2 Jun 2011 16:19:13 -0000 1.50
> +++ kdump/kdump.c 5 Jun 2011 09:14:35 -0000
> @@ -42,6 +42,7 @@
>
> #include <ctype.h>
> #include <err.h>
> +#include <locale.h>
> #include <signal.h>
> #include <stdio.h>
> #include <stdlib.h>
> @@ -129,6 +130,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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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.59
> diff -u -p -r1.59 main.c
> --- systat/main.c 5 Apr 2011 07:35:32 -0000 1.59
> +++ systat/main.c 5 Jun 2011 09:14:35 -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>
> @@ -391,6 +392,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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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 5 Jun 2011 09:14:35 -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();