]> xenbits.xensource.com Git - libvirt.git/commitdiff
buf: add virBufferVasprintf
authorEric Blake <eblake@redhat.com>
Sat, 30 Apr 2011 16:44:42 +0000 (10:44 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 5 May 2011 19:48:19 +0000 (13:48 -0600)
Match the fact that we have virAsprintf and virVasprintf.

* src/util/buf.h (virBufferVasprintf): New prototype.
* src/util/buf.c (virBufferAsprintf): Move guts...
(virBufferVasprintf): ...to new function.
* src/libvirt_private.syms (buf.h): Export it.
* bootstrap.conf (gnulib_modules): Add stdarg, for va_copy.

bootstrap.conf
src/libvirt_private.syms
src/util/buf.c
src/util/buf.h

index fde00da18aa0ad9826a58adaec3e87d593341e8f..09e82183fff64311ca6df7992b67cc16107d6cda 100644 (file)
@@ -70,6 +70,7 @@ sigaction
 sigpipe
 snprintf
 socket
+stdarg
 stpcpy
 strchrnul
 strndup
index fc8edb4d763a48d78b24e616ef89eb9a7d920030..00f7e08f9ad6fbc59491321b503bbc97f1b441d1 100644 (file)
@@ -22,6 +22,7 @@ virBitmapString;
 # buf.h
 virBufferAdd;
 virBufferAddChar;
+virBufferAsprintf;
 virBufferContentAndReset;
 virBufferError;
 virBufferEscapeSexpr;
@@ -30,7 +31,7 @@ virBufferFreeAndReset;
 virBufferStrcat;
 virBufferURIEncodeString;
 virBufferUse;
-virBufferAsprintf;
+virBufferVasprintf;
 
 
 # caps.h
index 7814e8e2f32b5a120ce6a393505bed608135f99d..750e2770b1cf24b0a1cf9f4ead00ae66bc6bc123 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * buf.c: buffers for libvirt
  *
- * Copyright (C) 2005-2008, 2010 Red Hat, Inc.
+ * Copyright (C) 2005-2008, 2010-2011 Red Hat, Inc.
  *
  * See COPYING.LIB for the License of this software
  *
@@ -223,8 +223,25 @@ virBufferUse(const virBufferPtr buf)
 void
 virBufferAsprintf(const virBufferPtr buf, const char *format, ...)
 {
-    int size, count, grow_size;
     va_list argptr;
+    va_start(argptr, format);
+    virBufferVasprintf(buf, format, argptr);
+    va_end(argptr);
+}
+
+/**
+ * virBufferVasprintf:
+ * @buf:  the buffer to dump
+ * @format:  the format
+ * @argptr:  the variable list of arguments
+ *
+ * Do a formatted print to an XML buffer.
+ */
+void
+virBufferVasprintf(const virBufferPtr buf, const char *format, va_list argptr)
+{
+    int size, count, grow_size;
+    va_list copy;
 
     if ((format == NULL) || (buf == NULL))
         return;
@@ -236,38 +253,34 @@ virBufferAsprintf(const virBufferPtr buf, const char *format, ...)
         virBufferGrow(buf, 100) < 0)
         return;
 
-    va_start(argptr, format);
+    va_copy(copy, argptr);
 
     size = buf->size - buf->use;
     if ((count = vsnprintf(&buf->content[buf->use],
-                           size, format, argptr)) < 0) {
+                           size, format, copy)) < 0) {
         virBufferSetError(buf);
-        goto err;
+        va_end(copy);
+        return;
     }
+    va_end(copy);
 
     /* Grow buffer if necessary and retry */
     if (count >= size) {
         buf->content[buf->use] = 0;
-        va_end(argptr);
-        va_start(argptr, format);
 
         grow_size = (count + 1 > 1000) ? count + 1 : 1000;
         if (virBufferGrow(buf, grow_size) < 0) {
-            goto err;
+            return;
         }
 
         size = buf->size - buf->use;
         if ((count = vsnprintf(&buf->content[buf->use],
                                size, format, argptr)) < 0) {
             virBufferSetError(buf);
-            goto err;
+            return;
         }
     }
     buf->use += count;
-
-err:
-    va_end(argptr);
-    return;
 }
 
 /**
index 00f204354f89e9ff7dcbd8a382efe73ea50281d1..06d01baeef23e5892cb1fbe19cd75df6881a03de 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * buf.h: buffers for libvirt
  *
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2008, 2011 Red Hat, Inc.
  *
  * See COPYING.LIB for the License of this software
  *
@@ -13,6 +13,8 @@
 
 # include "internal.h"
 
+# include <stdarg.h>
+
 /**
  * virBuffer:
  *
@@ -42,6 +44,8 @@ void virBufferAdd(const virBufferPtr buf, const char *str, int len);
 void virBufferAddChar(const virBufferPtr buf, char c);
 void virBufferAsprintf(const virBufferPtr buf, const char *format, ...)
   ATTRIBUTE_FMT_PRINTF(2, 3);
+void virBufferVasprintf(const virBufferPtr buf, const char *format, va_list ap)
+  ATTRIBUTE_FMT_PRINTF(2, 0);
 void virBufferStrcat(const virBufferPtr buf, ...)
   ATTRIBUTE_SENTINEL;
 void virBufferEscapeString(const virBufferPtr buf, const char *format, const char *str);