]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/asprintf.c
pex-common.c: New file.
[thirdparty/gcc.git] / libiberty / asprintf.c
CommitLineData
438998a9
JM
1/* Like sprintf but provides a pointer to malloc'd storage, which must
2 be freed by the caller.
8d398258 3 Copyright (C) 1997, 2003 Free Software Foundation, Inc.
438998a9
JM
4 Contributed by Cygnus Solutions.
5
6This file is part of the libiberty library.
7Libiberty is free software; you can redistribute it and/or
8modify it under the terms of the GNU Library General Public
9License as published by the Free Software Foundation; either
10version 2 of the License, or (at your option) any later version.
11
12Libiberty is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Library General Public License for more details.
16
17You should have received a copy of the GNU Library General Public
18License along with libiberty; see the file COPYING.LIB. If
19not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22#include "ansidecl.h"
23#include "libiberty.h"
24
438998a9 25#include <stdarg.h>
438998a9 26
aac04c15
DD
27/*
28
5bed56d9 29@deftypefn Extension int asprintf (char **@var{resptr}, const char *@var{format}, ...)
aac04c15
DD
30
31Like @code{sprintf}, but instead of passing a pointer to a buffer, you
32pass a pointer to a pointer. This function will compute the size of
33the buffer needed, allocate memory with @code{malloc}, and store a
34pointer to the allocated memory in @code{*@var{resptr}}. The value
35returned is the same as @code{sprintf} would return. If memory could
8d398258 36not be allocated, minus one is returned and @code{NULL} is stored in
aac04c15
DD
37@code{*@var{resptr}}.
38
39@end deftypefn
40
41*/
42
438998a9 43int
9486db4f 44asprintf (char **buf, const char *fmt, ...)
438998a9
JM
45{
46 int status;
7a98d9b2
KG
47 VA_OPEN (ap, fmt);
48 VA_FIXEDARG (ap, char **, buf);
49 VA_FIXEDARG (ap, const char *, fmt);
438998a9 50 status = vasprintf (buf, fmt, ap);
7a98d9b2 51 VA_CLOSE (ap);
438998a9
JM
52 return status;
53}