aboutsummaryrefslogtreecommitdiffstats
path: root/common/membuf.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2013-11-29 14:37:23 +0000
committerWerner Koch <[email protected]>2013-11-29 14:37:23 +0000
commit159d42ee6ab21d97f40ee129445f37209b875739 (patch)
tree7fa321e6669177a4db5c76594d2752a778d3fffa /common/membuf.c
parentAdd rendered versions of the gnupg logo to artwork. (diff)
downloadgnupg-159d42ee6ab21d97f40ee129445f37209b875739.tar.gz
gnupg-159d42ee6ab21d97f40ee129445f37209b875739.zip
common: Add put_membuf_printf.
* common/membuf.c (put_membuf_printf): New. -- This is just a convenience function for easier code readability. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/membuf.c')
-rw-r--r--common/membuf.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/common/membuf.c b/common/membuf.c
index c3480dffb..02f1b2795 100644
--- a/common/membuf.c
+++ b/common/membuf.c
@@ -1,5 +1,6 @@
/* membuf.c - A simple implementation of a dynamic buffer.
* Copyright (C) 2001, 2003, 2009, 2011 Free Software Foundation, Inc.
+ * Copyright (C) 2013 Werner Koch
*
* This file is part of GnuPG.
*
@@ -30,6 +31,7 @@
#include <config.h>
#include <stdlib.h>
#include <errno.h>
+#include <stdarg.h>
#include "membuf.h"
@@ -122,6 +124,26 @@ put_membuf_str (membuf_t *mb, const char *string)
}
+void
+put_membuf_printf (membuf_t *mb, const char *format, ...)
+{
+ int rc;
+ va_list arg_ptr;
+ char *buf;
+
+ va_start (arg_ptr, format);
+ rc = estream_vasprintf (&buf, format, arg_ptr);
+ if (rc < 0)
+ mb->out_of_core = errno ? errno : ENOMEM;
+ va_end (arg_ptr);
+ if (rc >= 0)
+ {
+ put_membuf (mb, buf, strlen (buf));
+ xfree (buf);
+ }
+}
+
+
void *
get_membuf (membuf_t *mb, size_t *len)
{