sl@0: /* GETCHAR.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: /* sl@0: FUNCTION sl@0: <>---read a character (macro) sl@0: sl@0: INDEX sl@0: getchar sl@0: INDEX sl@0: _getchar_r sl@0: sl@0: ANSI_SYNOPSIS sl@0: #include sl@0: int getchar(void); sl@0: sl@0: int _getchar_r(void *<[reent]>); sl@0: sl@0: TRAD_SYNOPSIS sl@0: #include sl@0: int getchar(); sl@0: sl@0: int _getchar_r(<[reent]>) sl@0: char * <[reent]>; sl@0: sl@0: DESCRIPTION sl@0: <> is a macro, defined in <>. You can use <> sl@0: to get the next single character from the standard input stream. sl@0: As a side effect, <> advances the standard input's sl@0: current position indicator. sl@0: sl@0: The alternate function <<_getchar_r>> is a reentrant version. The sl@0: extra argument <[reent]> is a pointer to a reentrancy structure. sl@0: sl@0: sl@0: RETURNS sl@0: The next character (read as an <>, and cast to sl@0: <>), unless there is no more data, or the host system reports a sl@0: read error; in either of these situations, <> returns <>. sl@0: sl@0: You can distinguish the two situations that cause an <> result by sl@0: using `<>' and `<>'. sl@0: sl@0: PORTABILITY sl@0: ANSI C requires <>; it suggests, but does not require, that sl@0: <> be implemented as a macro. sl@0: sl@0: Supporting OS subroutines required: <>, <>, <>, sl@0: <>, <>, <>, <>. sl@0: */ sl@0: sl@0: /* sl@0: * A subroutine version of the macro getchar. sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #undef getchar sl@0: sl@0: /** sl@0: A reentrant version of getchar(). sl@0: */ sl@0: EXPORT_C int sl@0: _getchar_r (struct _reent *f) sl@0: { sl@0: return getc (_stdin_r (f)); sl@0: } sl@0: sl@0: #ifndef _REENT_ONLY sl@0: sl@0: /** sl@0: Get the next character from stdin.Returns the next character from the sl@0: standard input. sl@0: sl@0: @return On Success, the character read is returned as an int. sl@0: On Failure, returns EOF, if the 'End Of File' is reached or there has sl@0: been an error reading and errno may be set. sl@0: */ sl@0: EXPORT_C int sl@0: getchar (void) sl@0: { sl@0: /* CHECK_INIT is called (eventually) by __srefill. */ 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: return _getchar_r (r); sl@0: } sl@0: sl@0: #endif