sl@0: /* SCANF.C
sl@0:  * 
sl@0:  * Portions Copyright (c) 1990-2006 Nokia Corporation and/or its subsidiary(-ies).
sl@0:  * All rights reserved.
sl@0:  */
sl@0: 
sl@0: /*
sl@0:  * Copyright (c) 1990 The Regents of the University of California.
sl@0:  * All rights reserved.
sl@0:  *
sl@0:  * Redistribution and use in source and binary forms are permitted
sl@0:  * provided that the above copyright notice and this paragraph are
sl@0:  * duplicated in all such forms and that any documentation,
sl@0:  * advertising materials, and other materials related to such
sl@0:  * distribution and use acknowledge that the software was developed
sl@0:  * by the University of California, Berkeley.  The name of the
sl@0:  * University may not be used to endorse or promote products derived
sl@0:  * from this software without specific prior written permission.
sl@0:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
sl@0:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
sl@0:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
sl@0:  */
sl@0: 
sl@0: #include <_ansi.h>
sl@0: #include <stdio_r.h>
sl@0: #include "LOCAL.H"
sl@0: #include <stdarg.h>
sl@0: 
sl@0: /**
sl@0: Read formatted data from standard input.
sl@0: Reads data from the standard input and stores it into the locations given by argument(s). 
sl@0: 
sl@0: @param fmt String that can contain one or more of these items:
sl@0: 	   Whitespace characters: the function will read and ignore any whitespace characters
sl@0: 	   (this includes blank, newline and tab characters) encountered before the next
sl@0: 	   non-whitespace character. This includes any quantity of whitespace characters
sl@0: 	   (including none). Non-whitespace characters (any character not including blank,
sl@0: 	   newline, tab, or any format specifier begining with % character): this cause that
sl@0: 	   the function read and discard any character that match the given non-whitespace
sl@0: 	   character. 
sl@0: 	   If this character is not found the function ends returning error.
sl@0: 
sl@0: @return On Success, the number of items succesfully read. 
sl@0: 		On Failure, EOF is returned and errno may be set.
sl@0: */
sl@0: EXPORT_C int scanf (const char *fmt, ...)
sl@0: {
sl@0:   int ret;
sl@0:   va_list ap;
sl@0:   struct _reent *r = _REENT2;
sl@0:   if (!r)
sl@0: 	return EOF; // Memory for library globals is not allocated (errno not set). 
sl@0:   va_start (ap, fmt);
sl@0:   ret = __svfscanf (_stdin_r (r), fmt, ap);
sl@0:   va_end (ap);
sl@0:   return ret;
sl@0: }
sl@0: 
sl@0: /**
sl@0: A reentrant version of scanf().
sl@0: */
sl@0: EXPORT_C  int _scanf_r (struct _reent *ptr, const char *fmt, ...)
sl@0: {
sl@0:   int ret;
sl@0:   va_list ap;
sl@0: 
sl@0:   va_start (ap, fmt);
sl@0:   ret = __svfscanf (_stdin_r (ptr), fmt, ap);
sl@0:   va_end (ap);
sl@0:   return (ret);
sl@0: }
sl@0: 
sl@0: /**
sl@0: Read formatted data from a stream.
sl@0: Reads data from the current position of stream and stores it 
sl@0: into the locations given by argument(s).
sl@0: Locations pointed by each argument are filled with their corresponding type of value 
sl@0: requested in the format string.
sl@0: There must be the same number of type specifiers in format string than arguments passed.
sl@0: @return   The number of items succesfully read.
sl@0: @param fp Pointer to an open file. 
sl@0: @param fmt String that can contain one or more of these item:
sl@0: Whitespace characters: the function will read and ignore any whitespace characters 
sl@0: (this includes blank, newline and tab characters)
sl@0: encountered before the next non-whitespace character.
sl@0: This includes any quantity of whitespace characters (including none).
sl@0: Non-whitespace characters (any character not including blank, newline, tab,
sl@0: or any format specifier begining with % character): 
sl@0: this cause that the function read and discard any character that match the given non-whitespace character.
sl@0: If this character is not found the function ends returning error.
sl@0: */
sl@0: EXPORT_C int
sl@0: fscanf (FILE * fp, const char *fmt, ...)
sl@0: {
sl@0:   int ret;
sl@0:   va_list ap;
sl@0: 
sl@0:   va_start (ap, fmt);
sl@0:   ret = __svfscanf (fp, fmt, ap);
sl@0:   va_end (ap);
sl@0:   return ret;
sl@0: }