From: Jes.Sorensen@redhat.com
To: kwolf@redhat.com
Cc: qemu-devel@nongnu.org, armbru@redhat.com, stefanha@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 1/2] Introduce strtosz_suffix()
Date: Thu, 9 Dec 2010 13:13:33 +0100 [thread overview]
Message-ID: <1291896814-3554-2-git-send-email-Jes.Sorensen@redhat.com> (raw)
In-Reply-To: <1291896814-3554-1-git-send-email-Jes.Sorensen@redhat.com>
From: Jes Sorensen <Jes.Sorensen@redhat.com>
This introduces strtosz_suffix() which allows the caller to specify a
default suffix in case the non default of MB is wanted.
strtosz() is kept as a wrapper for strtosz_suffix() which keeps it's
current default of MB.
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
cutils.c | 17 ++++++++++++++---
qemu-common.h | 7 +++++++
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/cutils.c b/cutils.c
index 28089aa..1d24d9a 100644
--- a/cutils.c
+++ b/cutils.c
@@ -291,10 +291,10 @@ int fcntl_setfl(int fd, int flag)
* value must be terminated by whitespace, ',' or '\0'. Return -1 on
* error.
*/
-ssize_t strtosz(const char *nptr, char **end)
+ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
{
ssize_t retval = -1;
- char *endptr, c;
+ char *endptr, c, d;
int mul_required = 0;
double val, mul, integral, fraction;
@@ -313,10 +313,16 @@ ssize_t strtosz(const char *nptr, char **end)
* part of a multi token argument.
*/
c = *endptr;
+ d = c;
if (isspace(c) || c == '\0' || c == ',') {
c = 0;
+ if (default_suffix) {
+ d = default_suffix;
+ } else {
+ d = c;
+ }
}
- switch (c) {
+ switch (d) {
case 'B':
case 'b':
mul = 1;
@@ -371,3 +377,8 @@ fail:
return retval;
}
+
+ssize_t strtosz(const char *nptr, char **end)
+{
+ return strtosz_suffix(nptr, end, 0);
+}
diff --git a/qemu-common.h b/qemu-common.h
index de82c2e..dc44cd6 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -149,7 +149,14 @@ time_t mktimegm(struct tm *tm);
int qemu_fls(int i);
int qemu_fdatasync(int fd);
int fcntl_setfl(int fd, int flag);
+
+#define STRTOSZ_DEFSUFFIX_TB 'T'
+#define STRTOSZ_DEFSUFFIX_GB 'G'
+#define STRTOSZ_DEFSUFFIX_MB 'M'
+#define STRTOSZ_DEFSUFFIX_KB 'K'
+#define STRTOSZ_DEFSUFFIX_B 'B'
ssize_t strtosz(const char *nptr, char **end);
+ssize_t strtosz_suffix(const char *nptr, char **end, const char);
/* path.c */
void init_paths(const char *prefix);
--
1.7.3.2
next prev parent reply other threads:[~2010-12-09 12:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-09 12:13 [Qemu-devel] [PATCH v4 0/2] Clean up img_create() and introduce strtosz_suffix() Jes.Sorensen
2010-12-09 12:13 ` Jes.Sorensen [this message]
2010-12-09 12:53 ` [Qemu-devel] Re: [PATCH 1/2] Introduce strtosz_suffix() Stefan Hajnoczi
2010-12-09 13:06 ` Jes Sorensen
2010-12-09 12:13 ` [Qemu-devel] [PATCH 2/2] qemu-img.c: Clean up handling of image size in img_create() Jes.Sorensen
-- strict thread matches above, loose matches on Subject: below --
2010-12-09 13:17 [Qemu-devel] [PATCH v5 0/2] Clean up img_create() and introduce strtosz_suffix() Jes.Sorensen
2010-12-09 13:17 ` [Qemu-devel] [PATCH 1/2] Introduce strtosz_suffix() Jes.Sorensen
2010-12-16 10:05 ` Markus Armbruster
2010-12-09 11:54 [Qemu-devel] [PATCH 0/2] Fix size default for qemu-img Jes.Sorensen
2010-12-09 11:54 ` [Qemu-devel] [PATCH 1/2] Introduce strtosz_suffix() Jes.Sorensen
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=1291896814-3554-2-git-send-email-Jes.Sorensen@redhat.com \
--to=jes.sorensen@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.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).