summaryrefslogtreecommitdiffstats
path: root/fs/parseopt.c
blob: 12dbe1813c825d0e75e7cff27d07d5be01678627 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <common.h>

#include "parseopt.h"

void parseopt_hu(const char *options, const char *opt, unsigned short *val)
{
	const char *start;
	size_t optlen = strlen(opt);
	ulong v;
	char *endp;

again:
	start = strstr(options, opt);

	if (!start)
		return;

	if (start > options && start[-1] != ',') {
		options = start;
		goto again;
	}

	if (start[optlen] != '=') {
		options = start;
		goto again;
	}

	v = simple_strtoul(start + optlen + 1, &endp, 0);
	if (v > USHRT_MAX)
		return;

	if (*endp == ',' || *endp == '\0')
		*val = v;
}