190792Sgshapiro/* 290792Sgshapiro * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. 390792Sgshapiro * All rights reserved. 490792Sgshapiro * Copyright (c) 1990, 1993 590792Sgshapiro * The Regents of the University of California. All rights reserved. 690792Sgshapiro * 790792Sgshapiro * This code is derived from software contributed to Berkeley by 890792Sgshapiro * Chris Torek. 990792Sgshapiro * 1090792Sgshapiro * By using this file, you agree to the terms and conditions set 1190792Sgshapiro * forth in the LICENSE file which can be found at the top level of 1290792Sgshapiro * the sendmail distribution. 1390792Sgshapiro */ 1490792Sgshapiro 1590792Sgshapiro#include <sm/gen.h> 1698121SgshapiroSM_RCSID("@(#)$Id: sscanf.c,v 1.25 2002/02/01 02:28:00 ca Exp $") 1790792Sgshapiro#include <string.h> 1890792Sgshapiro#include <sm/varargs.h> 1990792Sgshapiro#include <sm/io.h> 2090792Sgshapiro#include "local.h" 2190792Sgshapiro 2290792Sgshapiro/* 2390792Sgshapiro** SM_EOFREAD -- dummy read function for faked file below 2490792Sgshapiro** 2590792Sgshapiro** Parameters: 2690792Sgshapiro** fp -- file pointer 2790792Sgshapiro** buf -- location to place read data 2890792Sgshapiro** len -- number of bytes to read 2990792Sgshapiro** 3090792Sgshapiro** Returns: 3190792Sgshapiro** 0 (zero) always 3290792Sgshapiro*/ 3390792Sgshapiro 3490792Sgshapirostatic ssize_t 3590792Sgshapirosm_eofread __P(( 3690792Sgshapiro SM_FILE_T *fp, 3790792Sgshapiro char *buf, 3890792Sgshapiro size_t len)); 3990792Sgshapiro 4090792Sgshapiro/* ARGSUSED0 */ 4190792Sgshapirostatic ssize_t 4290792Sgshapirosm_eofread(fp, buf, len) 4390792Sgshapiro SM_FILE_T *fp; 4490792Sgshapiro char *buf; 4590792Sgshapiro size_t len; 4690792Sgshapiro{ 4790792Sgshapiro return 0; 4890792Sgshapiro} 4990792Sgshapiro 5090792Sgshapiro/* 5190792Sgshapiro** SM_IO_SSCANF -- scan a string to find data units 5290792Sgshapiro** 5390792Sgshapiro** Parameters: 5490792Sgshapiro** str -- strings containing data 5590792Sgshapiro** fmt -- format directive for finding data units 5690792Sgshapiro** ... -- memory locations to place format found data units 5790792Sgshapiro** 5890792Sgshapiro** Returns: 5990792Sgshapiro** Failure: SM_IO_EOF 6090792Sgshapiro** Success: number of data units found 6190792Sgshapiro** 6290792Sgshapiro** Side Effects: 6390792Sgshapiro** Attempts to strlen() 'str'; if not a '\0' terminated string 6490792Sgshapiro** then the call may SEGV/fail. 6590792Sgshapiro** Faking the string 'str' as a file. 6690792Sgshapiro*/ 6790792Sgshapiro 6890792Sgshapiroint 6990792Sgshapiro#if SM_VA_STD 7090792Sgshapirosm_io_sscanf(const char *str, char const *fmt, ...) 7190792Sgshapiro#else /* SM_VA_STD */ 7290792Sgshapirosm_io_sscanf(str, fmt, va_alist) 7390792Sgshapiro const char *str; 7490792Sgshapiro char *fmt; 7590792Sgshapiro va_dcl 7690792Sgshapiro#endif /* SM_VA_STD */ 7790792Sgshapiro{ 7890792Sgshapiro int ret; 7990792Sgshapiro SM_FILE_T fake; 8090792Sgshapiro SM_VA_LOCAL_DECL 8190792Sgshapiro 8290792Sgshapiro fake.sm_magic = SmFileMagic; 8390792Sgshapiro fake.f_flags = SMRD; 8490792Sgshapiro fake.f_bf.smb_base = fake.f_p = (unsigned char *) str; 8590792Sgshapiro fake.f_bf.smb_size = fake.f_r = strlen(str); 8690792Sgshapiro fake.f_file = -1; 8790792Sgshapiro fake.f_read = sm_eofread; 8890792Sgshapiro fake.f_write = NULL; 8990792Sgshapiro fake.f_close = NULL; 9090792Sgshapiro fake.f_open = NULL; 9190792Sgshapiro fake.f_seek = NULL; 9290792Sgshapiro fake.f_setinfo = fake.f_getinfo = NULL; 9390792Sgshapiro fake.f_type = "sm_io_sscanf:fake"; 9490792Sgshapiro fake.f_flushfp = NULL; 9590792Sgshapiro fake.f_ub.smb_base = NULL; 9690792Sgshapiro fake.f_timeout = SM_TIME_FOREVER; 9790792Sgshapiro fake.f_timeoutstate = SM_TIME_BLOCK; 9890792Sgshapiro SM_VA_START(ap, fmt); 9990792Sgshapiro ret = sm_vfscanf(&fake, SM_TIME_FOREVER, fmt, ap); 10090792Sgshapiro SM_VA_END(ap); 10190792Sgshapiro return ret; 10290792Sgshapiro} 103