summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>2021-06-04 22:01:17 +0200
committerRasmus Villemoes <rasmus.villemoes@prevas.dk>2021-06-04 22:10:42 +0200
commite2108573ff6d3e7877cce9288c391fe40f0fe068 (patch)
treedfa5aae9917cc25198e3ed4af100f91612ccbd8f
parent18b3cfd857fc9e29a88023654c66a469ca1352da (diff)
downloadgenimage-e2108573ff6d3e7877cce9288c391fe40f0fe068.tar.gz
genimage-e2108573ff6d3e7877cce9288c391fe40f0fe068.tar.xz
config.c: remove redundant helper add_opt()
In order to make the .hidden member actually visible to show_help(), init_config() would have to pass on yet another argument to add_opt(). At that point, one would surely change add_opt() to take the source 'struct config' by reference. But taking a closer look, there's actually no reason at all to memdup each struct option; we might as well just weave the elements of opts[] array itself into the linked list. And for that we don't need a helper function at all. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
-rw-r--r--config.c29
1 files changed, 3 insertions, 26 deletions
diff --git a/config.c b/config.c
index 17423d2..2e1f9e7 100644
--- a/config.c
+++ b/config.c
@@ -96,28 +96,6 @@ static int set_opt(const char *name, const char *value)
}
/*
- * Add a new option
- *
- * name: name of the option
- * env: environment variable this option corresponds to
- * opt: confuse option
- * def: default value
- */
-static int add_opt(const char *name, const char *env, cfg_opt_t *opt, char *def)
-{
- struct config *c = xzalloc(sizeof(*c));
-
- c->name = name;
- c->env = env;
- c->def = def;
- memcpy(&c->opt, opt, sizeof(cfg_opt_t));
-
- list_add_tail(&c->list, &optlist);
-
- return 0;
-}
-
-/*
* convert all options from the options list to a cfg_opt_t
* array suitable for confuse
*/
@@ -466,12 +444,11 @@ static struct config opts[] = {
int init_config(void)
{
unsigned int i;
- int ret;
for (i = 0; i < ARRAY_SIZE(opts); i++) {
- ret = add_opt(opts[i].name, opts[i].env, &opts[i].opt, opts[i].def);
- if (ret)
- return ret;
+ struct config *c = &opts[i];
+
+ list_add_tail(&c->list, &optlist);
}
return 0;