summaryrefslogtreecommitdiff
path: root/lib/common/parse_size.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common/parse_size.c')
-rw-r--r--lib/common/parse_size.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/common/parse_size.c b/lib/common/parse_size.c
index aede38a..1285d3b 100644
--- a/lib/common/parse_size.c
+++ b/lib/common/parse_size.c
@@ -9,7 +9,8 @@
#include <ctype.h>
#include <limits.h>
-int parse_size(const char *what, size_t *out, const char *str)
+int parse_size(const char *what, size_t *out, const char *str,
+ size_t reference)
{
const char *in = str;
size_t acc = 0, x;
@@ -49,6 +50,15 @@ int parse_size(const char *what, size_t *out, const char *str)
acc <<= 30;
++in;
break;
+ case '%':
+ if (reference == 0)
+ goto fail_suffix;
+
+ if (SZ_MUL_OV(acc, reference, &acc))
+ goto fail_ov;
+
+ acc /= 100;
+ break;
case '\0':
break;
default: