1*544c191cSchristos /* Id: test-vasprintf.c,v 1.5 2018/08/15 02:15:52 schwarze Exp */
29ff1f2acSchristos /*
39ff1f2acSchristos * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
49ff1f2acSchristos *
59ff1f2acSchristos * Permission to use, copy, modify, and distribute this software for any
69ff1f2acSchristos * purpose with or without fee is hereby granted, provided that the above
79ff1f2acSchristos * copyright notice and this permission notice appear in all copies.
89ff1f2acSchristos *
99ff1f2acSchristos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
109ff1f2acSchristos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
119ff1f2acSchristos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
129ff1f2acSchristos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
139ff1f2acSchristos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
149ff1f2acSchristos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
159ff1f2acSchristos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
169ff1f2acSchristos */
179ff1f2acSchristos
189ff1f2acSchristos #include <stdarg.h>
199ff1f2acSchristos #include <stdio.h>
209ff1f2acSchristos #include <string.h>
219ff1f2acSchristos
229508192eSchristos static int testfunc(char **, const char *, ...);
239508192eSchristos
249508192eSchristos
259508192eSchristos static int
testfunc(char ** ret,const char * format,...)269ff1f2acSchristos testfunc(char **ret, const char *format, ...)
279ff1f2acSchristos {
289ff1f2acSchristos va_list ap;
299ff1f2acSchristos int irc;
309ff1f2acSchristos
319ff1f2acSchristos va_start(ap, format);
329ff1f2acSchristos irc = vasprintf(ret, format, ap);
339ff1f2acSchristos va_end(ap);
349ff1f2acSchristos
359ff1f2acSchristos return irc;
369ff1f2acSchristos }
379ff1f2acSchristos
389ff1f2acSchristos int
main(void)399ff1f2acSchristos main(void)
409ff1f2acSchristos {
419ff1f2acSchristos char *ret;
429ff1f2acSchristos
439ff1f2acSchristos if (testfunc(&ret, "%s.", "Text") != 5)
449ff1f2acSchristos return 1;
459ff1f2acSchristos if (strcmp(ret, "Text."))
469ff1f2acSchristos return 2;
479ff1f2acSchristos return 0;
489ff1f2acSchristos }
49