1 /* Like sprintf but provides a pointer to malloc'd storage, which must
2 be freed by the caller.
3 Copyright (C) 1997, 2003 Free Software Foundation, Inc.
4 Contributed by Cygnus Solutions.
6 This file is part of the libiberty library.
7 Libiberty is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 Libiberty is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with libiberty; see the file COPYING.LIB. If
19 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "libiberty.h"
29 @deftypefn Extension int asprintf (char **@var{resptr}, const char *@var{format}, ...)
31 Like @code{sprintf}, but instead of passing a pointer to a buffer, you
32 pass a pointer to a pointer. This function will compute the size of
33 the buffer needed, allocate memory with @code{malloc}, and store a
34 pointer to the allocated memory in @code{*@var{resptr}}. The value
35 returned is the same as @code{sprintf} would return. If memory could
36 not be allocated, minus one is returned and @code{NULL} is stored in
44 asprintf (char **buf
, const char *fmt
, ...)
48 VA_FIXEDARG (ap
, char **, buf
);
49 VA_FIXEDARG (ap
, const char *, fmt
);
50 status
= vasprintf (buf
, fmt
, ap
);