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