2 * Android c-library does not have getsubopt,
3 * so code lifted from uClibc
4 * http://git.uclibc.org/uClibc/tree/libc/unistd/getsubopt.c
7 /* Parse comma separate list into words.
8 Copyright (C) 1996, 1997, 1999, 2004 Free Software Foundation, Inc.
9 This file is part of the GNU C Library.
10 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
11 The GNU C Library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
15 The GNU C Library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with the GNU C Library; if not, write to the Free
21 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 char *strchrnul(const char *s
, int c
)
32 result
= strchr( s
, c
);
36 result
= (char *)s
+ strlen( s
);
42 /* Parse comma separated suboption from *OPTIONP and match against
43 strings in TOKENS. If found return index and set *VALUEP to
44 optional value introduced by an equal sign. If the suboption is
45 not part of TOKENS return in *VALUEP beginning of unknown
46 suboption. On exit *OPTIONP is set to the beginning of the next
47 token or at the terminating NUL character. */
49 getsubopt (char **optionp
, char *const *tokens
, char **valuep
)
54 if (**optionp
== '\0')
57 /* Find end of next token. */
58 endp
= strchrnul (*optionp
, ',');
60 /* Find start of value. */
61 vstart
= memchr (*optionp
, '=', endp
- *optionp
);
65 /* Try to match the characters between *OPTIONP and VSTART against
67 for (cnt
= 0; tokens
[cnt
] != NULL
; ++cnt
)
68 if (strncmp (*optionp
, tokens
[cnt
], vstart
- *optionp
) == 0
69 && tokens
[cnt
][vstart
- *optionp
] == '\0')
71 /* We found the current option in TOKENS. */
72 *valuep
= vstart
!= endp ? vstart
+ 1 : NULL
;
81 /* The current suboption does not match any option. */