aboutsummaryrefslogtreecommitdiff
path: root/lib/compat/getsubopt.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-24 16:21:24 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-24 23:35:30 +0100
commitcad65de2a9a9b7d29b98f0d2997772c057f92e29 (patch)
treef3ad209f389acb6499cd3b352e061fe730daa760 /lib/compat/getsubopt.c
parent87713e563f0005553f8d075d3839d3960d7f17cb (diff)
Provide Musl derived fallbacks for getopt/getopt_long/getsubopt
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/compat/getsubopt.c')
-rw-r--r--lib/compat/getsubopt.c42
1 files changed, 12 insertions, 30 deletions
diff --git a/lib/compat/getsubopt.c b/lib/compat/getsubopt.c
index d53a37d..e6fea1a 100644
--- a/lib/compat/getsubopt.c
+++ b/lib/compat/getsubopt.c
@@ -1,10 +1,3 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * getsubopt.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
#include "compat.h"
#include <stdlib.h>
@@ -13,33 +6,22 @@
#ifndef HAVE_GETSUBOPT
int getsubopt(char **opt, char *const *keys, char **val)
{
- char *str = *opt;
- size_t i, len;
+ char *s = *opt;
+ int i;
*val = NULL;
- *opt = strchr(str, ',');
-
- if (*opt == NULL) {
- *opt = str + strlen(str);
- } else {
- *(*opt)++ = '\0';
- }
-
- for (i = 0; keys[i]; ++i) {
- len = strlen(keys[i]);
-
- if (strncmp(keys[i], str, len) != 0)
- continue;
-
- if (str[len] != '=' && str[len] != '\0')
- continue;
-
- if (str[len] == '=')
- *val = str + len + 1;
-
+ *opt = strchr(s, ',');
+ if (*opt) *(*opt)++ = 0;
+ else *opt = s + strlen(s);
+
+ for (i=0; keys[i]; i++) {
+ size_t l = strlen(keys[i]);
+ if (strncmp(keys[i], s, l)) continue;
+ if (s[l] == '=')
+ *val = s + l + 1;
+ else if (s[l]) continue;
return i;
}
-
return -1;
}
#endif