From b894583fd0246060d908a0cc7b5f3ef72a5a2112 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 20 May 2010 15:02:03 -0700 Subject: [PATCH] Add xtalloc_asprintf I expect this to be useful in the upcoming implementation of token pasting. --- glcpp.h | 3 +++ xtalloc.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/glcpp.h b/glcpp.h index 2e93cb981d8..048a9be76bb 100644 --- a/glcpp.h +++ b/glcpp.h @@ -149,4 +149,7 @@ xtalloc_strdup (const void *t, const char *p); char * xtalloc_strndup (const void *t, const char *p, size_t n); +char * +xtalloc_asprintf (const void *t, const char *fmt, ...); + #endif diff --git a/xtalloc.c b/xtalloc.c index d9893ae8893..e52d12ac6b2 100644 --- a/xtalloc.c +++ b/xtalloc.c @@ -64,3 +64,21 @@ xtalloc_strndup (const void *t, const char *p, size_t n) return ret; } + +char * +xtalloc_asprintf (const void *t, const char *fmt, ...) +{ + va_list ap; + char *ret; + + va_start(ap, fmt); + + ret = talloc_vasprintf(t, fmt, ap); + if (ret == NULL) { + fprintf (stderr, "Out of memory.\n"); + exit (1); + } + + va_end(ap); + return ret; +} -- 2.30.2