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