summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/parseopt.h2
-rw-r--r--lib/parseopt.c30
2 files changed, 32 insertions, 0 deletions
diff --git a/include/parseopt.h b/include/parseopt.h
index 1f9763f8c9..273a371ac3 100644
--- a/include/parseopt.h
+++ b/include/parseopt.h
@@ -1,5 +1,7 @@
#ifndef __PARSEOPT_H__
#define __PARSEOPT_H__
+void parseopt_llu_suffix(const char *options, const char *opt,
+ unsigned long long *val);
void parseopt_b(const char *options, const char *opt, bool *val);
void parseopt_hu(const char *options, const char *opt, unsigned short *val);
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;
+}