Add xtalloc_asprintf
authorCarl Worth <cworth@cworth.org>
Thu, 20 May 2010 22:02:03 +0000 (15:02 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 20 May 2010 22:02:03 +0000 (15:02 -0700)
I expect this to be useful in the upcoming implementation of token pasting.

glcpp.h
xtalloc.c

diff --git a/glcpp.h b/glcpp.h
index 2e93cb9..048a9be 100644 (file)
--- 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
index d9893ae..e52d12a 100644 (file)
--- 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;
+}