To set the flag parameter change options arguments as not const variables.
Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
int parse_and_open(struct nvme_dev **dev, int argc, char **argv,
const char *desc,
- const struct argconfig_commandline_options *opts)
+ struct argconfig_commandline_options *opts)
{
int ret;
if (err)
goto ret;
- if (!cfg.namespace_id) {
+ if (!opts[1].seen) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
if (errno != ENOTTY) {
if (err)
goto ret;
- if (!cfg.namespace_id) {
+ if (!opts[0].seen) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
if (errno != ENOTTY) {
fprintf(stderr, "get-namespace-id: %s\n", nvme_strerror(errno));
goto close_dev;
}
-
cfg.namespace_id = NVME_NSID_ALL;
}
}
* parse_and_open - parses arguments and opens the NVMe device, populating @dev
*/
int parse_and_open(struct nvme_dev **dev, int argc, char **argv, const char *desc,
- const struct argconfig_commandline_options *clo);
+ struct argconfig_commandline_options *clo);
void dev_close(struct nvme_dev *dev);
.disable = false,
};
- const struct argconfig_commandline_options command_line_options[] = {
+ struct argconfig_commandline_options command_line_options[] = {
{"enable", 'e', "", CFG_FLAG, &cfg.enable, no_argument, enable_desc},
{"disable", 'd', "", CFG_FLAG, &cfg.disable, no_argument, disable_desc},
{NULL}
.disable = false,
};
- const struct argconfig_commandline_options command_line_options[] = {
+ struct argconfig_commandline_options command_line_options[] = {
{"enable", 'e', "", CFG_FLAG, &cfg.enable, no_argument, enable_desc},
{"disable", 'd', "", CFG_FLAG, &cfg.disable, no_argument, disable_desc},
{NULL}
*/
static int micron_parse_options(struct nvme_dev **dev, int argc, char **argv,
const char *desc,
- const struct argconfig_commandline_options *opts,
+ struct argconfig_commandline_options *opts,
eDriveModel *modelp)
{
int idx = 0;
}
int argconfig_parse(int argc, char *argv[], const char *program_desc,
- const struct argconfig_commandline_options *options)
+ struct argconfig_commandline_options *options)
{
char *short_opts;
char *endptr;
struct option *long_opts;
- const struct argconfig_commandline_options *s;
+ struct argconfig_commandline_options *s;
int c, option_index = 0, short_index = 0, options_count = 0;
void *value_addr;
int ret = -EINVAL;
long_opts[option_index].flag = NULL;
long_opts[option_index].val = 0;
}
+ s->seen = false;
option_index++;
}
}
s = &options[option_index];
+ s->seen = true;
value_addr = (void *)(char *)s->default_value;
if (s->config_type == CFG_STRING) {
*((char **)value_addr) = optarg;
#include <getopt.h>
#include <stdarg.h>
#include <stdio.h>
+#include <stdbool.h>
enum argconfig_types {
CFG_FLAG,
};
#define OPT_ARGS(n) \
- const struct argconfig_commandline_options n[]
+ struct argconfig_commandline_options n[]
#define OPT_END() { NULL }
void *default_value;
int argument_type;
const char *help;
+ bool seen;
};
#define CFG_MAX_SUBOPTS 500
void argconfig_print_help(const char *program_desc,
const struct argconfig_commandline_options *options);
int argconfig_parse(int argc, char *argv[], const char *program_desc,
- const struct argconfig_commandline_options *options);
+ struct argconfig_commandline_options *options);
int argconfig_parse_subopt_string(char *string, char **options,
size_t max_options);
int argconfig_parse_comma_sep_array(char *string, int *ret,