1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSTDIO/SCANF.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,102 @@
1.4 +/* SCANF.C
1.5 + *
1.6 + * Portions Copyright (c) 1990-2006 Nokia Corporation and/or its subsidiary(-ies).
1.7 + * All rights reserved.
1.8 + */
1.9 +
1.10 +/*
1.11 + * Copyright (c) 1990 The Regents of the University of California.
1.12 + * All rights reserved.
1.13 + *
1.14 + * Redistribution and use in source and binary forms are permitted
1.15 + * provided that the above copyright notice and this paragraph are
1.16 + * duplicated in all such forms and that any documentation,
1.17 + * advertising materials, and other materials related to such
1.18 + * distribution and use acknowledge that the software was developed
1.19 + * by the University of California, Berkeley. The name of the
1.20 + * University may not be used to endorse or promote products derived
1.21 + * from this software without specific prior written permission.
1.22 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1.23 + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1.24 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1.25 + */
1.26 +
1.27 +#include <_ansi.h>
1.28 +#include <stdio_r.h>
1.29 +#include "LOCAL.H"
1.30 +#include <stdarg.h>
1.31 +
1.32 +/**
1.33 +Read formatted data from standard input.
1.34 +Reads data from the standard input and stores it into the locations given by argument(s).
1.35 +
1.36 +@param fmt String that can contain one or more of these items:
1.37 + Whitespace characters: the function will read and ignore any whitespace characters
1.38 + (this includes blank, newline and tab characters) encountered before the next
1.39 + non-whitespace character. This includes any quantity of whitespace characters
1.40 + (including none). Non-whitespace characters (any character not including blank,
1.41 + newline, tab, or any format specifier begining with % character): this cause that
1.42 + the function read and discard any character that match the given non-whitespace
1.43 + character.
1.44 + If this character is not found the function ends returning error.
1.45 +
1.46 +@return On Success, the number of items succesfully read.
1.47 + On Failure, EOF is returned and errno may be set.
1.48 +*/
1.49 +EXPORT_C int scanf (const char *fmt, ...)
1.50 +{
1.51 + int ret;
1.52 + va_list ap;
1.53 + struct _reent *r = _REENT2;
1.54 + if (!r)
1.55 + return EOF; // Memory for library globals is not allocated (errno not set).
1.56 + va_start (ap, fmt);
1.57 + ret = __svfscanf (_stdin_r (r), fmt, ap);
1.58 + va_end (ap);
1.59 + return ret;
1.60 +}
1.61 +
1.62 +/**
1.63 +A reentrant version of scanf().
1.64 +*/
1.65 +EXPORT_C int _scanf_r (struct _reent *ptr, const char *fmt, ...)
1.66 +{
1.67 + int ret;
1.68 + va_list ap;
1.69 +
1.70 + va_start (ap, fmt);
1.71 + ret = __svfscanf (_stdin_r (ptr), fmt, ap);
1.72 + va_end (ap);
1.73 + return (ret);
1.74 +}
1.75 +
1.76 +/**
1.77 +Read formatted data from a stream.
1.78 +Reads data from the current position of stream and stores it
1.79 +into the locations given by argument(s).
1.80 +Locations pointed by each argument are filled with their corresponding type of value
1.81 +requested in the format string.
1.82 +There must be the same number of type specifiers in format string than arguments passed.
1.83 +@return The number of items succesfully read.
1.84 +@param fp Pointer to an open file.
1.85 +@param fmt String that can contain one or more of these item:
1.86 +Whitespace characters: the function will read and ignore any whitespace characters
1.87 +(this includes blank, newline and tab characters)
1.88 +encountered before the next non-whitespace character.
1.89 +This includes any quantity of whitespace characters (including none).
1.90 +Non-whitespace characters (any character not including blank, newline, tab,
1.91 +or any format specifier begining with % character):
1.92 +this cause that the function read and discard any character that match the given non-whitespace character.
1.93 +If this character is not found the function ends returning error.
1.94 +*/
1.95 +EXPORT_C int
1.96 +fscanf (FILE * fp, const char *fmt, ...)
1.97 +{
1.98 + int ret;
1.99 + va_list ap;
1.100 +
1.101 + va_start (ap, fmt);
1.102 + ret = __svfscanf (fp, fmt, ap);
1.103 + va_end (ap);
1.104 + return ret;
1.105 +}