]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: string: Introduce helper to determine whether a byte buffer is printable
authorJohn Ferlan <jferlan@redhat.com>
Thu, 12 May 2016 15:43:39 +0000 (11:43 -0400)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 16 May 2016 10:58:48 +0000 (12:58 +0200)
Signed-off-by: John Ferlan <jferlan@redhat.com>
src/libvirt_private.syms
src/util/virstring.c
src/util/virstring.h

index 14a9b08f2dc6de1d3bd942c3a2fde31dc39b59cc..840808129098e9bac9f43aafa4fc5bef56297252 100644 (file)
@@ -2303,6 +2303,7 @@ virSkipSpacesBackwards;
 virStrcpy;
 virStrdup;
 virStringArrayHasString;
+virStringBufferIsPrintable;
 virStringEncodeBase64;
 virStringFreeList;
 virStringFreeListCount;
index 2702cecf206f83882cbeeaaeb22ad49e68664d26..0177a952101f69cc017bd799d1cf9b9741305893 100644 (file)
@@ -1069,6 +1069,25 @@ virStringIsPrintable(const char *str)
 }
 
 
+/**
+ * virBufferIsPrintable:
+ *
+ * Returns true if @buf of @buflen contains only printable characters
+ */
+bool
+virStringBufferIsPrintable(const uint8_t *buf,
+                           size_t buflen)
+{
+    size_t i;
+
+    for (i = 0; i < buflen; i++)
+        if (!c_isprint(buf[i]))
+            return false;
+
+    return true;
+}
+
+
 /**
  * virStringEncodeBase64:
  * @buf: buffer of bytes to encode
index 6bc2726a17d088f67b75df6ec3cbe0180ba377fe..040771e832c68601e271f9f14585dec2174f8c30 100644 (file)
@@ -276,6 +276,7 @@ bool virStringHasControlChars(const char *str);
 void virStringStripControlChars(char *str);
 
 bool virStringIsPrintable(const char *str);
+bool virStringBufferIsPrintable(const uint8_t *buf, size_t buflen);
 
 char *virStringEncodeBase64(const uint8_t *buf, size_t buflen);