isprint() needs setlocale(); for usr.bin

2011-04-04 Thread Stefan Sperling
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 -   1.34
+++ bc/bc.y 4 Apr 2011 21:32:29 -
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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 -   1.3
+++ bgplg/bgplgsh.c 4 Apr 2011 21:41:52 -
@@ -20,6 +20,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -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 -  1.37
+++ chpass/chpass.c 4 Apr 2011 21:34:44 -
@@ -45,6 +45,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -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 -  1.151
+++ cvs/cvs.c   4 Apr 2011 21:36:04 -
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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 -  1.57
+++ diff/diff.c 4 Apr 2011 21:38:23 -
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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 -  1.18
+++ finger/finger.c 4 Apr 2011 21:41:09 -
@@ -59,6 +59,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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 -   1.43
+++ grep/grep.c 4 Apr 2011 21:44:00 -
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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 -  1.20
+++ infocmp/infocmp.c   4 Apr 2011 21:46:04 -
@@ -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 *

Re: isprint() needs setlocale(); for usr.bin

2011-04-17 Thread Stefan Sperling
On Tue, Apr 05, 2011 at 12:25:37AM +0200, Stefan Sperling wrote:
> 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.

Todd Miller suggested using LC_ALL instead of LC_CTYPE so we don't have
to revisit these when we add support for more categories.

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 -   1.34
+++ bc/bc.y 4 Apr 2011 21:32:29 -
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1088,6 +1089,7 @@ main(int argc, char *argv[])
int p[2];
char*q;
 
+   setlocale(LC_ALL, "");
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 -   1.3
+++ bgplg/bgplgsh.c 4 Apr 2011 21:41:52 -
@@ -20,6 +20,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -225,6 +226,7 @@ main(void)
/* Ignore the whitespace character */
rl_basic_word_break_characters = "\t\n\"\\'`@$><=;|&{(";
 
+   setlocale(LC_ALL, "");
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 -  1.37
+++ chpass/chpass.c 4 Apr 2011 21:34:44 -
@@ -45,6 +45,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -74,6 +75,9 @@ main(int argc, char *argv[])
 #ifdef YP
use_yp = _yp_check(NULL);
 #endif
+
+   setlocale(LC_ALL, "");
+
/* 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 -  1.151
+++ cvs/cvs.c   4 Apr 2011 21:36:04 -
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -188,6 +189,7 @@ main(int argc, char **argv)
char fpath[MAXPATHLEN];
 
tzset();
+   setlocale(LC_ALL, "");
 
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 -  1.57
+++ diff/diff.c 4 Apr 2011 21:38:23 -
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -87,6 +88,7 @@ main(int argc, char **argv)
long  l;
int   ch, dflags, lastch, gotstdin, prevoptind, newarg;
 
+   setlocale(LC_ALL, "");
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 -  1.18
+++ finger/finger.c 4 Apr 2011 21:41:09 -
@@ -59,6 +59,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -84,6 +85,8 @@ main(int argc, char *argv[])
struct stat sb;
 
oflag = 1;  /* default to old "office" behavior */
+
+   setlocale(LC_ALL, "");
 
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 -   1.43
+++ grep/grep.c 4 Apr 2011 21:44:00 -
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -236,6 +237,8 @@ main(int argc, char *argv[])
struct patfile *patfile, *pf_next;
long l;
char *ep, **expr;
+
+   setlocale(LC_ALL, "");
 
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 -  1.20
+++ infocmp/infocmp.c   4 Apr 2011 21:46:04 -
@@ -

Re: isprint() needs setlocale(); for usr.bin

2011-04-17 Thread Philip Guenther
On Sun, Apr 17, 2011 at 1:56 AM, Stefan Sperling  wrote:
> On Tue, Apr 05, 2011 at 12:25:37AM +0200, Stefan Sperling wrote:
>> 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.
>
> Todd Miller suggested using LC_ALL instead of LC_CTYPE so we don't have
> to revisit these when we add support for more categories.

Has there been any sort of audit of how this will affect scripts
distributed with the system?  I seem to recall having to fix various
scripts elsewhere when Redhat started shipping with LANG=en_US.UTF-8
set in the default shell environment, things like character ranges in
grep patterns changing behavior.  The scripts didn't handle any sort
of non-C locale correctly; the change in default just made that
incredibly obvious.  The quick fix is to apply the hammer and pass
LC_ALL=C, but that's overkill when all you really want is to force
LC_CTYPE=C behavior.

Hmm...

export LC_CTYPE=C
[[ -n $LC_ALL ]] && export LC_COLLATE=$LC_ALL LC_TIME=$LC_ALL \
 LC_NUMERIC=$LC_ALL LC_MONETARY=$LC_ALL LC_MESSAGES=$LC_ALL

