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