projects
/
mono.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
2007-04-27 Jonathan Chambers <joncham@gmail.com>
[mono.git]
/
eglib
/
src
/
vasprintf.c
1
#include <stdarg.h>
2
#include <stdio.h>
3
#include <stdlib.h>
4
5
int vasprintf(char **ret, const char *fmt, va_list ap)
6
{
7
char *buf;
8
int len;
9
size_t buflen;
10
va_list ap2;
11
12
#ifdef _MSC_VER
13
ap2 = ap;
14
#else
15
va_copy(ap2, ap);
16
#endif
17
18
len = vsnprintf(NULL, 0, fmt, ap2);
19
20
if (len > 0 && (buf = malloc((buflen = (size_t) (len + 1)))) != NULL) {
21
len = vsnprintf(buf, buflen, fmt, ap);
22
*ret = buf;
23
} else {
24
*ret = NULL;
25
len = -1;
26
}
27
28
va_end(ap2);
29
return len;
30
}