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