1 1.1 christos /* Implement the xasprintf function. 2 1.1.1.7 christos Copyright (C) 2014-2026 Free Software Foundation, Inc. 3 1.1 christos Contributed by Manuel Lopez-Ibanez. 4 1.1 christos 5 1.1 christos This file is part of the libiberty library. 6 1.1 christos Libiberty is free software; you can redistribute it and/or 7 1.1 christos modify it under the terms of the GNU Library General Public 8 1.1 christos License as published by the Free Software Foundation; either 9 1.1 christos version 2 of the License, or (at your option) any later version. 10 1.1 christos 11 1.1 christos Libiberty is distributed in the hope that it will be useful, 12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 1.1 christos Library General Public License for more details. 15 1.1 christos 16 1.1 christos You should have received a copy of the GNU Library General Public 17 1.1 christos License along with libiberty; see the file COPYING.LIB. If not, write 18 1.1 christos to the Free Software Foundation, Inc., 51 Franklin Street - Fifth 19 1.1 christos Floor, Boston, MA 02110-1301, USA. */ 20 1.1 christos 21 1.1 christos #ifdef HAVE_CONFIG_H 22 1.1 christos #include "config.h" 23 1.1 christos #endif 24 1.1 christos #include "ansidecl.h" 25 1.1 christos #include "libiberty.h" 26 1.1 christos 27 1.1 christos #include <stdarg.h> 28 1.1 christos 29 1.1 christos /* 30 1.1 christos 31 1.1 christos @deftypefn Replacement char* xasprintf (const char *@var{format}, ...) 32 1.1 christos 33 1.1 christos Print to allocated string without fail. If @code{xasprintf} fails, 34 1.1 christos this will print a message to @code{stderr} (using the name set by 35 1.1 christos @code{xmalloc_set_program_name}, if any) and then call @code{xexit}. 36 1.1 christos 37 1.1 christos @end deftypefn 38 1.1 christos 39 1.1 christos */ 40 1.1 christos 41 1.1 christos char * 42 1.1 christos xasprintf (const char *fmt, ...) 43 1.1 christos { 44 1.1 christos char *buf; 45 1.1 christos va_list ap; 46 1.1 christos va_start (ap, fmt); 47 1.1 christos buf = xvasprintf (fmt, ap); 48 1.1 christos va_end (ap); 49 1.1 christos return buf; 50 1.1 christos } 51