Allow 'b' postfix for integer values
authorJens Axboe <jens.axboe@oracle.com>
Wed, 23 Dec 2009 07:54:52 +0000 (08:54 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Wed, 23 Dec 2009 07:54:52 +0000 (08:54 +0100)
Fio would previously regard '1tb' as just 1 byte, since the 'b' postfix
isn't a valid multiplier. Allow the 'b' as well, just ignore it.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
parse.c

diff --git a/parse.c b/parse.c
index 78218615b79246a50c02107b7907ef747dd95476..a55e52b02e513bc0c02603e4c1eb801f435029a9 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -162,9 +162,19 @@ int str_to_decimal(const char *str, long long *val, int kilo, void *data)
        if (*val == LONG_MAX && errno == ERANGE)
                return 1;
 
-       if (kilo)
-               *val *= get_mult_bytes(str[len - 1], data);
-       else
+       if (kilo) {
+               const char *p;
+               /*
+                * if the last char is 'b' or 'B', the user likely used
+                * "1gb" instead of just "1g". If the second to last is also
+                * a letter, adjust.
+                */
+               p = str + len - 1;
+               if ((*p == 'b' || *p == 'B') && isalpha(*(p - 1)))
+                       --p;
+
+               *val *= get_mult_bytes(*p, data);
+       } else
                *val *= get_mult_time(str[len - 1]);
 
        return 0;