Allow 0x (or 0X) prefix for any int value to indicate hex base
authorJens Axboe <jens.axboe@oracle.com>
Mon, 9 Mar 2009 13:15:21 +0000 (14:15 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Mon, 9 Mar 2009 13:15:21 +0000 (14:15 +0100)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
parse.c

diff --git a/parse.c b/parse.c
index d653f5e..4c6a9ea 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -112,13 +112,18 @@ static unsigned long get_mult_bytes(char c)
  */
 int str_to_decimal(const char *str, long long *val, int kilo)
 {
-       int len;
+       int len, base;
 
        len = strlen(str);
        if (!len)
                return 1;
 
-       *val = strtoll(str, NULL, 10);
+       if (strstr(str, "0x") || strstr(str, "0X"))
+               base = 16;
+       else
+               base = 10;
+
+       *val = strtoll(str, NULL, base);
        if (*val == LONG_MAX && errno == ERANGE)
                return 1;