diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2018-02-08 09:03:46 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-02-08 09:03:46 +0100 |
commit | 490a3c496454cea131dbd5edadbe7d7cfce4cfa8 (patch) | |
tree | 5222ffde63801a98ce90168d6be2247cc39bcfa7 /lib | |
parent | b84f8a712ffe04def5f3d402ef9be990d485ecce (diff) | |
parent | 5316da0098c913b1e548801a57b7d5d9fd5a4d6d (diff) | |
download | barebox-490a3c496454cea131dbd5edadbe7d7cfce4cfa8.tar.gz barebox-490a3c496454cea131dbd5edadbe7d7cfce4cfa8.tar.xz |
Merge branch 'for-next/misc'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/parseopt.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/parseopt.c b/lib/parseopt.c index 8211733e3b..70983066d9 100644 --- a/lib/parseopt.c +++ b/lib/parseopt.c @@ -122,3 +122,33 @@ again: *val = xstrndup(parsed, endp - parsed); } + +void parseopt_llu_suffix(const char *options, const char *opt, + unsigned long long *val) +{ + const char *start; + size_t optlen = strlen(opt); + unsigned long long 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 = strtoull_suffix(start + optlen + 1, &endp, 0); + + if (*endp == ',' || *endp == '\0') + *val = v; +} |