projects
/
oweals
/
musl.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
yet another ugly legacy syscall rename...
[oweals/musl.git]
/
src
/
stdio
/
vasprintf.c
1
#include <stdio.h>
2
#include <stdarg.h>
3
#include <stdlib.h>
4
5
#define GUESS 240U
6
7
int vasprintf(char **s, const char *fmt, va_list ap)
8
{
9
va_list ap2;
10
char *a;
11
int l=GUESS;
12
13
if (!(a=malloc(GUESS))) return -1;
14
15
va_copy(ap2, ap);
16
l=vsnprintf(a, GUESS, fmt, ap2);
17
va_end(ap2);
18
19
if (l<GUESS) {
20
char *b = realloc(a, l+1U);
21
*s = b ? b : a;
22
return l;
23
}
24
free(a);
25
if (l<0 || !(*s=malloc(l+1U))) return -1;
26
return vsnprintf(*s, l+1U, fmt, ap);
27
}