diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ebf830791e7cba4b906d67dd6c9b59a4828c56d8..7dfb2458eb31e446a052c07ebf66f0e533919e5e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1646,6 +1646,7 @@ virBufferStrcat; virBufferStrcatVArgs; virBufferTrim; virBufferTrimChars; +virBufferTrimLen; virBufferURIEncodeString; virBufferUse; virBufferVasprintf; diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 914c386b187b61a66a8833e00206f611f55d605e..b76d99b56f7edde025acb95a1a9d74ade32e9f5c 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -700,6 +700,25 @@ virBufferTrimChars(virBufferPtr buf, const char *trim) g_string_truncate(buf->str, i + 1); } +/** + * virBufferTrimLen: + * @buf: the buffer to trim + * @len: the number of bytes to trim + * + * Trim the tail of a buffer. + */ +void +virBufferTrimLen(virBufferPtr buf, int len) +{ + if (!buf || !buf->str) + return; + + if (len > buf->str->len) + return; + + g_string_truncate(buf->str, buf->str->len - len); +} + /** * virBufferAddStr: * @buf: the buffer to append to diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index 183f78f279359c4a29f1378997ba1a2a01d59cd4..7b068075b278ac1300ae3e80eafd2594632f9b99 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -93,4 +93,5 @@ size_t virBufferGetEffectiveIndent(const virBuffer *buf); void virBufferTrim(virBufferPtr buf, const char *trim, int len); void virBufferTrimChars(virBufferPtr buf, const char *trim); +void virBufferTrimLen(virBufferPtr buf, int len); void virBufferAddStr(virBufferPtr buf, const char *str);