]> git.cameronkatri.com Git - mandoc.git/blob - test-vasprintf.c
Decouple the token code for "no request or macro" from the individual
[mandoc.git] / test-vasprintf.c
1 /* $Id: test-vasprintf.c,v 1.2 2015/03/20 15:32:02 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 #if defined(__linux__) || defined(__MINT__)
19 #define _GNU_SOURCE /* vasprintf() */
20 #endif
21
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <string.h>
25
26 int
27 testfunc(char **ret, const char *format, ...)
28 {
29 va_list ap;
30 int irc;
31
32 va_start(ap, format);
33 irc = vasprintf(ret, format, ap);
34 va_end(ap);
35
36 return(irc);
37 }
38
39 int
40 main(void)
41 {
42 char *ret;
43
44 if (testfunc(&ret, "%s.", "Text") != 5)
45 return(1);
46 if (strcmp(ret, "Text."))
47 return(2);
48 return(0);
49 }