Subject: userlevel tools and setlocale(3)
To: None <tech-userlevel@NetBSD.org>
From: Aleksey Cheusov <cheusov@tut.by>
List: tech-userlevel
Date: 04/27/2006 21:53:56
Hi all.
What do you think about the following patch for nawk?
With this patch applied, awk will exit with error
if LANG or LC_ variable are set to incorrect value,
or if appropriate locale is not installed on a system.
I found that most (all?) NetBSD user level tools
silently ignore return value of setlocale(3).
Can anybody explain me why? In my view this is a bug.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Index: dist/nawk/main.c
===================================================================
RCS file: /cvsroot/src/dist/nawk/main.c,v
retrieving revision 1.4
diff -u -r1.4 main.c
--- dist/nawk/main.c    2 Aug 2003 22:42:00 -0000       1.4
+++ dist/nawk/main.c    27 Apr 2006 18:44:13 -0000
@@ -56,9 +56,14 @@
 {
        const char *fs = NULL;
 
-       setlocale(LC_CTYPE, "");
-       setlocale(LC_NUMERIC, "C"); /* for parsing cmdline & prog */
        cmdname = argv[0];
+
+       if (!setlocale(LC_CTYPE, ""))
+               FATAL("cannot setlocale (LC_CTYPE, \"\")");
+
+       if (!setlocale(LC_NUMERIC, "C")) /* for parsing cmdline & prog */
+               FATAL("cannot setlocale (LC_NUMERIC, \"C\")");
+
        if (argc == 1) {
                fprintf(stderr, "Usage: %s [-f programfile | 'program'] [-Ffieldsep] [-v var=value] [files]\n", cmdname);
                exit(1);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-- 
Best regards, Aleksey Cheusov.