diff options
Diffstat (limited to 'include/asprintf.h')
-rw-r--r-- | include/asprintf.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/include/asprintf.h b/include/asprintf.h new file mode 100644 index 0000000..3ed35be --- /dev/null +++ b/include/asprintf.h @@ -0,0 +1,36 @@ +#ifndef __ASPRINTF_H +#define __ASPRINTF_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> + +#ifndef HAVE_VASPRINTF +static inline int vasprintf(char **PTR, const char *TEMPLATE, va_list AP) +{ + int res; + char buf[16]; + res = vsnprintf(buf, 16, TEMPLATE, AP); + if (res > 0) { + *PTR = (char*)malloc(res+1); + res = vsnprintf(*PTR, res+1, TEMPLATE, AP); + } + return res; +} +#endif + +#ifndef HAVE_ASPRINTF +static inline int asprintf(char **PTR, const char *TEMPLATE, ...) +{ + int res; + va_list AP; + va_start(AP, TEMPLATE); + res = vasprintf(PTR, TEMPLATE, AP); + va_end(AP); + return res; +} +#endif + +#endif /* ASPRINTF_H */ |