aboutsummaryrefslogtreecommitdiffstats
path: root/common/xasprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/xasprintf.c')
-rw-r--r--common/xasprintf.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/common/xasprintf.c b/common/xasprintf.c
index 2c8fafc06..a3b5e27ac 100644
--- a/common/xasprintf.c
+++ b/common/xasprintf.c
@@ -1,5 +1,5 @@
/* xasprintf.c
- * Copyright (C) 2003 Free Software Foundation, Inc.
+ * Copyright (C) 2003, 2005 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -42,3 +42,21 @@ xasprintf (const char *fmt, ...)
free (buf);
return p;
}
+
+/* Same as above bit return NULL on memory failure. */
+char *
+xtryasprintf (const char *fmt, ...)
+{
+ int rc;
+ va_list ap;
+ char *buf, *p;
+
+ va_start (ap, fmt);
+ rc = vasprintf (&buf, fmt, ap);
+ va_end (ap);
+ if (rc < 0)
+ return NULL;
+ p = xtrystrdup (buf);
+ free (buf);
+ return p;
+}