Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: Set LC_ALL=C as default if -H option is not used #2004

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions util/argconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <stdarg.h>
#include <string.h>
#include <stdbool.h>
#include <locale.h>

static const char *append_usage_str = "";

Expand Down Expand Up @@ -177,15 +178,6 @@ static int argconfig_parse_type(struct argconfig_commandline_options *s, struct
if (errno || optarg == endptr)
ret = argconfig_error("integer", option[index].name, optarg);
break;
case CFG_BOOL: {
int tmp = strtol(optarg, &endptr, 0);

if (errno || tmp < 0 || tmp > 1 || optarg == endptr)
ret = argconfig_error("0 or 1", option[index].name, optarg);
else
*((int *)value) = tmp;
break;
}
case CFG_BYTE:
ret = argconfig_parse_byte(option[index].name, optarg, (uint8_t *)value);
break;
Expand Down Expand Up @@ -335,6 +327,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)
{
Expand Down Expand Up @@ -419,6 +421,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);
Expand Down
1 change: 0 additions & 1 deletion util/argconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ enum argconfig_types {
CFG_LONG,
CFG_LONG_SUFFIX,
CFG_DOUBLE,
CFG_BOOL,
CFG_BYTE,
CFG_SHORT,
CFG_POSITIVE,
Expand Down
Loading