xref: /freebsd/contrib/sendmail/test/t_snprintf.c (revision 13058a916175518dfbac6ce66b9b8e22ecf43155)
106f25ae9SGregory Neil Shapiro #include <stdio.h>
206f25ae9SGregory Neil Shapiro #include <sysexits.h>
306f25ae9SGregory Neil Shapiro 
406f25ae9SGregory Neil Shapiro #define TEST_STRING	"1234567890"
506f25ae9SGregory Neil Shapiro 
606f25ae9SGregory Neil Shapiro int
706f25ae9SGregory Neil Shapiro main(argc, argv)
806f25ae9SGregory Neil Shapiro 	int argc;
906f25ae9SGregory Neil Shapiro 	char **argv;
1006f25ae9SGregory Neil Shapiro {
1106f25ae9SGregory Neil Shapiro 	int r;
1206f25ae9SGregory Neil Shapiro 	char buf[5];
1306f25ae9SGregory Neil Shapiro 
1406f25ae9SGregory Neil Shapiro 	r = snprintf(buf, sizeof buf, "%s", TEST_STRING);
1506f25ae9SGregory Neil Shapiro 
1613058a91SGregory Neil Shapiro 	if (buf[sizeof buf - 1] != '\0' ||
1713058a91SGregory Neil Shapiro 	    r != strlen(TEST_STRING))
1806f25ae9SGregory Neil Shapiro 	{
1906f25ae9SGregory Neil Shapiro 		fprintf(stderr, "Add the following to devtools/Site/site.config.m4:\n\n");
2006f25ae9SGregory Neil Shapiro 		fprintf(stderr, "APPENDDEF(`confENVDEF', `-DSNPRINTF_IS_BROKEN=1')\n\n");
2106f25ae9SGregory Neil Shapiro 		exit(EX_OSERR);
2206f25ae9SGregory Neil Shapiro 	}
2306f25ae9SGregory Neil Shapiro 	fprintf(stderr, "snprintf() appears to work properly\n");
2406f25ae9SGregory Neil Shapiro 	exit(EX_OK);
2506f25ae9SGregory Neil Shapiro }
26