1 /*
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * and/or other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 /*
19 FUNCTION
20 <<siscanf>>, <<fiscanf>>, <<iscanf>>---scan and format non-floating input
21 
22 INDEX
23 	iscanf
24 INDEX
25 	_iscanf_r
26 INDEX
27 	fiscanf
28 INDEX
29 	_fiscanf_r
30 INDEX
31 	siscanf
32 INDEX
33 	_siscanf_r
34 
35 SYNOPSIS
36         #include <stdio.h>
37 
38         int iscanf(const char *<[format]>, ...);
39         int fiscanf(FILE *<[fd]>, const char *<[format]>, ...);
40         int siscanf(const char *<[str]>, const char *<[format]>, ...);
41 
42         int iscanf( const char *<[format]>, ...);
43         int fiscanf( FILE *<[fd]>,
44                        const char *<[format]>, ...);
45         int siscanf( const char *<[str]>,
46                    const char *<[format]>, ...);
47 
48 DESCRIPTION
49         <<iscanf>>, <<fiscanf>>, and <<siscanf>> are the same as
50 	<<scanf>>, <<fscanf>>, and <<sscanf>> respectively, only that
51 	they restrict the available formats to non-floating-point
52 	format specifiers.
53 
54         The routines <<_iscanf_r>>, <<_fiscanf_r>>, and <<_siscanf_r>> are reentrant
55         versions of <<iscanf>>, <<fiscanf>>, and <<siscanf>> that take an additional
56         first argument pointing to a reentrancy structure.
57 
58 RETURNS
59         <<iscanf>> returns the number of input fields successfully
60         scanned, converted and stored; the return value does
61         not include scanned fields which were not stored.
62 
63         If <<iscanf>> attempts to read at end-of-file, the return
64         value is <<EOF>>.
65 
66         If no fields were stored, the return value is <<0>>.
67 
68 PORTABILITY
69 <<iscanf>>, <<fiscanf>>, and <<siscanf>> are newlib extensions.
70 
71 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
72 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
73 */
74 
75 #define _DEFAULT_SOURCE
76 #include <_ansi.h>
77 #include <stdio.h>
78 #include <string.h>
79 #include <stdarg.h>
80 #include "local.h"
81 
82 int
siscanf(const char * str,const char * fmt,...)83 siscanf (const char *str,
84        const char *fmt, ...)
85 {
86   int ret;
87   va_list ap;
88   FILE f;
89 
90   f._flags = __SRD | __SSTR;
91   f._bf._base = f._p = (unsigned char *) str;
92   f._bf._size = f._r = strlen (str);
93   f._read = __seofread;
94   f._ub._base = NULL;
95   f._lb._base = NULL;
96   f._file = -1;  /* No file. */
97   va_start (ap, fmt);
98   ret = _ssvfiscanf ( &f, fmt, ap);
99   va_end (ap);
100   return ret;
101 }
102