barebox/fs/parseopt.c
Masahiro Yamada d27077bd76 linux/kernel.h: rename USHORT_MAX, SHORT_MAX, SHORT_MIN
Linux uses SHRT_* instead of SHORT_*.  The <limits.h> of C does
the same.  Let's follow this standard.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-01-21 14:58:07 +01:00

35 lines
538 B
C

#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;
}