OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [stdio/] [siscanf.c] - Blame information for rev 158

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/*
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
 * advertising materials, and 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
ANSI_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_r(struct _reent *<[ptr]>, const char *<[format]>, ...);
43
        int _fiscanf_r(struct _reent *<[ptr]>, FILE *<[fd]>,
44
                       const char *<[format]>, ...);
45
        int _siscanf_r(struct _reent *<[ptr]>, const char *<[str]>,
46
                   const char *<[format]>, ...);
47
 
48
 
49
TRAD_SYNOPSIS
50
        #include <stdio.h>
51
 
52
        int iscanf(<[format]> [, <[arg]>, ...])
53
        char *<[format]>;
54
 
55
        int fiscanf(<[fd]>, <[format]> [, <[arg]>, ...]);
56
        FILE *<[fd]>;
57
        char *<[format]>;
58
 
59
        int siscanf(<[str]>, <[format]> [, <[arg]>, ...]);
60
        char *<[str]>;
61
        char *<[format]>;
62
 
63
        int _iscanf_r(<[ptr]>, <[format]> [, <[arg]>, ...])
64
        struct _reent *<[ptr]>;
65
        char *<[format]>;
66
 
67
        int _fiscanf_r(<[ptr]>, <[fd]>, <[format]> [, <[arg]>, ...]);
68
        struct _reent *<[ptr]>;
69
        FILE *<[fd]>;
70
        char *<[format]>;
71
 
72
        int _siscanf_r(<[ptr]>, <[str]>, <[format]> [, <[arg]>, ...]);
73
        struct _reent *<[ptr]>;
74
        char *<[str]>;
75
        char *<[format]>;
76
 
77
 
78
DESCRIPTION
79
        <<iscanf>>, <<fiscanf>>, and <<siscanf>> are the same as
80
        <<scanf>>, <<fscanf>>, and <<sscanf>> respectively, only that
81
        they restrict the available formats to non-floating-point
82
        format specifiers.
83
 
84
        The routines <<_iscanf_r>>, <<_fiscanf_r>>, and <<_siscanf_r>> are reentrant
85
        versions of <<iscanf>>, <<fiscanf>>, and <<siscanf>> that take an additional
86
        first argument pointing to a reentrancy structure.
87
 
88
RETURNS
89
        <<iscanf>> returns the number of input fields successfully
90
        scanned, converted and stored; the return value does
91
        not include scanned fields which were not stored.
92
 
93
        If <<iscanf>> attempts to read at end-of-file, the return
94
        value is <<EOF>>.
95
 
96
        If no fields were stored, the return value is <<0>>.
97
 
98
PORTABILITY
99
<<iscanf>>, <<fiscanf>>, and <<siscanf>> are newlib extensions.
100
 
101
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
102
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
103
*/
104
 
105
#include <_ansi.h>
106
#include <reent.h>
107
#include <stdio.h>
108
#include <string.h>
109
#ifdef _HAVE_STDC
110
#include <stdarg.h>
111
#else
112
#include <varargs.h>
113
#endif
114
#include "local.h"
115
 
116
/* | ARGSUSED */
117
/*SUPPRESS 590*/
118
static _READ_WRITE_RETURN_TYPE
119
_DEFUN(eofread, (ptr, cookie, buf, len),
120
       struct _reent *ptr _AND
121
       _PTR cookie _AND
122
       char *buf   _AND
123
       int len)
124
{
125
  return 0;
126
}
127
 
128
#ifndef _REENT_ONLY 
129
 
130
#ifdef _HAVE_STDC
131
int
132
_DEFUN(siscanf, (str, fmt),
133
       _CONST char *str _AND
134
       _CONST char *fmt _DOTS)
135
#else
136
int
137
siscanf(str, fmt, va_alist)
138
       _CONST char *str;
139
       _CONST char *fmt;
140
       va_dcl
141
#endif
142
{
143
  int ret;
144
  va_list ap;
145
  FILE f;
146
 
147
  f._flags = __SRD | __SSTR;
148
  f._bf._base = f._p = (unsigned char *) str;
149
  f._bf._size = f._r = strlen (str);
150
  f._read = eofread;
151
  f._ub._base = NULL;
152
  f._lb._base = NULL;
153
  f._file = -1;  /* No file. */
154
#ifdef _HAVE_STDC
155
  va_start (ap, fmt);
156
#else
157
  va_start (ap);
158
#endif
159
  ret = __ssvfiscanf_r (_REENT, &f, fmt, ap);
160
  va_end (ap);
161
  return ret;
162
}
163
 
164
#endif /* !_REENT_ONLY */
165
 
166
#ifdef _HAVE_STDC
167
int
168
_DEFUN(_siscanf_r, (ptr, str, fmt),
169
       struct _reent *ptr _AND
170
       _CONST char *str   _AND
171
       _CONST char *fmt _DOTS)
172
#else
173
int
174
_siscanf_r(ptr, str, fmt, va_alist)
175
          struct _reent *ptr;
176
          _CONST char *str;
177
          _CONST char *fmt;
178
          va_dcl
179
#endif
180
{
181
  int ret;
182
  va_list ap;
183
  FILE f;
184
 
185
  f._flags = __SRD | __SSTR;
186
  f._bf._base = f._p = (unsigned char *) str;
187
  f._bf._size = f._r = strlen (str);
188
  f._read = eofread;
189
  f._ub._base = NULL;
190
  f._lb._base = NULL;
191
  f._file = -1;  /* No file. */
192
#ifdef _HAVE_STDC
193
  va_start (ap, fmt);
194
#else
195
  va_start (ap);
196
#endif
197
  ret = __ssvfiscanf_r (ptr, &f, fmt, ap);
198
  va_end (ap);
199
  return ret;
200
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.