8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / lib / libast / common / sfio / sfscanf.c
blob4a370902184c2da244bb8beba11f22b8ab1b3b3c
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 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"
24 /* Read formated data from a stream
26 ** Written by Kiem-Phong Vo.
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
36 va_list args;
37 reg int rv;
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
49 rv = (f && form) ? sfvscanf(f,form,args) : -1;
50 va_end(args);
51 return rv;
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
63 Sfio_t f;
65 if(!s || !form)
66 return -1;
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;
77 return sfvscanf(&f,form,args);
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
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
99 rv = (s && form) ? sfvsscanf(s,form,args) : -1;
100 va_end(args);
101 return rv;