[PATCHv2 1/2] sysinfo: add virSkipSpacesBackwards()

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

 



sysinfo: add virSkipSpacesBackwards()

  * Add virSkipSpacesBackwards() to src/util/util.[ch]

Signed-off-by: Minoru Usui <usui@xxxxxxxxxxxxxxxxx>
---
 src/util/util.c |   25 +++++++++++++++++++++++++
 src/util/util.h |    1 +
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/util/util.c b/src/util/util.c
index 463d2b8..1cf4de8 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1550,6 +1550,31 @@ virSkipSpaces(const char **str)
 }
 
 /**
+ * virSkipSpacesBackwards:
+ * @str : pointer to the target strings
+ * @endp: pointer to the end of @str
+ *
+ * Skip potential blanks backwards.
+ */
+void
+virSkipSpacesBackwards(const char *str, char **endp)
+{
+    char *cur;
+
+    if (!endp || !*endp)
+        return;
+
+    cur = *endp - 1;
+    while (cur >= str) {
+        if (!c_isspace(*cur))
+            break;
+        cur--;
+    }
+
+    *endp = (cur >= str) ? cur + 1 : NULL;
+}
+
+/**
  * virParseNumber:
  * @str: pointer to the char pointer used
  *
diff --git a/src/util/util.h b/src/util/util.h
index 0c43f7a..ae74c30 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 virSkipSpacesBackwards(const char *str, char **endp);
 int virParseNumber(const char **str);
 int virParseVersionString(const char *str, unsigned long *version);
 int virAsprintf(char **strp, const char *fmt, ...)
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]