summaryrefslogtreecommitdiffstats
path: root/libc
diff options
context:
space:
mode:
author"Steven J. Hill" <sjhill@realitydiluted.com>2006-02-27 23:11:46 +0000
committer"Steven J. Hill" <sjhill@realitydiluted.com>2006-02-27 23:11:46 +0000
commit589a76ea96e1153a3d4c30a09ecb6b54546d3bf8 (patch)
treed195ae4d64f3aceb80155db370aff1357911fabe /libc
parent3ac8d1c87995eda84764e4239218d24f81e8e6a9 (diff)
downloaduClibc-alpine-589a76ea96e1153a3d4c30a09ecb6b54546d3bf8.tar.bz2
uClibc-alpine-589a76ea96e1153a3d4c30a09ecb6b54546d3bf8.tar.xz
Copy from trunk.
Diffstat (limited to 'libc')
-rw-r--r--libc/unistd/getsubopt-susv3.c33
1 files changed, 33 insertions, 0 deletions
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 <dalias@aerifal.cx>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+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;
+}