1 #include <ccan/asprintf/asprintf.h>
5 char *PRINTF_FMT(1, 2) afmt(const char *fmt, ...)
11 /* The BSD version apparently sets ptr to NULL on fail. GNU loses. */
12 if (vasprintf(&ptr, fmt, ap) < 0)
22 int vasprintf(char **strp, const char *fmt, va_list ap)
27 /* We need to make a copy of ap, since it's a use-once. */
29 len = vsnprintf(NULL, 0, fmt, ap_copy);
32 /* Until version 2.0.6 glibc would return -1 on truncated output.
33 * OTOH, they had asprintf. */
37 *strp = malloc(len+1);
41 return vsprintf(*strp, fmt, ap);
44 int asprintf(char **strp, const char *fmt, ...)
50 len = vasprintf(strp, fmt, ap);
55 #endif /* !HAVE_ASPRINTF */