OSDN Git Service

2003-09-22 Andrew Cagney <cagney@redhat.com>
[pf3gnuchains/gcc-fork.git] / libiberty / vasprintf.c
index 32faa84..7752604 100644 (file)
@@ -1,6 +1,6 @@
 /* Like vsprintf but provides a pointer to malloc'd storage, which must
    be freed by the caller.
-   Copyright (C) 1994 Free Software Foundation, Inc.
+   Copyright (C) 1994, 2003 Free Software Foundation, Inc.
 
 This file is part of the libiberty library.
 Libiberty is free software; you can redistribute it and/or
@@ -43,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, minus one is returned and @code{NULL} is stored in
+@code{*@var{resptr}}.
+
+@end deftypefn
+
+*/
 
 static int int_vasprintf PARAMS ((char **, const char *, va_list *));
 
@@ -123,11 +138,11 @@ int_vasprintf (result, format, args)
 #ifdef TEST
   global_total_width = total_width;
 #endif
-  *result = malloc (total_width);
+  *result = (char *) malloc (total_width);
   if (*result != NULL)
     return vsprintf (*result, format, *args);
   else
-    return 0;
+    return -1;
 }
 
 int