1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
13 #include <bits/uClibc_va_copy.h>
15 #ifndef __STDIO_HAS_VSNPRINTF
16 #warning Skipping vasprintf since no vsnprintf!
19 int vasprintf(char **__restrict buf
, const char * __restrict format
,
22 #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
30 if ((f
= open_memstream(buf
, &size
)) != NULL
) {
31 rv
= vfprintf(f
, format
, arg
);
37 *buf
= realloc(*buf
, rv
+ 1);
45 #else /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
47 /* This implementation actually calls the printf machinery twice, but
48 * only does one malloc. This can be a problem though when custom printf
49 * specs or the %m specifier are involved because the results of the
50 * second call might be different from the first. */
55 rv
= vsnprintf(NULL
, 0, format
, arg2
);
61 if ((*buf
= malloc(++rv
)) != NULL
) {
62 if ((rv
= vsnprintf(*buf
, rv
, format
, arg
)) < 0) {
73 #endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
75 libc_hidden_def(vasprintf
)