summaryrefslogtreecommitdiff
path: root/src/basic/parse-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic/parse-util.c')
-rw-r--r--src/basic/parse-util.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c
index 6c11b605a9..503a895731 100644
--- a/src/basic/parse-util.c
+++ b/src/basic/parse-util.c
@@ -532,3 +532,22 @@ int parse_fractional_part_u(const char **p, size_t digits, unsigned *res) {
return 0;
}
+
+int parse_percent(const char *p) {
+ const char *pc, *n;
+ unsigned v;
+ int r;
+
+ pc = endswith(p, "%");
+ if (!pc)
+ return -EINVAL;
+
+ n = strndupa(p, pc - p);
+ r = safe_atou(n, &v);
+ if (r < 0)
+ return r;
+ if (v > 100)
+ return -ERANGE;
+
+ return (int) v;
+}