xref: /illumos-gate/usr/src/cmd/sendmail/libsm/sscanf.c (revision 2a8bcb4e)
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 #include <sm/gen.h>
16*7c478bd9Sstevel@tonic-gate SM_RCSID("@(#)$Id: sscanf.c,v 1.25 2002/02/01 02:28:00 ca Exp $")
17*7c478bd9Sstevel@tonic-gate #include <string.h>
18*7c478bd9Sstevel@tonic-gate #include <sm/varargs.h>
19*7c478bd9Sstevel@tonic-gate #include <sm/io.h>
20*7c478bd9Sstevel@tonic-gate #include "local.h"
21*7c478bd9Sstevel@tonic-gate 
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate **  SM_EOFREAD -- dummy read function for faked file below
24*7c478bd9Sstevel@tonic-gate **
25*7c478bd9Sstevel@tonic-gate **	Parameters:
26*7c478bd9Sstevel@tonic-gate **		fp -- file pointer
27*7c478bd9Sstevel@tonic-gate **		buf -- location to place read data
28*7c478bd9Sstevel@tonic-gate **		len -- number of bytes to read
29*7c478bd9Sstevel@tonic-gate **
30*7c478bd9Sstevel@tonic-gate **	Returns:
31*7c478bd9Sstevel@tonic-gate **		0 (zero) always
32*7c478bd9Sstevel@tonic-gate */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate static ssize_t
35*7c478bd9Sstevel@tonic-gate sm_eofread __P((
36*7c478bd9Sstevel@tonic-gate 	SM_FILE_T *fp,
37*7c478bd9Sstevel@tonic-gate 	char *buf,
38*7c478bd9Sstevel@tonic-gate 	size_t len));
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate /* ARGSUSED0 */
41*7c478bd9Sstevel@tonic-gate static ssize_t
sm_eofread(fp,buf,len)42*7c478bd9Sstevel@tonic-gate sm_eofread(fp, buf, len)
43*7c478bd9Sstevel@tonic-gate 	SM_FILE_T *fp;
44*7c478bd9Sstevel@tonic-gate 	char *buf;
45*7c478bd9Sstevel@tonic-gate 	size_t len;
46*7c478bd9Sstevel@tonic-gate {
47*7c478bd9Sstevel@tonic-gate 	return 0;
48*7c478bd9Sstevel@tonic-gate }
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate **  SM_IO_SSCANF -- scan a string to find data units
52*7c478bd9Sstevel@tonic-gate **
53*7c478bd9Sstevel@tonic-gate **	Parameters:
54*7c478bd9Sstevel@tonic-gate **		str -- strings containing data
55*7c478bd9Sstevel@tonic-gate **		fmt -- format directive for finding data units
56*7c478bd9Sstevel@tonic-gate **		... -- memory locations to place format found data units
57*7c478bd9Sstevel@tonic-gate **
58*7c478bd9Sstevel@tonic-gate **	Returns:
59*7c478bd9Sstevel@tonic-gate **		Failure: SM_IO_EOF
60*7c478bd9Sstevel@tonic-gate **		Success: number of data units found
61*7c478bd9Sstevel@tonic-gate **
62*7c478bd9Sstevel@tonic-gate **	Side Effects:
63*7c478bd9Sstevel@tonic-gate **		Attempts to strlen() 'str'; if not a '\0' terminated string
64*7c478bd9Sstevel@tonic-gate **			then the call may SEGV/fail.
65*7c478bd9Sstevel@tonic-gate **		Faking the string 'str' as a file.
66*7c478bd9Sstevel@tonic-gate */
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate int
69*7c478bd9Sstevel@tonic-gate #if SM_VA_STD
sm_io_sscanf(const char * str,char const * fmt,...)70*7c478bd9Sstevel@tonic-gate sm_io_sscanf(const char *str, char const *fmt, ...)
71*7c478bd9Sstevel@tonic-gate #else /* SM_VA_STD */
72*7c478bd9Sstevel@tonic-gate sm_io_sscanf(str, fmt, va_alist)
73*7c478bd9Sstevel@tonic-gate 	const char *str;
74*7c478bd9Sstevel@tonic-gate 	char *fmt;
75*7c478bd9Sstevel@tonic-gate 	va_dcl
76*7c478bd9Sstevel@tonic-gate #endif /* SM_VA_STD */
77*7c478bd9Sstevel@tonic-gate {
78*7c478bd9Sstevel@tonic-gate 	int ret;
79*7c478bd9Sstevel@tonic-gate 	SM_FILE_T fake;
80*7c478bd9Sstevel@tonic-gate 	SM_VA_LOCAL_DECL
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate 	fake.sm_magic = SmFileMagic;
83*7c478bd9Sstevel@tonic-gate 	fake.f_flags = SMRD;
84*7c478bd9Sstevel@tonic-gate 	fake.f_bf.smb_base = fake.f_p = (unsigned char *) str;
85*7c478bd9Sstevel@tonic-gate 	fake.f_bf.smb_size = fake.f_r = strlen(str);
86*7c478bd9Sstevel@tonic-gate 	fake.f_file = -1;
87*7c478bd9Sstevel@tonic-gate 	fake.f_read = sm_eofread;
88*7c478bd9Sstevel@tonic-gate 	fake.f_write = NULL;
89*7c478bd9Sstevel@tonic-gate 	fake.f_close = NULL;
90*7c478bd9Sstevel@tonic-gate 	fake.f_open = NULL;
91*7c478bd9Sstevel@tonic-gate 	fake.f_seek = NULL;
92*7c478bd9Sstevel@tonic-gate 	fake.f_setinfo = fake.f_getinfo = NULL;
93*7c478bd9Sstevel@tonic-gate 	fake.f_type = "sm_io_sscanf:fake";
94*7c478bd9Sstevel@tonic-gate 	fake.f_flushfp = NULL;
95*7c478bd9Sstevel@tonic-gate 	fake.f_ub.smb_base = NULL;
96*7c478bd9Sstevel@tonic-gate 	fake.f_timeout = SM_TIME_FOREVER;
97*7c478bd9Sstevel@tonic-gate 	fake.f_timeoutstate = SM_TIME_BLOCK;
98*7c478bd9Sstevel@tonic-gate 	SM_VA_START(ap, fmt);
99*7c478bd9Sstevel@tonic-gate 	ret = sm_vfscanf(&fake, SM_TIME_FOREVER, fmt, ap);
100*7c478bd9Sstevel@tonic-gate 	SM_VA_END(ap);
101*7c478bd9Sstevel@tonic-gate 	return ret;
102*7c478bd9Sstevel@tonic-gate }
103