sscanf.c revision 1574
167754Smsmith/*-
267754Smsmith * Copyright (c) 1990, 1993
377424Smsmith *	The Regents of the University of California.  All rights reserved.
467754Smsmith *
567754Smsmith * This code is derived from software contributed to Berkeley by
667754Smsmith * Chris Torek.
7217365Sjkim *
8245582Sjkim * Redistribution and use in source and binary forms, with or without
970243Smsmith * modification, are permitted provided that the following conditions
1067754Smsmith * are met:
11217365Sjkim * 1. Redistributions of source code must retain the above copyright
12217365Sjkim *    notice, this list of conditions and the following disclaimer.
13217365Sjkim * 2. Redistributions in binary form must reproduce the above copyright
14217365Sjkim *    notice, this list of conditions and the following disclaimer in the
15217365Sjkim *    documentation and/or other materials provided with the distribution.
16217365Sjkim * 3. All advertising materials mentioning features or use of this software
17217365Sjkim *    must display the following acknowledgement:
18217365Sjkim *	This product includes software developed by the University of
19217365Sjkim *	California, Berkeley and its contributors.
20217365Sjkim * 4. Neither the name of the University nor the names of its contributors
21217365Sjkim *    may be used to endorse or promote products derived from this software
22217365Sjkim *    without specific prior written permission.
23217365Sjkim *
24217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2567754Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26217365Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27217365Sjkim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28217365Sjkim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2967754Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32217365Sjkim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33217365Sjkim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34217365Sjkim * SUCH DAMAGE.
35217365Sjkim */
36217365Sjkim
37217365Sjkim#if defined(LIBC_SCCS) && !defined(lint)
38217365Sjkimstatic char sccsid[] = "@(#)sscanf.c	8.1 (Berkeley) 6/4/93";
39217365Sjkim#endif /* LIBC_SCCS and not lint */
40217365Sjkim
41217365Sjkim#include <stdio.h>
42217365Sjkim#include <string.h>
4367754Smsmith#if __STDC__
4467754Smsmith#include <stdarg.h>
4567754Smsmith#else
46193341Sjkim#include <varargs.h>
47193341Sjkim#endif
48193341Sjkim#include "local.h"
4967754Smsmith
5077424Smsmith/* ARGSUSED */
5191116Smsmithstatic int
5267754Smsmitheofread(cookie, buf, len)
5367754Smsmith	void *cookie;
54151937Sjkim	char *buf;
55151937Sjkim	int len;
56151937Sjkim{
57151937Sjkim
58151937Sjkim	return (0);
59151937Sjkim}
60151937Sjkim
61151937Sjkim#if __STDC__
62151937Sjkimsscanf(const char *str, char const *fmt, ...)
6367754Smsmith#else
6467754Smsmithsscanf(str, fmt, va_alist)
65151937Sjkim	char *str;
6667754Smsmith	char *fmt;
67151937Sjkim	va_dcl
68151937Sjkim#endif
69151937Sjkim{
7067754Smsmith	int ret;
7177424Smsmith	va_list ap;
7267754Smsmith	FILE f;
73151937Sjkim
74151937Sjkim	f._flags = __SRD;
7567754Smsmith	f._bf._base = f._p = (unsigned char *)str;
7667754Smsmith	f._bf._size = f._r = strlen(str);
7767754Smsmith	f._read = eofread;
7867754Smsmith	f._ub._base = NULL;
79151937Sjkim	f._lb._base = NULL;
80151937Sjkim#if __STDC__
81151937Sjkim	va_start(ap, fmt);
82151937Sjkim#else
8367754Smsmith	va_start(ap);
84151937Sjkim#endif
85151937Sjkim	ret = __svfscanf(&f, fmt, ap);
86151937Sjkim	va_end(ap);
87151937Sjkim	return (ret);
88151937Sjkim}
89151937Sjkim