1217770Sadrian/*-
2217770Sadrian * Copyright (c) 2012 Dag-Erling Sm��rgrav
3217770Sadrian * All rights reserved.
4217770Sadrian *
5217770Sadrian * Redistribution and use in source and binary forms, with or without
6217770Sadrian * modification, are permitted provided that the following conditions
7217770Sadrian * are met:
8217770Sadrian * 1. Redistributions of source code must retain the above copyright
9217770Sadrian *    notice, this list of conditions and the following disclaimer.
10217770Sadrian * 2. Redistributions in binary form must reproduce the above copyright
11217770Sadrian *    notice, this list of conditions and the following disclaimer in the
12217770Sadrian *    documentation and/or other materials provided with the distribution.
13217770Sadrian * 3. The name of the author may not be used to endorse or promote
14217770Sadrian *    products derived from this software without specific prior written
15217770Sadrian *    permission.
16217770Sadrian *
17217770Sadrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18217770Sadrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19217770Sadrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20217770Sadrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21217770Sadrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22217770Sadrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23217770Sadrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24217770Sadrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25217770Sadrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26217770Sadrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27217770Sadrian * SUCH DAMAGE.
28217770Sadrian *
29217770Sadrian * $Id: openpam_asprintf.c 648 2013-03-05 17:54:27Z des $
30217770Sadrian */
31217770Sadrian
32217770Sadrian#ifdef HAVE_CONFIG_H
33217770Sadrian# include "config.h"
34217770Sadrian#endif
35217770Sadrian
36217770Sadrian#ifndef HAVE_ASPRINTF
37217770Sadrian
38217770Sadrian#include <stdarg.h>
39217770Sadrian#include <stdio.h>
40217770Sadrian
41217770Sadrian#include "openpam_asprintf.h"
42217770Sadrian#include "openpam_vasprintf.h"
43217770Sadrian
44217770Sadrian/* like sprintf(3), but allocates memory for the result. */
45217770Sadrianint
46217770Sadrianopenpam_asprintf(char **str, const char *fmt, ...)
47217770Sadrian{
48217770Sadrian        va_list ap;
49217770Sadrian        int ret;
50217770Sadrian
51217770Sadrian        va_start(ap, fmt);
52217770Sadrian        ret = vasprintf(str, fmt, ap);
53217770Sadrian        va_end(ap);
54217770Sadrian        return (ret);
55217770Sadrian}
56217770Sadrian
57217770Sadrian#endif
58217770Sadrian