A quick grep of /etc/*/* on a Redhat box finds *lots* of LANG=C
settings on commands.  Wheee


Philip Guenther



Re: isprint() needs setlocale(); for usr.bin

2011-05-08 Thread Stefan Sperling
On Sun, Apr 17, 2011 at 03:52:14PM -0700, Philip Guenther wrote:
> On Sun, Apr 17, 2011 at 1:56 AM, Stefan Sperling  wrote:
> > On Tue, Apr 05, 2011 at 12:25:37AM +0200, Stefan Sperling wrote:
> >> 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.
> >
> > Todd Miller suggested using LC_ALL instead of LC_CTYPE so we don't have
> > to revisit these when we add support for more categories.
> 
> Has there been any sort of audit of how this will affect scripts
> distributed with the system?

No.

> I seem to recall having to fix various
> scripts elsewhere when Redhat started shipping with LANG=en_US.UTF-8
> set in the default shell environment, things like character ranges in
> grep patterns changing behavior.  The scripts didn't handle any sort
> of non-C locale correctly; the change in default just made that
> incredibly obvious.  The quick fix is to apply the hammer and pass
> LC_ALL=C, but that's overkill when all you really want is to force
> LC_CTYPE=C behavior.

Is this really a problem we need to be concerned about?
We're far from making a UTF-8 locale the default locale, if ever.
Our default locale is C, with the addition of latin1 semantics for some
functions like isprint(). It has been ever since the initial citrus bits
were imported in 2005. So it's already a little bit more than ASCII.

> Hmm...
> 
> export LC_CTYPE=C
> [[ -n $LC_ALL ]] && export LC_COLLATE=$LC_ALL LC_TIME=$LC_ALL \
>  LC_NUMERIC=$LC_ALL LC_MONETARY=$LC_ALL LC_MESSAGES=$LC_ALL
> 
> A quick grep of /etc/*/* on a Redhat box finds *lots* of LANG=C
> settings on commands.  Wheee

Setting LANG=C for system scripts makes sense to me if the default
locale is something else. I suppose their problems are exacerbated by having
implemented LC_NUMERIC and LC_TIME, which can change output of programs
like bc(1) and date(1). We don't implement those.

Regarding LC_CTYPE, properties of characters in the range scripts care
about remain the same in C, ISO8859-1, and UTF-8 locales. In fact, the
UTF-8 locale is now stricter than our default locale because it does not
even consider single-byte characters above 0x7f valid, just like C probably
should.



Re: isprint() needs setlocale(); for usr.bin

2011-05-08 Thread Stefan Sperling
On Sun, May 08, 2011 at 01:22:55PM +0200, Stefan Sperling wrote:
> Setting LANG=C for system scripts makes sense to me if the default
> locale is something else. I suppose their problems are exacerbated by having
> implemented LC_NUMERIC and LC_TIME, which can change output of programs
> like bc(1) and date(1). We don't implement those.

Point being that we might want to use LC_CTYPE instead of LC_ALL in
this patch after all.



Re: isprint() needs setlocale(); for usr.bin

2011-06-19 Thread Stefan Sperling
On Sun, May 08, 2011 at 01:34:27PM +0200, Stefan Sperling wrote:
> On Sun, May 08, 2011 at 01:22:55PM +0200, Stefan Sperling wrote:
> > Setting LANG=C for system scripts makes sense to me if the default
> > locale is something else. I suppose their problems are exacerbated by having
> > implemented LC_NUMERIC and LC_TIME, which can change output of programs
> > like bc(1) and date(1). We don't implement those.
> 
> Point being that we might want to use LC_CTYPE instead of LC_ALL in
> this patch after all.

[ pinging old diffs ]

So... you still object to this going in?
Or is it fine with LC_CTYPE?

Note again that it does not change the default behaviour.

And none of these tools use wide character stuff. So they're going to have
a reduced amount of printable characters if the UTF-8 locale is active
(only ASCII), not more than they already do (default is all of latin1).

[[[
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.
]]]

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 -   1.37
+++ bc/bc.y 5 Jun 2011 09:14:35 -
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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 -   1.3
+++ bgplg/bgplgsh.c 5 Jun 2011 09:14:35 -
@@ -20,6 +20,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -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 -  1.37
+++ chpass/chpass.c 5 Jun 2011 09:14:35 -
@@ -45,6 +45,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -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 -  1.151
+++ cvs/cvs.c   5 Jun 2011 09:14:35 -
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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 -  1.57
+++ diff/diff.c 5 Jun 2011 09:14:35 -
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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 -  1.18
+++ finger/finger.c 5 Jun 2011 09:14:35 -
@@ -59,6 +59,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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 -   1.43
+++ grep/grep.c

Re: isprint() needs setlocale(); for usr.bin

2011-07-06 Thread Stefan Sperling
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 -   1.37
> +++ bc/bc.y   5 Jun 2011 09:14:35 -
> @@ -38,6 +38,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -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 -   1.3
> +++ bgplg/bgplgsh.c   5 Jun 2011 09:14:35 -
> @@ -20,6 +20,7 @@
>  #include 
>  #include 
>  
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -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 -  1.37
> +++ chpass/chpass.c   5 Jun 2011 09:14:35 -
> @@ -45,6 +45,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  
> @@ -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 -  1.151
> +++ cvs/cvs.c 5 Jun 2011 09:14:35 -
> @@ -30,6 +30,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -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 -  1.57
> +++ diff/diff.c   5 Jun 2011 09:14:35 -
> @@ -27,6 +27,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -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 -  1.18
> +++ finger/finger.c   5 Jun 2011 09:14:35 -
> @@ -59,6 +59,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -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 -   1.43
> +++ grep/grep.c   5 Jun 2011 09:14:35 -
> @@ -35,6 +35,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -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.