From dee6b7601009688cfb931379b47a701f7dd771e3 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Tue, 22 Sep 2015 02:07:41 +0100 Subject: 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 --- src/numfmt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/numfmt.c') 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)) -- cgit v1.2.3-54-g00ecf