X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=parse.c;h=4c6a9ea984ee28475c0f47eeabec549d68e7c55e;hp=44c02f60eb1488dba372ea34683bb4a3bba54e70;hb=b347f9daece7d65a6e596cd3bd0ef3602e40b059;hpb=e3cedca76d9fc104eb4f6f869606fb5bf4c0d59c diff --git a/parse.c b/parse.c index 44c02f60..4c6a9ea9 100644 --- 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; @@ -152,7 +157,7 @@ void strip_blank_front(char **p) void strip_blank_end(char *p) { - char *s; + char *start = p, *s; s = strchr(p, ';'); if (s) @@ -164,7 +169,7 @@ void strip_blank_end(char *p) p = s; s = p + strlen(p); - while ((isspace(*s) || iscntrl(*s)) && (s > p)) + while ((isspace(*s) || iscntrl(*s)) && (s > start)) s--; *(s + 1) = '\0'; @@ -474,6 +479,7 @@ static struct fio_option *get_option(const char *opt, *ret = '\0'; ret = (char *) opt; (*post)++; + strip_blank_end(ret); o = find_option(options, ret); } else { o = find_option(options, opt); @@ -520,7 +526,7 @@ int parse_cmd_option(const char *opt, const char *val, o = find_option(options, opt); if (!o) { - fprintf(stderr, "Bad option %s\n", opt); + fprintf(stderr, "Bad option <%s>\n", opt); return 1; } @@ -589,7 +595,7 @@ int parse_option(const char *opt, struct fio_option *options, void *data) o = get_option(tmp, options, &post); if (!o) { - fprintf(stderr, "Bad option %s\n", tmp); + fprintf(stderr, "Bad option <%s>\n", tmp); free(tmp); return 1; }