source: vendor/gcc/current/libiberty/asprintf.c

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.8 KB
Line 
1/* Like sprintf but provides a pointer to malloc'd storage, which must
2 be freed by the caller.
3 Copyright (C) 1997 Free Software Foundation, Inc.
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
25#ifdef ANSI_PROTOTYPES
26#include <stdarg.h>
27#else
28#include <varargs.h>
29#endif
30
31/*
32
33@deftypefn Extension int asprintf (char **@var{resptr}, const char *@var{format}, ...)
34
35Like @code{sprintf}, but instead of passing a pointer to a buffer, you
36pass a pointer to a pointer. This function will compute the size of
37the buffer needed, allocate memory with @code{malloc}, and store a
38pointer to the allocated memory in @code{*@var{resptr}}. The value
39returned is the same as @code{sprintf} would return. If memory could
40not be allocated, zero is returned and @code{NULL} is stored in
41@code{*@var{resptr}}.
42
43@end deftypefn
44
45*/
46
47int
48asprintf VPARAMS ((char **buf, const char *fmt, ...))
49{
50 int status;
51 VA_OPEN (ap, fmt);
52 VA_FIXEDARG (ap, char **, buf);
53 VA_FIXEDARG (ap, const char *, fmt);
54 status = vasprintf (buf, fmt, ap);
55 VA_CLOSE (ap);
56 return status;
57}
Note: See TracBrowser for help on using the repository browser.