Blame SOURCES/kvm-qemu-io-Make-cvtnum-a-wrapper-around-strtosz_suffix.patch

34b321
From 94787daf53d6eb2936704f7d9089b26cc5803699 Mon Sep 17 00:00:00 2001
34b321
From: John Snow <jsnow@redhat.com>
34b321
Date: Mon, 23 Nov 2015 17:38:22 +0100
34b321
Subject: [PATCH 03/27] qemu-io: Make cvtnum() a wrapper around
34b321
 strtosz_suffix()
34b321
34b321
RH-Author: John Snow <jsnow@redhat.com>
34b321
Message-id: <1448300320-7772-4-git-send-email-jsnow@redhat.com>
34b321
Patchwork-id: 68432
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 03/21] qemu-io: Make cvtnum() a wrapper around strtosz_suffix()
34b321
Bugzilla: 1272523
34b321
RH-Acked-by: Thomas Huth <thuth@redhat.com>
34b321
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
34b321
RH-Acked-by: Max Reitz <mreitz@redhat.com>
34b321
34b321
From: Kevin Wolf <kwolf@redhat.com>
34b321
34b321
No reason to implement the same thing multiple times. A nice side effect
34b321
is that fractional numbers like 0.5M can be used in qemu-io now.
34b321
34b321
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
34b321
Reviewed-by: Eric Blake <eblake@redhat.com>
34b321
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
34b321
(cherry picked from commit b6e356aa25c81d928e1c463292048d29cf25f04e)
34b321
Signed-off-by: John Snow <jsnow@redhat.com>
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
---
34b321
 cmd.c     | 37 -------------------------------------
34b321
 cmd.h     |  1 -
34b321
 qemu-io.c |  6 ++++++
34b321
 3 files changed, 6 insertions(+), 38 deletions(-)
34b321
34b321
diff --git a/cmd.c b/cmd.c
34b321
index 4e7579b..214c6f7 100644
34b321
--- a/cmd.c
34b321
+++ b/cmd.c
34b321
@@ -344,43 +344,6 @@ doneline(
34b321
 #define MEGABYTES(x)	((long long)(x) << 20)
34b321
 #define KILOBYTES(x)	((long long)(x) << 10)
34b321
 
34b321
-long long
34b321
-cvtnum(
34b321
-	char		*s)
34b321
-{
34b321
-	long long	i;
34b321
-	char		*sp;
34b321
-	int		c;
34b321
-
34b321
-	i = strtoll(s, &sp, 0);
34b321
-	if (i == 0 && sp == s)
34b321
-		return -1LL;
34b321
-	if (*sp == '\0')
34b321
-		return i;
34b321
-
34b321
-	if (sp[1] != '\0')
34b321
-		return -1LL;
34b321
-
34b321
-	c = qemu_tolower(*sp);
34b321
-	switch (c) {
34b321
-	default:
34b321
-		return i;
34b321
-	case 'k':
34b321
-		return KILOBYTES(i);
34b321
-	case 'm':
34b321
-		return MEGABYTES(i);
34b321
-	case 'g':
34b321
-		return GIGABYTES(i);
34b321
-	case 't':
34b321
-		return TERABYTES(i);
34b321
-	case 'p':
34b321
-		return PETABYTES(i);
34b321
-	case 'e':
34b321
-		return  EXABYTES(i);
34b321
-	}
34b321
-	return -1LL;
34b321
-}
34b321
-
34b321
 #define TO_EXABYTES(x)	((x) / EXABYTES(1))
34b321
 #define TO_PETABYTES(x)	((x) / PETABYTES(1))
34b321
 #define TO_TERABYTES(x)	((x) / TERABYTES(1))
34b321
diff --git a/cmd.h b/cmd.h
34b321
index 8e6f753..4dcfe88 100644
34b321
--- a/cmd.h
34b321
+++ b/cmd.h
34b321
@@ -58,7 +58,6 @@ char **breakline(char *input, int *count);
34b321
 void doneline(char *input, char **vec);
34b321
 char *fetchline(void);
34b321
 
34b321
-long long cvtnum(char *s);
34b321
 void cvtstr(double value, char *str, size_t sz);
34b321
 
34b321
 struct timeval tsub(struct timeval t1, struct timeval t2);
34b321
diff --git a/qemu-io.c b/qemu-io.c
34b321
index 9f66a78..3b5890e 100644
34b321
--- a/qemu-io.c
34b321
+++ b/qemu-io.c
34b321
@@ -33,6 +33,12 @@ static BlockDriverState *bs;
34b321
 
34b321
 static int misalign;
34b321
 
34b321
+static int64_t cvtnum(const char *s)
34b321
+{
34b321
+    char *end;
34b321
+    return strtosz_suffix(s, &end, STRTOSZ_DEFSUFFIX_B);
34b321
+}
34b321
+
34b321
 /*
34b321
  * Parse the pattern argument to various sub-commands.
34b321
  *
34b321
-- 
34b321
1.8.3.1
34b321