aboutsummaryrefslogtreecommitdiffstats
path: root/common/miscellaneous.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2003-12-17 12:26:38 +0000
committerWerner Koch <[email protected]>2003-12-17 12:26:38 +0000
commit8ab35a7d26707dfa0032b3b0dbde6a984a9683cb (patch)
tree6506bd41badddfc72100a5f6c37a51c7f2099560 /common/miscellaneous.c
parent(initialize): Replaced use of non-literal forma (diff)
downloadgnupg-8ab35a7d26707dfa0032b3b0dbde6a984a9683cb.tar.gz
gnupg-8ab35a7d26707dfa0032b3b0dbde6a984a9683cb.zip
* gettime.c (asctimestamp): Add a note on a non-avoidable gcc warning.
* util.h [!HAVE_VASPRINTF]: Add printf format attribute to the replacement function. * miscellaneous.c (xasprintf): New.
Diffstat (limited to 'common/miscellaneous.c')
-rw-r--r--common/miscellaneous.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/common/miscellaneous.c b/common/miscellaneous.c
index bdb12c574..4937bd7ce 100644
--- a/common/miscellaneous.c
+++ b/common/miscellaneous.c
@@ -25,6 +25,26 @@
#include "util.h"
#include "iobuf.h"
+/* Same as asprintf but return an allocated buffer suitable to be
+ freed using xfree. This function simply dies on memory failure,
+ thus no extra check is required. */
+char *
+xasprintf (const char *fmt, ...)
+{
+ va_list ap;
+ char *buf, *p;
+
+ va_start (ap, fmt);
+ if (vasprintf (&buf, fmt, ap) < 0)
+ log_fatal ("asprintf failed: %s\n", strerror (errno));
+ va_end (ap);
+ p = xstrdup (buf);
+ free (buf);
+ return p;
+}
+
+
+
/* Decide whether the filename is stdout or a real filename and return
* an appropriate string. */
const char *