sscanf.c revision 256281
137985Sphk/* 237985Sphk * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. 337985Sphk * All rights reserved. 437985Sphk * Copyright (c) 1990, 1993 537985Sphk * The Regents of the University of California. All rights reserved. 637985Sphk * 737985Sphk * This code is derived from software contributed to Berkeley by 837985Sphk * Chris Torek. 937985Sphk * 1037985Sphk * By using this file, you agree to the terms and conditions set 1137985Sphk * forth in the LICENSE file which can be found at the top level of 1237985Sphk * the sendmail distribution. 1337985Sphk */ 1437985Sphk 1537985Sphk#include <sm/gen.h> 1637985SphkSM_RCSID("@(#)$Id: sscanf.c,v 1.25 2002/02/01 02:28:00 ca Exp $") 1737985Sphk#include <string.h> 1837985Sphk#include <sm/varargs.h> 1937985Sphk#include <sm/io.h> 2037985Sphk#include "local.h" 2137985Sphk 2237985Sphk/* 2337985Sphk** SM_EOFREAD -- dummy read function for faked file below 2437985Sphk** 2537985Sphk** Parameters: 2637985Sphk** fp -- file pointer 2737985Sphk** buf -- location to place read data 2850476Speter** len -- number of bytes to read 2948794Snik** 30163983Strhodes** Returns: 3137985Sphk** 0 (zero) always 3279531Sru*/ 3337985Sphk 3437985Sphkstatic ssize_t 3537985Sphksm_eofread __P(( 3659501Sphantom SM_FILE_T *fp, 37124535Sru char *buf, 3837985Sphk size_t len)); 3984306Sru 4037985Sphk/* ARGSUSED0 */ 4138056Sbdestatic ssize_t 4237985Sphksm_eofread(fp, buf, len) 4337985Sphk SM_FILE_T *fp; 4437985Sphk char *buf; 4537985Sphk size_t len; 4637985Sphk{ 4737985Sphk return 0; 4837985Sphk} 4937985Sphk 5037985Sphk/* 5137985Sphk** SM_IO_SSCANF -- scan a string to find data units 5237985Sphk** 5337985Sphk** Parameters: 5437985Sphk** str -- strings containing data 5537985Sphk** fmt -- format directive for finding data units 5637985Sphk** ... -- memory locations to place format found data units 57110442Scharnier** 5837985Sphk** Returns: 59110442Scharnier** Failure: SM_IO_EOF 6037985Sphk** Success: number of data units found 6137985Sphk** 6237985Sphk** Side Effects: 6337985Sphk** Attempts to strlen() 'str'; if not a '\0' terminated string 6437985Sphk** then the call may SEGV/fail. 6537985Sphk** Faking the string 'str' as a file. 6637985Sphk*/ 6737985Sphk 6837985Sphkint 6977741Sdd#if SM_VA_STD 7077741Sddsm_io_sscanf(const char *str, char const *fmt, ...) 7137985Sphk#else /* SM_VA_STD */ 7237985Sphksm_io_sscanf(str, fmt, va_alist) 73163983Strhodes const char *str; 7438702Swosch char *fmt; 7537985Sphk va_dcl 7638702Swosch#endif /* SM_VA_STD */ 7737985Sphk{ 7838702Swosch int ret; 7937985Sphk SM_FILE_T fake; 80110442Scharnier SM_VA_LOCAL_DECL 8137985Sphk 82110442Scharnier fake.sm_magic = SmFileMagic; 8373093Sru fake.f_flags = SMRD; 84 fake.f_bf.smb_base = fake.f_p = (unsigned char *) str; 85 fake.f_bf.smb_size = fake.f_r = strlen(str); 86 fake.f_file = -1; 87 fake.f_read = sm_eofread; 88 fake.f_write = NULL; 89 fake.f_close = NULL; 90 fake.f_open = NULL; 91 fake.f_seek = NULL; 92 fake.f_setinfo = fake.f_getinfo = NULL; 93 fake.f_type = "sm_io_sscanf:fake"; 94 fake.f_flushfp = NULL; 95 fake.f_ub.smb_base = NULL; 96 fake.f_timeout = SM_TIME_FOREVER; 97 fake.f_timeoutstate = SM_TIME_BLOCK; 98 SM_VA_START(ap, fmt); 99 ret = sm_vfscanf(&fake, SM_TIME_FOREVER, fmt, ap); 100 SM_VA_END(ap); 101 return ret; 102} 103