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