/[gnats]/gnats/libiberty/vasprintf.c
ViewVC logotype

Diff of /gnats/libiberty/vasprintf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by jsm, Tue Oct 26 07:10:16 1999 UTC revision 1.3 by pdm, Mon Dec 10 23:03:26 2001 UTC
# Line 18  License along with libiberty; see the fi Line 18  License along with libiberty; see the fi
18  not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,  not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  Boston, MA 02111-1307, USA.  */  Boston, MA 02111-1307, USA.  */
20    
21  #ifdef __STDC__  #ifdef HAVE_CONFIG_H
22    #include "config.h"
23    #endif
24    #include <ansidecl.h>
25    #ifdef ANSI_PROTOTYPES
26  #include <stdarg.h>  #include <stdarg.h>
27  #else  #else
28  #include <varargs.h>  #include <varargs.h>
29  #endif  #endif
30  #include <stdio.h>  #include <stdio.h>
31  #include <string.h>  #include <string.h>
32  #include <ansidecl.h>  #ifdef HAVE_STDLIB_H
33    #include <stdlib.h>
34    #else
35    extern unsigned long strtoul ();
36    extern PTR malloc ();
37    #endif
38    #include "libiberty.h"
39    
40  #ifdef TEST  #ifdef TEST
41  int global_total_width;  int global_total_width;
42  #endif  #endif
43    
44  unsigned long strtoul ();  
45  char *malloc ();  static int int_vasprintf PARAMS ((char **, const char *, va_list *));
46    
47  static int  static int
48  int_vasprintf (result, format, args)  int_vasprintf (result, format, args)
# Line 60  int_vasprintf (result, format, args) Line 70  int_vasprintf (result, format, args)
70                total_width += abs (va_arg (ap, int));                total_width += abs (va_arg (ap, int));
71              }              }
72            else            else
73              total_width += strtoul (p, &p, 10);              total_width += strtoul (p, (char **) &p, 10);
74            if (*p == '.')            if (*p == '.')
75              {              {
76                ++p;                ++p;
# Line 70  int_vasprintf (result, format, args) Line 80  int_vasprintf (result, format, args)
80                    total_width += abs (va_arg (ap, int));                    total_width += abs (va_arg (ap, int));
81                  }                  }
82                else                else
83                total_width += strtoul (p, &p, 10);                total_width += strtoul (p, (char **) &p, 10);
84              }              }
85            while (strchr ("hlL", *p))            while (strchr ("hlL", *p))
86              ++p;              ++p;
# Line 105  int_vasprintf (result, format, args) Line 115  int_vasprintf (result, format, args)
115                (void) va_arg (ap, char *);                (void) va_arg (ap, char *);
116                break;                break;
117              }              }
118              p++;
119          }          }
120      }      }
121  #ifdef TEST  #ifdef TEST
# Line 131  vasprintf (result, format, args) Line 142  vasprintf (result, format, args)
142  }  }
143    
144  #ifdef TEST  #ifdef TEST
145  void  static void checkit PARAMS ((const char *, ...));
146  checkit  
147  #ifdef __STDC__  static void
148       (const char* format, ...)  checkit VPARAMS ((const char* format, ...))
 #else  
      (va_alist)  
      va_dcl  
 #endif  
149  {  {
150    va_list args;    va_list args;
151    char *result;    char *result;
152    #ifndef ANSI_PROTOTYPES
153      const char *format;
154    #endif
155    
156  #ifdef __STDC__    VA_START (args, format);
157    va_start (args, format);  
158  #else  #ifndef ANSI_PROTOTYPES
159    char *format;    format = va_arg (args, const char *);
   va_start (args);  
   format = va_arg (args, char *);  
160  #endif  #endif
161    
162    vasprintf (&result, format, args);    vasprintf (&result, format, args);
163    if (strlen (result) < global_total_width)    if (strlen (result) < (size_t) global_total_width)
164      printf ("PASS: ");      printf ("PASS: ");
165    else    else
166      printf ("FAIL: ");      printf ("FAIL: ");
167    printf ("%d %s\n", global_total_width, result);    printf ("%d %s\n", global_total_width, result);
168  }  }
169    
170    extern int main PARAMS ((void));
171    
172  int  int
173  main ()  main ()
174  {  {
# Line 168  main () Line 179  main ()
179    checkit ("%s", "jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\    checkit ("%s", "jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\
180  777777777777777777333333333333366666666666622222222222777777777777733333");  777777777777777777333333333333366666666666622222222222777777777777733333");
181    checkit ("%f%s%d%s", 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx");    checkit ("%f%s%d%s", 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx");
182    
183      return 0;
184  }  }
185  #endif /* TEST */  #endif /* TEST */

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26