render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
9119d9
From b9dbdee2b7d35cb6d338e6f24c7a8fd09409b80e Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <b9dbdee2b7d35cb6d338e6f24c7a8fd09409b80e@dist-git>
9119d9
From: Peter Krempa <pkrempa@redhat.com>
9119d9
Date: Wed, 22 Oct 2014 18:29:45 +0200
9119d9
Subject: [PATCH] util: string: Add helper to check whether string is empty
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1142693
9119d9
9119d9
The helper checks whether a string contains only whitespace or is NULL.
9119d9
This will be helpful to skip cases where a user string is optional, but
9119d9
may be provided empty with the same meaning.
9119d9
9119d9
(cherry picked from commit 0eeafeedebe4469fce33d7942551957853856619)
9119d9
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/libvirt_private.syms |  1 +
9119d9
 src/util/virstring.c     | 16 ++++++++++++++++
9119d9
 src/util/virstring.h     |  2 ++
9119d9
 3 files changed, 19 insertions(+)
9119d9
9119d9
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
9119d9
index 138d84f..f569417 100644
9119d9
--- a/src/libvirt_private.syms
9119d9
+++ b/src/libvirt_private.syms
9119d9
@@ -1964,6 +1964,7 @@ virStrdup;
9119d9
 virStringArrayHasString;
9119d9
 virStringFreeList;
9119d9
 virStringFreeListCount;
9119d9
+virStringIsEmpty;
9119d9
 virStringJoin;
9119d9
 virStringListLength;
9119d9
 virStringReplace;
9119d9
diff --git a/src/util/virstring.c b/src/util/virstring.c
9119d9
index b14f785..583ffd0 100644
9119d9
--- a/src/util/virstring.c
9119d9
+++ b/src/util/virstring.c
9119d9
@@ -616,6 +616,22 @@ virSkipSpacesBackwards(const char *str, char **endp)
9119d9
         *endp = NULL;
9119d9
 }
9119d9
 
9119d9
+/**
9119d9
+ * virStringIsEmpty:
9119d9
+ * @str: string to check
9119d9
+ *
9119d9
+ * Returns true if string is empty (may contain only whitespace) or NULL.
9119d9
+ */
9119d9
+bool
9119d9
+virStringIsEmpty(const char *str)
9119d9
+{
9119d9
+    if (!str)
9119d9
+        return true;
9119d9
+
9119d9
+    virSkipSpaces(&str);
9119d9
+    return str[0] == '\0';
9119d9
+}
9119d9
+
9119d9
 char *
9119d9
 virArgvToString(const char *const *argv)
9119d9
 {
9119d9
diff --git a/src/util/virstring.h b/src/util/virstring.h
9119d9
index 267fbd0..2ec9a4d 100644
9119d9
--- a/src/util/virstring.h
9119d9
+++ b/src/util/virstring.h
9119d9
@@ -105,6 +105,8 @@ void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1);
9119d9
 void virSkipSpacesBackwards(const char *str, char **endp)
9119d9
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
9119d9
 
9119d9
+bool virStringIsEmpty(const char *str);
9119d9
+
9119d9
 char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
9119d9
     ATTRIBUTE_RETURN_CHECK;
9119d9
 char *virStrcpy(char *dest, const char *src, size_t destbytes)
9119d9
-- 
9119d9
2.1.3
9119d9