summaryrefslogtreecommitdiff
path: root/lib/compat/getsubopt.c
diff options
context:
space:
mode:
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