1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSTDIO/GETCHAR.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,110 @@
1.4 +/* GETCHAR.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 +/*
1.28 +FUNCTION
1.29 +<<getchar>>---read a character (macro)
1.30 +
1.31 +INDEX
1.32 + getchar
1.33 +INDEX
1.34 + _getchar_r
1.35 +
1.36 +ANSI_SYNOPSIS
1.37 + #include <stdio.h>
1.38 + int getchar(void);
1.39 +
1.40 + int _getchar_r(void *<[reent]>);
1.41 +
1.42 +TRAD_SYNOPSIS
1.43 + #include <stdio.h>
1.44 + int getchar();
1.45 +
1.46 + int _getchar_r(<[reent]>)
1.47 + char * <[reent]>;
1.48 +
1.49 +DESCRIPTION
1.50 +<<getchar>> is a macro, defined in <<stdio.h>>. You can use <<getchar>>
1.51 +to get the next single character from the standard input stream.
1.52 +As a side effect, <<getchar>> advances the standard input's
1.53 +current position indicator.
1.54 +
1.55 +The alternate function <<_getchar_r>> is a reentrant version. The
1.56 +extra argument <[reent]> is a pointer to a reentrancy structure.
1.57 +
1.58 +
1.59 +RETURNS
1.60 +The next character (read as an <<unsigned char>>, and cast to
1.61 +<<int>>), unless there is no more data, or the host system reports a
1.62 +read error; in either of these situations, <<getchar>> returns <<EOF>>.
1.63 +
1.64 +You can distinguish the two situations that cause an <<EOF>> result by
1.65 +using `<<ferror(stdin)>>' and `<<feof(stdin)>>'.
1.66 +
1.67 +PORTABILITY
1.68 +ANSI C requires <<getchar>>; it suggests, but does not require, that
1.69 +<<getchar>> be implemented as a macro.
1.70 +
1.71 +Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
1.72 +<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
1.73 +*/
1.74 +
1.75 +/*
1.76 + * A subroutine version of the macro getchar.
1.77 + */
1.78 +
1.79 +#include <stdio_r.h>
1.80 +#include <reent.h>
1.81 +
1.82 +#undef getchar
1.83 +
1.84 +/**
1.85 +A reentrant version of getchar().
1.86 +*/
1.87 +EXPORT_C int
1.88 +_getchar_r (struct _reent *f)
1.89 +{
1.90 + return getc (_stdin_r (f));
1.91 +}
1.92 +
1.93 +#ifndef _REENT_ONLY
1.94 +
1.95 +/**
1.96 +Get the next character from stdin.Returns the next character from the
1.97 +standard input.
1.98 +
1.99 +@return On Success, the character read is returned as an int.
1.100 + On Failure, returns EOF, if the 'End Of File' is reached or there has
1.101 + been an error reading and errno may be set.
1.102 +*/
1.103 +EXPORT_C int
1.104 +getchar (void)
1.105 +{
1.106 + /* CHECK_INIT is called (eventually) by __srefill. */
1.107 + struct _reent *r = _REENT2;
1.108 + if (!r)
1.109 + return EOF; // Memory for library globals is not allocated (errno not set).
1.110 + return _getchar_r (r);
1.111 +}
1.112 +
1.113 +#endif