xref: /original-bsd/lib/libc/stdio/sscanf.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Chris Torek.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #if defined(LIBC_SCCS) && !defined(lint)
12 static char sccsid[] = "@(#)sscanf.c	8.1 (Berkeley) 06/04/93";
13 #endif /* LIBC_SCCS and not lint */
14 
15 #include <stdio.h>
16 #include <string.h>
17 #if __STDC__
18 #include <stdarg.h>
19 #else
20 #include <varargs.h>
21 #endif
22 #include "local.h"
23 
24 /* ARGSUSED */
25 static int
26 eofread(cookie, buf, len)
27 	void *cookie;
28 	char *buf;
29 	int len;
30 {
31 
32 	return (0);
33 }
34 
35 #if __STDC__
36 sscanf(const char *str, char const *fmt, ...)
37 #else
38 sscanf(str, fmt, va_alist)
39 	char *str;
40 	char *fmt;
41 	va_dcl
42 #endif
43 {
44 	int ret;
45 	va_list ap;
46 	FILE f;
47 
48 	f._flags = __SRD;
49 	f._bf._base = f._p = (unsigned char *)str;
50 	f._bf._size = f._r = strlen(str);
51 	f._read = eofread;
52 	f._ub._base = NULL;
53 	f._lb._base = NULL;
54 #if __STDC__
55 	va_start(ap, fmt);
56 #else
57 	va_start(ap);
58 #endif
59 	ret = __svfscanf(&f, fmt, ap);
60 	va_end(ap);
61 	return (ret);
62 }
63