190792Sgshapiro/* 2261194Sgshapiro * Copyright (c) 2001 Proofpoint, Inc. and its suppliers. 390792Sgshapiro * All rights reserved. 490792Sgshapiro * 590792Sgshapiro * By using this file, you agree to the terms and conditions set 690792Sgshapiro * forth in the LICENSE file which can be found at the top level of 790792Sgshapiro * the sendmail distribution. 890792Sgshapiro */ 990792Sgshapiro 1090792Sgshapiro#include <sm/gen.h> 11266527SgshapiroSM_IDSTR(id, "@(#)$Id: t-scanf.c,v 1.6 2013-11-22 20:51:43 ca Exp $") 1290792Sgshapiro 1390792Sgshapiro#include <sm/limits.h> 1490792Sgshapiro#include <sm/io.h> 1590792Sgshapiro#include <sm/string.h> 1690792Sgshapiro#include <sm/test.h> 1790792Sgshapiro#include <sm/types.h> 1890792Sgshapiro 1990792Sgshapiroint 2090792Sgshapiromain(argc, argv) 2190792Sgshapiro int argc; 2290792Sgshapiro char **argv; 2390792Sgshapiro{ 2490792Sgshapiro int i, d, h; 2590792Sgshapiro char buf[128]; 2690792Sgshapiro char *r; 2790792Sgshapiro 2890792Sgshapiro sm_test_begin(argc, argv, "test scanf point stuff"); 2990792Sgshapiro#if !SM_CONF_BROKEN_SIZE_T 3090792Sgshapiro (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, 3190792Sgshapiro"If tests for \"h == 2\" fail, check whether size_t is signed on your OS.\n\ 3290792SgshapiroIf that is the case, add -DSM_CONF_BROKEN_SIZE_T to confENVDEF\n\ 3390792Sgshapiroand start over. Otherwise contact sendmail.org.\n"); 34363466Sgshapiro#endif 3590792Sgshapiro 3690792Sgshapiro d = 2; 3790792Sgshapiro sm_snprintf(buf, sizeof(buf), "%d", d); 3890792Sgshapiro r = "2"; 3990792Sgshapiro if (!SM_TEST(strcmp(buf, r) == 0)) 4090792Sgshapiro (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 4190792Sgshapiro "got %s instead\n", buf); 4290792Sgshapiro 4390792Sgshapiro i = sm_io_sscanf(buf, "%d", &h); 4490792Sgshapiro SM_TEST(i == 1); 4590792Sgshapiro SM_TEST(h == 2); 4690792Sgshapiro 4790792Sgshapiro d = 2; 4890792Sgshapiro sm_snprintf(buf, sizeof(buf), "%d\n", d); 4990792Sgshapiro r = "2\n"; 5090792Sgshapiro if (!SM_TEST(strcmp(buf, r) == 0)) 5190792Sgshapiro (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 5290792Sgshapiro "got %s instead\n", buf); 5390792Sgshapiro 5490792Sgshapiro i = sm_io_sscanf(buf, "%d", &h); 5590792Sgshapiro SM_TEST(i == 1); 5690792Sgshapiro SM_TEST(h == 2); 5790792Sgshapiro 5890792Sgshapiro return sm_test_end(); 5990792Sgshapiro} 60