xref: /freebsd/contrib/mandoc/test-vasprintf.c (revision a7623790fb345e6dc986dfd31df0ace115e6f2e4)
1 /*	$Id: test-vasprintf.c,v 1.5 2018/08/15 02:15:52 schwarze Exp $	*/
2 /*
3  * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <stdarg.h>
19 #include <stdio.h>
20 #include <string.h>
21 
22 static int	 testfunc(char **, const char *, ...);
23 
24 
25 static int
26 testfunc(char **ret, const char *format, ...)
27 {
28 	va_list	 ap;
29 	int	 irc;
30 
31 	va_start(ap, format);
32 	irc = vasprintf(ret, format, ap);
33 	va_end(ap);
34 
35 	return irc;
36 }
37 
38 int
39 main(void)
40 {
41 	char	*ret;
42 
43 	if (testfunc(&ret, "%s.", "Text") != 5)
44 		return 1;
45 	if (strcmp(ret, "Text."))
46 		return 2;
47 	return 0;
48 }
49