summaryrefslogtreecommitdiffstats
path: root/arguments.c
diff options
context:
space:
mode:
authornicm <nicm>2021-08-20 17:53:54 +0000
committernicm <nicm>2021-08-20 17:53:54 +0000
commit6cbc83c6a64f272575aac1ee32cc0a0b1cb75c7b (patch)
treee9fbbcc2c2c0ee34e2926aa569528b556b025484 /arguments.c
parente463e8622dff28394145868a124b10101afc2269 (diff)
Add a way to create an empty arguments set.
Diffstat (limited to 'arguments.c')
-rw-r--r--arguments.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/arguments.c b/arguments.c
index dd92a952..91141b99 100644
--- a/arguments.c
+++ b/arguments.c
@@ -64,6 +64,17 @@ args_find(struct args *args, u_char flag)
return (RB_FIND(args_tree, &args->tree, &entry));
}
+/* Create an empty arguments set. */
+struct args *
+args_create(void)
+{
+ struct args *args;
+
+ args = xcalloc(1, sizeof *args);
+ RB_INIT(&args->tree);
+ return (args);
+}
+
/* Parse an argv and argc into a new argument set. */
struct args *
args_parse(const char *template, int argc, char **argv)
@@ -71,12 +82,11 @@ args_parse(const char *template, int argc, char **argv)
struct args *args;
int opt;
- args = xcalloc(1, sizeof *args);
-
optreset = 1;
optind = 1;
optarg = NULL;
+ args = args_create();
while ((opt = getopt(argc, argv, template)) != -1) {
if (opt < 0)
continue;