xref: /third_party/musl/src/misc/getsubopt.c
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/musl/src/misc/
1570af302Sopenharmony_ci#include <stdlib.h>
2570af302Sopenharmony_ci#include <string.h>
3570af302Sopenharmony_ci
4570af302Sopenharmony_ciint getsubopt(char **opt, char *const *keys, char **val)
5570af302Sopenharmony_ci{
6570af302Sopenharmony_ci	char *s = *opt;
7570af302Sopenharmony_ci	int i;
8570af302Sopenharmony_ci
9570af302Sopenharmony_ci	*val = NULL;
10570af302Sopenharmony_ci	*opt = strchr(s, ',');
11570af302Sopenharmony_ci	if (*opt) *(*opt)++ = 0;
12570af302Sopenharmony_ci	else *opt = s + strlen(s);
13570af302Sopenharmony_ci
14570af302Sopenharmony_ci	for (i=0; keys[i]; i++) {
15570af302Sopenharmony_ci		size_t l = strlen(keys[i]);
16570af302Sopenharmony_ci		if (strncmp(keys[i], s, l)) continue;
17570af302Sopenharmony_ci		if (s[l] == '=')
18570af302Sopenharmony_ci			*val = s + l + 1;
19570af302Sopenharmony_ci		else if (s[l]) continue;
20570af302Sopenharmony_ci		return i;
21570af302Sopenharmony_ci	}
22570af302Sopenharmony_ci	return -1;
23570af302Sopenharmony_ci}
24

Indexes created Thu Nov 07 10:32:03 CST 2024