1 #define _GNU_SOURCE
2 #define __CRT__NO_INLINE
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <stdarg.h>
7
__mingw_vasprintf(char ** __restrict__ ret,const char * __restrict__ format,va_list ap)8 int __mingw_vasprintf(char ** __restrict__ ret,
9 const char * __restrict__ format,
10 va_list ap) {
11 int len;
12 /* Get Length */
13 len = __mingw_vsnprintf(NULL,0,format,ap);
14 if (len < 0) return -1;
15 /* +1 for \0 terminator. */
16 *ret = malloc(len + 1);
17 /* Check malloc fail*/
18 if (!*ret) return -1;
19 /* Write String */
20 __mingw_vsnprintf(*ret,len+1,format,ap);
21 /* Terminate explicitly */
22 (*ret)[len] = '\0';
23 return len;
24 }
25
26