diff options
author | Carl Worth <cworth@cworth.org> | 2010-05-20 15:02:03 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2010-05-20 15:02:03 -0700 |
commit | b894583fd0246060d908a0cc7b5f3ef72a5a2112 (patch) | |
tree | 692c0b1cde199af682f0f702ee44c1c19df74906 | |
parent | 876e510bdab96574c4ca5ee94c580fe6ad7f0106 (diff) |
Add xtalloc_asprintf
I expect this to be useful in the upcoming implementation of token pasting.
-rw-r--r-- | glcpp.h | 3 | ||||
-rw-r--r-- | xtalloc.c | 18 |
2 files changed, 21 insertions, 0 deletions
@@ -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 @@ -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; +} |