[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2 1/3] xen: introduce parse_size_and_unit_or_int



Introduce parse_size_and_unit_or_int() similar to parse_size_and_unit()
but not defaulting to kbytes in case the parameter is a number followed
by a specified character.

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
 xen/common/lib.c      | 11 +++++++++--
 xen/include/xen/lib.h |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/xen/common/lib.c b/xen/common/lib.c
index 62330205fe..262e9f1053 100644
--- a/xen/common/lib.c
+++ b/xen/common/lib.c
@@ -452,7 +452,8 @@ uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
 #endif
 }
 
-unsigned long long parse_size_and_unit(const char *s, const char **ps)
+unsigned long long parse_size_and_unit_or_int(const char *s, const char **ps,
+                                              char no_size)
 {
     unsigned long long ret;
     const char *s1;
@@ -477,7 +478,8 @@ unsigned long long parse_size_and_unit(const char *s, const 
char **ps)
         s1++;
         break;
     default:
-        ret <<= 10; /* default to kB */
+        if ( *s1 && *s1 != no_size )
+            ret <<= 10; /* default to kB */
         break;
     }
 
@@ -487,6 +489,11 @@ unsigned long long parse_size_and_unit(const char *s, 
const char **ps)
     return ret;
 }
 
+unsigned long long parse_size_and_unit(const char *s, const char **ps)
+{
+    return parse_size_and_unit_or_int(s, ps, '\0');
+}
+
 typedef void (*ctor_func_t)(void);
 extern const ctor_func_t __ctors_start[], __ctors_end[];
 
diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
index 972fc843fa..4db6e6419c 100644
--- a/xen/include/xen/lib.h
+++ b/xen/include/xen/lib.h
@@ -153,6 +153,8 @@ unsigned long long simple_strtoull(
     const char *cp,const char **endp, unsigned int base);
 
 unsigned long long parse_size_and_unit(const char *s, const char **ps);
+unsigned long long parse_size_and_unit_or_int(const char *s, const char **ps,
+                                              char no_size);
 
 uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
 
-- 
2.16.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.