1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright (c) 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-scanf.c,v 1.5 2001/11/13 00:51:28 ca Exp $") 14*7c478bd9Sstevel@tonic-gate 15*7c478bd9Sstevel@tonic-gate #include <sm/limits.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 #include <sm/types.h> 20*7c478bd9Sstevel@tonic-gate 21*7c478bd9Sstevel@tonic-gate int 22*7c478bd9Sstevel@tonic-gate main(argc, argv) 23*7c478bd9Sstevel@tonic-gate int argc; 24*7c478bd9Sstevel@tonic-gate char **argv; 25*7c478bd9Sstevel@tonic-gate { 26*7c478bd9Sstevel@tonic-gate int i, d, h; 27*7c478bd9Sstevel@tonic-gate char buf[128]; 28*7c478bd9Sstevel@tonic-gate char *r; 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate sm_test_begin(argc, argv, "test scanf point stuff"); 31*7c478bd9Sstevel@tonic-gate #if !SM_CONF_BROKEN_SIZE_T 32*7c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, 33*7c478bd9Sstevel@tonic-gate "If tests for \"h == 2\" fail, check whether size_t is signed on your OS.\n\ 34*7c478bd9Sstevel@tonic-gate If that is the case, add -DSM_CONF_BROKEN_SIZE_T to confENVDEF\n\ 35*7c478bd9Sstevel@tonic-gate and start over. Otherwise contact sendmail.org.\n"); 36*7c478bd9Sstevel@tonic-gate #endif /* !SM_CONF_BROKEN_SIZE_T */ 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate d = 2; 39*7c478bd9Sstevel@tonic-gate sm_snprintf(buf, sizeof(buf), "%d", d); 40*7c478bd9Sstevel@tonic-gate r = "2"; 41*7c478bd9Sstevel@tonic-gate if (!SM_TEST(strcmp(buf, r) == 0)) 42*7c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 43*7c478bd9Sstevel@tonic-gate "got %s instead\n", buf); 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate i = sm_io_sscanf(buf, "%d", &h); 46*7c478bd9Sstevel@tonic-gate SM_TEST(i == 1); 47*7c478bd9Sstevel@tonic-gate SM_TEST(h == 2); 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate d = 2; 50*7c478bd9Sstevel@tonic-gate sm_snprintf(buf, sizeof(buf), "%d\n", d); 51*7c478bd9Sstevel@tonic-gate r = "2\n"; 52*7c478bd9Sstevel@tonic-gate if (!SM_TEST(strcmp(buf, r) == 0)) 53*7c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 54*7c478bd9Sstevel@tonic-gate "got %s instead\n", buf); 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate i = sm_io_sscanf(buf, "%d", &h); 57*7c478bd9Sstevel@tonic-gate SM_TEST(i == 1); 58*7c478bd9Sstevel@tonic-gate SM_TEST(h == 2); 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate return sm_test_end(); 61*7c478bd9Sstevel@tonic-gate } 62