diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-07-14 18:28:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-07-16 15:12:07 +0000 |
commit | 589986012c4b3ab68e299a2eadca18f90080113b (patch) | |
tree | f29a53b04a1950cdddae69344bccb3f0146fa728 /util/argconfig.c | |
parent | Releasing debian version 1.16-4. (diff) | |
download | nvme-cli-589986012c4b3ab68e299a2eadca18f90080113b.tar.xz nvme-cli-589986012c4b3ab68e299a2eadca18f90080113b.zip |
Merging upstream version 2.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'util/argconfig.c')
-rw-r--r-- | util/argconfig.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/util/argconfig.c b/util/argconfig.c index 341a049..59d8f1d 100644 --- a/util/argconfig.c +++ b/util/argconfig.c @@ -39,6 +39,7 @@ #include <stdlib.h> #include <stdarg.h> #include <string.h> +#include <stdbool.h> static argconfig_help_func *help_funcs[MAX_HELP_FUNC] = { NULL }; @@ -176,17 +177,8 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, if (s->option && strlen(s->option)) { long_opts[option_index].name = s->option; long_opts[option_index].has_arg = s->argument_type; - - if (s->argument_type == no_argument - && s->default_value != NULL) { - value_addr = (void *)(char *)s->default_value; - - long_opts[option_index].flag = value_addr; - long_opts[option_index].val = 1; - } else { - long_opts[option_index].flag = NULL; - long_opts[option_index].val = 0; - } + long_opts[option_index].flag = NULL; + long_opts[option_index].val = 0; } option_index++; } @@ -219,10 +211,6 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, } if (option_index == options_count) continue; - if (long_opts[option_index].flag) { - *(uint8_t *)(long_opts[option_index].flag) = 1; - continue; - } } s = &options[option_index]; @@ -282,7 +270,7 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, } *((uint32_t *) value_addr) = tmp; } else if (s->config_type == CFG_INCREMENT) { - (*((int *)value_addr))++; + *((int *)value_addr) += 1; } else if (s->config_type == CFG_LONG) { *((unsigned long *)value_addr) = strtoul(optarg, &endptr, 0); if (errno || optarg == endptr) { @@ -363,6 +351,8 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, goto out; } *((FILE **) value_addr) = f; + } else if (s->config_type == CFG_FLAG) { + *((bool *)value_addr) = true; } } free(short_opts); |