summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-09-22 02:07:41 +0100
committerPádraig Brady <P@draigBrady.com>2015-09-22 02:30:30 +0100
commitdee6b7601009688cfb931379b47a701f7dd771e3 (patch)
tree17b00da6f156e1c34a8c35e88d944b39f0d170f3 /src
parentd4a22dff9b4cd8b05cb01e654fa84b189d3b5721 (diff)
downloadcoreutils-dee6b7601009688cfb931379b47a701f7dd771e3.tar.xz
sort,numfmt: with --debug, diagnose failure to set locale
* src/sort.c (main): With --debug, warn upon setlocale() failure, which can happen due to incorrectly specified environment variables, or due to memory exhaustion (simulated with ulimit -v), etc. * tests/misc/sort-debug-warn.sh: Add a test case. See also http://savannah.gnu.org/bugs/11004
Diffstat (limited to 'src')
-rw-r--r--src/numfmt.c6
-rw-r--r--src/sort.c8
2 files changed, 11 insertions, 3 deletions
diff --git a/src/numfmt.c b/src/numfmt.c
index 24bf45b37..109947e20 100644
--- a/src/numfmt.c
+++ b/src/numfmt.c
@@ -1429,10 +1429,11 @@ int
main (int argc, char **argv)
{
int valid_numbers = 1;
+ bool locale_ok;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
- setlocale (LC_ALL, "");
+ locale_ok = setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
@@ -1558,6 +1559,9 @@ main (int argc, char **argv)
if (format_str != NULL && grouping)
error (EXIT_FAILURE, 0, _("--grouping cannot be combined with --format"));
+ if (debug && ! locale_ok)
+ error (0, 0, _("failed to set locale"));
+
/* Warn about no-op. */
if (debug && scale_from == scale_none && scale_to == scale_none
&& !grouping && (padding_width == 0) && (format_str == NULL))
diff --git a/src/sort.c b/src/sort.c
index 7ce059282..9396f46dc 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -4187,10 +4187,11 @@ main (int argc, char **argv)
char *files_from = NULL;
struct Tokens tok;
char const *outfile = NULL;
+ bool locale_ok;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
- setlocale (LC_ALL, "");
+ locale_ok = setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
@@ -4664,7 +4665,10 @@ main (int argc, char **argv)
error (0, 0, _("using %s sorting rules"),
quote (setlocale (LC_COLLATE, NULL)));
else
- error (0, 0, _("using simple byte comparison"));
+ {
+ error (0, 0, "%s%s", locale_ok ? "" : _("failed to set locale; "),
+ _("using simple byte comparison"));
+ }
key_warnings (&gkey, gkey_only);
}