1*ce77a8d6SDag-Erling Smørgrav /*-
2*ce77a8d6SDag-Erling Smørgrav * Copyright (c) 2012 Dag-Erling Smørgrav
3*ce77a8d6SDag-Erling Smørgrav * All rights reserved.
4*ce77a8d6SDag-Erling Smørgrav *
5*ce77a8d6SDag-Erling Smørgrav * Redistribution and use in source and binary forms, with or without
6*ce77a8d6SDag-Erling Smørgrav * modification, are permitted provided that the following conditions
7*ce77a8d6SDag-Erling Smørgrav * are met:
8*ce77a8d6SDag-Erling Smørgrav * 1. Redistributions of source code must retain the above copyright
9*ce77a8d6SDag-Erling Smørgrav * notice, this list of conditions and the following disclaimer.
10*ce77a8d6SDag-Erling Smørgrav * 2. Redistributions in binary form must reproduce the above copyright
11*ce77a8d6SDag-Erling Smørgrav * notice, this list of conditions and the following disclaimer in the
12*ce77a8d6SDag-Erling Smørgrav * documentation and/or other materials provided with the distribution.
13*ce77a8d6SDag-Erling Smørgrav * 3. The name of the author may not be used to endorse or promote
14*ce77a8d6SDag-Erling Smørgrav * products derived from this software without specific prior written
15*ce77a8d6SDag-Erling Smørgrav * permission.
16*ce77a8d6SDag-Erling Smørgrav *
17*ce77a8d6SDag-Erling Smørgrav * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18*ce77a8d6SDag-Erling Smørgrav * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*ce77a8d6SDag-Erling Smørgrav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*ce77a8d6SDag-Erling Smørgrav * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21*ce77a8d6SDag-Erling Smørgrav * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*ce77a8d6SDag-Erling Smørgrav * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*ce77a8d6SDag-Erling Smørgrav * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*ce77a8d6SDag-Erling Smørgrav * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*ce77a8d6SDag-Erling Smørgrav * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*ce77a8d6SDag-Erling Smørgrav * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*ce77a8d6SDag-Erling Smørgrav * SUCH DAMAGE.
28*ce77a8d6SDag-Erling Smørgrav */
29*ce77a8d6SDag-Erling Smørgrav
30*ce77a8d6SDag-Erling Smørgrav #ifdef HAVE_CONFIG_H
31*ce77a8d6SDag-Erling Smørgrav # include "config.h"
32*ce77a8d6SDag-Erling Smørgrav #endif
33*ce77a8d6SDag-Erling Smørgrav
34*ce77a8d6SDag-Erling Smørgrav #ifndef HAVE_ASPRINTF
35*ce77a8d6SDag-Erling Smørgrav
36*ce77a8d6SDag-Erling Smørgrav #include <stdarg.h>
37*ce77a8d6SDag-Erling Smørgrav #include <stdio.h>
38*ce77a8d6SDag-Erling Smørgrav
39*ce77a8d6SDag-Erling Smørgrav #include "openpam_asprintf.h"
40*ce77a8d6SDag-Erling Smørgrav #include "openpam_vasprintf.h"
41*ce77a8d6SDag-Erling Smørgrav
42*ce77a8d6SDag-Erling Smørgrav /* like sprintf(3), but allocates memory for the result. */
43*ce77a8d6SDag-Erling Smørgrav int
openpam_asprintf(char ** str,const char * fmt,...)44*ce77a8d6SDag-Erling Smørgrav openpam_asprintf(char **str, const char *fmt, ...)
45*ce77a8d6SDag-Erling Smørgrav {
46*ce77a8d6SDag-Erling Smørgrav va_list ap;
47*ce77a8d6SDag-Erling Smørgrav int ret;
48*ce77a8d6SDag-Erling Smørgrav
49*ce77a8d6SDag-Erling Smørgrav va_start(ap, fmt);
50*ce77a8d6SDag-Erling Smørgrav ret = vasprintf(str, fmt, ap);
51*ce77a8d6SDag-Erling Smørgrav va_end(ap);
52*ce77a8d6SDag-Erling Smørgrav return (ret);
53*ce77a8d6SDag-Erling Smørgrav }
54*ce77a8d6SDag-Erling Smørgrav
55*ce77a8d6SDag-Erling Smørgrav #endif
56