From: Oliver Kurth Date: Mon, 15 Apr 2019 18:32:59 +0000 (-0700) Subject: Add a DynBuf_InitWithString() function to the dynamic buffer routines. X-Git-Tag: stable-11.0.0~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0ec4f8294ec6428ee2a7f7284b37f79f4661bf3;p=thirdparty%2Fopen-vm-tools.git Add a DynBuf_InitWithString() function to the dynamic buffer routines. --- diff --git a/open-vm-tools/lib/include/dynbuf.h b/open-vm-tools/lib/include/dynbuf.h index 6c771f225..f1a5111b7 100644 --- a/open-vm-tools/lib/include/dynbuf.h +++ b/open-vm-tools/lib/include/dynbuf.h @@ -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 diff --git a/open-vm-tools/lib/misc/dynbuf.c b/open-vm-tools/lib/misc/dynbuf.c index dc36d0708..7e9e1785d 100644 --- a/open-vm-tools/lib/misc/dynbuf.c +++ b/open-vm-tools/lib/misc/dynbuf.c @@ -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); + } +} + + /* *----------------------------------------------------------------------------- *