Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/libiberty/vasprintf.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    2929#endif
    3030#include <stdio.h>
     31#ifdef HAVE_STRING_H
    3132#include <string.h>
     33#endif
    3234#ifdef HAVE_STDLIB_H
    3335#include <stdlib.h>
     
    4244#endif
    4345
     46/*
     47
     48@deftypefn Extension int vasprintf (char **@var{resptr}, const char *@var{format}, va_list @var{args})
     49
     50Like @code{vsprintf}, but instead of passing a pointer to a buffer,
     51you pass a pointer to a pointer.  This function will compute the size
     52of the buffer needed, allocate memory with @code{malloc}, and store a
     53pointer to the allocated memory in @code{*@var{resptr}}.  The value
     54returned is the same as @code{vsprintf} would return.  If memory could
     55not be allocated, zero is returned and @code{NULL} is stored in
     56@code{*@var{resptr}}.
     57
     58@end deftypefn
     59
     60*/
    4461
    4562static int int_vasprintf PARAMS ((char **, const char *, va_list *));
     
    122139  global_total_width = total_width;
    123140#endif
    124   *result = malloc (total_width);
     141  *result = (char *) malloc (total_width);
    125142  if (*result != NULL)
    126143    return vsprintf (*result, format, *args);
     
    143160
    144161#ifdef TEST
    145 static void checkit PARAMS ((const char *, ...));
     162static void ATTRIBUTE_PRINTF_1
     163checkit VPARAMS ((const char *format, ...))
     164{
     165  char *result;
     166  VA_OPEN (args, format);
     167  VA_FIXEDARG (args, const char *, format);
     168  vasprintf (&result, format, args);
     169  VA_CLOSE (args);
    146170
    147 static void
    148 checkit VPARAMS ((const char* format, ...))
    149 {
    150   va_list args;
    151   char *result;
    152 #ifndef ANSI_PROTOTYPES
    153   const char *format;
    154 #endif
    155 
    156   VA_START (args, format);
    157 
    158 #ifndef ANSI_PROTOTYPES
    159   format = va_arg (args, const char *);
    160 #endif
    161 
    162   vasprintf (&result, format, args);
    163171  if (strlen (result) < (size_t) global_total_width)
    164172    printf ("PASS: ");
     
    166174    printf ("FAIL: ");
    167175  printf ("%d %s\n", global_total_width, result);
     176
     177  free (result);
    168178}
    169179
Note: See TracChangeset for help on using the changeset viewer.