From: Carl Worth Date: Thu, 20 May 2010 22:02:03 +0000 (-0700) Subject: Add xtalloc_asprintf X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b894583fd0246060d908a0cc7b5f3ef72a5a2112;p=mesa.git Add xtalloc_asprintf I expect this to be useful in the upcoming implementation of token pasting. --- 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; +}