Commit b6e356aa authored by Kevin Wolf's avatar Kevin Wolf Committed by Stefan Hajnoczi

qemu-io: Make cvtnum() a wrapper around strtosz_suffix()

No reason to implement the same thing multiple times. A nice side effect
is that fractional numbers like 0.5M can be used in qemu-io now.
Signed-off-by: default avatarKevin Wolf <>
Reviewed-by: default avatarEric Blake <>
Signed-off-by: default avatarStefan Hajnoczi <>
parent 5e00984a
......@@ -344,43 +344,6 @@ doneline(
#define MEGABYTES(x) ((long long)(x) << 20)
#define KILOBYTES(x) ((long long)(x) << 10)
long long
char *s)
long long i;
char *sp;
int c;
i = strtoll(s, &sp, 0);
if (i == 0 && sp == s)
return -1LL;
if (*sp == '\0')
return i;
if (sp[1] != '\0')
return -1LL;
c = qemu_tolower(*sp);
switch (c) {
return i;
case 'k':
return KILOBYTES(i);
case 'm':
return MEGABYTES(i);
case 'g':
return GIGABYTES(i);
case 't':
return TERABYTES(i);
case 'p':
return PETABYTES(i);
case 'e':
return EXABYTES(i);
return -1LL;
#define TO_EXABYTES(x) ((x) / EXABYTES(1))
#define TO_PETABYTES(x) ((x) / PETABYTES(1))
#define TO_TERABYTES(x) ((x) / TERABYTES(1))
......@@ -58,7 +58,6 @@ char **breakline(char *input, int *count);
void doneline(char *input, char **vec);
char *fetchline(void);
long long cvtnum(char *s);
void cvtstr(double value, char *str, size_t sz);
struct timeval tsub(struct timeval t1, struct timeval t2);
......@@ -29,6 +29,12 @@ static BlockDriverState *bs;
static int misalign;
static int64_t cvtnum(const char *s)
char *end;
return strtosz_suffix(s, &end, STRTOSZ_DEFSUFFIX_B);
* Parse the pattern argument to various sub-commands.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment