[libvirt] [PATCH v2 1/3] util: virbuffer: introduce virBufferEscapeN

Ján Tomko jtomko at redhat.com
Fri Feb 24 10:53:01 UTC 2017


On Thu, Feb 23, 2017 at 09:36:16PM +0100, Pavel Hrdina wrote:
>+/**
>+ * virBufferEscapeN:
>+ * @buf: the buffer to append to
>+ * @format: a printf like format string but with only one %s parameter
>+ * @str: the string argument which needs to be escaped

>+ * @...: the variable list of arguments composed

s/arguments composed/escape pairs/ maybe?

>+ *
>+ * The variable list of arguments @... must be composed of
>+ * 'char escape, char *toescape' pairs followed by NULL.
>+ *
>+ * This has the same functionality as virBufferEscape with the extension
>+ * that allows to specify multiple pairs of chars that needs to be escaped.
>+ */
>+void
>+virBufferEscapeN(virBufferPtr buf,
>+                 const char *format,
>+                 const char *str,
>+                 ...)
>+{
>+    int len;
>+    size_t i;
>+    char escape;
>+    char *toescape;
>+    char *escaped = NULL;
>+    char *out;
>+    const char *cur;
>+    struct _virBufferEscapePair escapeItem;
>+    struct _virBufferEscapePair *escapeList = NULL;
>+    size_t nescapeList = 0;
>+    va_list ap;
>+
>+    if ((format == NULL) || (buf == NULL) || (str == NULL))
>+        return;
>+
>+    if (buf->error)
>+        return;
>+
>+    len = strlen(str);
>+
>+    va_start(ap, str);
>+

>+    while ((escape = va_arg(ap, int))) {
>+        if (!(toescape = va_arg(ap, char *))) {

You can either assign directly to escapeItem.{to,}escape here,
or declare toescape and escapeItem inside the while loop to reduce
the number of function-wide variables.

>+            virBufferSetError(buf, errno);
>+            goto cleanup;
>+        }

Jan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20170224/1f837198/attachment-0001.sig>


More information about the libvir-list mailing list