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