sl@0
|
1 |
/* GETCHAR.C
|
sl@0
|
2 |
*
|
sl@0
|
3 |
* Portions Copyright (c) 1990-2006 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
4 |
* All rights reserved.
|
sl@0
|
5 |
*/
|
sl@0
|
6 |
|
sl@0
|
7 |
/*
|
sl@0
|
8 |
* Copyright (c) 1990 The Regents of the University of California.
|
sl@0
|
9 |
* All rights reserved.
|
sl@0
|
10 |
*
|
sl@0
|
11 |
* Redistribution and use in source and binary forms are permitted
|
sl@0
|
12 |
* provided that the above copyright notice and this paragraph are
|
sl@0
|
13 |
* duplicated in all such forms and that any documentation,
|
sl@0
|
14 |
* advertising materials, and other materials related to such
|
sl@0
|
15 |
* distribution and use acknowledge that the software was developed
|
sl@0
|
16 |
* by the University of California, Berkeley. The name of the
|
sl@0
|
17 |
* University may not be used to endorse or promote products derived
|
sl@0
|
18 |
* from this software without specific prior written permission.
|
sl@0
|
19 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
sl@0
|
20 |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
sl@0
|
21 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
|
sl@0
|
24 |
/*
|
sl@0
|
25 |
FUNCTION
|
sl@0
|
26 |
<<getchar>>---read a character (macro)
|
sl@0
|
27 |
|
sl@0
|
28 |
INDEX
|
sl@0
|
29 |
getchar
|
sl@0
|
30 |
INDEX
|
sl@0
|
31 |
_getchar_r
|
sl@0
|
32 |
|
sl@0
|
33 |
ANSI_SYNOPSIS
|
sl@0
|
34 |
#include <stdio.h>
|
sl@0
|
35 |
int getchar(void);
|
sl@0
|
36 |
|
sl@0
|
37 |
int _getchar_r(void *<[reent]>);
|
sl@0
|
38 |
|
sl@0
|
39 |
TRAD_SYNOPSIS
|
sl@0
|
40 |
#include <stdio.h>
|
sl@0
|
41 |
int getchar();
|
sl@0
|
42 |
|
sl@0
|
43 |
int _getchar_r(<[reent]>)
|
sl@0
|
44 |
char * <[reent]>;
|
sl@0
|
45 |
|
sl@0
|
46 |
DESCRIPTION
|
sl@0
|
47 |
<<getchar>> is a macro, defined in <<stdio.h>>. You can use <<getchar>>
|
sl@0
|
48 |
to get the next single character from the standard input stream.
|
sl@0
|
49 |
As a side effect, <<getchar>> advances the standard input's
|
sl@0
|
50 |
current position indicator.
|
sl@0
|
51 |
|
sl@0
|
52 |
The alternate function <<_getchar_r>> is a reentrant version. The
|
sl@0
|
53 |
extra argument <[reent]> is a pointer to a reentrancy structure.
|
sl@0
|
54 |
|
sl@0
|
55 |
|
sl@0
|
56 |
RETURNS
|
sl@0
|
57 |
The next character (read as an <<unsigned char>>, and cast to
|
sl@0
|
58 |
<<int>>), unless there is no more data, or the host system reports a
|
sl@0
|
59 |
read error; in either of these situations, <<getchar>> returns <<EOF>>.
|
sl@0
|
60 |
|
sl@0
|
61 |
You can distinguish the two situations that cause an <<EOF>> result by
|
sl@0
|
62 |
using `<<ferror(stdin)>>' and `<<feof(stdin)>>'.
|
sl@0
|
63 |
|
sl@0
|
64 |
PORTABILITY
|
sl@0
|
65 |
ANSI C requires <<getchar>>; it suggests, but does not require, that
|
sl@0
|
66 |
<<getchar>> be implemented as a macro.
|
sl@0
|
67 |
|
sl@0
|
68 |
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
sl@0
|
69 |
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
|
sl@0
|
70 |
*/
|
sl@0
|
71 |
|
sl@0
|
72 |
/*
|
sl@0
|
73 |
* A subroutine version of the macro getchar.
|
sl@0
|
74 |
*/
|
sl@0
|
75 |
|
sl@0
|
76 |
#include <stdio_r.h>
|
sl@0
|
77 |
#include <reent.h>
|
sl@0
|
78 |
|
sl@0
|
79 |
#undef getchar
|
sl@0
|
80 |
|
sl@0
|
81 |
/**
|
sl@0
|
82 |
A reentrant version of getchar().
|
sl@0
|
83 |
*/
|
sl@0
|
84 |
EXPORT_C int
|
sl@0
|
85 |
_getchar_r (struct _reent *f)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
return getc (_stdin_r (f));
|
sl@0
|
88 |
}
|
sl@0
|
89 |
|
sl@0
|
90 |
#ifndef _REENT_ONLY
|
sl@0
|
91 |
|
sl@0
|
92 |
/**
|
sl@0
|
93 |
Get the next character from stdin.Returns the next character from the
|
sl@0
|
94 |
standard input.
|
sl@0
|
95 |
|
sl@0
|
96 |
@return On Success, the character read is returned as an int.
|
sl@0
|
97 |
On Failure, returns EOF, if the 'End Of File' is reached or there has
|
sl@0
|
98 |
been an error reading and errno may be set.
|
sl@0
|
99 |
*/
|
sl@0
|
100 |
EXPORT_C int
|
sl@0
|
101 |
getchar (void)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
/* CHECK_INIT is called (eventually) by __srefill. */
|
sl@0
|
104 |
struct _reent *r = _REENT2;
|
sl@0
|
105 |
if (!r)
|
sl@0
|
106 |
return EOF; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
107 |
return _getchar_r (r);
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
#endif
|