From cc7fbc32612c169253c073f2ad617a358862e502 Mon Sep 17 00:00:00 2001 From: "Peter S. Mazinger" Date: Mon, 27 Feb 2006 15:02:45 +0000 Subject: Add Rich Felker's getsubopt, smaller then the glibc copied one --- libc/unistd/getsubopt-susv3.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 libc/unistd/getsubopt-susv3.c (limited to 'libc/unistd/getsubopt-susv3.c') diff --git a/libc/unistd/getsubopt-susv3.c b/libc/unistd/getsubopt-susv3.c new file mode 100644 index 000000000..464223c42 --- /dev/null +++ b/libc/unistd/getsubopt-susv3.c @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Rich Felker + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +#include +#include + +libc_hidden_proto(strchr) +libc_hidden_proto(strlen) +libc_hidden_proto(strncmp) + +int getsubopt(char **opt, char *const *keys, char **val) +{ + char *s = *opt; + int i; + + *val = NULL; + *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; + else if (s[l]) continue; + return i; + } + return -1; +} -- cgit v1.2.3