116dce513Schristos /* Implement the xasprintf function.
2*e992f068Schristos Copyright (C) 2014-2022 Free Software Foundation, Inc.
316dce513Schristos Contributed by Manuel Lopez-Ibanez.
416dce513Schristos
516dce513Schristos This file is part of the libiberty library.
616dce513Schristos Libiberty is free software; you can redistribute it and/or
716dce513Schristos modify it under the terms of the GNU Library General Public
816dce513Schristos License as published by the Free Software Foundation; either
916dce513Schristos version 2 of the License, or (at your option) any later version.
1016dce513Schristos
1116dce513Schristos Libiberty is distributed in the hope that it will be useful,
1216dce513Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
1316dce513Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1416dce513Schristos Library General Public License for more details.
1516dce513Schristos
1616dce513Schristos You should have received a copy of the GNU Library General Public
1716dce513Schristos License along with libiberty; see the file COPYING.LIB. If not, write
1816dce513Schristos to the Free Software Foundation, Inc., 51 Franklin Street - Fifth
1916dce513Schristos Floor, Boston, MA 02110-1301, USA. */
2016dce513Schristos
2116dce513Schristos #ifdef HAVE_CONFIG_H
2216dce513Schristos #include "config.h"
2316dce513Schristos #endif
2416dce513Schristos #include "ansidecl.h"
2516dce513Schristos #include "libiberty.h"
2616dce513Schristos
2716dce513Schristos #include <stdarg.h>
2816dce513Schristos
2916dce513Schristos /*
3016dce513Schristos
3116dce513Schristos @deftypefn Replacement char* xasprintf (const char *@var{format}, ...)
3216dce513Schristos
3316dce513Schristos Print to allocated string without fail. If @code{xasprintf} fails,
3416dce513Schristos this will print a message to @code{stderr} (using the name set by
3516dce513Schristos @code{xmalloc_set_program_name}, if any) and then call @code{xexit}.
3616dce513Schristos
3716dce513Schristos @end deftypefn
3816dce513Schristos
3916dce513Schristos */
4016dce513Schristos
4116dce513Schristos char *
xasprintf(const char * fmt,...)4216dce513Schristos xasprintf (const char *fmt, ...)
4316dce513Schristos {
4416dce513Schristos char *buf;
4516dce513Schristos va_list ap;
4616dce513Schristos va_start (ap, fmt);
4716dce513Schristos buf = xvasprintf (fmt, ap);
4816dce513Schristos va_end (ap);
4916dce513Schristos return buf;
5016dce513Schristos }
51