newlib-cygwin/newlib/libc/stdio/sscanf.c

479 lines
13 KiB
C
Raw Normal View History

2000-02-18 03:39:52 +08:00
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* and/or other materials related to such
2000-02-18 03:39:52 +08:00
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<sscanf>>, <<fscanf>>, <<scanf>>---scan and format input
2000-02-18 03:39:52 +08:00
INDEX
scanf
INDEX
_scanf_r
2000-02-18 03:39:52 +08:00
INDEX
fscanf
INDEX
_fscanf_r
2000-02-18 03:39:52 +08:00
INDEX
sscanf
INDEX
_sscanf_r
2000-02-18 03:39:52 +08:00
SYNOPSIS
2000-02-18 03:39:52 +08:00
#include <stdio.h>
int scanf(const char *restrict <[format]>, ...);
int fscanf(FILE *restrict <[fd]>, const char *restrict <[format]>, ...);
int sscanf(const char *restrict <[str]>, const char *restrict <[format]>, ...);
2000-02-18 03:39:52 +08:00
int _scanf_r(struct _reent *<[ptr]>, const char *restrict <[format]>, ...);
int _fscanf_r(struct _reent *<[ptr]>, FILE *restrict <[fd]>,
const char *restrict <[format]>, ...);
int _sscanf_r(struct _reent *<[ptr]>, const char *restrict <[str]>,
const char *restrict <[format]>, ...);
2000-02-18 03:39:52 +08:00
DESCRIPTION
<<scanf>> scans a series of input fields from standard input,
one character at a time. Each field is interpreted according to
a format specifier passed to <<scanf>> in the format string at
<<*<[format]>>>. <<scanf>> stores the interpreted input from
each field at the address passed to it as the corresponding argument
following <[format]>. You must supply the same number of
format specifiers and address arguments as there are input fields.
There must be sufficient address arguments for the given format
specifiers; if not the results are unpredictable and likely
disasterous. Excess address arguments are merely ignored.
<<scanf>> often produces unexpected results if the input diverges from
an expected pattern. Since the combination of <<gets>> or <<fgets>>
followed by <<sscanf>> is safe and easy, that is the preferred way
to be certain that a program is synchronized with input at the end
of a line.
<<fscanf>> and <<sscanf>> are identical to <<scanf>>, other than the
source of input: <<fscanf>> reads from a file, and <<sscanf>>
from a string.
The routines <<_scanf_r>>, <<_fscanf_r>>, and <<_sscanf_r>> are reentrant
versions of <<scanf>>, <<fscanf>>, and <<sscanf>> that take an additional
first argument pointing to a reentrancy structure.
2000-02-18 03:39:52 +08:00
The string at <<*<[format]>>> is a character sequence composed
of zero or more directives. Directives are composed of
one or more whitespace characters, non-whitespace characters,
and format specifications.
Whitespace characters are blank (<< >>), tab (<<\t>>), or
newline (<<\n>>).
When <<scanf>> encounters a whitespace character in the format string
it will read (but not store) all consecutive whitespace characters
up to the next non-whitespace character in the input.
Non-whitespace characters are all other ASCII characters except the
percent sign (<<%>>). When <<scanf>> encounters a non-whitespace
character in the format string it will read, but not store
a matching non-whitespace character.
Format specifications tell <<scanf>> to read and convert characters
from the input field into specific types of values, and store then
in the locations specified by the address arguments.
Trailing whitespace is left unread unless explicitly
matched in the format string.
The format specifiers must begin with a percent sign (<<%>>)
and have the following form:
. %[*][<[width]>][<[size]>]<[type]>
Each format specification begins with the percent character (<<%>>).
The other fields are:
O+
2000-02-18 03:39:52 +08:00
o *
2000-02-18 03:39:52 +08:00
an optional marker; if present, it suppresses interpretation and
assignment of this input field.
o <[width]>
2000-02-18 03:39:52 +08:00
an optional maximum field width: a decimal integer,
which controls the maximum number of characters that
will be read before converting the current input field. If the
input field has fewer than <[width]> characters, <<scanf>>
reads all the characters in the field, and then
proceeds with the next field and its format specification.
If a whitespace or a non-convertable character occurs
before <[width]> character are read, the characters up
to that character are read, converted, and stored.
Then <<scanf>> proceeds to the next format specification.
o <[size]>
<<h>>, <<j>>, <<l>>, <<L>>, <<t>>, and <<z>> are optional size
characters which override the default way that <<scanf>>
interprets the data type of the corresponding argument.
2000-02-18 03:39:52 +08:00
@multitable @columnfractions 0.18 0.30 0.52
@headitem
Modifier
@tab
Type(s)
@tab
@item
hh
@tab
d, i, o, u, x, n
@tab
convert input to char, store in char object
@item
h
@tab
d, i, o, u, x, n
@tab
convert input to short, store in short object
@item
h
@tab
D, I, O, U, X, e, f, c, s, p
@tab
no effect
@item
j
@tab
d, i, o, u, x, n
@tab
convert input to intmax_t, store in intmax_t object
@item
j
@tab
all others
@tab
no effect
@item
l
@tab
d, i, o, u, x, n
@tab
convert input to long, store in long object
@item
l
@tab
e, f, g
@tab
convert input to double, store in a double object
@item
l
@tab
D, I, O, U, X, c, s, p
@tab
no effect
@item
ll
@tab
d, i, o, u, x, n
@tab
convert to long long, store in long long object
@item
L
@tab
d, i, o, u, x, n
@tab
convert to long long, store in long long object
@item
L
@tab
e, f, g, E, G
@tab
convert to long double, store in long double object
@item
L
@tab
all others
@tab
no effect
@item
t
@tab
d, i, o, u, x, n
@tab
convert input to ptrdiff_t, store in ptrdiff_t object
@item
t
@tab
all others
@tab
no effect
@item
z
@tab
d, i, o, u, x, n
@tab
convert input to size_t, store in size_t object
@item
z
@tab
all others
@tab
no effect
@end multitable
2000-02-18 03:39:52 +08:00
o <[type]>
A character to specify what kind of conversion
<<scanf>> performs. Here is a table of the conversion
characters:
o+
o %
2000-02-18 03:39:52 +08:00
No conversion is done; the percent character (<<%>>) is stored.
o c
Scans one character. Corresponding <[arg]>: <<(char *arg)>>.
o s
Reads a character string into the array supplied.
Corresponding <[arg]>: <<(char arg[])>>.
o [<[pattern]>]
2000-02-18 03:39:52 +08:00
Reads a non-empty character string into memory
starting at <[arg]>. This area must be large
enough to accept the sequence and a
terminating null character which will be added
automatically. (<[pattern]> is discussed in the paragraph following
this table). Corresponding <[arg]>: <<(char *arg)>>.
o d
Reads a decimal integer into the corresponding <[arg]>: <<(int *arg)>>.
o D
Reads a decimal integer into the corresponding
<[arg]>: <<(long *arg)>>.
o o
Reads an octal integer into the corresponding <[arg]>: <<(int *arg)>>.
o O
Reads an octal integer into the corresponding <[arg]>: <<(long *arg)>>.
o u
Reads an unsigned decimal integer into the corresponding
<[arg]>: <<(unsigned int *arg)>>.
o U
Reads an unsigned decimal integer into the corresponding <[arg]>:
<<(unsigned long *arg)>>.
o x,X
Read a hexadecimal integer into the corresponding <[arg]>:
<<(int *arg)>>.
o e, f, g
2003-10-20 Bob Wilson <bob.wilson@acm.org> * libc/locale/locale.c: Use double quotes in code. * libc/locale/locale.tex: Likewise. * libc/libc.texinfo: Hyphenate "floating-point". * libc/machine/necv70/necv70.tex: Likewise. * libc/stdio/sprintf.c: Likewise. * libc/stdio/sscanf.c: Likewise. * libc/stdlib/atof.c: Likewise. * libc/stdlib/ldtoa.c: Fix comment typo. * libc/stdlib/div.c: Use @ifnottex instead of @ifinfo. * libc/stdlib/ldiv.c: Likewise. * libm/common/s_expm1.c: Likewise. * libm/common/s_ilogb.c: Hyphenate "floating-point". Use "nonzero". * libm/common/s_infinity: Hyphenate "double- and single-precision". * libm/common/s_nan.c: Likewise. Also correct the FUNCTION summary. * libm/common/s_nextafter.c: Fix typo. Hyphenate "double-precision" and "floating-point". * libm/common/s_scalbn.c: Correct the FUNCTION summary. * libm/math/e_pow.c: Fix comment typo. * libm/math/math.tex: Hyphenate "single-precision" and "floating-point". * libm/math/s_asinh.c: Use @ifnottex instead of @ifinfo. * libm/math/s_atan.c: Likewise. * libm/math/s_frexp.c: Likewise. Also use "nonzero". * libm/math/s_isnan.c: Hyphenate "single-precision" and "floating-point". Use "nonzero". * libm/math/s_ldexp.c: Use @ifnottex instead of @ifinfo. * libm/math/w_acos.c: Likewise. * libm/math/w_acosh.c: Likewise. * libm/math/w_asin.c: Likewise. * libm/math/w_atan2.c: Likewise. * libm/math/w_atanh.c: Likewise. * libm/math/w_cosh.c: Likewise. * libm/math/w_exp.c: Likewise. * libm/math/w_exp2.c: Likewise. Add missing @end and missing @tex version of 2^x in the description. * libm/math/w_fmod.c: Use @ifnottex instead of @ifinfo. * libm/math/w_gamma.c: Likewise. * libm/math/w_hypot.c: Likewise. * libm/math/w_j0.c: Likewise. * libm/math/w_sinh.c: Likewise. * libm/math/w_pow.c: Replace "exp1.0nt" with "exponent". * libm/mathfp/mathfp.tex: Hyphenate "single-precision" and "floating-point". * libm/mathfp/e_acosh.c: Use @ifnottex instead of @ifinfo. * libm/mathfp/e_atanh.c: Likewise. * libm/mathfp/e_hypot.c: Likewise. * libm/mathfp/er_lgamma.c: Likewise. * libm/mathfp/s_acos.c: Likewise. * libm/mathfp/s_asine.c: Likewise. * libm/mathfp/s_asinh.c: Likewise. * libm/mathfp/s_atan.c: Likewise. * libm/mathfp/s_atan2.c: Likewise. * libm/mathfp/s_atangent.c: Likewise. * libm/mathfp/s_cosh.c: Likewise. * libm/mathfp/s_exp.c: Likewise. * libm/mathfp/s_fmod.c: Likewise. * libm/mathfp/s_frexp.c: Likewise. Also use "nonzero". * libm/mathfp/s_isnan.c: Hyphenate "single-precision" and "floating-point". Use "nonzero". * libm/math/s_pow.c: Replace "exp1.0nt" with "exponent". * libm/mathfp/s_ldexp.c: Use @ifnottex instead of @ifinfo. * libm/mathfp/s_sineh.c: Likewise. * libm/mathfp/w_jn.c: Likewise.
2003-10-21 02:46:38 +08:00
Read a floating-point number into the corresponding <[arg]>:
2000-02-18 03:39:52 +08:00
<<(float *arg)>>.
o E, F, G
2003-10-20 Bob Wilson <bob.wilson@acm.org> * libc/locale/locale.c: Use double quotes in code. * libc/locale/locale.tex: Likewise. * libc/libc.texinfo: Hyphenate "floating-point". * libc/machine/necv70/necv70.tex: Likewise. * libc/stdio/sprintf.c: Likewise. * libc/stdio/sscanf.c: Likewise. * libc/stdlib/atof.c: Likewise. * libc/stdlib/ldtoa.c: Fix comment typo. * libc/stdlib/div.c: Use @ifnottex instead of @ifinfo. * libc/stdlib/ldiv.c: Likewise. * libm/common/s_expm1.c: Likewise. * libm/common/s_ilogb.c: Hyphenate "floating-point". Use "nonzero". * libm/common/s_infinity: Hyphenate "double- and single-precision". * libm/common/s_nan.c: Likewise. Also correct the FUNCTION summary. * libm/common/s_nextafter.c: Fix typo. Hyphenate "double-precision" and "floating-point". * libm/common/s_scalbn.c: Correct the FUNCTION summary. * libm/math/e_pow.c: Fix comment typo. * libm/math/math.tex: Hyphenate "single-precision" and "floating-point". * libm/math/s_asinh.c: Use @ifnottex instead of @ifinfo. * libm/math/s_atan.c: Likewise. * libm/math/s_frexp.c: Likewise. Also use "nonzero". * libm/math/s_isnan.c: Hyphenate "single-precision" and "floating-point". Use "nonzero". * libm/math/s_ldexp.c: Use @ifnottex instead of @ifinfo. * libm/math/w_acos.c: Likewise. * libm/math/w_acosh.c: Likewise. * libm/math/w_asin.c: Likewise. * libm/math/w_atan2.c: Likewise. * libm/math/w_atanh.c: Likewise. * libm/math/w_cosh.c: Likewise. * libm/math/w_exp.c: Likewise. * libm/math/w_exp2.c: Likewise. Add missing @end and missing @tex version of 2^x in the description. * libm/math/w_fmod.c: Use @ifnottex instead of @ifinfo. * libm/math/w_gamma.c: Likewise. * libm/math/w_hypot.c: Likewise. * libm/math/w_j0.c: Likewise. * libm/math/w_sinh.c: Likewise. * libm/math/w_pow.c: Replace "exp1.0nt" with "exponent". * libm/mathfp/mathfp.tex: Hyphenate "single-precision" and "floating-point". * libm/mathfp/e_acosh.c: Use @ifnottex instead of @ifinfo. * libm/mathfp/e_atanh.c: Likewise. * libm/mathfp/e_hypot.c: Likewise. * libm/mathfp/er_lgamma.c: Likewise. * libm/mathfp/s_acos.c: Likewise. * libm/mathfp/s_asine.c: Likewise. * libm/mathfp/s_asinh.c: Likewise. * libm/mathfp/s_atan.c: Likewise. * libm/mathfp/s_atan2.c: Likewise. * libm/mathfp/s_atangent.c: Likewise. * libm/mathfp/s_cosh.c: Likewise. * libm/mathfp/s_exp.c: Likewise. * libm/mathfp/s_fmod.c: Likewise. * libm/mathfp/s_frexp.c: Likewise. Also use "nonzero". * libm/mathfp/s_isnan.c: Hyphenate "single-precision" and "floating-point". Use "nonzero". * libm/math/s_pow.c: Replace "exp1.0nt" with "exponent". * libm/mathfp/s_ldexp.c: Use @ifnottex instead of @ifinfo. * libm/mathfp/s_sineh.c: Likewise. * libm/mathfp/w_jn.c: Likewise.
2003-10-21 02:46:38 +08:00
Read a floating-point number into the corresponding <[arg]>:
2000-02-18 03:39:52 +08:00
<<(double *arg)>>.
o i
2000-02-18 03:39:52 +08:00
Reads a decimal, octal or hexadecimal integer into the
corresponding <[arg]>: <<(int *arg)>>.
o I
2000-02-18 03:39:52 +08:00
Reads a decimal, octal or hexadecimal integer into the
corresponding <[arg]>: <<(long *arg)>>.
o n
2000-02-18 03:39:52 +08:00
Stores the number of characters read in the corresponding
<[arg]>: <<(int *arg)>>.
o p
2000-02-18 03:39:52 +08:00
Stores a scanned pointer. ANSI C leaves the details
to each implementation; this implementation treats
<<%p>> exactly the same as <<%U>>. Corresponding
<[arg]>: <<(void **arg)>>.
o-
A <[pattern]> of characters surrounded by square brackets can be used
instead of the <<s>> type character. <[pattern]> is a set of
characters which define a search set of possible characters making up
the <<scanf>> input field. If the first character in the brackets is a
caret (<<^>>), the search set is inverted to include all ASCII characters
except those between the brackets. There is also a range facility
which you can use as a shortcut. <<%[0-9] >> matches all decimal digits.
The hyphen must not be the first or last character in the set.
The character prior to the hyphen must be lexically less than the
character after it.
Here are some <[pattern]> examples:
o+
o %[abcd]
matches strings containing only <<a>>, <<b>>, <<c>>, and <<d>>.
o %[^abcd]
matches strings containing any characters except <<a>>, <<b>>,
<<c>>, or <<d>>
o %[A-DW-Z]
matches strings containing <<A>>, <<B>>, <<C>>, <<D>>, <<W>>,
<<X>>, <<Y>>, <<Z>>
o %[z-a]
matches the characters <<z>>, <<->>, and <<a>>
o-
Floating point numbers (for field types <<e>>, <<f>>, <<g>>, <<E>>,
<<F>>, <<G>>) must correspond to the following general form:
. [+/-] ddddd[.]ddd [E|e[+|-]ddd]
where objects inclosed in square brackets are optional, and <<ddd>>
represents decimal, octal, or hexadecimal digits.
O-
2000-02-18 03:39:52 +08:00
RETURNS
<<scanf>> returns the number of input fields successfully
scanned, converted and stored; the return value does
not include scanned fields which were not stored.
If <<scanf>> attempts to read at end-of-file, the return
value is <<EOF>>.
If no fields were stored, the return value is <<0>>.
<<scanf>> might stop scanning a particular field before
reaching the normal field end character, or may
terminate entirely.
<<scanf>> stops scanning and storing the current field
and moves to the next input field (if any)
in any of the following situations:
O+
o The assignment suppressing character (<<*>>) appears
after the <<%>> in the format specification; the current
input field is scanned but not stored.
o <[width]> characters have been read (<[width]> is a
width specification, a positive decimal integer).
o The next character read cannot be converted
under the the current format (for example,
if a <<Z>> is read when the format is decimal).
o The next character in the input field does not appear
in the search set (or does appear in the inverted search set).
O-
When <<scanf>> stops scanning the current input field for one of
these reasons, the next character is considered unread and
used as the first character of the following input field, or the
first character in a subsequent read operation on the input.
<<scanf>> will terminate under the following circumstances:
O+
o The next character in the input field conflicts
with a corresponding non-whitespace character in the
format string.
o The next character in the input field is <<EOF>>.
o The format string has been exhausted.
O-
When the format string contains a character sequence that is
not part of a format specification, the same character
sequence must appear in the input; <<scanf>> will
scan but not store the matched characters. If a
conflict occurs, the first conflicting character remains in the input
as if it had never been read.
PORTABILITY
<<scanf>> is ANSI C.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "local.h"
#ifndef _REENT_ONLY
2000-02-18 03:39:52 +08:00
int
sscanf (const char *__restrict str,
const char * fmt, ...)
2000-02-18 03:39:52 +08:00
{
int ret;
va_list ap;
FILE f;
f._flags = __SRD | __SSTR;
2000-02-18 03:39:52 +08:00
f._bf._base = f._p = (unsigned char *) str;
f._bf._size = f._r = strlen (str);
f._read = __seofread;
2000-02-18 03:39:52 +08:00
f._ub._base = NULL;
f._lb._base = NULL;
f._file = -1; /* No file. */
2000-02-18 03:39:52 +08:00
va_start (ap, fmt);
2008-04-14 Jeff Johnston <jjohnstn@redhat.com> * libc/stdio/Makefile.am: Build vfprintf.c and vfscanf.c with -DSTRING_ONLY defined with and without -DINTEGER_ONLY defined to build special versions for sprintf/sscanf family functions. * libc/stdio/Makefile.in: Regenerated. * libc/stdio/vfprintf.c[STRING_ONLY][INTEGER_ONLY](_VFPRINTF_R): Redefine to be _svfiprintf_r which is optimized to work with siprintf family of functions (i.e. no I/O) and does not support floating-point. [STRING_ONLY][!INTEGER_ONLY](_VFPRINTF_R): Redefine to be _svfprintf_r which is optimized to work with sprintf family of functions and not use I/O. [STRING_ONLY](__sprint_r): New string only version of static function. designed to work with sprintf family of functions. * libc/stdio/vfscanf.c[STRING_ONLY][INTEGER_ONLY](_SVFSCANF_R): Redefine to be _ssvfiscanf_r which is optimized to work with siscanf family of functions (i.e. no I/O) and no float-point support. [STRING_ONLY][!INTEGER_ONLY](_SVFSCANF_R): Redefine to be __ssvfscanf_r which is optimized to work with sscanf family of functions and does not require I/O functions. * libc/stdio/asprintf.c: Call _svfprintf_r instead of _vfprintf_r. * libc/stdio/snprintf.c: Ditto. * libc/stdio/sprintf.c: Ditto. * libc/stdio/vasnprintf.c: Ditto. * libc/stdio/vasprintf.c: Ditto. * libc/stdio/siprintf.c: Call _svfiprintf_r instead of _vfiprintf_r. * libc/stdio/sniprintf.c: Ditto. * libc/stdio/vasiprintf.c: Ditto. * libc/stdio/vsiprintf.c: Ditto. * libc/stdio/vsniprintf.c: Ditto. * libc/stdio/vsprintf.c: Ditto. * libc/stdio/local.h: Add prototypes for _svfprintf_r, _svfiprintf_r, _ssvfscanf_r, and _ssvfiscanf_r. * libc/stdio/sscanf.c: Call _ssvfscanf_r instead of _svfscanf_r. * libc/stdio/vsscanf.c: Ditto. * libc/stdio/siscanf.c: Call _ssvfiscanf_r instead of _svfiscanf_r. * libc/stdio/vsiscanf.c: Ditto.
2008-04-15 05:14:55 +08:00
ret = __ssvfscanf_r (_REENT, &f, fmt, ap);
va_end (ap);
return ret;
}
2014-07-04 Bin Cheng <bin.cheng@arm.com> * README (--enable-newlib-nano-formatted-io): Describe. * acconfig.h (_NANO_FORMATTED_IO): Undef. * newlib.hin (_NANO_FORMATTED_IO): Undef. * configure.in (--enable-newlib-nano-formatted-io): New option. * configure: Regenerated. * libc/configure.in (--enable-newlib-nano-formatted-io): New option. * libc/configure: Regenerated. * libc/stdio/Makefile.am (NEWLIB_NANO_FORMATTED_IO): Support new configuration option. * libc/stdio/Makefile.in: Regenerated. * libc/stdio/asnprintf.c (_asniprintf_r, asniprintf): Use _NANO_FORMATTED_IO to declare alias prototypes. * libc/stdio/asprintf.c (_asiprintf_r, asiprintf): Ditto. * libc/stdio/dprintf.c (_diprintf_r, diprintf): Ditto. * libc/stdio/fprintf.c (_fiprintf_r, fiprintf): Ditto. * libc/stdio/fscanf.c (fiscanf, _fiscanf_r): Ditto. * libc/stdio/printf.c (_iprintf_r, iprintf): Ditto. * libc/stdio/scanf.c (iscanf, _iscanf_r): Ditto. * libc/stdio/snprintf.c (_sniprintf_r, sniprintf): Ditto. * libc/stdio/sprintf.c (_siprintf_r, siprintf): Ditto. * libc/stdio/sscanf.c (siscanf, _siscanf_r): Ditto. * libc/stdio/vasnprintf.c (_vasniprintf_r, vasniprintf): Ditto. * libc/stdio/vasprintf.c (vasiprintf, _vasiprintf_r): Ditto. * libc/stdio/vdprintf.c (_vdiprintf_r, vdiprintf): Ditto. * libc/stdio/vprintf.c (viprintf, _viprintf_r): Ditto. * libc/stdio/vscanf.c (viscanf, _viscanf_r): Ditto. * libc/stdio/vsnprintf.c (vsniprintf, _vsniprintf_r): Ditto. * libc/stdio/vsprintf.c (vsiprintf, _vsiprintf_r): Ditto. * libc/stdio/vsscanf.c (vsiscanf, _vsiscanf_r): Ditto. * libc/stdio/nano-vfprintf.c: New file. * libc/stdio/nano-vfprintf_float.c: New file. * libc/stdio/nano-vfprintf_i.c: New file. * libc/stdio/nano-vfprintf_local.h: New file. * libc/stdio/nano-vfscanf.c: New file. * libc/stdio/nano-vfscanf_float.c: New file. * libc/stdio/nano-vfscanf_i.c: New file. * libc/stdio/nano-vfscanf_local.h: New file.
2014-07-05 01:21:45 +08:00
#ifdef _NANO_FORMATTED_IO
int
siscanf (const char *, const char *, ...)
_ATTRIBUTE ((__alias__("sscanf")));
2014-07-04 Bin Cheng <bin.cheng@arm.com> * README (--enable-newlib-nano-formatted-io): Describe. * acconfig.h (_NANO_FORMATTED_IO): Undef. * newlib.hin (_NANO_FORMATTED_IO): Undef. * configure.in (--enable-newlib-nano-formatted-io): New option. * configure: Regenerated. * libc/configure.in (--enable-newlib-nano-formatted-io): New option. * libc/configure: Regenerated. * libc/stdio/Makefile.am (NEWLIB_NANO_FORMATTED_IO): Support new configuration option. * libc/stdio/Makefile.in: Regenerated. * libc/stdio/asnprintf.c (_asniprintf_r, asniprintf): Use _NANO_FORMATTED_IO to declare alias prototypes. * libc/stdio/asprintf.c (_asiprintf_r, asiprintf): Ditto. * libc/stdio/dprintf.c (_diprintf_r, diprintf): Ditto. * libc/stdio/fprintf.c (_fiprintf_r, fiprintf): Ditto. * libc/stdio/fscanf.c (fiscanf, _fiscanf_r): Ditto. * libc/stdio/printf.c (_iprintf_r, iprintf): Ditto. * libc/stdio/scanf.c (iscanf, _iscanf_r): Ditto. * libc/stdio/snprintf.c (_sniprintf_r, sniprintf): Ditto. * libc/stdio/sprintf.c (_siprintf_r, siprintf): Ditto. * libc/stdio/sscanf.c (siscanf, _siscanf_r): Ditto. * libc/stdio/vasnprintf.c (_vasniprintf_r, vasniprintf): Ditto. * libc/stdio/vasprintf.c (vasiprintf, _vasiprintf_r): Ditto. * libc/stdio/vdprintf.c (_vdiprintf_r, vdiprintf): Ditto. * libc/stdio/vprintf.c (viprintf, _viprintf_r): Ditto. * libc/stdio/vscanf.c (viscanf, _viscanf_r): Ditto. * libc/stdio/vsnprintf.c (vsniprintf, _vsniprintf_r): Ditto. * libc/stdio/vsprintf.c (vsiprintf, _vsiprintf_r): Ditto. * libc/stdio/vsscanf.c (vsiscanf, _vsiscanf_r): Ditto. * libc/stdio/nano-vfprintf.c: New file. * libc/stdio/nano-vfprintf_float.c: New file. * libc/stdio/nano-vfprintf_i.c: New file. * libc/stdio/nano-vfprintf_local.h: New file. * libc/stdio/nano-vfscanf.c: New file. * libc/stdio/nano-vfscanf_float.c: New file. * libc/stdio/nano-vfscanf_i.c: New file. * libc/stdio/nano-vfscanf_local.h: New file.
2014-07-05 01:21:45 +08:00
#endif
#endif /* !_REENT_ONLY */
int
_sscanf_r (struct _reent *ptr,
const char *__restrict str,
const char *__restrict fmt, ...)
{
int ret;
va_list ap;
FILE f;
f._flags = __SRD | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
f._bf._size = f._r = strlen (str);
f._read = __seofread;
f._ub._base = NULL;
f._lb._base = NULL;
f._file = -1; /* No file. */
va_start (ap, fmt);
2008-04-14 Jeff Johnston <jjohnstn@redhat.com> * libc/stdio/Makefile.am: Build vfprintf.c and vfscanf.c with -DSTRING_ONLY defined with and without -DINTEGER_ONLY defined to build special versions for sprintf/sscanf family functions. * libc/stdio/Makefile.in: Regenerated. * libc/stdio/vfprintf.c[STRING_ONLY][INTEGER_ONLY](_VFPRINTF_R): Redefine to be _svfiprintf_r which is optimized to work with siprintf family of functions (i.e. no I/O) and does not support floating-point. [STRING_ONLY][!INTEGER_ONLY](_VFPRINTF_R): Redefine to be _svfprintf_r which is optimized to work with sprintf family of functions and not use I/O. [STRING_ONLY](__sprint_r): New string only version of static function. designed to work with sprintf family of functions. * libc/stdio/vfscanf.c[STRING_ONLY][INTEGER_ONLY](_SVFSCANF_R): Redefine to be _ssvfiscanf_r which is optimized to work with siscanf family of functions (i.e. no I/O) and no float-point support. [STRING_ONLY][!INTEGER_ONLY](_SVFSCANF_R): Redefine to be __ssvfscanf_r which is optimized to work with sscanf family of functions and does not require I/O functions. * libc/stdio/asprintf.c: Call _svfprintf_r instead of _vfprintf_r. * libc/stdio/snprintf.c: Ditto. * libc/stdio/sprintf.c: Ditto. * libc/stdio/vasnprintf.c: Ditto. * libc/stdio/vasprintf.c: Ditto. * libc/stdio/siprintf.c: Call _svfiprintf_r instead of _vfiprintf_r. * libc/stdio/sniprintf.c: Ditto. * libc/stdio/vasiprintf.c: Ditto. * libc/stdio/vsiprintf.c: Ditto. * libc/stdio/vsniprintf.c: Ditto. * libc/stdio/vsprintf.c: Ditto. * libc/stdio/local.h: Add prototypes for _svfprintf_r, _svfiprintf_r, _ssvfscanf_r, and _ssvfiscanf_r. * libc/stdio/sscanf.c: Call _ssvfscanf_r instead of _svfscanf_r. * libc/stdio/vsscanf.c: Ditto. * libc/stdio/siscanf.c: Call _ssvfiscanf_r instead of _svfiscanf_r. * libc/stdio/vsiscanf.c: Ditto.
2008-04-15 05:14:55 +08:00
ret = __ssvfscanf_r (ptr, &f, fmt, ap);
2000-02-18 03:39:52 +08:00
va_end (ap);
return ret;
}
2014-07-04 Bin Cheng <bin.cheng@arm.com> * README (--enable-newlib-nano-formatted-io): Describe. * acconfig.h (_NANO_FORMATTED_IO): Undef. * newlib.hin (_NANO_FORMATTED_IO): Undef. * configure.in (--enable-newlib-nano-formatted-io): New option. * configure: Regenerated. * libc/configure.in (--enable-newlib-nano-formatted-io): New option. * libc/configure: Regenerated. * libc/stdio/Makefile.am (NEWLIB_NANO_FORMATTED_IO): Support new configuration option. * libc/stdio/Makefile.in: Regenerated. * libc/stdio/asnprintf.c (_asniprintf_r, asniprintf): Use _NANO_FORMATTED_IO to declare alias prototypes. * libc/stdio/asprintf.c (_asiprintf_r, asiprintf): Ditto. * libc/stdio/dprintf.c (_diprintf_r, diprintf): Ditto. * libc/stdio/fprintf.c (_fiprintf_r, fiprintf): Ditto. * libc/stdio/fscanf.c (fiscanf, _fiscanf_r): Ditto. * libc/stdio/printf.c (_iprintf_r, iprintf): Ditto. * libc/stdio/scanf.c (iscanf, _iscanf_r): Ditto. * libc/stdio/snprintf.c (_sniprintf_r, sniprintf): Ditto. * libc/stdio/sprintf.c (_siprintf_r, siprintf): Ditto. * libc/stdio/sscanf.c (siscanf, _siscanf_r): Ditto. * libc/stdio/vasnprintf.c (_vasniprintf_r, vasniprintf): Ditto. * libc/stdio/vasprintf.c (vasiprintf, _vasiprintf_r): Ditto. * libc/stdio/vdprintf.c (_vdiprintf_r, vdiprintf): Ditto. * libc/stdio/vprintf.c (viprintf, _viprintf_r): Ditto. * libc/stdio/vscanf.c (viscanf, _viscanf_r): Ditto. * libc/stdio/vsnprintf.c (vsniprintf, _vsniprintf_r): Ditto. * libc/stdio/vsprintf.c (vsiprintf, _vsiprintf_r): Ditto. * libc/stdio/vsscanf.c (vsiscanf, _vsiscanf_r): Ditto. * libc/stdio/nano-vfprintf.c: New file. * libc/stdio/nano-vfprintf_float.c: New file. * libc/stdio/nano-vfprintf_i.c: New file. * libc/stdio/nano-vfprintf_local.h: New file. * libc/stdio/nano-vfscanf.c: New file. * libc/stdio/nano-vfscanf_float.c: New file. * libc/stdio/nano-vfscanf_i.c: New file. * libc/stdio/nano-vfscanf_local.h: New file.
2014-07-05 01:21:45 +08:00
#ifdef _NANO_FORMATTED_IO
int
_siscanf_r (struct _reent *, const char *, const char *, ...)
_ATTRIBUTE ((__alias__("_sscanf_r")));
2014-07-04 Bin Cheng <bin.cheng@arm.com> * README (--enable-newlib-nano-formatted-io): Describe. * acconfig.h (_NANO_FORMATTED_IO): Undef. * newlib.hin (_NANO_FORMATTED_IO): Undef. * configure.in (--enable-newlib-nano-formatted-io): New option. * configure: Regenerated. * libc/configure.in (--enable-newlib-nano-formatted-io): New option. * libc/configure: Regenerated. * libc/stdio/Makefile.am (NEWLIB_NANO_FORMATTED_IO): Support new configuration option. * libc/stdio/Makefile.in: Regenerated. * libc/stdio/asnprintf.c (_asniprintf_r, asniprintf): Use _NANO_FORMATTED_IO to declare alias prototypes. * libc/stdio/asprintf.c (_asiprintf_r, asiprintf): Ditto. * libc/stdio/dprintf.c (_diprintf_r, diprintf): Ditto. * libc/stdio/fprintf.c (_fiprintf_r, fiprintf): Ditto. * libc/stdio/fscanf.c (fiscanf, _fiscanf_r): Ditto. * libc/stdio/printf.c (_iprintf_r, iprintf): Ditto. * libc/stdio/scanf.c (iscanf, _iscanf_r): Ditto. * libc/stdio/snprintf.c (_sniprintf_r, sniprintf): Ditto. * libc/stdio/sprintf.c (_siprintf_r, siprintf): Ditto. * libc/stdio/sscanf.c (siscanf, _siscanf_r): Ditto. * libc/stdio/vasnprintf.c (_vasniprintf_r, vasniprintf): Ditto. * libc/stdio/vasprintf.c (vasiprintf, _vasiprintf_r): Ditto. * libc/stdio/vdprintf.c (_vdiprintf_r, vdiprintf): Ditto. * libc/stdio/vprintf.c (viprintf, _viprintf_r): Ditto. * libc/stdio/vscanf.c (viscanf, _viscanf_r): Ditto. * libc/stdio/vsnprintf.c (vsniprintf, _vsniprintf_r): Ditto. * libc/stdio/vsprintf.c (vsiprintf, _vsiprintf_r): Ditto. * libc/stdio/vsscanf.c (vsiscanf, _vsiscanf_r): Ditto. * libc/stdio/nano-vfprintf.c: New file. * libc/stdio/nano-vfprintf_float.c: New file. * libc/stdio/nano-vfprintf_i.c: New file. * libc/stdio/nano-vfprintf_local.h: New file. * libc/stdio/nano-vfscanf.c: New file. * libc/stdio/nano-vfscanf_float.c: New file. * libc/stdio/nano-vfscanf_i.c: New file. * libc/stdio/nano-vfscanf_local.h: New file.
2014-07-05 01:21:45 +08:00
#endif