19573673dSchristos /* Implement the xasprintf function.
2*cb63e24eSchristos Copyright (C) 2014-2024 Free Software Foundation, Inc.
39573673dSchristos Contributed by Manuel Lopez-Ibanez.
49573673dSchristos
59573673dSchristos This file is part of the libiberty library.
69573673dSchristos Libiberty is free software; you can redistribute it and/or
79573673dSchristos modify it under the terms of the GNU Library General Public
89573673dSchristos License as published by the Free Software Foundation; either
99573673dSchristos version 2 of the License, or (at your option) any later version.
109573673dSchristos
119573673dSchristos Libiberty is distributed in the hope that it will be useful,
129573673dSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of
139573673dSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
149573673dSchristos Library General Public License for more details.
159573673dSchristos
169573673dSchristos You should have received a copy of the GNU Library General Public
179573673dSchristos License along with libiberty; see the file COPYING.LIB. If not, write
189573673dSchristos to the Free Software Foundation, Inc., 51 Franklin Street - Fifth
199573673dSchristos Floor, Boston, MA 02110-1301, USA. */
209573673dSchristos
219573673dSchristos #ifdef HAVE_CONFIG_H
229573673dSchristos #include "config.h"
239573673dSchristos #endif
249573673dSchristos #include "ansidecl.h"
259573673dSchristos #include "libiberty.h"
269573673dSchristos
279573673dSchristos #include <stdarg.h>
289573673dSchristos
299573673dSchristos /*
309573673dSchristos
319573673dSchristos @deftypefn Replacement char* xasprintf (const char *@var{format}, ...)
329573673dSchristos
339573673dSchristos Print to allocated string without fail. If @code{xasprintf} fails,
349573673dSchristos this will print a message to @code{stderr} (using the name set by
359573673dSchristos @code{xmalloc_set_program_name}, if any) and then call @code{xexit}.
369573673dSchristos
379573673dSchristos @end deftypefn
389573673dSchristos
399573673dSchristos */
409573673dSchristos
419573673dSchristos char *
xasprintf(const char * fmt,...)429573673dSchristos xasprintf (const char *fmt, ...)
439573673dSchristos {
449573673dSchristos char *buf;
459573673dSchristos va_list ap;
469573673dSchristos va_start (ap, fmt);
479573673dSchristos buf = xvasprintf (fmt, ap);
489573673dSchristos va_end (ap);
499573673dSchristos return buf;
509573673dSchristos }
51