1255365Sdes/*-
2255365Sdes * Copyright (c) 2012 Dag-Erling Sm��rgrav
3255365Sdes * All rights reserved.
4255365Sdes *
5255365Sdes * Redistribution and use in source and binary forms, with or without
6255365Sdes * modification, are permitted provided that the following conditions
7255365Sdes * are met:
8255365Sdes * 1. Redistributions of source code must retain the above copyright
9255365Sdes *    notice, this list of conditions and the following disclaimer.
10255365Sdes * 2. Redistributions in binary form must reproduce the above copyright
11255365Sdes *    notice, this list of conditions and the following disclaimer in the
12255365Sdes *    documentation and/or other materials provided with the distribution.
13255365Sdes * 3. The name of the author may not be used to endorse or promote
14255365Sdes *    products derived from this software without specific prior written
15255365Sdes *    permission.
16255365Sdes *
17255365Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18255365Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19255365Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20255365Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21255365Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22255365Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23255365Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24255365Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25255365Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26255365Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27255365Sdes * SUCH DAMAGE.
28255365Sdes *
29255365Sdes * $Id: openpam_asprintf.c 648 2013-03-05 17:54:27Z des $
30255365Sdes */
31255365Sdes
32255365Sdes#ifdef HAVE_CONFIG_H
33255365Sdes# include "config.h"
34255365Sdes#endif
35255365Sdes
36255365Sdes#ifndef HAVE_ASPRINTF
37255365Sdes
38255365Sdes#include <stdarg.h>
39255365Sdes#include <stdio.h>
40255365Sdes
41255365Sdes#include "openpam_asprintf.h"
42255365Sdes#include "openpam_vasprintf.h"
43255365Sdes
44255365Sdes/* like sprintf(3), but allocates memory for the result. */
45255365Sdesint
46255365Sdesopenpam_asprintf(char **str, const char *fmt, ...)
47255365Sdes{
48255365Sdes        va_list ap;
49255365Sdes        int ret;
50255365Sdes
51255365Sdes        va_start(ap, fmt);
52255365Sdes        ret = vasprintf(str, fmt, ap);
53255365Sdes        va_end(ap);
54255365Sdes        return (ret);
55255365Sdes}
56255365Sdes
57255365Sdes#endif
58