summaryrefslogtreecommitdiffstats
path: root/include/asprintf.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asprintf.h')
-rw-r--r--include/asprintf.h36
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 @@
1#ifndef __ASPRINTF_H
2#define __ASPRINTF_H
3
4#ifdef HAVE_CONFIG_H
5#include <config.h>
6#endif
7
8#include <stdio.h>
9
10#ifndef HAVE_VASPRINTF
11static inline int vasprintf(char **PTR, const char *TEMPLATE, va_list AP)
12{
13 int res;
14 char buf[16];
15 res = vsnprintf(buf, 16, TEMPLATE, AP);
16 if (res > 0) {
17 *PTR = (char*)malloc(res+1);
18 res = vsnprintf(*PTR, res+1, TEMPLATE, AP);
19 }
20 return res;
21}
22#endif
23
24#ifndef HAVE_ASPRINTF
25static inline int asprintf(char **PTR, const char *TEMPLATE, ...)
26{
27 int res;
28 va_list AP;
29 va_start(AP, TEMPLATE);
30 res = vasprintf(PTR, TEMPLATE, AP);
31 va_end(AP);
32 return res;
33}
34#endif
35
36#endif /* ASPRINTF_H */