1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
3*7c478bd9Sstevel@tonic-gate  *	All rights reserved.
4*7c478bd9Sstevel@tonic-gate  *
5*7c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
6*7c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
7*7c478bd9Sstevel@tonic-gate  * the sendmail distribution.
8*7c478bd9Sstevel@tonic-gate  */
9*7c478bd9Sstevel@tonic-gate 
10*7c478bd9Sstevel@tonic-gate #include <sm/gen.h>
11*7c478bd9Sstevel@tonic-gate SM_IDSTR(id, "@(#)$Id: t-scanf.c,v 1.5 2001/11/13 00:51:28 ca Exp $")
12*7c478bd9Sstevel@tonic-gate 
13*7c478bd9Sstevel@tonic-gate #include <sm/limits.h>
14*7c478bd9Sstevel@tonic-gate #include <sm/io.h>
15*7c478bd9Sstevel@tonic-gate #include <sm/string.h>
16*7c478bd9Sstevel@tonic-gate #include <sm/test.h>
17*7c478bd9Sstevel@tonic-gate #include <sm/types.h>
18*7c478bd9Sstevel@tonic-gate 
19*7c478bd9Sstevel@tonic-gate int
20*7c478bd9Sstevel@tonic-gate main(argc, argv)
21*7c478bd9Sstevel@tonic-gate 	int argc;
22*7c478bd9Sstevel@tonic-gate 	char **argv;
23*7c478bd9Sstevel@tonic-gate {
24*7c478bd9Sstevel@tonic-gate 	int i, d, h;
25*7c478bd9Sstevel@tonic-gate 	char buf[128];
26*7c478bd9Sstevel@tonic-gate 	char *r;
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate 	sm_test_begin(argc, argv, "test scanf point stuff");
29*7c478bd9Sstevel@tonic-gate #if !SM_CONF_BROKEN_SIZE_T
30*7c478bd9Sstevel@tonic-gate 	(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
31*7c478bd9Sstevel@tonic-gate "If tests for \"h == 2\" fail, check whether size_t is signed on your OS.\n\
32*7c478bd9Sstevel@tonic-gate If that is the case, add -DSM_CONF_BROKEN_SIZE_T to confENVDEF\n\
33*7c478bd9Sstevel@tonic-gate and start over. Otherwise contact sendmail.org.\n");
34*7c478bd9Sstevel@tonic-gate #endif /* !SM_CONF_BROKEN_SIZE_T */
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate 	d = 2;
37*7c478bd9Sstevel@tonic-gate 	sm_snprintf(buf, sizeof(buf), "%d", d);
38*7c478bd9Sstevel@tonic-gate 	r = "2";
39*7c478bd9Sstevel@tonic-gate 	if (!SM_TEST(strcmp(buf, r) == 0))
40*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
41*7c478bd9Sstevel@tonic-gate 				     "got %s instead\n", buf);
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate 	i = sm_io_sscanf(buf, "%d", &h);
44*7c478bd9Sstevel@tonic-gate 	SM_TEST(i == 1);
45*7c478bd9Sstevel@tonic-gate 	SM_TEST(h == 2);
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate 	d = 2;
48*7c478bd9Sstevel@tonic-gate 	sm_snprintf(buf, sizeof(buf), "%d\n", d);
49*7c478bd9Sstevel@tonic-gate 	r = "2\n";
50*7c478bd9Sstevel@tonic-gate 	if (!SM_TEST(strcmp(buf, r) == 0))
51*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
52*7c478bd9Sstevel@tonic-gate 				     "got %s instead\n", buf);
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate 	i = sm_io_sscanf(buf, "%d", &h);
55*7c478bd9Sstevel@tonic-gate 	SM_TEST(i == 1);
56*7c478bd9Sstevel@tonic-gate 	SM_TEST(h == 2);
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate 	return sm_test_end();
59*7c478bd9Sstevel@tonic-gate }
60