This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

patch: PR libc/2254: make locale(1) report errors and improve help

Here is a patch to solve the problems reported in PR libc/2254.  The
problem is that no error message is printed by locale(1) when an
incorrect locale environment variable is in use, and that 'locale
--help' do not mention how to use the 'NAME' argument.  Neither does
the documentation, as far as I can see.

This patch tries to improve both these situations.  I choose to make
the setlocale() error a non-fatal one, to make locale(1) behave as it
does now, ignoring the problem and just keep running.

When this patch is applied, the problem report 2254 can be closed as

2003-05-18  Petter Reinholdtsen <>

	* locale/programs/locale.c (main): Report an error if setlocale()
	fails. [PR libc/2254].
	* locale/programs/locale.c (more_help) Document some examples of
	valid names to use as arguments to the locale program. [PR

Index: locale/programs/locale.c
RCS file: /cvs/glibc/libc/locale/programs/locale.c,v
retrieving revision 1.48
diff -u -3 -p -u -r1.48 locale.c
--- locale/programs/locale.c	27 Apr 2003 08:58:05 -0000	1.48
+++ locale/programs/locale.c	18 May 2003 10:58:02 -0000
@@ -191,8 +191,10 @@ main (int argc, char *argv[])
   /* Set locale.  Do not set LC_ALL because the other categories must
      not be affected (according to POSIX.2).  */
-  setlocale (LC_CTYPE, "");
-  setlocale (LC_MESSAGES, "");
+  if (NULL == setlocale (LC_CTYPE, ""))
+    error (0, errno, gettext ("while setting LC_CTYPE to default locale"));
+  if (NULL == setlocale (LC_MESSAGES, ""))
+    error (0, errno, gettext ("while setting LC_MESSAGES to default locale"));
   /* Initialize the message catalog.  */
   textdomain (PACKAGE);
@@ -203,7 +205,9 @@ main (int argc, char *argv[])
   /* `-a' requests the names of all available locales.  */
   if (do_all != 0)
-      setlocale (LC_COLLATE, "");
+      if (NULL == setlocale (LC_COLLATE, ""))
+	error (0, errno,
+	       gettext ("while setting LC_COLLATE to default locale"));
       write_locales ();
       exit (EXIT_SUCCESS);
@@ -218,7 +222,8 @@ main (int argc, char *argv[])
   /* Specific information about the current locale are requested.
      Change to this locale now.  */
-  setlocale (LC_ALL, "");
+  if (NULL == setlocale (LC_ALL, ""))
+    error (0, errno, gettext ("while setting LC_ALL to default locale"));
   /* If no real argument is given we have to print the contents of the
      current locale definition variables.  These are LANG and the LC_*.  */
@@ -271,8 +276,11 @@ more_help (int key, const char *text, vo
       /* We print some extra information.  */
-      return xstrdup (gettext ("\
-Report bugs using the `glibcbug' script to <>.\n"));
+      return xstrdup (gettext ("\n"
+"NAME is the name of a locale data entry.  Examples are 'charmap' and\n"
+"'int_curr_symbol'  See the source for the full list.\n"
+"Report bugs using the `glibcbug' script to <>.\n"));

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]