diff options
Diffstat (limited to 'fs/parseopt.c')
-rw-r--r-- | fs/parseopt.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/fs/parseopt.c b/fs/parseopt.c new file mode 100644 index 0000000000..fbe53cfb02 --- /dev/null +++ b/fs/parseopt.c @@ -0,0 +1,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 > USHORT_MAX) + return; + + if (*endp == ',' || *endp == '\0') + *val = v; +} |