Changeset 609 for branches/GNU/src/binutils/libiberty/vasprintf.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/libiberty/vasprintf.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 29 29 #endif 30 30 #include <stdio.h> 31 #ifdef HAVE_STRING_H 31 32 #include <string.h> 33 #endif 32 34 #ifdef HAVE_STDLIB_H 33 35 #include <stdlib.h> … … 42 44 #endif 43 45 46 /* 47 48 @deftypefn Extension int vasprintf (char **@var{resptr}, const char *@var{format}, va_list @var{args}) 49 50 Like @code{vsprintf}, but instead of passing a pointer to a buffer, 51 you pass a pointer to a pointer. This function will compute the size 52 of the buffer needed, allocate memory with @code{malloc}, and store a 53 pointer to the allocated memory in @code{*@var{resptr}}. The value 54 returned is the same as @code{vsprintf} would return. If memory could 55 not be allocated, zero is returned and @code{NULL} is stored in 56 @code{*@var{resptr}}. 57 58 @end deftypefn 59 60 */ 44 61 45 62 static int int_vasprintf PARAMS ((char **, const char *, va_list *)); … … 122 139 global_total_width = total_width; 123 140 #endif 124 *result = malloc (total_width);141 *result = (char *) malloc (total_width); 125 142 if (*result != NULL) 126 143 return vsprintf (*result, format, *args); … … 143 160 144 161 #ifdef TEST 145 static void checkit PARAMS ((const char *, ...)); 162 static void ATTRIBUTE_PRINTF_1 163 checkit 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); 146 170 147 static void148 checkit VPARAMS ((const char* format, ...))149 {150 va_list args;151 char *result;152 #ifndef ANSI_PROTOTYPES153 const char *format;154 #endif155 156 VA_START (args, format);157 158 #ifndef ANSI_PROTOTYPES159 format = va_arg (args, const char *);160 #endif161 162 vasprintf (&result, format, args);163 171 if (strlen (result) < (size_t) global_total_width) 164 172 printf ("PASS: "); … … 166 174 printf ("FAIL: "); 167 175 printf ("%d %s\n", global_total_width, result); 176 177 free (result); 168 178 } 169 179 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.