]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
util: Set LC_ALL=C as default if -H option is not used
authorTokunori Ikegami <ikegami.t@gmail.com>
Sat, 15 Jul 2023 18:00:53 +0000 (03:00 +0900)
committerDaniel Wagner <wagi@monom.org>
Mon, 17 Jul 2023 16:19:33 +0000 (18:19 +0200)
Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
util/argconfig.c

index effeea2f6aeea2411452b564a51c947ef87066fb..9f88957b43bb18429a68fc55935da8ec81580249 100644 (file)
@@ -41,6 +41,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <stdbool.h>
+#include <locale.h>
 
 static const char *append_usage_str = "";
 
@@ -335,6 +336,16 @@ static bool argconfig_check_output_format_json(struct argconfig_commandline_opti
        return false;
 }
 
+static bool argconfig_check_human_readable(struct argconfig_commandline_options *s)
+{
+       for (; s && s->option; s++) {
+               if (!strcmp(s->option, "human-readable") && s->config_type == CFG_FLAG)
+                       return s->seen;
+       }
+
+       return false;
+}
+
 int argconfig_parse(int argc, char *argv[], const char *program_desc,
                    struct argconfig_commandline_options *options)
 {
@@ -419,6 +430,9 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc,
        if (argconfig_check_output_format_json(options))
                argconfig_output_format_json(true);
 
+       if (!argconfig_check_human_readable(options))
+               setlocale(LC_ALL, "C");
+
 out:
        free(short_opts);
        free(long_opts);