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