xref: /titanic_41/usr/src/lib/libast/common/sfio/sfscanf.c (revision 5fbb41393be5d63f75952b1d72d4df2642d22557)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #include	"sfhdr.h"
23 
24 /*	Read formated data from a stream
25 **
26 **	Written by Kiem-Phong Vo.
27 */
28 
29 #if __STD_C
30 int sfscanf(Sfio_t* f, const char* form, ...)
31 #else
32 int sfscanf(va_alist)
33 va_dcl
34 #endif
35 {
36 	va_list	args;
37 	reg int	rv;
38 
39 #if __STD_C
40 	va_start(args,form);
41 #else
42 	reg Sfio_t*	f;
43 	reg char*	form;
44 	va_start(args);
45 	f = va_arg(args,Sfio_t*);
46 	form = va_arg(args,char*);
47 #endif
48 
49 	rv = (f && form) ? sfvscanf(f,form,args) : -1;
50 	va_end(args);
51 	return rv;
52 }
53 
54 #if __STD_C
55 int sfvsscanf(const char* s, const char* form, va_list args)
56 #else
57 int sfvsscanf(s, form, args)
58 char*	s;
59 char*	form;
60 va_list	args;
61 #endif
62 {
63 	Sfio_t	f;
64 
65 	if(!s || !form)
66 		return -1;
67 
68 	/* make a fake stream */
69 	SFCLEAR(&f,NIL(Vtmutex_t*));
70 	f.flags = SF_STRING|SF_READ;
71 	f.bits = SF_PRIVATE;
72 	f.mode = SF_READ;
73 	f.size = strlen((char*)s);
74 	f.data = f.next = f.endw = (uchar*)s;
75 	f.endb = f.endr = f.data+f.size;
76 
77 	return sfvscanf(&f,form,args);
78 }
79 
80 #if __STD_C
81 int sfsscanf(const char* s, const char* form,...)
82 #else
83 int sfsscanf(va_alist)
84 va_dcl
85 #endif
86 {
87 	va_list		args;
88 	reg int		rv;
89 #if __STD_C
90 	va_start(args,form);
91 #else
92 	reg char*	s;
93 	reg char*	form;
94 	va_start(args);
95 	s = va_arg(args,char*);
96 	form = va_arg(args,char*);
97 #endif
98 
99 	rv = (s && form) ? sfvsscanf(s,form,args) : -1;
100 	va_end(args);
101 	return rv;
102 }
103