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

[libvirt] [PATCHv3 1/3] util: fix virSkipSpaces



Most clients of virSkipSpaces don't want to omit backslashes.
Also, open-coding the list of spaces is not as nice as using
c_isspace.

* src/util/util.c (virSkipSpaces): Use c_isspace.
(virSkipSpacesAndBackslash): New function.
* src/util/util.h (virSkipSpacesAndBackslash): New prototype.
* src/xen/xend_internal.c (sexpr_to_xend_topology): Update caller.
* src/libvirt_private.syms (util.h): Export new function.
---
 src/libvirt_private.syms |    1 +
 src/util/util.c          |   23 +++++++++++++++++++----
 src/util/util.h          |    1 +
 src/xen/xend_internal.c  |    4 ++--
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 626ac6c..024b3f1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1030,6 +1030,7 @@ virSetInherit;
 virSetNonBlock;
 virSetUIDGID;
 virSkipSpaces;
+virSkipSpacesAndBackslash;
 virStrToDouble;
 virStrToLong_i;
 virStrToLong_l;
diff --git a/src/util/util.c b/src/util/util.c
index 463d2b8..27eefb2 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1535,16 +1535,31 @@ virHexToBin(unsigned char c)
  * @str: pointer to the char pointer used
  *
  * Skip potential blanks, this includes space tabs, line feed,
- * carriage returns and also '\\' which can be erronously emitted
- * by xend
+ * carriage returns.
  */
 void
 virSkipSpaces(const char **str)
 {
     const char *cur = *str;

-    while ((*cur == ' ') || (*cur == '\t') || (*cur == '\n') ||
-           (*cur == '\r') || (*cur == '\\'))
+    while (c_isspace(*cur))
+        cur++;
+    *str = cur;
+}
+
+/**
+ * virSkipSpacesAndBackslash:
+ * @str: pointer to the char pointer used
+ *
+ * Like virSkipSpaces, but also skip backslashes erroneously emitted
+ * by xend
+ */
+void
+virSkipSpacesAndBackslash(const char **str)
+{
+    const char *cur = *str;
+
+    while (c_isspace(*cur) || *cur == '\\')
         cur++;
     *str = cur;
 }
diff --git a/src/util/util.h b/src/util/util.h
index 0c43f7a..8dec78a 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -167,6 +167,7 @@ int virHexToBin(unsigned char c);
 int virMacAddrCompare (const char *mac1, const char *mac2);

 void virSkipSpaces(const char **str);
+void virSkipSpacesAndBackslash(const char **str);
 int virParseNumber(const char **str);
 int virParseVersionString(const char *str, unsigned long *version);
 int virAsprintf(char **strp, const char *fmt, ...)
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index d418847..d0eb32a0 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -1199,11 +1199,11 @@ sexpr_to_xend_topology(const struct sexpr *root,
         cell = virParseNumber(&cur);
         if (cell < 0)
             goto parse_error;
-        virSkipSpaces(&cur);
+        virSkipSpacesAndBackslash(&cur);
         if (*cur != ':')
             goto parse_error;
         cur++;
-        virSkipSpaces(&cur);
+        virSkipSpacesAndBackslash(&cur);
         if (STRPREFIX(cur, "no cpus")) {
             nb_cpus = 0;
             for (cpu = 0; cpu < numCpus; cpu++)
-- 
1.7.4.4


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