xref: /titanic_41/usr/src/cmd/sendmail/libsm/sscanf.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3*7c478bd9Sstevel@tonic-gate  *      All rights reserved.
4*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1990, 1993
5*7c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
6*7c478bd9Sstevel@tonic-gate  *
7*7c478bd9Sstevel@tonic-gate  * This code is derived from software contributed to Berkeley by
8*7c478bd9Sstevel@tonic-gate  * Chris Torek.
9*7c478bd9Sstevel@tonic-gate  *
10*7c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
11*7c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
12*7c478bd9Sstevel@tonic-gate  * the sendmail distribution.
13*7c478bd9Sstevel@tonic-gate  */
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate #include <sm/gen.h>
18*7c478bd9Sstevel@tonic-gate SM_RCSID("@(#)$Id: sscanf.c,v 1.25 2002/02/01 02:28:00 ca Exp $")
19*7c478bd9Sstevel@tonic-gate #include <string.h>
20*7c478bd9Sstevel@tonic-gate #include <sm/varargs.h>
21*7c478bd9Sstevel@tonic-gate #include <sm/io.h>
22*7c478bd9Sstevel@tonic-gate #include "local.h"
23*7c478bd9Sstevel@tonic-gate 
24*7c478bd9Sstevel@tonic-gate /*
25*7c478bd9Sstevel@tonic-gate **  SM_EOFREAD -- dummy read function for faked file below
26*7c478bd9Sstevel@tonic-gate **
27*7c478bd9Sstevel@tonic-gate **	Parameters:
28*7c478bd9Sstevel@tonic-gate **		fp -- file pointer
29*7c478bd9Sstevel@tonic-gate **		buf -- location to place read data
30*7c478bd9Sstevel@tonic-gate **		len -- number of bytes to read
31*7c478bd9Sstevel@tonic-gate **
32*7c478bd9Sstevel@tonic-gate **	Returns:
33*7c478bd9Sstevel@tonic-gate **		0 (zero) always
34*7c478bd9Sstevel@tonic-gate */
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate static ssize_t
37*7c478bd9Sstevel@tonic-gate sm_eofread __P((
38*7c478bd9Sstevel@tonic-gate 	SM_FILE_T *fp,
39*7c478bd9Sstevel@tonic-gate 	char *buf,
40*7c478bd9Sstevel@tonic-gate 	size_t len));
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /* ARGSUSED0 */
43*7c478bd9Sstevel@tonic-gate static ssize_t
sm_eofread(fp,buf,len)44*7c478bd9Sstevel@tonic-gate sm_eofread(fp, buf, len)
45*7c478bd9Sstevel@tonic-gate 	SM_FILE_T *fp;
46*7c478bd9Sstevel@tonic-gate 	char *buf;
47*7c478bd9Sstevel@tonic-gate 	size_t len;
48*7c478bd9Sstevel@tonic-gate {
49*7c478bd9Sstevel@tonic-gate 	return 0;
50*7c478bd9Sstevel@tonic-gate }
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate /*
53*7c478bd9Sstevel@tonic-gate **  SM_IO_SSCANF -- scan a string to find data units
54*7c478bd9Sstevel@tonic-gate **
55*7c478bd9Sstevel@tonic-gate **	Parameters:
56*7c478bd9Sstevel@tonic-gate **		str -- strings containing data
57*7c478bd9Sstevel@tonic-gate **		fmt -- format directive for finding data units
58*7c478bd9Sstevel@tonic-gate **		... -- memory locations to place format found data units
59*7c478bd9Sstevel@tonic-gate **
60*7c478bd9Sstevel@tonic-gate **	Returns:
61*7c478bd9Sstevel@tonic-gate **		Failure: SM_IO_EOF
62*7c478bd9Sstevel@tonic-gate **		Success: number of data units found
63*7c478bd9Sstevel@tonic-gate **
64*7c478bd9Sstevel@tonic-gate **	Side Effects:
65*7c478bd9Sstevel@tonic-gate **		Attempts to strlen() 'str'; if not a '\0' terminated string
66*7c478bd9Sstevel@tonic-gate **			then the call may SEGV/fail.
67*7c478bd9Sstevel@tonic-gate **		Faking the string 'str' as a file.
68*7c478bd9Sstevel@tonic-gate */
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate int
71*7c478bd9Sstevel@tonic-gate #if SM_VA_STD
sm_io_sscanf(const char * str,char const * fmt,...)72*7c478bd9Sstevel@tonic-gate sm_io_sscanf(const char *str, char const *fmt, ...)
73*7c478bd9Sstevel@tonic-gate #else /* SM_VA_STD */
74*7c478bd9Sstevel@tonic-gate sm_io_sscanf(str, fmt, va_alist)
75*7c478bd9Sstevel@tonic-gate 	const char *str;
76*7c478bd9Sstevel@tonic-gate 	char *fmt;
77*7c478bd9Sstevel@tonic-gate 	va_dcl
78*7c478bd9Sstevel@tonic-gate #endif /* SM_VA_STD */
79*7c478bd9Sstevel@tonic-gate {
80*7c478bd9Sstevel@tonic-gate 	int ret;
81*7c478bd9Sstevel@tonic-gate 	SM_FILE_T fake;
82*7c478bd9Sstevel@tonic-gate 	SM_VA_LOCAL_DECL
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate 	fake.sm_magic = SmFileMagic;
85*7c478bd9Sstevel@tonic-gate 	fake.f_flags = SMRD;
86*7c478bd9Sstevel@tonic-gate 	fake.f_bf.smb_base = fake.f_p = (unsigned char *) str;
87*7c478bd9Sstevel@tonic-gate 	fake.f_bf.smb_size = fake.f_r = strlen(str);
88*7c478bd9Sstevel@tonic-gate 	fake.f_file = -1;
89*7c478bd9Sstevel@tonic-gate 	fake.f_read = sm_eofread;
90*7c478bd9Sstevel@tonic-gate 	fake.f_write = NULL;
91*7c478bd9Sstevel@tonic-gate 	fake.f_close = NULL;
92*7c478bd9Sstevel@tonic-gate 	fake.f_open = NULL;
93*7c478bd9Sstevel@tonic-gate 	fake.f_seek = NULL;
94*7c478bd9Sstevel@tonic-gate 	fake.f_setinfo = fake.f_getinfo = NULL;
95*7c478bd9Sstevel@tonic-gate 	fake.f_type = "sm_io_sscanf:fake";
96*7c478bd9Sstevel@tonic-gate 	fake.f_flushfp = NULL;
97*7c478bd9Sstevel@tonic-gate 	fake.f_ub.smb_base = NULL;
98*7c478bd9Sstevel@tonic-gate 	fake.f_timeout = SM_TIME_FOREVER;
99*7c478bd9Sstevel@tonic-gate 	fake.f_timeoutstate = SM_TIME_BLOCK;
100*7c478bd9Sstevel@tonic-gate 	SM_VA_START(ap, fmt);
101*7c478bd9Sstevel@tonic-gate 	ret = sm_vfscanf(&fake, SM_TIME_FOREVER, fmt, ap);
102*7c478bd9Sstevel@tonic-gate 	SM_VA_END(ap);
103*7c478bd9Sstevel@tonic-gate 	return ret;
104*7c478bd9Sstevel@tonic-gate }
105