From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6983 invoked by alias); 7 Jan 2015 17:36:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 6960 invoked by uid 89); 7 Jan 2015 17:36:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.0 required=5.0 tests=AWL,BAYES_00,SPF_PASS,UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: service87.mimecast.com Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Jan 2015 17:36:21 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by service87.mimecast.com; Wed, 07 Jan 2015 17:36:19 +0000 Received: from e105689-lin.cambridge.arm.com ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 7 Jan 2015 17:36:19 +0000 Message-ID: <54AD6E92.7090803@arm.com> Date: Wed, 07 Jan 2015 17:36:00 -0000 From: Richard Earnshaw User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: binutils@sourceware.org, gdb-patches@sourceware.org Subject: Sync libiberty with gcc X-MC-Unique: 115010717361905001 Content-Type: multipart/mixed; boundary="------------010608070400070400020802" X-IsSubscribed: yes X-SW-Source: 2015-01/txt/msg00121.txt.bz2 This is a multi-part message in MIME format. --------------010608070400070400020802 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-length: 123 This patch just resyncs libiberty with the recent changes to GCC's version. No other changes. Committed as obvious. R.= --------------010608070400070400020802 Content-Type: text/plain; charset=UTF-8; name=libiberty.all.patches Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="libiberty.all.patches" Content-length: 22219 diff --git a/include/ChangeLog b/include/ChangeLog index 011c4ef..e0185fa 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -2,6 +2,12 @@ =20 Update year range in copyright notice of all files. =20 +2014-12-24 Uros Bizjak + Ben Elliston + Manuel Lopez-Ibanez + + * libiberty.h (xasprintf): Declare. + 2014-12-23 Alan Modra =20 * bfdlink.h (struct bfd_link_hash_entry): Comment non_ir_ref. Add @@ -15,6 +21,12 @@ * gcc-c-interface.h: New file. * gcc-interface.h: New file. =20 +2014-12-11 Uros Bizjak + Ben Elliston + Manuel Lopez-Ibanez + + * libiberty.h (xvasprintf): Declare. + 2014-12-06 Eric Botcazou =20 * dis-asm.h (print_insn_visium): Declare. diff --git a/include/libiberty.h b/include/libiberty.h index 9ef1b11..eec8009 100644 --- a/include/libiberty.h +++ b/include/libiberty.h @@ -623,6 +623,11 @@ extern int pwait (int, int *, int); extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; #endif =20 +/* Like asprintf but allocates memory without fail. This works like + xmalloc. */ + +extern char *xasprintf (const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_PRIN= TF_1; + #if !HAVE_DECL_VASPRINTF /* Like vsprintf but provides a pointer to malloc'd storage, which must be freed by the caller. */ @@ -630,6 +635,11 @@ extern int asprintf (char **, const char *, ...) ATTRI= BUTE_PRINTF_2; extern int vasprintf (char **, const char *, va_list) ATTRIBUTE_PRINTF(2,0= ); #endif =20 +/* Like vasprintf but allocates memory without fail. This works like + xmalloc. */ + +extern char *xvasprintf (const char *, va_list) ATTRIBUTE_MALLOC ATTRIBUTE= _PRINTF(1,0); + #if defined(HAVE_DECL_SNPRINTF) && !HAVE_DECL_SNPRINTF /* Like sprintf but prints at most N characters. */ extern int snprintf (char *, size_t, const char *, ...) ATTRIBUTE_PRINTF_3; diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 82a49ea..ac23875 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,34 @@ +2014-12-24 Uros Bizjak + Ben Elliston + Manuel Lopez-Ibanez + + * xasprintf.c: New file. + * Makefile.in (CFILES): Add xasprintf.c. + (REQUIRED_OFILES): Add xasprintf.$(objext). + (xasprintf.$(objext)): New target. + * functions.texi: Regenerate. + +2014-12-11 Uros Bizjak + Ben Elliston + Manuel Lopez-Ibanez + + * xvasprintf.c: New file. + * vprintf-support.h: Likewise. + * vprintf-support.c: Likewise. + * Makefile.in (CFILES): Add vprintf-support.c, xvasprintf.c. + (REQUIRED_OFILES): Add vprintf-support.$(objext), xvasprintf.$(objext). + (vprintf-support.$(objext), xvasprintf.$(objext)): New targets. + (vasprintf.$(objext)): Depend on $(srcdir)/vprintf-support.h. + * functions.texi: Regenerate. + * vasprintf.c (int_vasprintf): Use libiberty_vprintf_buffer_size. + +2014-11-22 John David Anglin + + PR other/63694 + * configure.ac: Check for strtol, strtoul, strtoll and strtoull + declarations. + * configure: Regenerated. + 2014-11-12 Kirill Yukhin =20 * testsuite/test-strtol.c (run_tests): Cast strtol return to diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in index 1b0d8ae..f06cc69 100644 --- a/libiberty/Makefile.in +++ b/libiberty/Makefile.in @@ -155,10 +155,11 @@ CFILES =3D alloca.c argv.c asprintf.c atexit.c \ strtoll.c strtoul.c strtoull.c strndup.c strnlen.c \ strverscmp.c timeval-utils.c tmpnam.c \ unlink-if-ordinary.c \ - vasprintf.c vfork.c vfprintf.c vprintf.c vsnprintf.c vsprintf.c \ + vasprintf.c vfork.c vfprintf.c vprintf.c vprintf-support.c \ + vsnprintf.c vsprintf.c \ waitpid.c \ - xatexit.c xexit.c xmalloc.c xmemdup.c xstrdup.c xstrerror.c \ - xstrndup.c + xasprintf.c xatexit.c xexit.c xmalloc.c xmemdup.c xstrdup.c \ + xstrerror.c xstrndup.c xvasprintf.c =20 # These are always included in the library. The first four are listed # first and by compile time to optimize parallel builds. @@ -180,7 +181,7 @@ REQUIRED_OFILES =3D \ ./obstack.$(objext) \ ./partition.$(objext) ./pexecute.$(objext) ./physmem.$(objext) \ ./pex-common.$(objext) ./pex-one.$(objext) \ - ./@pexecute@.$(objext) \ + ./@pexecute@.$(objext) ./vprintf-support.$(objext) \ ./safe-ctype.$(objext) \ ./simple-object.$(objext) ./simple-object-coff.$(objext) \ ./simple-object-elf.$(objext) ./simple-object-mach-o.$(objext) \ @@ -189,9 +190,10 @@ REQUIRED_OFILES =3D \ ./splay-tree.$(objext) ./stack-limit.$(objext) \ ./strerror.$(objext) ./strsignal.$(objext) \ ./timeval-utils.$(objext) ./unlink-if-ordinary.$(objext) \ - ./xatexit.$(objext) ./xexit.$(objext) ./xmalloc.$(objext) \ - ./xmemdup.$(objext) ./xstrdup.$(objext) ./xstrerror.$(objext) \ - ./xstrndup.$(objext) + ./xasprintf.$(objext) ./xatexit.$(objext) ./xexit.$(objext) \ + ./xmalloc.$(objext) ./xmemdup.$(objext) ./xstrdup.$(objext) \ + ./xstrerror.$(objext) ./xstrndup.$(objext) \ + ./xvasprintf.$(objext) =20 # These are all the objects that configure may add to the library via # $funcs or EXTRA_OFILES. This list exists here only for "make @@ -1543,7 +1545,7 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir $(COMPILE.c) $(srcdir)/unlink-if-ordinary.c $(OUTPUT_OPTION) =20 ./vasprintf.$(objext): $(srcdir)/vasprintf.c config.h $(INCDIR)/ansidecl.h= \ - $(INCDIR)/libiberty.h + $(INCDIR)/libiberty.h $(srcdir)/vprintf-support.h if [ x"$(PICFLAG)" !=3D x ]; then \ $(COMPILE.c) $(PICFLAG) $(srcdir)/vasprintf.c -o pic/$@; \ else true; fi @@ -1570,6 +1572,16 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir else true; fi $(COMPILE.c) $(srcdir)/vfprintf.c $(OUTPUT_OPTION) =20 +./vprintf-support.$(objext): $(srcdir)/vprintf-support.c config.h \ + $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h + if [ x"$(PICFLAG)" !=3D x ]; then \ + $(COMPILE.c) $(PICFLAG) $(srcdir)/vprintf-support.c -o pic/$@; \ + else true; fi + if [ x"$(NOASANFLAG)" !=3D x ]; then \ + $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/vprintf-support.c -o no= asan/$@; \ + else true; fi + $(COMPILE.c) $(srcdir)/vprintf-support.c $(OUTPUT_OPTION) + ./vprintf.$(objext): $(srcdir)/vprintf.c $(INCDIR)/ansidecl.h if [ x"$(PICFLAG)" !=3D x ]; then \ $(COMPILE.c) $(PICFLAG) $(srcdir)/vprintf.c -o pic/$@; \ @@ -1607,6 +1619,16 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir else true; fi $(COMPILE.c) $(srcdir)/waitpid.c $(OUTPUT_OPTION) =20 +./xasprintf.$(objext): $(srcdir)/xasprintf.c config.h $(INCDIR)/ansidecl.h= \ + $(INCDIR)/libiberty.h + if [ x"$(PICFLAG)" !=3D x ]; then \ + $(COMPILE.c) $(PICFLAG) $(srcdir)/xasprintf.c -o pic/$@; \ + else true; fi + if [ x"$(NOASANFLAG)" !=3D x ]; then \ + $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/xasprintf.c -o noasan/$= @; \ + else true; fi + $(COMPILE.c) $(srcdir)/xasprintf.c $(OUTPUT_OPTION) + ./xatexit.$(objext): $(srcdir)/xatexit.c config.h $(INCDIR)/ansidecl.h \ $(INCDIR)/libiberty.h if [ x"$(PICFLAG)" !=3D x ]; then \ @@ -1677,3 +1699,12 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir else true; fi $(COMPILE.c) $(srcdir)/xstrndup.c $(OUTPUT_OPTION) =20 +./xvasprintf.$(objext): $(srcdir)/xvasprintf.c config.h $(INCDIR)/ansidecl= .h \ + $(INCDIR)/libiberty.h $(srcdir)/vprintf-support.h + if [ x"$(PICFLAG)" !=3D x ]; then \ + $(COMPILE.c) $(PICFLAG) $(srcdir)/xvasprintf.c -o pic/$@; \ + else true; fi + if [ x"$(NOASANFLAG)" !=3D x ]; then \ + $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/xvasprintf.c -o noasan/= $@; \ + else true; fi + $(COMPILE.c) $(srcdir)/xvasprintf.c $(OUTPUT_OPTION) diff --git a/libiberty/configure b/libiberty/configure index 4a5e40a..2007ecc 100755 --- a/libiberty/configure +++ b/libiberty/configure @@ -6700,6 +6700,47 @@ cat >>confdefs.h <<_ACEOF #define HAVE_DECL_SBRK $ac_have_decl _ACEOF =20 + ac_fn_c_check_decl "$LINENO" "strtol" "ac_cv_have_decl_strtol" "$ac_incl= udes_default" +if test "x$ac_cv_have_decl_strtol" =3D x""yes; then : + ac_have_decl=3D1 +else + ac_have_decl=3D0 +fi + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_STRTOL $ac_have_decl +_ACEOF +ac_fn_c_check_decl "$LINENO" "strtoul" "ac_cv_have_decl_strtoul" "$ac_incl= udes_default" +if test "x$ac_cv_have_decl_strtoul" =3D x""yes; then : + ac_have_decl=3D1 +else + ac_have_decl=3D0 +fi + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_STRTOUL $ac_have_decl +_ACEOF +ac_fn_c_check_decl "$LINENO" "strtoll" "ac_cv_have_decl_strtoll" "$ac_incl= udes_default" +if test "x$ac_cv_have_decl_strtoll" =3D x""yes; then : + ac_have_decl=3D1 +else + ac_have_decl=3D0 +fi + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_STRTOLL $ac_have_decl +_ACEOF +ac_fn_c_check_decl "$LINENO" "strtoull" "ac_cv_have_decl_strtoull" "$ac_in= cludes_default" +if test "x$ac_cv_have_decl_strtoull" =3D x""yes; then : + ac_have_decl=3D1 +else + ac_have_decl=3D0 +fi + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_STRTOULL $ac_have_decl +_ACEOF + ac_fn_c_check_decl "$LINENO" "strverscmp" "ac_cv_have_decl_strverscmp" "= $ac_includes_default" if test "x$ac_cv_have_decl_strverscmp" =3D x""yes; then : ac_have_decl=3D1 diff --git a/libiberty/configure.ac b/libiberty/configure.ac index 90adaea..922aa86 100644 --- a/libiberty/configure.ac +++ b/libiberty/configure.ac @@ -678,6 +678,7 @@ if test -z "${setobjs}"; then AC_CHECK_FUNCS($checkfuncs) AC_CHECK_DECLS([basename(char *), ffs, asprintf, vasprintf, snprintf, vs= nprintf]) AC_CHECK_DECLS([calloc, getenv, getopt, malloc, realloc, sbrk]) + AC_CHECK_DECLS([strtol, strtoul, strtoll, strtoull]) AC_CHECK_DECLS([strverscmp]) libiberty_NEED_DECLARATION(canonicalize_file_name) fi diff --git a/libiberty/functions.texi b/libiberty/functions.texi index 9ed9ff0..b5f4e80 100644 --- a/libiberty/functions.texi +++ b/libiberty/functions.texi @@ -1923,6 +1923,15 @@ if an error occurred while writing to FILE. =20 @end deftypefn =20 +@c xasprintf.c:31 +@deftypefn Replacement char* xasprintf (const char *@var{format}, ...) + +Print to allocated string without fail. If @code{xasprintf} fails, +this will print a message to @code{stderr} (using the name set by +@code{xmalloc_set_program_name}, if any) and then call @code{xexit}. + +@end deftypefn + @c xatexit.c:11 @deftypefun int xatexit (void (*@var{fn}) (void)) =20 @@ -2022,4 +2031,13 @@ always NUL terminated. =20 @end deftypefn =20 +@c xvasprintf.c:38 +@deftypefn Replacement char* xvasprintf (const char *@var{format}, va_list= @var{args}) + +Print to allocated string without fail. If @code{xvasprintf} fails, +this will print a message to @code{stderr} (using the name set by +@code{xmalloc_set_program_name}, if any) and then call @code{xexit}. + +@end deftypefn + =20 diff --git a/libiberty/vasprintf.c b/libiberty/vasprintf.c index 4925060..6ffe2dd 100644 --- a/libiberty/vasprintf.c +++ b/libiberty/vasprintf.c @@ -14,9 +14,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See= the GNU Library General Public License for more details. =20 You should have received a copy of the GNU Library General Public -License along with libiberty; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fif= th Floor, -Boston, MA 02110-1301, USA. */ +License along with libiberty; see the file COPYING.LIB. If not, write +to the Free Software Foundation, Inc., 51 Franklin Street - Fifth +Floor, Boston, MA 02110-1301, USA. */ =20 #ifdef HAVE_CONFIG_H #include "config.h" @@ -33,10 +33,10 @@ Boston, MA 02110-1301, USA. */ #ifdef HAVE_STDLIB_H #include #else -extern unsigned long strtoul (); extern PTR malloc (); #endif #include "libiberty.h" +#include "vprintf-support.h" =20 #ifdef TEST int global_total_width; @@ -64,81 +64,7 @@ static int int_vasprintf (char **, const char *, va_list= ); static int int_vasprintf (char **result, const char *format, va_list args) { - const char *p =3D format; - /* Add one to make sure that it is never zero, which might cause malloc - to return NULL. */ - int total_width =3D strlen (format) + 1; - va_list ap; - -#ifdef va_copy - va_copy (ap, args); -#else - memcpy ((PTR) &ap, (PTR) &args, sizeof (va_list)); -#endif - - while (*p !=3D '\0') - { - if (*p++ =3D=3D '%') - { - while (strchr ("-+ #0", *p)) - ++p; - if (*p =3D=3D '*') - { - ++p; - total_width +=3D abs (va_arg (ap, int)); - } - else - total_width +=3D strtoul (p, (char **) &p, 10); - if (*p =3D=3D '.') - { - ++p; - if (*p =3D=3D '*') - { - ++p; - total_width +=3D abs (va_arg (ap, int)); - } - else - total_width +=3D strtoul (p, (char **) &p, 10); - } - while (strchr ("hlL", *p)) - ++p; - /* Should be big enough for any format specifier except %s and floats. = */ - total_width +=3D 30; - switch (*p) - { - case 'd': - case 'i': - case 'o': - case 'u': - case 'x': - case 'X': - case 'c': - (void) va_arg (ap, int); - break; - case 'f': - case 'e': - case 'E': - case 'g': - case 'G': - (void) va_arg (ap, double); - /* Since an ieee double can have an exponent of 307, we'll - make the buffer wide enough to cover the gross case. */ - total_width +=3D 307; - break; - case 's': - total_width +=3D strlen (va_arg (ap, char *)); - break; - case 'p': - case 'n': - (void) va_arg (ap, char *); - break; - } - p++; - } - } -#ifdef va_copy - va_end (ap); -#endif + int total_width =3D libiberty_vprintf_buffer_size (format, args); #ifdef TEST global_total_width =3D total_width; #endif diff --git a/libiberty/vprintf-support.c b/libiberty/vprintf-support.c new file mode 100644 index 0000000..171232f --- /dev/null +++ b/libiberty/vprintf-support.c @@ -0,0 +1,119 @@ +/* Estimate the length of the string generated by a vprintf-like + function. Used by vasprintf and xvasprintf. + Copyright (C) 1994, 2003, 2011, 2013, 2014 Free Software Foundation, In= c. + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If not, write +to the Free Software Foundation, Inc., 51 Franklin Street - Fifth +Floor, Boston, MA 02110-1301, USA. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#if !defined (va_copy) && defined (__va_copy) +# define va_copy(d,s) __va_copy((d),(s)) +#endif +#include +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#else +extern unsigned long strtoul (); +#endif +#include "libiberty.h" + +int +libiberty_vprintf_buffer_size (const char *format, va_list args) +{ + const char *p =3D format; + /* Add one to make sure that it is never zero, which might cause malloc + to return NULL. */ + int total_width =3D strlen (format) + 1; + va_list ap; + +#ifdef va_copy + va_copy (ap, args); +#else + memcpy ((PTR) &ap, (PTR) &args, sizeof (va_list)); +#endif + + while (*p !=3D '\0') + { + if (*p++ =3D=3D '%') + { + while (strchr ("-+ #0", *p)) + ++p; + if (*p =3D=3D '*') + { + ++p; + total_width +=3D abs (va_arg (ap, int)); + } + else + total_width +=3D strtoul (p, (char **) &p, 10); + if (*p =3D=3D '.') + { + ++p; + if (*p =3D=3D '*') + { + ++p; + total_width +=3D abs (va_arg (ap, int)); + } + else + total_width +=3D strtoul (p, (char **) &p, 10); + } + while (strchr ("hlL", *p)) + ++p; + /* Should be big enough for any format specifier except %s and floats. = */ + total_width +=3D 30; + switch (*p) + { + case 'd': + case 'i': + case 'o': + case 'u': + case 'x': + case 'X': + case 'c': + (void) va_arg (ap, int); + break; + case 'f': + case 'e': + case 'E': + case 'g': + case 'G': + (void) va_arg (ap, double); + /* Since an ieee double can have an exponent of 307, we'll + make the buffer wide enough to cover the gross case. */ + total_width +=3D 307; + break; + case 's': + total_width +=3D strlen (va_arg (ap, char *)); + break; + case 'p': + case 'n': + (void) va_arg (ap, char *); + break; + } + p++; + } + } +#ifdef va_copy + va_end (ap); +#endif + return total_width; +} diff --git a/libiberty/vprintf-support.h b/libiberty/vprintf-support.h new file mode 100644 index 0000000..9d2680a --- /dev/null +++ b/libiberty/vprintf-support.h @@ -0,0 +1,22 @@ +/* Estimate the length of the string generated by a vprintf-like + function. Use by vasprintf and xvasprintf. + Copyright (C) 1994, 2003, 2011, 2013, 2014 Free Software Foundation, In= c. + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If not, write +to the Free Software Foundation, Inc., 51 Franklin Street - Fifth +Floor, Boston, MA 02110-1301, USA. */ + + +extern int libiberty_vprintf_buffer_size (const char *, va_list); diff --git a/libiberty/xasprintf.c b/libiberty/xasprintf.c new file mode 100644 index 0000000..4f72bb2 --- /dev/null +++ b/libiberty/xasprintf.c @@ -0,0 +1,50 @@ +/* Implement the xasprintf function. + Copyright (C) 2014 Free Software Foundation, Inc. + Contributed by Manuel Lopez-Ibanez. + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If not, write +to the Free Software Foundation, Inc., 51 Franklin Street - Fifth +Floor, Boston, MA 02110-1301, USA. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "ansidecl.h" +#include "libiberty.h" + +#include + +/* + +@deftypefn Replacement char* xasprintf (const char *@var{format}, ...) + +Print to allocated string without fail. If @code{xasprintf} fails, +this will print a message to @code{stderr} (using the name set by +@code{xmalloc_set_program_name}, if any) and then call @code{xexit}. + +@end deftypefn + +*/ + +char * +xasprintf (const char *fmt, ...) +{ + char *buf; + va_list ap; + va_start (ap, fmt); + buf =3D xvasprintf (fmt, ap); + va_end (ap); + return buf; +} diff --git a/libiberty/xvasprintf.c b/libiberty/xvasprintf.c new file mode 100644 index 0000000..9e9a9d3 --- /dev/null +++ b/libiberty/xvasprintf.c @@ -0,0 +1,61 @@ +/* Implement the xvasprintf function. + Copyright (C) 2014 Free Software Foundation, Inc. + Contributed by Manuel Lopez-Ibanez. + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If not, write +to the Free Software Foundation, Inc., 51 Franklin Street - Fifth +Floor, Boston, MA 02110-1301, USA. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#if !defined (va_copy) && defined (__va_copy) +# define va_copy(d,s) __va_copy((d),(s)) +#endif +#include +#ifdef HAVE_STRING_H +#include +#endif +#include "libiberty.h" +#include "vprintf-support.h" + +/* + +@deftypefn Replacement char* xvasprintf (const char *@var{format}, va_list= @var{args}) + +Print to allocated string without fail. If @code{xvasprintf} fails, +this will print a message to @code{stderr} (using the name set by +@code{xmalloc_set_program_name}, if any) and then call @code{xexit}. + +@end deftypefn + +*/ + +char * +xvasprintf (const char *format, +#if defined (_BSD_VA_LIST_) && defined (__FreeBSD__) + _BSD_VA_LIST_ args) +#else + va_list args) +#endif +{ + char *result; + int total_width =3D libiberty_vprintf_buffer_size (format, args); + result =3D (char *) xmalloc (total_width); + vsprintf (result, format, args); + return result; +}= --------------010608070400070400020802--