123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include <stdlib.h>
- #include <string.h>
- extern char *__strchrnul(const char *s, int c);
- int getsubopt(char **optionp, char *const *tokens, char **valuep)
- {
- char *endp, *vstart;
- int cnt;
- if (**optionp == '\0')
- return -1;
-
- endp = __strchrnul (*optionp, ',');
-
- vstart = memchr (*optionp, '=', endp - *optionp);
- if (vstart == NULL)
- vstart = endp;
-
- for (cnt = 0; tokens[cnt] != NULL; ++cnt)
- if (memcmp (*optionp, tokens[cnt], vstart - *optionp) == 0
- && tokens[cnt][vstart - *optionp] == '\0')
- {
-
- *valuep = vstart != endp ? vstart + 1 : NULL;
- if (*endp != '\0')
- *endp++ = '\0';
- *optionp = endp;
- return cnt;
- }
-
- *valuep = *optionp;
- if (*endp != '\0')
- *endp++ = '\0';
- *optionp = endp;
- return -1;
- }
|