diff options
Diffstat (limited to 'contrib/binutils/libiberty/vasprintf.c')
-rw-r--r-- | contrib/binutils/libiberty/vasprintf.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/contrib/binutils/libiberty/vasprintf.c b/contrib/binutils/libiberty/vasprintf.c index c34585d..d438225 100644 --- a/contrib/binutils/libiberty/vasprintf.c +++ b/contrib/binutils/libiberty/vasprintf.c @@ -28,7 +28,9 @@ Boston, MA 02111-1307, USA. */ #include <varargs.h> #endif #include <stdio.h> +#ifdef HAVE_STRING_H #include <string.h> +#endif #ifdef HAVE_STDLIB_H #include <stdlib.h> #else @@ -41,6 +43,21 @@ extern PTR malloc (); int global_total_width; #endif +/* + +@deftypefn Extension int vasprintf (char **@var{resptr}, const char *@var{format}, va_list @var{args}) + +Like @code{vsprintf}, but instead of passing a pointer to a buffer, +you pass a pointer to a pointer. This function will compute the size +of the buffer needed, allocate memory with @code{malloc}, and store a +pointer to the allocated memory in @code{*@var{resptr}}. The value +returned is the same as @code{vsprintf} would return. If memory could +not be allocated, zero is returned and @code{NULL} is stored in +@code{*@var{resptr}}. + +@end deftypefn + +*/ static int int_vasprintf PARAMS ((char **, const char *, va_list *)); @@ -142,29 +159,22 @@ vasprintf (result, format, args) } #ifdef TEST -static void checkit PARAMS ((const char *, ...)); - -static void -checkit VPARAMS ((const char* format, ...)) +static void ATTRIBUTE_PRINTF_1 +checkit VPARAMS ((const char *format, ...)) { - va_list args; char *result; -#ifndef ANSI_PROTOTYPES - const char *format; -#endif - - VA_START (args, format); - -#ifndef ANSI_PROTOTYPES - format = va_arg (args, const char *); -#endif - + VA_OPEN (args, format); + VA_FIXEDARG (args, const char *, format); vasprintf (&result, format, args); + VA_CLOSE (args); + if (strlen (result) < (size_t) global_total_width) printf ("PASS: "); else printf ("FAIL: "); printf ("%d %s\n", global_total_width, result); + + free (result); } extern int main PARAMS ((void)); |