xref: /titanic_41/usr/src/cmd/sendmail/libsm/t-string.c (revision 6185db853e024a486ff8837e6784dd290d866112)
1 /*
2  * Copyright (c) 2000-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-string.c,v 1.9 2001/01/26 03:28:43 ca Exp $")
14 
15 #include <sm/exc.h>
16 #include <sm/io.h>
17 #include <sm/string.h>
18 #include <sm/test.h>
19 
20 int
21 main(argc, argv)
22 	int argc;
23 	char **argv;
24 {
25 	char *s;
26 	char buf[4096];
27 	char foo[4];
28 	char *r;
29 	int n;
30 
31 	sm_test_begin(argc, argv, "test string utilities");
32 
33 	s = sm_stringf_x("%.3s%03d", "foobar", 42);
34 	r = "foo042";
35 	SM_TEST(strcmp(s, r) == 0);
36 
37 	s = sm_stringf_x("+%*x+", 2000, 0xCAFE);
38 	sm_snprintf(buf, 4096, "+%*x+", 2000, 0xCAFE);
39 	SM_TEST(strcmp(s, buf) == 0);
40 
41 	foo[3] = 1;
42 	n = sm_snprintf(foo, sizeof(foo), "foobar%dbaz", 42);
43 	SM_TEST(n == 11);
44 	r = "foo";
45 	SM_TEST(strcmp(foo, r) == 0);
46 
47 	return sm_test_end();
48 }
49