configure: add gettid() test
[fio.git] / oslib / asprintf.c
1 #include <stdarg.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "oslib/asprintf.h"
5
6 #ifndef CONFIG_HAVE_VASPRINTF
7 int vasprintf(char **strp, const char *fmt, va_list ap)
8 {
9         va_list ap_copy;
10         char *str;
11         int len;
12
13 #ifdef va_copy
14         va_copy(ap_copy, ap);
15 #else
16         __va_copy(ap_copy, ap);
17 #endif
18         len = vsnprintf(NULL, 0, fmt, ap_copy);
19         va_end(ap_copy);
20
21         if (len < 0)
22                 return len;
23
24         len++;
25         str = malloc(len);
26         *strp = str;
27         return str ? vsnprintf(str, len, fmt, ap) : -1;
28 }
29 #endif
30
31 #ifndef CONFIG_HAVE_ASPRINTF
32 int asprintf(char **strp, const char *fmt, ...)
33 {
34         va_list arg;
35         int done;
36
37         va_start(arg, fmt);
38         done = vasprintf(strp, fmt, arg);
39         va_end(arg);
40
41         return done;
42 }
43 #endif