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