xref: /freebsd/contrib/sendmail/libsm/sscanf.c (revision 6cec9cad762b6476313fb1f8e931a1647822db6b)
140266059SGregory Neil Shapiro /*
25dd76dd0SGregory Neil Shapiro  * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
340266059SGregory Neil Shapiro  *      All rights reserved.
440266059SGregory Neil Shapiro  * Copyright (c) 1990, 1993
540266059SGregory Neil Shapiro  *	The Regents of the University of California.  All rights reserved.
640266059SGregory Neil Shapiro  *
740266059SGregory Neil Shapiro  * This code is derived from software contributed to Berkeley by
840266059SGregory Neil Shapiro  * Chris Torek.
940266059SGregory Neil Shapiro  *
1040266059SGregory Neil Shapiro  * By using this file, you agree to the terms and conditions set
1140266059SGregory Neil Shapiro  * forth in the LICENSE file which can be found at the top level of
1240266059SGregory Neil Shapiro  * the sendmail distribution.
1340266059SGregory Neil Shapiro  */
1440266059SGregory Neil Shapiro 
1540266059SGregory Neil Shapiro #include <sm/gen.h>
16*4313cc83SGregory Neil Shapiro SM_RCSID("@(#)$Id: sscanf.c,v 1.26 2013-11-22 20:51:43 ca Exp $")
1740266059SGregory Neil Shapiro #include <string.h>
1840266059SGregory Neil Shapiro #include <sm/varargs.h>
1940266059SGregory Neil Shapiro #include <sm/io.h>
2040266059SGregory Neil Shapiro #include "local.h"
2140266059SGregory Neil Shapiro 
2240266059SGregory Neil Shapiro /*
2340266059SGregory Neil Shapiro **  SM_EOFREAD -- dummy read function for faked file below
2440266059SGregory Neil Shapiro **
2540266059SGregory Neil Shapiro **	Parameters:
2640266059SGregory Neil Shapiro **		fp -- file pointer
2740266059SGregory Neil Shapiro **		buf -- location to place read data
2840266059SGregory Neil Shapiro **		len -- number of bytes to read
2940266059SGregory Neil Shapiro **
3040266059SGregory Neil Shapiro **	Returns:
3140266059SGregory Neil Shapiro **		0 (zero) always
3240266059SGregory Neil Shapiro */
3340266059SGregory Neil Shapiro 
3440266059SGregory Neil Shapiro static ssize_t
3540266059SGregory Neil Shapiro sm_eofread __P((
3640266059SGregory Neil Shapiro 	SM_FILE_T *fp,
3740266059SGregory Neil Shapiro 	char *buf,
3840266059SGregory Neil Shapiro 	size_t len));
3940266059SGregory Neil Shapiro 
4040266059SGregory Neil Shapiro /* ARGSUSED0 */
4140266059SGregory Neil Shapiro static ssize_t
sm_eofread(fp,buf,len)4240266059SGregory Neil Shapiro sm_eofread(fp, buf, len)
4340266059SGregory Neil Shapiro 	SM_FILE_T *fp;
4440266059SGregory Neil Shapiro 	char *buf;
4540266059SGregory Neil Shapiro 	size_t len;
4640266059SGregory Neil Shapiro {
4740266059SGregory Neil Shapiro 	return 0;
4840266059SGregory Neil Shapiro }
4940266059SGregory Neil Shapiro 
5040266059SGregory Neil Shapiro /*
5140266059SGregory Neil Shapiro **  SM_IO_SSCANF -- scan a string to find data units
5240266059SGregory Neil Shapiro **
5340266059SGregory Neil Shapiro **	Parameters:
5440266059SGregory Neil Shapiro **		str -- strings containing data
5540266059SGregory Neil Shapiro **		fmt -- format directive for finding data units
5640266059SGregory Neil Shapiro **		... -- memory locations to place format found data units
5740266059SGregory Neil Shapiro **
5840266059SGregory Neil Shapiro **	Returns:
5940266059SGregory Neil Shapiro **		Failure: SM_IO_EOF
6040266059SGregory Neil Shapiro **		Success: number of data units found
6140266059SGregory Neil Shapiro **
6240266059SGregory Neil Shapiro **	Side Effects:
6340266059SGregory Neil Shapiro **		Attempts to strlen() 'str'; if not a '\0' terminated string
6440266059SGregory Neil Shapiro **			then the call may SEGV/fail.
6540266059SGregory Neil Shapiro **		Faking the string 'str' as a file.
6640266059SGregory Neil Shapiro */
6740266059SGregory Neil Shapiro 
6840266059SGregory Neil Shapiro int
6940266059SGregory Neil Shapiro #if SM_VA_STD
sm_io_sscanf(const char * str,char const * fmt,...)7040266059SGregory Neil Shapiro sm_io_sscanf(const char *str, char const *fmt, ...)
7140266059SGregory Neil Shapiro #else /* SM_VA_STD */
7240266059SGregory Neil Shapiro sm_io_sscanf(str, fmt, va_alist)
7340266059SGregory Neil Shapiro 	const char *str;
7440266059SGregory Neil Shapiro 	char *fmt;
7540266059SGregory Neil Shapiro 	va_dcl
7640266059SGregory Neil Shapiro #endif /* SM_VA_STD */
7740266059SGregory Neil Shapiro {
7840266059SGregory Neil Shapiro 	int ret;
7940266059SGregory Neil Shapiro 	SM_FILE_T fake;
8040266059SGregory Neil Shapiro 	SM_VA_LOCAL_DECL
8140266059SGregory Neil Shapiro 
8240266059SGregory Neil Shapiro 	fake.sm_magic = SmFileMagic;
8340266059SGregory Neil Shapiro 	fake.f_flags = SMRD;
8440266059SGregory Neil Shapiro 	fake.f_bf.smb_base = fake.f_p = (unsigned char *) str;
8540266059SGregory Neil Shapiro 	fake.f_bf.smb_size = fake.f_r = strlen(str);
8640266059SGregory Neil Shapiro 	fake.f_file = -1;
8740266059SGregory Neil Shapiro 	fake.f_read = sm_eofread;
8840266059SGregory Neil Shapiro 	fake.f_write = NULL;
8940266059SGregory Neil Shapiro 	fake.f_close = NULL;
9040266059SGregory Neil Shapiro 	fake.f_open = NULL;
9140266059SGregory Neil Shapiro 	fake.f_seek = NULL;
9240266059SGregory Neil Shapiro 	fake.f_setinfo = fake.f_getinfo = NULL;
9340266059SGregory Neil Shapiro 	fake.f_type = "sm_io_sscanf:fake";
9440266059SGregory Neil Shapiro 	fake.f_flushfp = NULL;
9540266059SGregory Neil Shapiro 	fake.f_ub.smb_base = NULL;
9640266059SGregory Neil Shapiro 	fake.f_timeout = SM_TIME_FOREVER;
9740266059SGregory Neil Shapiro 	fake.f_timeoutstate = SM_TIME_BLOCK;
9840266059SGregory Neil Shapiro 	SM_VA_START(ap, fmt);
9940266059SGregory Neil Shapiro 	ret = sm_vfscanf(&fake, SM_TIME_FOREVER, fmt, ap);
10040266059SGregory Neil Shapiro 	SM_VA_END(ap);
10140266059SGregory Neil Shapiro 	return ret;
10240266059SGregory Neil Shapiro }
103