Rev 4874 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4874 | Rev 4921 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 1990 The Regents of the University of California. |
2 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms are permitted |
5 | * Redistribution and use in source and binary forms are permitted |
6 | * provided that the above copyright notice and this paragraph are |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, |
7 | * duplicated in all such forms and that any documentation, |
8 | * advertising materials, and other materials related to such |
8 | * advertising materials, and other materials related to such |
9 | * distribution and use acknowledge that the software was developed |
9 | * distribution and use acknowledge that the software was developed |
10 | * by the University of California, Berkeley. The name of the |
10 | * by the University of California, Berkeley. The name of the |
11 | * University may not be used to endorse or promote products derived |
11 | * University may not be used to endorse or promote products derived |
12 | * from this software without specific prior written permission. |
12 | * from this software without specific prior written permission. |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
16 | */ |
16 | */ |
17 | 17 | ||
18 | /* |
18 | /* |
19 | FUNCTION |
19 | FUNCTION |
20 | < |
20 | < |
21 | 21 | ||
22 | INDEX |
22 | INDEX |
23 | scanf |
23 | scanf |
24 | INDEX |
24 | INDEX |
25 | _scanf_r |
25 | _scanf_r |
26 | INDEX |
26 | INDEX |
27 | fscanf |
27 | fscanf |
28 | INDEX |
28 | INDEX |
29 | _fscanf_r |
29 | _fscanf_r |
30 | INDEX |
30 | INDEX |
31 | sscanf |
31 | sscanf |
32 | INDEX |
32 | INDEX |
33 | _sscanf_r |
33 | _sscanf_r |
34 | 34 | ||
35 | ANSI_SYNOPSIS |
35 | ANSI_SYNOPSIS |
36 | #include |
36 | #include |
37 | 37 | ||
38 | int scanf(const char *<[format]>, ...); |
38 | int scanf(const char *restrict <[format]>, ...); |
39 | int fscanf(FILE *<[fd]>, const char *<[format]>, ...); |
39 | int fscanf(FILE *restrict <[fd]>, const char *restrict <[format]>, ...); |
40 | int sscanf(const char *<[str]>, const char *<[format]>, ...); |
40 | int sscanf(const char *restrict <[str]>, const char *restrict <[format]>, ...); |
41 | 41 | ||
42 | int _scanf_r(struct _reent *<[ptr]>, const char *<[format]>, ...); |
42 | int _scanf_r(struct _reent *<[ptr]>, const char *restrict <[format]>, ...); |
43 | int _fscanf_r(struct _reent *<[ptr]>, FILE *<[fd]>, |
43 | int _fscanf_r(struct _reent *<[ptr]>, FILE *restrict <[fd]>, |
44 | const char *<[format]>, ...); |
44 | const char *restrict <[format]>, ...); |
45 | int _sscanf_r(struct _reent *<[ptr]>, const char *<[str]>, |
45 | int _sscanf_r(struct _reent *<[ptr]>, const char *restrict <[str]>, |
46 | const char *<[format]>, ...); |
46 | const char *restrict <[format]>, ...); |
47 | 47 | ||
48 | 48 | ||
49 | TRAD_SYNOPSIS |
49 | TRAD_SYNOPSIS |
50 | #include |
50 | #include |
51 | 51 | ||
52 | int scanf(<[format]> [, <[arg]>, ...]) |
52 | int scanf(<[format]> [, <[arg]>, ...]) |
53 | char *<[format]>; |
53 | char *<[format]>; |
54 | 54 | ||
55 | int fscanf(<[fd]>, <[format]> [, <[arg]>, ...]); |
55 | int fscanf(<[fd]>, <[format]> [, <[arg]>, ...]); |
56 | FILE *<[fd]>; |
56 | FILE *<[fd]>; |
57 | char *<[format]>; |
57 | char *<[format]>; |
58 | 58 | ||
59 | int sscanf(<[str]>, <[format]> [, <[arg]>, ...]); |
59 | int sscanf(<[str]>, <[format]> [, <[arg]>, ...]); |
60 | char *<[str]>; |
60 | char *<[str]>; |
61 | char *<[format]>; |
61 | char *<[format]>; |
62 | 62 | ||
63 | int _scanf_r(<[ptr]>, <[format]> [, <[arg]>, ...]) |
63 | int _scanf_r(<[ptr]>, <[format]> [, <[arg]>, ...]) |
64 | struct _reent *<[ptr]>; |
64 | struct _reent *<[ptr]>; |
65 | char *<[format]>; |
65 | char *<[format]>; |
66 | 66 | ||
67 | int _fscanf_r(<[ptr]>, <[fd]>, <[format]> [, <[arg]>, ...]); |
67 | int _fscanf_r(<[ptr]>, <[fd]>, <[format]> [, <[arg]>, ...]); |
68 | struct _reent *<[ptr]>; |
68 | struct _reent *<[ptr]>; |
69 | FILE *<[fd]>; |
69 | FILE *<[fd]>; |
70 | char *<[format]>; |
70 | char *<[format]>; |
71 | 71 | ||
72 | int _sscanf_r(<[ptr]>, <[str]>, <[format]> [, <[arg]>, ...]); |
72 | int _sscanf_r(<[ptr]>, <[str]>, <[format]> [, <[arg]>, ...]); |
73 | struct _reent *<[ptr]>; |
73 | struct _reent *<[ptr]>; |
74 | char *<[str]>; |
74 | char *<[str]>; |
75 | char *<[format]>; |
75 | char *<[format]>; |
76 | 76 | ||
77 | 77 | ||
78 | DESCRIPTION |
78 | DESCRIPTION |
79 | < |
79 | < |
80 | one character at a time. Each field is interpreted according to |
80 | one character at a time. Each field is interpreted according to |
81 | a format specifier passed to < |
81 | a format specifier passed to < |
82 | <<*<[format]>>>. < |
82 | <<*<[format]>>>. < |
83 | each field at the address passed to it as the corresponding argument |
83 | each field at the address passed to it as the corresponding argument |
84 | following <[format]>. You must supply the same number of |
84 | following <[format]>. You must supply the same number of |
85 | format specifiers and address arguments as there are input fields. |
85 | format specifiers and address arguments as there are input fields. |
86 | 86 | ||
87 | There must be sufficient address arguments for the given format |
87 | There must be sufficient address arguments for the given format |
88 | specifiers; if not the results are unpredictable and likely |
88 | specifiers; if not the results are unpredictable and likely |
89 | disasterous. Excess address arguments are merely ignored. |
89 | disasterous. Excess address arguments are merely ignored. |
90 | 90 | ||
91 | < |
91 | < |
92 | an expected pattern. Since the combination of < |
92 | an expected pattern. Since the combination of < |
93 | followed by < |
93 | followed by < |
94 | to be certain that a program is synchronized with input at the end |
94 | to be certain that a program is synchronized with input at the end |
95 | of a line. |
95 | of a line. |
96 | 96 | ||
97 | < |
97 | < |
98 | source of input: < |
98 | source of input: < |
99 | from a string. |
99 | from a string. |
100 | 100 | ||
101 | The routines <<_scanf_r>>, <<_fscanf_r>>, and <<_sscanf_r>> are reentrant |
101 | The routines <<_scanf_r>>, <<_fscanf_r>>, and <<_sscanf_r>> are reentrant |
102 | versions of < |
102 | versions of < |
103 | first argument pointing to a reentrancy structure. |
103 | first argument pointing to a reentrancy structure. |
104 | 104 | ||
105 | The string at <<*<[format]>>> is a character sequence composed |
105 | The string at <<*<[format]>>> is a character sequence composed |
106 | of zero or more directives. Directives are composed of |
106 | of zero or more directives. Directives are composed of |
107 | one or more whitespace characters, non-whitespace characters, |
107 | one or more whitespace characters, non-whitespace characters, |
108 | and format specifications. |
108 | and format specifications. |
109 | 109 | ||
110 | Whitespace characters are blank (<< >>), tab (<<\t>>), or |
110 | Whitespace characters are blank (<< >>), tab (<<\t>>), or |
111 | newline (<<\n>>). |
111 | newline (<<\n>>). |
112 | When < |
112 | When < |
113 | it will read (but not store) all consecutive whitespace characters |
113 | it will read (but not store) all consecutive whitespace characters |
114 | up to the next non-whitespace character in the input. |
114 | up to the next non-whitespace character in the input. |
115 | 115 | ||
116 | Non-whitespace characters are all other ASCII characters except the |
116 | Non-whitespace characters are all other ASCII characters except the |
117 | percent sign (<<%>>). When < |
117 | percent sign (<<%>>). When < |
118 | character in the format string it will read, but not store |
118 | character in the format string it will read, but not store |
119 | a matching non-whitespace character. |
119 | a matching non-whitespace character. |
120 | 120 | ||
121 | Format specifications tell < |
121 | Format specifications tell < |
122 | from the input field into specific types of values, and store then |
122 | from the input field into specific types of values, and store then |
123 | in the locations specified by the address arguments. |
123 | in the locations specified by the address arguments. |
124 | 124 | ||
125 | Trailing whitespace is left unread unless explicitly |
125 | Trailing whitespace is left unread unless explicitly |
126 | matched in the format string. |
126 | matched in the format string. |
127 | 127 | ||
128 | The format specifiers must begin with a percent sign (<<%>>) |
128 | The format specifiers must begin with a percent sign (<<%>>) |
129 | and have the following form: |
129 | and have the following form: |
130 | 130 | ||
131 | . %[*][<[width]>][<[size]>]<[type]> |
131 | . %[*][<[width]>][<[size]>]<[type]> |
132 | 132 | ||
133 | Each format specification begins with the percent character (<<%>>). |
133 | Each format specification begins with the percent character (<<%>>). |
134 | The other fields are: |
134 | The other fields are: |
135 | o+ |
135 | o+ |
136 | o * |
136 | o * |
137 | an optional marker; if present, it suppresses interpretation and |
137 | an optional marker; if present, it suppresses interpretation and |
138 | assignment of this input field. |
138 | assignment of this input field. |
139 | 139 | ||
140 | o <[width]> |
140 | o <[width]> |
141 | an optional maximum field width: a decimal integer, |
141 | an optional maximum field width: a decimal integer, |
142 | which controls the maximum number of characters that |
142 | which controls the maximum number of characters that |
143 | will be read before converting the current input field. If the |
143 | will be read before converting the current input field. If the |
144 | input field has fewer than <[width]> characters, < |
144 | input field has fewer than <[width]> characters, < |
145 | reads all the characters in the field, and then |
145 | reads all the characters in the field, and then |
146 | proceeds with the next field and its format specification. |
146 | proceeds with the next field and its format specification. |
147 | 147 | ||
148 | If a whitespace or a non-convertable character occurs |
148 | If a whitespace or a non-convertable character occurs |
149 | before <[width]> character are read, the characters up |
149 | before <[width]> character are read, the characters up |
150 | to that character are read, converted, and stored. |
150 | to that character are read, converted, and stored. |
151 | Then < |
151 | Then < |
152 | 152 | ||
153 | o size |
153 | o size |
154 | < |
154 | < |
155 | characters which override the default way that < |
155 | characters which override the default way that < |
156 | interprets the data type of the corresponding argument. |
156 | interprets the data type of the corresponding argument. |
157 | 157 | ||
158 | 158 | ||
159 | .Modifier Type(s) |
159 | .Modifier Type(s) |
160 | . hh d, i, o, u, x, n convert input to char, |
160 | . hh d, i, o, u, x, n convert input to char, |
161 | . store in char object |
161 | . store in char object |
162 | . |
162 | . |
163 | . h d, i, o, u, x, n convert input to short, |
163 | . h d, i, o, u, x, n convert input to short, |
164 | . store in short object |
164 | . store in short object |
165 | . |
165 | . |
166 | . h D, I, O, U, X no effect |
166 | . h D, I, O, U, X no effect |
167 | . e, f, c, s, p |
167 | . e, f, c, s, p |
168 | . |
168 | . |
169 | . j d, i, o, u, x, n convert input to intmax_t, |
169 | . j d, i, o, u, x, n convert input to intmax_t, |
170 | . store in intmax_t object |
170 | . store in intmax_t object |
171 | . |
171 | . |
172 | . j all others no effect |
172 | . j all others no effect |
173 | . |
173 | . |
174 | . l d, i, o, u, x, n convert input to long, |
174 | . l d, i, o, u, x, n convert input to long, |
175 | . store in long object |
175 | . store in long object |
176 | . |
176 | . |
177 | . l e, f, g convert input to double |
177 | . l e, f, g convert input to double |
178 | . store in a double object |
178 | . store in a double object |
179 | . |
179 | . |
180 | . l D, I, O, U, X no effect |
180 | . l D, I, O, U, X no effect |
181 | . c, s, p |
181 | . c, s, p |
182 | . |
182 | . |
183 | . ll d, i, o, u, x, n convert to long long, |
183 | . ll d, i, o, u, x, n convert to long long, |
184 | . store in long long |
184 | . store in long long |
185 | . |
185 | . |
186 | . L d, i, o, u, x, n convert to long long, |
186 | . L d, i, o, u, x, n convert to long long, |
187 | . store in long long |
187 | . store in long long |
188 | . |
188 | . |
189 | . L e, f, g, E, G convert to long double, |
189 | . L e, f, g, E, G convert to long double, |
190 | . store in long double |
190 | . store in long double |
191 | . |
191 | . |
192 | . L all others no effect |
192 | . L all others no effect |
193 | . |
193 | . |
194 | . t d, i, o, u, x, n convert input to ptrdiff_t, |
194 | . t d, i, o, u, x, n convert input to ptrdiff_t, |
195 | . store in ptrdiff_t object |
195 | . store in ptrdiff_t object |
196 | . |
196 | . |
197 | . t all others no effect |
197 | . t all others no effect |
198 | . |
198 | . |
199 | . z d, i, o, u, x, n convert input to size_t, |
199 | . z d, i, o, u, x, n convert input to size_t, |
200 | . store in size_t object |
200 | . store in size_t object |
201 | . |
201 | . |
202 | . z all others no effect |
202 | . z all others no effect |
203 | . |
203 | . |
204 | 204 | ||
205 | 205 | ||
206 | o <[type]> |
206 | o <[type]> |
207 | 207 | ||
208 | A character to specify what kind of conversion |
208 | A character to specify what kind of conversion |
209 | < |
209 | < |
210 | characters: |
210 | characters: |
211 | 211 | ||
212 | o+ |
212 | o+ |
213 | o % |
213 | o % |
214 | No conversion is done; the percent character (<<%>>) is stored. |
214 | No conversion is done; the percent character (<<%>>) is stored. |
215 | 215 | ||
216 | o c |
216 | o c |
217 | Scans one character. Corresponding <[arg]>: <<(char *arg)>>. |
217 | Scans one character. Corresponding <[arg]>: <<(char *arg)>>. |
218 | 218 | ||
219 | o s |
219 | o s |
220 | Reads a character string into the array supplied. |
220 | Reads a character string into the array supplied. |
221 | Corresponding <[arg]>: <<(char arg[])>>. |
221 | Corresponding <[arg]>: <<(char arg[])>>. |
222 | 222 | ||
223 | o [<[pattern]>] |
223 | o [<[pattern]>] |
224 | Reads a non-empty character string into memory |
224 | Reads a non-empty character string into memory |
225 | starting at <[arg]>. This area must be large |
225 | starting at <[arg]>. This area must be large |
226 | enough to accept the sequence and a |
226 | enough to accept the sequence and a |
227 | terminating null character which will be added |
227 | terminating null character which will be added |
228 | automatically. (<[pattern]> is discussed in the paragraph following |
228 | automatically. (<[pattern]> is discussed in the paragraph following |
229 | this table). Corresponding <[arg]>: <<(char *arg)>>. |
229 | this table). Corresponding <[arg]>: <<(char *arg)>>. |
230 | 230 | ||
231 | o d |
231 | o d |
232 | Reads a decimal integer into the corresponding <[arg]>: <<(int *arg)>>. |
232 | Reads a decimal integer into the corresponding <[arg]>: <<(int *arg)>>. |
233 | 233 | ||
234 | o D |
234 | o D |
235 | Reads a decimal integer into the corresponding |
235 | Reads a decimal integer into the corresponding |
236 | <[arg]>: <<(long *arg)>>. |
236 | <[arg]>: <<(long *arg)>>. |
237 | 237 | ||
238 | o o |
238 | o o |
239 | Reads an octal integer into the corresponding <[arg]>: <<(int *arg)>>. |
239 | Reads an octal integer into the corresponding <[arg]>: <<(int *arg)>>. |
240 | 240 | ||
241 | o O |
241 | o O |
242 | Reads an octal integer into the corresponding <[arg]>: <<(long *arg)>>. |
242 | Reads an octal integer into the corresponding <[arg]>: <<(long *arg)>>. |
243 | 243 | ||
244 | o u |
244 | o u |
245 | Reads an unsigned decimal integer into the corresponding |
245 | Reads an unsigned decimal integer into the corresponding |
246 | <[arg]>: <<(unsigned int *arg)>>. |
246 | <[arg]>: <<(unsigned int *arg)>>. |
247 | 247 | ||
248 | 248 | ||
249 | o U |
249 | o U |
250 | Reads an unsigned decimal integer into the corresponding <[arg]>: |
250 | Reads an unsigned decimal integer into the corresponding <[arg]>: |
251 | <<(unsigned long *arg)>>. |
251 | <<(unsigned long *arg)>>. |
252 | 252 | ||
253 | o x,X |
253 | o x,X |
254 | Read a hexadecimal integer into the corresponding <[arg]>: |
254 | Read a hexadecimal integer into the corresponding <[arg]>: |
255 | <<(int *arg)>>. |
255 | <<(int *arg)>>. |
256 | 256 | ||
257 | o e, f, g |
257 | o e, f, g |
258 | Read a floating-point number into the corresponding <[arg]>: |
258 | Read a floating-point number into the corresponding <[arg]>: |
259 | <<(float *arg)>>. |
259 | <<(float *arg)>>. |
260 | 260 | ||
261 | o E, F, G |
261 | o E, F, G |
262 | Read a floating-point number into the corresponding <[arg]>: |
262 | Read a floating-point number into the corresponding <[arg]>: |
263 | <<(double *arg)>>. |
263 | <<(double *arg)>>. |
264 | 264 | ||
265 | o i |
265 | o i |
266 | Reads a decimal, octal or hexadecimal integer into the |
266 | Reads a decimal, octal or hexadecimal integer into the |
267 | corresponding <[arg]>: <<(int *arg)>>. |
267 | corresponding <[arg]>: <<(int *arg)>>. |
268 | 268 | ||
269 | o I |
269 | o I |
270 | Reads a decimal, octal or hexadecimal integer into the |
270 | Reads a decimal, octal or hexadecimal integer into the |
271 | corresponding <[arg]>: <<(long *arg)>>. |
271 | corresponding <[arg]>: <<(long *arg)>>. |
272 | 272 | ||
273 | o n |
273 | o n |
274 | Stores the number of characters read in the corresponding |
274 | Stores the number of characters read in the corresponding |
275 | <[arg]>: <<(int *arg)>>. |
275 | <[arg]>: <<(int *arg)>>. |
276 | 276 | ||
277 | o p |
277 | o p |
278 | Stores a scanned pointer. ANSI C leaves the details |
278 | Stores a scanned pointer. ANSI C leaves the details |
279 | to each implementation; this implementation treats |
279 | to each implementation; this implementation treats |
280 | <<%p>> exactly the same as <<%U>>. Corresponding |
280 | <<%p>> exactly the same as <<%U>>. Corresponding |
281 | <[arg]>: <<(void **arg)>>. |
281 | <[arg]>: <<(void **arg)>>. |
282 | o- |
282 | o- |
283 | 283 | ||
284 | A <[pattern]> of characters surrounded by square brackets can be used |
284 | A <[pattern]> of characters surrounded by square brackets can be used |
285 | instead of the < |
285 | instead of the < |
286 | characters which define a search set of possible characters making up |
286 | characters which define a search set of possible characters making up |
287 | the < |
287 | the < |
288 | caret (<<^>>), the search set is inverted to include all ASCII characters |
288 | caret (<<^>>), the search set is inverted to include all ASCII characters |
289 | except those between the brackets. There is also a range facility |
289 | except those between the brackets. There is also a range facility |
290 | which you can use as a shortcut. <<%[0-9] >> matches all decimal digits. |
290 | which you can use as a shortcut. <<%[0-9] >> matches all decimal digits. |
291 | The hyphen must not be the first or last character in the set. |
291 | The hyphen must not be the first or last character in the set. |
292 | The character prior to the hyphen must be lexically less than the |
292 | The character prior to the hyphen must be lexically less than the |
293 | character after it. |
293 | character after it. |
294 | 294 | ||
295 | Here are some <[pattern]> examples: |
295 | Here are some <[pattern]> examples: |
296 | o+ |
296 | o+ |
297 | o %[abcd] |
297 | o %[abcd] |
298 | matches strings containing only <>, <>, < |
298 | matches strings containing only <>, <>, < |
299 | 299 | ||
300 | o %[^abcd] |
300 | o %[^abcd] |
301 | matches strings containing any characters except <>, <>, |
301 | matches strings containing any characters except <>, <>, |
302 | < |
302 | < |
303 | 303 | ||
304 | o %[A-DW-Z] |
304 | o %[A-DW-Z] |
305 | matches strings containing <>, <>, < |
305 | matches strings containing <>, <>, < |
306 | < |
306 | < |
307 | 307 | ||
308 | o %[z-a] |
308 | o %[z-a] |
309 | matches the characters < |
309 | matches the characters < |
310 | o- |
310 | o- |
311 | 311 | ||
312 | Floating point numbers (for field types < |
312 | Floating point numbers (for field types < |
313 | < |
313 | < |
314 | 314 | ||
315 | . [+/-] ddddd[.]ddd [E|e[+|-]ddd] |
315 | . [+/-] ddddd[.]ddd [E|e[+|-]ddd] |
316 | 316 | ||
317 | where objects inclosed in square brackets are optional, and < |
317 | where objects inclosed in square brackets are optional, and < |
318 | represents decimal, octal, or hexadecimal digits. |
318 | represents decimal, octal, or hexadecimal digits. |
319 | o- |
319 | o- |
320 | 320 | ||
321 | RETURNS |
321 | RETURNS |
322 | < |
322 | < |
323 | scanned, converted and stored; the return value does |
323 | scanned, converted and stored; the return value does |
324 | not include scanned fields which were not stored. |
324 | not include scanned fields which were not stored. |
325 | 325 | ||
326 | If < |
326 | If < |
327 | value is < |
327 | value is < |
328 | 328 | ||
329 | If no fields were stored, the return value is <<0>>. |
329 | If no fields were stored, the return value is <<0>>. |
330 | 330 | ||
331 | < |
331 | < |
332 | reaching the normal field end character, or may |
332 | reaching the normal field end character, or may |
333 | terminate entirely. |
333 | terminate entirely. |
334 | 334 | ||
335 | < |
335 | < |
336 | and moves to the next input field (if any) |
336 | and moves to the next input field (if any) |
337 | in any of the following situations: |
337 | in any of the following situations: |
338 | 338 | ||
339 | O+ |
339 | O+ |
340 | o The assignment suppressing character (<<*>>) appears |
340 | o The assignment suppressing character (<<*>>) appears |
341 | after the <<%>> in the format specification; the current |
341 | after the <<%>> in the format specification; the current |
342 | input field is scanned but not stored. |
342 | input field is scanned but not stored. |
343 | 343 | ||
344 | o <[width]> characters have been read (<[width]> is a |
344 | o <[width]> characters have been read (<[width]> is a |
345 | width specification, a positive decimal integer). |
345 | width specification, a positive decimal integer). |
346 | 346 | ||
347 | o The next character read cannot be converted |
347 | o The next character read cannot be converted |
348 | under the the current format (for example, |
348 | under the the current format (for example, |
349 | if a < |
349 | if a < |
350 | 350 | ||
351 | o The next character in the input field does not appear |
351 | o The next character in the input field does not appear |
352 | in the search set (or does appear in the inverted search set). |
352 | in the search set (or does appear in the inverted search set). |
353 | O- |
353 | O- |
354 | 354 | ||
355 | When < |
355 | When < |
356 | these reasons, the next character is considered unread and |
356 | these reasons, the next character is considered unread and |
357 | used as the first character of the following input field, or the |
357 | used as the first character of the following input field, or the |
358 | first character in a subsequent read operation on the input. |
358 | first character in a subsequent read operation on the input. |
359 | 359 | ||
360 | < |
360 | < |
361 | 361 | ||
362 | O+ |
362 | O+ |
363 | o The next character in the input field conflicts |
363 | o The next character in the input field conflicts |
364 | with a corresponding non-whitespace character in the |
364 | with a corresponding non-whitespace character in the |
365 | format string. |
365 | format string. |
366 | 366 | ||
367 | o The next character in the input field is < |
367 | o The next character in the input field is < |
368 | 368 | ||
369 | o The format string has been exhausted. |
369 | o The format string has been exhausted. |
370 | O- |
370 | O- |
371 | 371 | ||
372 | When the format string contains a character sequence that is |
372 | When the format string contains a character sequence that is |
373 | not part of a format specification, the same character |
373 | not part of a format specification, the same character |
374 | sequence must appear in the input; < |
374 | sequence must appear in the input; < |
375 | scan but not store the matched characters. If a |
375 | scan but not store the matched characters. If a |
376 | conflict occurs, the first conflicting character remains in the input |
376 | conflict occurs, the first conflicting character remains in the input |
377 | as if it had never been read. |
377 | as if it had never been read. |
378 | 378 | ||
379 | PORTABILITY |
379 | PORTABILITY |
380 | < |
380 | < |
381 | 381 | ||
382 | Supporting OS subroutines required: < |
382 | Supporting OS subroutines required: < |
383 | < |
383 | < |
384 | */ |
384 | */ |
385 | 385 | ||
386 | #include <_ansi.h> |
386 | #include <_ansi.h> |
387 | #include |
387 | #include |
388 | #include |
388 | #include |
389 | #include |
389 | #include |
390 | #ifdef _HAVE_STDC |
390 | #ifdef _HAVE_STDC |
391 | #include |
391 | #include |
392 | #else |
392 | #else |
393 | #include |
393 | #include |
394 | #endif |
394 | #endif |
395 | #include "local.h" |
395 | #include "local.h" |
396 | 396 | ||
397 | #ifndef _REENT_ONLY |
397 | #ifndef _REENT_ONLY |
398 | 398 | ||
399 | #ifdef _HAVE_STDC |
399 | #ifdef _HAVE_STDC |
400 | int |
400 | int |
401 | _DEFUN(sscanf, (str, fmt), |
401 | _DEFUN(sscanf, (str, fmt), |
402 | _CONST char *str _AND |
402 | _CONST char *__restrict str _AND |
403 | _CONST char *fmt _DOTS) |
403 | _CONST char * fmt _DOTS) |
404 | #else |
404 | #else |
405 | int |
405 | int |
406 | sscanf(str, fmt, va_alist) |
406 | sscanf(str, fmt, va_alist) |
407 | _CONST char *str; |
407 | _CONST char *str; |
408 | _CONST char *fmt; |
408 | _CONST char *fmt; |
409 | va_dcl |
409 | va_dcl |
410 | #endif |
410 | #endif |
411 | { |
411 | { |
412 | int ret; |
412 | int ret; |
413 | va_list ap; |
413 | va_list ap; |
414 | FILE f; |
414 | FILE f; |
415 | 415 | ||
416 | f._flags = __SRD | __SSTR; |
416 | f._flags = __SRD | __SSTR; |
417 | f._bf._base = f._p = (unsigned char *) str; |
417 | f._bf._base = f._p = (unsigned char *) str; |
418 | f._bf._size = f._r = strlen (str); |
418 | f._bf._size = f._r = strlen (str); |
419 | f._read = __seofread; |
419 | f._read = __seofread; |
420 | f._ub._base = NULL; |
420 | f._ub._base = NULL; |
421 | f._lb._base = NULL; |
421 | f._lb._base = NULL; |
422 | f._file = -1; /* No file. */ |
422 | f._file = -1; /* No file. */ |
423 | #ifdef _HAVE_STDC |
423 | #ifdef _HAVE_STDC |
424 | va_start (ap, fmt); |
424 | va_start (ap, fmt); |
425 | #else |
425 | #else |
426 | va_start (ap); |
426 | va_start (ap); |
427 | #endif |
427 | #endif |
428 | ret = __ssvfscanf_r (_REENT, &f, fmt, ap); |
428 | ret = __ssvfscanf_r (_REENT, &f, fmt, ap); |
429 | va_end (ap); |
429 | va_end (ap); |
430 | return ret; |
430 | return ret; |
431 | } |
431 | } |
432 | 432 | ||
433 | #endif /* !_REENT_ONLY */ |
433 | #endif /* !_REENT_ONLY */ |
434 | 434 | ||
435 | #ifdef _HAVE_STDC |
435 | #ifdef _HAVE_STDC |
436 | int |
436 | int |
437 | _DEFUN(_sscanf_r, (ptr, str, fmt), |
437 | _DEFUN(_sscanf_r, (ptr, str, fmt), |
438 | struct _reent *ptr _AND |
438 | struct _reent *ptr _AND |
439 | _CONST char *str _AND |
439 | _CONST char *__restrict str _AND |
440 | _CONST char *fmt _DOTS) |
440 | _CONST char *__restrict fmt _DOTS) |
441 | #else |
441 | #else |
442 | int |
442 | int |
443 | _sscanf_r(ptr, str, fmt, va_alist) |
443 | _sscanf_r(ptr, str, fmt, va_alist) |
444 | struct _reent *ptr; |
444 | struct _reent *ptr; |
445 | _CONST char *str; |
445 | _CONST char *__restrict str; |
446 | _CONST char *fmt; |
446 | _CONST char *__restrict fmt; |
447 | va_dcl |
447 | va_dcl |
448 | #endif |
448 | #endif |
449 | { |
449 | { |
450 | int ret; |
450 | int ret; |
451 | va_list ap; |
451 | va_list ap; |
452 | FILE f; |
452 | FILE f; |
453 | 453 | ||
454 | f._flags = __SRD | __SSTR; |
454 | f._flags = __SRD | __SSTR; |
455 | f._bf._base = f._p = (unsigned char *) str; |
455 | f._bf._base = f._p = (unsigned char *) str; |
456 | f._bf._size = f._r = strlen (str); |
456 | f._bf._size = f._r = strlen (str); |
457 | f._read = __seofread; |
457 | f._read = __seofread; |
458 | f._ub._base = NULL; |
458 | f._ub._base = NULL; |
459 | f._lb._base = NULL; |
459 | f._lb._base = NULL; |
460 | f._file = -1; /* No file. */ |
460 | f._file = -1; /* No file. */ |
461 | #ifdef _HAVE_STDC |
461 | #ifdef _HAVE_STDC |
462 | va_start (ap, fmt); |
462 | va_start (ap, fmt); |
463 | #else |
463 | #else |
464 | va_start (ap); |
464 | va_start (ap); |
465 | #endif |
465 | #endif |
466 | ret = __ssvfscanf_r (ptr, &f, fmt, ap); |
466 | ret = __ssvfscanf_r (ptr, &f, fmt, ap); |
467 | va_end (ap); |
467 | va_end (ap); |
468 | return ret; |
468 | return ret; |
469 | } |
469 | } |