summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-03-02 00:05:16 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-03-02 13:59:02 -0500
commit9480794b277b5ce33e467578ed669996df576bb9 (patch)
tree1592a98d0947cebe047e1cca96a473235630f80c /src/shared
parente525326bd07ebf3cabcfd730bc479166723f2d44 (diff)
Allow fractional parts in disk sizes
It seems natural to be able to say SystemMaxUsage=1.5G. https://bugzilla.redhat.com/show_bug.cgi?id=1047568
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 5cb598c4c5..3164515a9e 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2198,6 +2198,8 @@ int parse_size(const char *t, off_t base, off_t *size) {
p = t;
do {
long long l;
+ unsigned long long l2;
+ double frac = 0;
char *e;
unsigned i;
@@ -2213,14 +2215,32 @@ int parse_size(const char *t, off_t base, off_t *size) {
if (e == p)
return -EINVAL;
+ if (*e == '.') {
+ e++;
+ if (*e >= '0' && *e <= '9') {
+ char *e2;
+
+ /* strotoull itself would accept space/+/- */
+ l2 = strtoull(e, &e2, 10);
+
+ if (errno == ERANGE)
+ return -errno;
+
+ /* Ignore failure. E.g. 10.M is valid */
+ frac = l2;
+ for (; e < e2; e++)
+ frac /= 10;
+ }
+ }
+
e += strspn(e, WHITESPACE);
for (i = 0; i < n_entries; i++)
if (startswith(e, table[i].suffix)) {
unsigned long long tmp;
- if ((unsigned long long) l > ULLONG_MAX / table[i].factor)
+ if ((unsigned long long) l + (frac > 0) > ULLONG_MAX / table[i].factor)
return -ERANGE;
- tmp = l * table[i].factor;
+ tmp = l * table[i].factor + (unsigned long long) (frac * table[i].factor);
if (tmp > ULLONG_MAX - r)
return -ERANGE;