]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: with --debug, flag setlocale() failures on OpenBSD
authorPádraig Brady <P@draigBrady.com>
Thu, 14 Jan 2016 01:17:57 +0000 (01:17 +0000)
committerPádraig Brady <P@draigBrady.com>
Thu, 14 Jan 2016 01:26:00 +0000 (01:26 +0000)
Locale categories are not equivalent on OpenBSD,
and LC_COLLATE only supports "C" for example.
Now LC_ALL is supported to set multiple other categories
on OpenBSD, so setlocale(LC_ALL, "") returns a string
indicating which categories were updated and which ignored.
Therefore...

* src/sort.c (main): ...Call setlocale(LC_COLLATE, "")
to explicitly check whether a specified LC_ALL or
LC_COLLATE environment variable value is supported
for the LC_COLLATE category.  Also use !! to explicitly
convert to bool to support c89 systems where bool is an int,
and thus would get values > 1.
Reported by Assaf Gordon.

src/sort.c

index 575877d22ff05bc84203fbe4258eb875f6b6aa21..62acb6298b0e1bbf793910dfd4a679f6b859903a 100644 (file)
@@ -4192,7 +4192,7 @@ main (int argc, char **argv)
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
-  locale_ok = setlocale (LC_ALL, "");
+  locale_ok = !! setlocale (LC_ALL, "");
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
@@ -4667,6 +4667,10 @@ main (int argc, char **argv)
                quote (setlocale (LC_COLLATE, NULL)));
       else
         {
+          /* OpenBSD can only set some categories with LC_ALL above,
+             so set LC_COLLATE explicitly to flag errors.  */
+          if (locale_ok)
+            locale_ok = !! setlocale (LC_COLLATE, "");
           error (0, 0, "%s%s", locale_ok ? "" : _("failed to set locale; "),
                  _("using simple byte comparison"));
         }