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>
16 #ifdef __UCLIBC_MJN3_ONLY__
17 /* Do the memstream stuff inline to avoid fclose and the openlist? */
18 #warning CONSIDER: avoid open_memstream call?
21 #ifndef __STDIO_HAS_VSNPRINTF
22 #warning Skipping vasprintf since no vsnprintf!
25 int vasprintf(char **__restrict buf, const char * __restrict format,
28 #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
36 if ((f = open_memstream(buf, &size)) != NULL) {
37 rv = vfprintf(f, format, arg);
49 #else /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
51 /* This implementation actually calls the printf machinery twice, but
52 * only does one malloc. This can be a problem though when custom printf
53 * specs or the %m specifier are involved because the results of the
54 * second call might be different from the first. */
59 rv = vsnprintf(NULL, 0, format, arg2);
65 if ((*buf = malloc(++rv)) != NULL) {
66 if ((rv = vsnprintf(*buf, rv, format, arg)) < 0) {
77 #endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
79 libc_hidden_def(vasprintf)