]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: handle musl locale differences in --debug reporting
authorPádraig Brady <P@draigBrady.com>
Sun, 13 Aug 2017 07:45:32 +0000 (00:45 -0700)
committerPádraig Brady <P@draigBrady.com>
Mon, 14 Aug 2017 04:32:11 +0000 (21:32 -0700)
* src/sort.c (main): Don't assume hard_LC_COLLATE implies
a successful setting of the locale as musl defaults to
UTF8 when failing to set the specified locale.
* tests/misc/sort-debug-warn.sh: Adjust for the now
separated locale debug info and map the musl specific
message back to the common case.
Addresses https://bugs.gnu.org/28054

src/sort.c
tests/misc/sort-debug-warn.sh

index 015e40e3a2173a6800760c70bb81dcf069449aa1..ba6ceac276bee5ffbef66cf3ca499a88db01253d 100644 (file)
@@ -4675,18 +4675,19 @@ main (int argc, char **argv)
 
       /* Always output the locale in debug mode, since this
          is such a common source of confusion.  */
+
+      /* 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, "");
+      if (! locale_ok)
+          error (0, 0, "%s", _("failed to set locale"));
       if (hard_LC_COLLATE)
         error (0, 0, _("using %s sorting rules"),
                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"));
-        }
+        error (0, 0, "%s", _("using simple byte comparison"));
+
       key_warnings (&gkey, gkey_only);
     }
 
index 3602c84fcf9c44ba8a89706cadc9062fd36caaad..8119693496a770f75cf983ce3a3bcec7237f0f2c 100755 (executable)
@@ -71,7 +71,8 @@ sort: using simple byte comparison
 17
 sort: using simple byte comparison
 18
-sort: failed to set locale; using simple byte comparison
+sort: failed to set locale
+sort: using simple byte comparison
 EOF
 
 echo 1 >> out
@@ -109,7 +110,11 @@ sort -rM --debug /dev/null 2>>out #no warning
 echo 17 >> out
 sort -rM -k1,1 --debug /dev/null 2>>out #no warning
 echo 18 >> out
-LC_ALL=missing sort --debug /dev/null 2>>out
+LC_ALL=missing sort --debug /dev/null 2>>out.t
+# musl libc accepts "missing" and implicitly uses UTF8,
+# so adjust the expected message accordingly.
+sed 's/using .*missing.* sorting rules/using simple byte comparison/' \
+  out.t >>out
 
 compare exp out || fail=1