|
1 /* SCANF.C |
|
2 * |
|
3 * Portions Copyright (c) 1990-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
4 * All rights reserved. |
|
5 */ |
|
6 |
|
7 /* |
|
8 * Copyright (c) 1990 The Regents of the University of California. |
|
9 * All rights reserved. |
|
10 * |
|
11 * Redistribution and use in source and binary forms are permitted |
|
12 * provided that the above copyright notice and this paragraph are |
|
13 * duplicated in all such forms and that any documentation, |
|
14 * advertising materials, and other materials related to such |
|
15 * distribution and use acknowledge that the software was developed |
|
16 * by the University of California, Berkeley. The name of the |
|
17 * University may not be used to endorse or promote products derived |
|
18 * from this software without specific prior written permission. |
|
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
|
20 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
|
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
|
22 */ |
|
23 |
|
24 #include <_ansi.h> |
|
25 #include <stdio_r.h> |
|
26 #include "LOCAL.H" |
|
27 #include <stdarg.h> |
|
28 |
|
29 /** |
|
30 Read formatted data from standard input. |
|
31 Reads data from the standard input and stores it into the locations given by argument(s). |
|
32 |
|
33 @param fmt String that can contain one or more of these items: |
|
34 Whitespace characters: the function will read and ignore any whitespace characters |
|
35 (this includes blank, newline and tab characters) encountered before the next |
|
36 non-whitespace character. This includes any quantity of whitespace characters |
|
37 (including none). Non-whitespace characters (any character not including blank, |
|
38 newline, tab, or any format specifier begining with % character): this cause that |
|
39 the function read and discard any character that match the given non-whitespace |
|
40 character. |
|
41 If this character is not found the function ends returning error. |
|
42 |
|
43 @return On Success, the number of items succesfully read. |
|
44 On Failure, EOF is returned and errno may be set. |
|
45 */ |
|
46 EXPORT_C int scanf (const char *fmt, ...) |
|
47 { |
|
48 int ret; |
|
49 va_list ap; |
|
50 struct _reent *r = _REENT2; |
|
51 if (!r) |
|
52 return EOF; // Memory for library globals is not allocated (errno not set). |
|
53 va_start (ap, fmt); |
|
54 ret = __svfscanf (_stdin_r (r), fmt, ap); |
|
55 va_end (ap); |
|
56 return ret; |
|
57 } |
|
58 |
|
59 /** |
|
60 A reentrant version of scanf(). |
|
61 */ |
|
62 EXPORT_C int _scanf_r (struct _reent *ptr, const char *fmt, ...) |
|
63 { |
|
64 int ret; |
|
65 va_list ap; |
|
66 |
|
67 va_start (ap, fmt); |
|
68 ret = __svfscanf (_stdin_r (ptr), fmt, ap); |
|
69 va_end (ap); |
|
70 return (ret); |
|
71 } |
|
72 |
|
73 /** |
|
74 Read formatted data from a stream. |
|
75 Reads data from the current position of stream and stores it |
|
76 into the locations given by argument(s). |
|
77 Locations pointed by each argument are filled with their corresponding type of value |
|
78 requested in the format string. |
|
79 There must be the same number of type specifiers in format string than arguments passed. |
|
80 @return The number of items succesfully read. |
|
81 @param fp Pointer to an open file. |
|
82 @param fmt String that can contain one or more of these item: |
|
83 Whitespace characters: the function will read and ignore any whitespace characters |
|
84 (this includes blank, newline and tab characters) |
|
85 encountered before the next non-whitespace character. |
|
86 This includes any quantity of whitespace characters (including none). |
|
87 Non-whitespace characters (any character not including blank, newline, tab, |
|
88 or any format specifier begining with % character): |
|
89 this cause that the function read and discard any character that match the given non-whitespace character. |
|
90 If this character is not found the function ends returning error. |
|
91 */ |
|
92 EXPORT_C int |
|
93 fscanf (FILE * fp, const char *fmt, ...) |
|
94 { |
|
95 int ret; |
|
96 va_list ap; |
|
97 |
|
98 va_start (ap, fmt); |
|
99 ret = __svfscanf (fp, fmt, ap); |
|
100 va_end (ap); |
|
101 return ret; |
|
102 } |