]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Add a DynBuf_InitWithString() function to the dynamic buffer routines.
authorOliver Kurth <okurth@vmware.com>
Mon, 15 Apr 2019 18:32:59 +0000 (11:32 -0700)
committerOliver Kurth <okurth@vmware.com>
Mon, 15 Apr 2019 18:32:59 +0000 (11:32 -0700)
open-vm-tools/lib/include/dynbuf.h
open-vm-tools/lib/misc/dynbuf.c

index 6c771f225bb994fdc1cee13c2b29cdb94e50e034..f1a5111b773c8c459ed0244ed94c7748e2e0fc7c 100644 (file)
@@ -48,6 +48,10 @@ DynBuf_InitWithMemory(DynBuf *b,
                       size_t dataSize,
                       void *data);
 
+void
+DynBuf_InitWithString(DynBuf *b,
+                      char *str);
+
 void
 DynBuf_Destroy(DynBuf *b); // IN
 
index dc36d07086e03e117ed87decdf612f034c86e564..7e9e1785d46eca8db083c5b9587cba83350b8106 100644 (file)
@@ -90,6 +90,36 @@ DynBuf_InitWithMemory(DynBuf *b,        // IN/OUT:
 }
 
 
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * DynBuf_InitWithString --
+ *
+ *      Initialize buffer with a pre-allocated string.
+ *
+ * Results:
+ *      None
+ *
+ * Side effects:
+ *      None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+DynBuf_InitWithString(DynBuf *b, // IN/OUT
+                      char *str) // IN
+{
+   if (str != NULL) {
+      int len = strlen(str);
+      DynBuf_InitWithMemory(b, len + 1, str);
+      DynBuf_SetSize(b, len);
+   } else {
+      DynBuf_Init(b);
+   }
+}
+
+
 /*
  *-----------------------------------------------------------------------------
  *