From: Jes Sorensen <jes.soren...@redhat.com>

Signed-off-by: Jes Sorensen <jes.soren...@redhat.com>
---
 cutils.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/cutils.c b/cutils.c
index a3087fe..d34ed08 100644
--- a/cutils.c
+++ b/cutils.c
@@ -259,16 +259,38 @@ int fcntl_setfl(int fd, int flag)
  */
 uint64_t strtobytes(const char *nptr, char **end)
 {
-    uint64_t value;
+    uint64_t value, value2;
     char *endptr;
+    int divider = 0;
 
     value = strtoll(nptr, &endptr, 0);
+    if (endptr[0] == '.') {
+        endptr++;
+        value2 = 0;
+        divider = 10;
+        while ((endptr[0] == '0') && (endptr[1] >= '0') && (endptr[1] <= '9')) 
{
+            divider = divider * 10;
+            endptr++;
+        }
+
+        if ((endptr[0] >= '0') && (endptr[0] <= '9')) {
+            value2 = strtoll(endptr, &endptr, 0);
+            value = value * divider + value2;
+        } else {
+            value = 0;
+            goto fail;
+        }
+    }
     switch (*endptr++) {
     case 'K':
     case 'k':
         value <<= 10;
         break;
     case 0:
+        if (divider) {
+            value = 0;
+            break;
+        }
     case 'M':
     case 'm':
         value <<= 20;
@@ -284,9 +306,12 @@ uint64_t strtobytes(const char *nptr, char **end)
     default:
         value = 0;
     }
+    if (divider)
+        value /= divider;
 
     if (end)
         *end = endptr;
 
+fail:
     return value;
 }
-- 
1.7.2.2


Reply via email to