qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com,
	lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH v2 03/16] qemu-io: Make cvtnum() a wrapper around strtosz_suffix()
Date: Wed,  5 Jun 2013 14:19:28 +0200	[thread overview]
Message-ID: <1370434781-28570-4-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1370434781-28570-1-git-send-email-kwolf@redhat.com>

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: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 cmd.c     | 37 -------------------------------------
 cmd.h     |  1 -
 qemu-io.c |  6 ++++++
 3 files changed, 6 insertions(+), 38 deletions(-)

diff --git a/cmd.c b/cmd.c
index 4e7579b..214c6f7 100644
--- a/cmd.c
+++ b/cmd.c
@@ -344,43 +344,6 @@ doneline(
 #define MEGABYTES(x)	((long long)(x) << 20)
 #define KILOBYTES(x)	((long long)(x) << 10)
 
-long long
-cvtnum(
-	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) {
-	default:
-		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))
diff --git a/cmd.h b/cmd.h
index 8e6f753..4dcfe88 100644
--- a/cmd.h
+++ b/cmd.h
@@ -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);
diff --git a/qemu-io.c b/qemu-io.c
index 4288b8c..8a719a8 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -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.
  *
-- 
1.8.1.4

  parent reply	other threads:[~2013-06-05 12:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-05 12:19 [Qemu-devel] [PATCH v2 00/16] Make qemu-io commands available in the monitor Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 01/16] qemu-io: Remove unused args_command Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 02/16] cutils: Support 'P' and 'E' suffixes in strtosz() Kevin Wolf
2013-06-05 12:19 ` Kevin Wolf [this message]
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 04/16] qemu-io: Handle cvtnum() errors in 'alloc' Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 05/16] qemu-io: Don't use global bs in command implementations Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 06/16] qemu-io: Split off commands to qemu-io-cmds.c Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 07/16] qemu-io: Factor out qemuio_command Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 08/16] qemu-io: Move 'help' function Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 09/16] qemu-io: Move 'quit' function Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 10/16] qemu-io: Move qemu_strsep() to cutils.c Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 11/16] qemu-io: Move functions for registering and running commands Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 12/16] qemu-io: Move command_loop() and friends Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 13/16] qemu-io: Move remaining helpers from cmd.c Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 14/16] qemu-io: Interface cleanup Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 15/16] qemu-io: Use the qemu version for -V Kevin Wolf
2013-06-05 12:19 ` [Qemu-devel] [PATCH v2 16/16] Make qemu-io commands available in HMP Kevin Wolf
2013-06-07 14:17   ` Luiz Capitulino
2013-06-06  9:46 ` [Qemu-devel] [PATCH v2 00/16] Make qemu-io commands available in the monitor Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1370434781-28570-4-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).