qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix
@ 2015-09-16 16:02 marcandre.lureau
  2015-09-16 16:02 ` [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests marcandre.lureau
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: marcandre.lureau @ 2015-09-16 16:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Not only it makes sense, but it gets rid of checkpatch warning:
WARNING: consider using qemu_strtosz in preference to strtosz

Also remove get rid of tabs to please checkpatch.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/qemu-common.h | 27 ++++++++++++++-------------
 monitor.c             |  2 +-
 qapi/opts-visitor.c   |  4 ++--
 qemu-img.c            |  5 +++--
 qemu-io-cmds.c        |  2 +-
 target-i386/cpu.c     |  4 ++--
 util/cutils.c         | 25 +++++++++++++------------
 7 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/include/qemu-common.h b/include/qemu-common.h
index 01d29dd..0bd212b 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -217,22 +217,23 @@ int parse_uint(const char *s, unsigned long long *value, char **endptr,
 int parse_uint_full(const char *s, unsigned long long *value, int base);
 
 /*
- * strtosz() suffixes used to specify the default treatment of an
- * argument passed to strtosz() without an explicit suffix.
+ * qemu_strtosz() suffixes used to specify the default treatment of an
+ * argument passed to qemu_strtosz() without an explicit suffix.
  * These should be defined using upper case characters in the range
- * A-Z, as strtosz() will use qemu_toupper() on the given argument
+ * A-Z, as qemu_strtosz() will use qemu_toupper() on the given argument
  * prior to comparison.
  */
-#define STRTOSZ_DEFSUFFIX_EB	'E'
-#define STRTOSZ_DEFSUFFIX_PB	'P'
-#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'
-int64_t strtosz(const char *nptr, char **end);
-int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
-int64_t strtosz_suffix_unit(const char *nptr, char **end,
+#define QEMU_STRTOSZ_DEFSUFFIX_EB 'E'
+#define QEMU_STRTOSZ_DEFSUFFIX_PB 'P'
+#define QEMU_STRTOSZ_DEFSUFFIX_TB 'T'
+#define QEMU_STRTOSZ_DEFSUFFIX_GB 'G'
+#define QEMU_STRTOSZ_DEFSUFFIX_MB 'M'
+#define QEMU_STRTOSZ_DEFSUFFIX_KB 'K'
+#define QEMU_STRTOSZ_DEFSUFFIX_B 'B'
+int64_t qemu_strtosz(const char *nptr, char **end);
+int64_t qemu_strtosz_suffix(const char *nptr, char **end,
+                            const char default_suffix);
+int64_t qemu_strtosz_suffix_unit(const char *nptr, char **end,
                             const char default_suffix, int64_t unit);
 #define K_BYTE     (1ULL << 10)
 #define M_BYTE     (1ULL << 20)
diff --git a/monitor.c b/monitor.c
index 5455ab9..1221977 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3911,7 +3911,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
                         break;
                     }
                 }
-                val = strtosz(p, &end);
+                val = qemu_strtosz(p, &end);
                 if (val < 0) {
                     monitor_printf(mon, "invalid size\n");
                     goto fail;
diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
index 7ae33b3..cd10392 100644
--- a/qapi/opts-visitor.c
+++ b/qapi/opts-visitor.c
@@ -474,8 +474,8 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
         return;
     }
 
-    val = strtosz_suffix(opt->str ? opt->str : "", &endptr,
-                         STRTOSZ_DEFSUFFIX_B);
+    val = qemu_strtosz_suffix(opt->str ? opt->str : "", &endptr,
+                         QEMU_STRTOSZ_DEFSUFFIX_B);
     if (val < 0 || *endptr) {
         error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name,
                    "a size value representible as a non-negative int64");
diff --git a/qemu-img.c b/qemu-img.c
index 6ff4e85..7d65c0a 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -338,7 +338,8 @@ static int img_create(int argc, char **argv)
     if (optind < argc) {
         int64_t sval;
         char *end;
-        sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B);
+        sval = qemu_strtosz_suffix(argv[optind++], &end,
+                                   QEMU_STRTOSZ_DEFSUFFIX_B);
         if (sval < 0 || *end) {
             if (sval == -ERANGE) {
                 error_report("Image size must be less than 8 EiB!");
@@ -1607,7 +1608,7 @@ static int img_convert(int argc, char **argv)
         {
             int64_t sval;
             char *end;
-            sval = strtosz_suffix(optarg, &end, STRTOSZ_DEFSUFFIX_B);
+            sval = qemu_strtosz_suffix(optarg, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
             if (sval < 0 || *end) {
                 error_report("Invalid minimum zero buffer size for sparse output specified");
                 ret = -1;
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index d6572a8..6e5d1e4 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -136,7 +136,7 @@ static char **breakline(char *input, int *count)
 static int64_t cvtnum(const char *s)
 {
     char *end;
-    return strtosz_suffix(s, &end, STRTOSZ_DEFSUFFIX_B);
+    return qemu_strtosz_suffix(s, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
 }
 
 #define EXABYTES(x)     ((long long)(x) << 60)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index cfb8aa7..a5bea42 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1893,8 +1893,8 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
                 char *err;
                 char num[32];
 
-                tsc_freq = strtosz_suffix_unit(val, &err,
-                                               STRTOSZ_DEFSUFFIX_B, 1000);
+                tsc_freq = qemu_strtosz_suffix_unit(val, &err,
+                                               QEMU_STRTOSZ_DEFSUFFIX_B, 1000);
                 if (tsc_freq < 0 || *err) {
                     error_setg(errp, "bad numerical value %s", val);
                     return;
diff --git a/util/cutils.c b/util/cutils.c
index ae35198..cfeb848 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -276,19 +276,19 @@ int fcntl_setfl(int fd, int flag)
 static int64_t suffix_mul(char suffix, int64_t unit)
 {
     switch (qemu_toupper(suffix)) {
-    case STRTOSZ_DEFSUFFIX_B:
+    case QEMU_STRTOSZ_DEFSUFFIX_B:
         return 1;
-    case STRTOSZ_DEFSUFFIX_KB:
+    case QEMU_STRTOSZ_DEFSUFFIX_KB:
         return unit;
-    case STRTOSZ_DEFSUFFIX_MB:
+    case QEMU_STRTOSZ_DEFSUFFIX_MB:
         return unit * unit;
-    case STRTOSZ_DEFSUFFIX_GB:
+    case QEMU_STRTOSZ_DEFSUFFIX_GB:
         return unit * unit * unit;
-    case STRTOSZ_DEFSUFFIX_TB:
+    case QEMU_STRTOSZ_DEFSUFFIX_TB:
         return unit * unit * unit * unit;
-    case STRTOSZ_DEFSUFFIX_PB:
+    case QEMU_STRTOSZ_DEFSUFFIX_PB:
         return unit * unit * unit * unit * unit;
-    case STRTOSZ_DEFSUFFIX_EB:
+    case QEMU_STRTOSZ_DEFSUFFIX_EB:
         return unit * unit * unit * unit * unit * unit;
     }
     return -1;
@@ -300,7 +300,7 @@ static int64_t suffix_mul(char suffix, int64_t unit)
  * in *end, if not NULL. Return -ERANGE on overflow, Return -EINVAL on
  * other error.
  */
-int64_t strtosz_suffix_unit(const char *nptr, char **end,
+int64_t qemu_strtosz_suffix_unit(const char *nptr, char **end,
                             const char default_suffix, int64_t unit)
 {
     int64_t retval = -EINVAL;
@@ -343,14 +343,15 @@ fail:
     return retval;
 }
 
-int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
+int64_t qemu_strtosz_suffix(const char *nptr, char **end,
+                            const char default_suffix)
 {
-    return strtosz_suffix_unit(nptr, end, default_suffix, 1024);
+    return qemu_strtosz_suffix_unit(nptr, end, default_suffix, 1024);
 }
 
-int64_t strtosz(const char *nptr, char **end)
+int64_t qemu_strtosz(const char *nptr, char **end)
 {
-    return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB);
+    return qemu_strtosz_suffix(nptr, end, QEMU_STRTOSZ_DEFSUFFIX_MB);
 }
 
 /**
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests
  2015-09-16 16:02 [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix marcandre.lureau
@ 2015-09-16 16:02 ` marcandre.lureau
  2015-09-16 16:19   ` Eric Blake
  2015-09-16 16:13 ` [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix Eric Blake
  2015-09-16 16:34 ` Paolo Bonzini
  2 siblings, 1 reply; 6+ messages in thread
From: marcandre.lureau @ 2015-09-16 16:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau

From: Marc-André Lureau <marcandre.lureau@redhat.com>

While reading the function I decided to write some tests.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 tests/test-cutils.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/tests/test-cutils.c b/tests/test-cutils.c
index 0046c61..a3de6ab 100644
--- a/tests/test-cutils.c
+++ b/tests/test-cutils.c
@@ -1352,6 +1352,86 @@ static void test_qemu_strtoull_full_max(void)
     g_assert_cmpint(res, ==, ULLONG_MAX);
 }
 
+static void test_qemu_strtosz_simple(void)
+{
+    const char *str = "12345M";
+    char *endptr = NULL;
+    int64_t res;
+
+    res = qemu_strtosz(str, &endptr);
+    g_assert_cmpint(res, ==, 12345 * M_BYTE);
+    g_assert(endptr == str + 6);
+
+    res = qemu_strtosz(str, NULL);
+    g_assert_cmpint(res, ==, 12345 * M_BYTE);
+}
+
+static void test_qemu_strtosz_units(void)
+{
+    const char *none = "1";
+    const char *b = "1B";
+    const char *k = "1K";
+    const char *m = "1M";
+    const char *g = "1G";
+    const char *t = "1T";
+    const char *p = "1P";
+    const char *e = "1E";
+    int64_t res;
+
+    /* default is M */
+    res = qemu_strtosz(none, NULL);
+    g_assert_cmpint(res, ==, M_BYTE);
+
+    res = qemu_strtosz(b, NULL);
+    g_assert_cmpint(res, ==, 1);
+
+    res = qemu_strtosz(k, NULL);
+    g_assert_cmpint(res, ==, K_BYTE);
+
+    res = qemu_strtosz(m, NULL);
+    g_assert_cmpint(res, ==, M_BYTE);
+
+    res = qemu_strtosz(g, NULL);
+    g_assert_cmpint(res, ==, G_BYTE);
+
+    res = qemu_strtosz(t, NULL);
+    g_assert_cmpint(res, ==, T_BYTE);
+
+    res = qemu_strtosz(p, NULL);
+    g_assert_cmpint(res, ==, P_BYTE);
+
+    res = qemu_strtosz(e, NULL);
+    g_assert_cmpint(res, ==, E_BYTE);
+}
+
+static void test_qemu_strtosz_float(void)
+{
+    const char *str = "12.345M";
+    int64_t res;
+
+    res = qemu_strtosz(str, NULL);
+    g_assert_cmpint(res, ==, 12.345 * M_BYTE);
+}
+
+static void test_qemu_strtosz_erange(void)
+{
+    const char *str = "10E";
+    int64_t res;
+
+    res = qemu_strtosz(str, NULL);
+    g_assert_cmpint(res, ==, -ERANGE);
+}
+
+static void test_qemu_strtosz_suffix_unit(void)
+{
+    const char *str = "12345";
+    int64_t res;
+
+    res = qemu_strtosz_suffix_unit(str, NULL,
+                                   QEMU_STRTOSZ_DEFSUFFIX_KB, 1000);
+    g_assert_cmpint(res, ==, 12345000);
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
@@ -1502,5 +1582,16 @@ int main(int argc, char **argv)
     g_test_add_func("/cutils/qemu_strtoull_full/max",
                     test_qemu_strtoull_full_max);
 
+    g_test_add_func("/cutils/strtosz/simple",
+                    test_qemu_strtosz_simple);
+    g_test_add_func("/cutils/strtosz/units",
+                    test_qemu_strtosz_units);
+    g_test_add_func("/cutils/strtosz/float",
+                    test_qemu_strtosz_float);
+    g_test_add_func("/cutils/strtosz/erange",
+                    test_qemu_strtosz_erange);
+    g_test_add_func("/cutils/strtosz/suffix-unit",
+                    test_qemu_strtosz_suffix_unit);
+
     return g_test_run();
 }
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix
  2015-09-16 16:02 [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix marcandre.lureau
  2015-09-16 16:02 ` [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests marcandre.lureau
@ 2015-09-16 16:13 ` Eric Blake
  2015-09-16 16:17   ` Marc-André Lureau
  2015-09-16 16:34 ` Paolo Bonzini
  2 siblings, 1 reply; 6+ messages in thread
From: Eric Blake @ 2015-09-16 16:13 UTC (permalink / raw)
  To: marcandre.lureau, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 667 bytes --]

On 09/16/2015 10:02 AM, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Not only it makes sense, but it gets rid of checkpatch warning:
> WARNING: consider using qemu_strtosz in preference to strtosz

Indeed, POSIX reserves the entire str*() namespace for future extension,
so avoiding the collision is worthwhile.

> 
> Also remove get rid of tabs to please checkpatch.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix
  2015-09-16 16:13 ` [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix Eric Blake
@ 2015-09-16 16:17   ` Marc-André Lureau
  0 siblings, 0 replies; 6+ messages in thread
From: Marc-André Lureau @ 2015-09-16 16:17 UTC (permalink / raw)
  To: Eric Blake; +Cc: marcandre lureau, qemu-devel



----- Original Message -----
> On 09/16/2015 10:02 AM, marcandre.lureau@redhat.com wrote:
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> > 
> > Not only it makes sense, but it gets rid of checkpatch warning:
> > WARNING: consider using qemu_strtosz in preference to strtosz
> 
> Indeed, POSIX reserves the entire str*() namespace for future extension,
> so avoiding the collision is worthwhile.
> 
> > 
> > Also remove get rid of tabs to please checkpatch.

I'll fix this spelling too

> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>
> 
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests
  2015-09-16 16:02 ` [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests marcandre.lureau
@ 2015-09-16 16:19   ` Eric Blake
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2015-09-16 16:19 UTC (permalink / raw)
  To: marcandre.lureau, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1673 bytes --]

On 09/16/2015 10:02 AM, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> While reading the function I decided to write some tests.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  tests/test-cutils.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 91 insertions(+)
> 
> diff --git a/tests/test-cutils.c b/tests/test-cutils.c
> index 0046c61..a3de6ab 100644
> --- a/tests/test-cutils.c
> +++ b/tests/test-cutils.c
> @@ -1352,6 +1352,86 @@ static void test_qemu_strtoull_full_max(void)
>      g_assert_cmpint(res, ==, ULLONG_MAX);
>  }
>  
> +static void test_qemu_strtosz_simple(void)
> +{
> +    const char *str = "12345M";
> +    char *endptr = NULL;
> +    int64_t res;
> +
> +    res = qemu_strtosz(str, &endptr);
> +    g_assert_cmpint(res, ==, 12345 * M_BYTE);
> +    g_assert(endptr == str + 6);
> +
> +    res = qemu_strtosz(str, NULL);
> +    g_assert_cmpint(res, ==, 12345 * M_BYTE);
> +}

Would it also be worth some negative tests, such as bogus suffix (for
example, does "1234x" fail to parse, or parse "1234" and leave "x"
unparsed?)

But what you have is a strict improvement (any test is better than none!) so

Reviewed-by: Eric Blake <eblake@redhat.com>


> +static void test_qemu_strtosz_erange(void)
> +{
> +    const char *str = "10E";
> +    int64_t res;
> +
> +    res = qemu_strtosz(str, NULL);
> +    g_assert_cmpint(res, ==, -ERANGE);
> +}

This was the only negative test I see.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix
  2015-09-16 16:02 [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix marcandre.lureau
  2015-09-16 16:02 ` [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests marcandre.lureau
  2015-09-16 16:13 ` [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix Eric Blake
@ 2015-09-16 16:34 ` Paolo Bonzini
  2 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2015-09-16 16:34 UTC (permalink / raw)
  To: marcandre.lureau, qemu-devel



On 16/09/2015 18:02, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Not only it makes sense, but it gets rid of checkpatch warning:
> WARNING: consider using qemu_strtosz in preference to strtosz

Oops. :)

However, we also need something like this:

----------- 8< ------------
From: Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH] checkpatch: do not recomment qemu_strtok

If anything, it should recommend strtok_r!

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b59a87a..272eef1 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2474,7 +2474,7 @@ sub process {
 			WARN("__func__ should be used instead of gcc specific __FUNCTION__\n"  . $herecurr);
 		}
 
-# recommend qemu_strto* over strto*
-		if ($line =~ /\b(strto.*?)\s*\(/) {
+# recommend qemu_strto* over strto* for numeric conversions
+		if ($line =~ /\b(strto[^k].*?)\s*\(/) {
 			WARN("consider using qemu_$1 in preference to $1\n" . $herecurr);
 		}
 # check for module_init(), use category-specific init macros explicitly please
------------- 8< ----------------

Paolo

> Also remove get rid of tabs to please checkpatch.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  include/qemu-common.h | 27 ++++++++++++++-------------
>  monitor.c             |  2 +-
>  qapi/opts-visitor.c   |  4 ++--
>  qemu-img.c            |  5 +++--
>  qemu-io-cmds.c        |  2 +-
>  target-i386/cpu.c     |  4 ++--
>  util/cutils.c         | 25 +++++++++++++------------
>  7 files changed, 36 insertions(+), 33 deletions(-)
> 
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index 01d29dd..0bd212b 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -217,22 +217,23 @@ int parse_uint(const char *s, unsigned long long *value, char **endptr,
>  int parse_uint_full(const char *s, unsigned long long *value, int base);
>  
>  /*
> - * strtosz() suffixes used to specify the default treatment of an
> - * argument passed to strtosz() without an explicit suffix.
> + * qemu_strtosz() suffixes used to specify the default treatment of an
> + * argument passed to qemu_strtosz() without an explicit suffix.
>   * These should be defined using upper case characters in the range
> - * A-Z, as strtosz() will use qemu_toupper() on the given argument
> + * A-Z, as qemu_strtosz() will use qemu_toupper() on the given argument
>   * prior to comparison.
>   */
> -#define STRTOSZ_DEFSUFFIX_EB	'E'
> -#define STRTOSZ_DEFSUFFIX_PB	'P'
> -#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'
> -int64_t strtosz(const char *nptr, char **end);
> -int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
> -int64_t strtosz_suffix_unit(const char *nptr, char **end,
> +#define QEMU_STRTOSZ_DEFSUFFIX_EB 'E'
> +#define QEMU_STRTOSZ_DEFSUFFIX_PB 'P'
> +#define QEMU_STRTOSZ_DEFSUFFIX_TB 'T'
> +#define QEMU_STRTOSZ_DEFSUFFIX_GB 'G'
> +#define QEMU_STRTOSZ_DEFSUFFIX_MB 'M'
> +#define QEMU_STRTOSZ_DEFSUFFIX_KB 'K'
> +#define QEMU_STRTOSZ_DEFSUFFIX_B 'B'
> +int64_t qemu_strtosz(const char *nptr, char **end);
> +int64_t qemu_strtosz_suffix(const char *nptr, char **end,
> +                            const char default_suffix);
> +int64_t qemu_strtosz_suffix_unit(const char *nptr, char **end,
>                              const char default_suffix, int64_t unit);
>  #define K_BYTE     (1ULL << 10)
>  #define M_BYTE     (1ULL << 20)
> diff --git a/monitor.c b/monitor.c
> index 5455ab9..1221977 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -3911,7 +3911,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
>                          break;
>                      }
>                  }
> -                val = strtosz(p, &end);
> +                val = qemu_strtosz(p, &end);
>                  if (val < 0) {
>                      monitor_printf(mon, "invalid size\n");
>                      goto fail;
> diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
> index 7ae33b3..cd10392 100644
> --- a/qapi/opts-visitor.c
> +++ b/qapi/opts-visitor.c
> @@ -474,8 +474,8 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
>          return;
>      }
>  
> -    val = strtosz_suffix(opt->str ? opt->str : "", &endptr,
> -                         STRTOSZ_DEFSUFFIX_B);
> +    val = qemu_strtosz_suffix(opt->str ? opt->str : "", &endptr,
> +                         QEMU_STRTOSZ_DEFSUFFIX_B);
>      if (val < 0 || *endptr) {
>          error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name,
>                     "a size value representible as a non-negative int64");
> diff --git a/qemu-img.c b/qemu-img.c
> index 6ff4e85..7d65c0a 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -338,7 +338,8 @@ static int img_create(int argc, char **argv)
>      if (optind < argc) {
>          int64_t sval;
>          char *end;
> -        sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B);
> +        sval = qemu_strtosz_suffix(argv[optind++], &end,
> +                                   QEMU_STRTOSZ_DEFSUFFIX_B);
>          if (sval < 0 || *end) {
>              if (sval == -ERANGE) {
>                  error_report("Image size must be less than 8 EiB!");
> @@ -1607,7 +1608,7 @@ static int img_convert(int argc, char **argv)
>          {
>              int64_t sval;
>              char *end;
> -            sval = strtosz_suffix(optarg, &end, STRTOSZ_DEFSUFFIX_B);
> +            sval = qemu_strtosz_suffix(optarg, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
>              if (sval < 0 || *end) {
>                  error_report("Invalid minimum zero buffer size for sparse output specified");
>                  ret = -1;
> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
> index d6572a8..6e5d1e4 100644
> --- a/qemu-io-cmds.c
> +++ b/qemu-io-cmds.c
> @@ -136,7 +136,7 @@ static char **breakline(char *input, int *count)
>  static int64_t cvtnum(const char *s)
>  {
>      char *end;
> -    return strtosz_suffix(s, &end, STRTOSZ_DEFSUFFIX_B);
> +    return qemu_strtosz_suffix(s, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
>  }
>  
>  #define EXABYTES(x)     ((long long)(x) << 60)
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index cfb8aa7..a5bea42 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1893,8 +1893,8 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
>                  char *err;
>                  char num[32];
>  
> -                tsc_freq = strtosz_suffix_unit(val, &err,
> -                                               STRTOSZ_DEFSUFFIX_B, 1000);
> +                tsc_freq = qemu_strtosz_suffix_unit(val, &err,
> +                                               QEMU_STRTOSZ_DEFSUFFIX_B, 1000);
>                  if (tsc_freq < 0 || *err) {
>                      error_setg(errp, "bad numerical value %s", val);
>                      return;
> diff --git a/util/cutils.c b/util/cutils.c
> index ae35198..cfeb848 100644
> --- a/util/cutils.c
> +++ b/util/cutils.c
> @@ -276,19 +276,19 @@ int fcntl_setfl(int fd, int flag)
>  static int64_t suffix_mul(char suffix, int64_t unit)
>  {
>      switch (qemu_toupper(suffix)) {
> -    case STRTOSZ_DEFSUFFIX_B:
> +    case QEMU_STRTOSZ_DEFSUFFIX_B:
>          return 1;
> -    case STRTOSZ_DEFSUFFIX_KB:
> +    case QEMU_STRTOSZ_DEFSUFFIX_KB:
>          return unit;
> -    case STRTOSZ_DEFSUFFIX_MB:
> +    case QEMU_STRTOSZ_DEFSUFFIX_MB:
>          return unit * unit;
> -    case STRTOSZ_DEFSUFFIX_GB:
> +    case QEMU_STRTOSZ_DEFSUFFIX_GB:
>          return unit * unit * unit;
> -    case STRTOSZ_DEFSUFFIX_TB:
> +    case QEMU_STRTOSZ_DEFSUFFIX_TB:
>          return unit * unit * unit * unit;
> -    case STRTOSZ_DEFSUFFIX_PB:
> +    case QEMU_STRTOSZ_DEFSUFFIX_PB:
>          return unit * unit * unit * unit * unit;
> -    case STRTOSZ_DEFSUFFIX_EB:
> +    case QEMU_STRTOSZ_DEFSUFFIX_EB:
>          return unit * unit * unit * unit * unit * unit;
>      }
>      return -1;
> @@ -300,7 +300,7 @@ static int64_t suffix_mul(char suffix, int64_t unit)
>   * in *end, if not NULL. Return -ERANGE on overflow, Return -EINVAL on
>   * other error.
>   */
> -int64_t strtosz_suffix_unit(const char *nptr, char **end,
> +int64_t qemu_strtosz_suffix_unit(const char *nptr, char **end,
>                              const char default_suffix, int64_t unit)
>  {
>      int64_t retval = -EINVAL;
> @@ -343,14 +343,15 @@ fail:
>      return retval;
>  }
>  
> -int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
> +int64_t qemu_strtosz_suffix(const char *nptr, char **end,
> +                            const char default_suffix)
>  {
> -    return strtosz_suffix_unit(nptr, end, default_suffix, 1024);
> +    return qemu_strtosz_suffix_unit(nptr, end, default_suffix, 1024);
>  }
>  
> -int64_t strtosz(const char *nptr, char **end)
> +int64_t qemu_strtosz(const char *nptr, char **end)
>  {
> -    return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB);
> +    return qemu_strtosz_suffix(nptr, end, QEMU_STRTOSZ_DEFSUFFIX_MB);
>  }
>  
>  /**
> 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-09-16 16:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-16 16:02 [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix marcandre.lureau
2015-09-16 16:02 ` [Qemu-devel] [PATCH 2/2] tests: add some qemu_strtosz() tests marcandre.lureau
2015-09-16 16:19   ` Eric Blake
2015-09-16 16:13 ` [Qemu-devel] [PATCH 1/2] utils: rename strtosz to use qemu prefix Eric Blake
2015-09-16 16:17   ` Marc-André Lureau
2015-09-16 16:34 ` Paolo Bonzini

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).