138889Sjdp/* Like sprintf but provides a pointer to malloc'd storage, which must 238889Sjdp be freed by the caller. 3130561Sobrien Copyright (C) 1997, 2003 Free Software Foundation, Inc. 438889Sjdp Contributed by Cygnus Solutions. 538889Sjdp 638889SjdpThis file is part of the libiberty library. 738889SjdpLibiberty is free software; you can redistribute it and/or 838889Sjdpmodify it under the terms of the GNU Library General Public 938889SjdpLicense as published by the Free Software Foundation; either 1038889Sjdpversion 2 of the License, or (at your option) any later version. 1138889Sjdp 1238889SjdpLibiberty is distributed in the hope that it will be useful, 1338889Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of 1438889SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1538889SjdpLibrary General Public License for more details. 1638889Sjdp 1738889SjdpYou should have received a copy of the GNU Library General Public 1838889SjdpLicense along with libiberty; see the file COPYING.LIB. If 19218822Sdimnot, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 20218822SdimBoston, MA 02110-1301, USA. */ 2138889Sjdp 22218822Sdim#ifdef HAVE_CONFIG_H 23218822Sdim#include "config.h" 24218822Sdim#endif 2538889Sjdp#include "ansidecl.h" 2638889Sjdp#include "libiberty.h" 2738889Sjdp 2838889Sjdp#include <stdarg.h> 2938889Sjdp 3089857Sobrien/* 3189857Sobrien 3289857Sobrien@deftypefn Extension int asprintf (char **@var{resptr}, const char *@var{format}, ...) 3389857Sobrien 3489857SobrienLike @code{sprintf}, but instead of passing a pointer to a buffer, you 3589857Sobrienpass a pointer to a pointer. This function will compute the size of 3689857Sobrienthe buffer needed, allocate memory with @code{malloc}, and store a 3789857Sobrienpointer to the allocated memory in @code{*@var{resptr}}. The value 3889857Sobrienreturned is the same as @code{sprintf} would return. If memory could 39130561Sobriennot be allocated, minus one is returned and @code{NULL} is stored in 4089857Sobrien@code{*@var{resptr}}. 4189857Sobrien 4289857Sobrien@end deftypefn 4389857Sobrien 4489857Sobrien*/ 4589857Sobrien 4638889Sjdpint 47218822Sdimasprintf (char **buf, const char *fmt, ...) 4838889Sjdp{ 4938889Sjdp int status; 5089857Sobrien VA_OPEN (ap, fmt); 5189857Sobrien VA_FIXEDARG (ap, char **, buf); 5289857Sobrien VA_FIXEDARG (ap, const char *, fmt); 5338889Sjdp status = vasprintf (buf, fmt, ap); 5489857Sobrien VA_CLOSE (ap); 5538889Sjdp return status; 5638889Sjdp} 57