]>
Commit | Line | Data |
---|---|---|
5b2abdfb A |
1 | .\" Copyright (c) 1990, 1991, 1993 |
2 | .\" The Regents of the University of California. All rights reserved. | |
3 | .\" | |
4 | .\" This code is derived from software contributed to Berkeley by | |
5 | .\" Chris Torek and the American National Standards Committee X3, | |
6 | .\" on Information Processing Systems. | |
7 | .\" | |
8 | .\" Redistribution and use in source and binary forms, with or without | |
9 | .\" modification, are permitted provided that the following conditions | |
10 | .\" are met: | |
11 | .\" 1. Redistributions of source code must retain the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer. | |
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
14 | .\" notice, this list of conditions and the following disclaimer in the | |
15 | .\" documentation and/or other materials provided with the distribution. | |
16 | .\" 3. All advertising materials mentioning features or use of this software | |
17 | .\" must display the following acknowledgement: | |
18 | .\" This product includes software developed by the University of | |
19 | .\" California, Berkeley and its contributors. | |
20 | .\" 4. Neither the name of the University nor the names of its contributors | |
21 | .\" may be used to endorse or promote products derived from this software | |
22 | .\" without specific prior written permission. | |
23 | .\" | |
24 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
25 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | .\" SUCH DAMAGE. | |
35 | .\" | |
36 | .\" @(#)getc.3 8.1 (Berkeley) 6/4/93 | |
3d9156a7 | 37 | .\" $FreeBSD: src/lib/libc/stdio/getc.3,v 1.19 2004/03/17 12:37:28 tjr Exp $ |
5b2abdfb | 38 | .\" |
9385eb3d | 39 | .Dd January 10, 2003 |
5b2abdfb A |
40 | .Dt GETC 3 |
41 | .Os | |
42 | .Sh NAME | |
43 | .Nm fgetc , | |
44 | .Nm getc , | |
9385eb3d | 45 | .Nm getc_unlocked , |
5b2abdfb | 46 | .Nm getchar , |
9385eb3d | 47 | .Nm getchar_unlocked , |
5b2abdfb A |
48 | .Nm getw |
49 | .Nd get next character or word from input stream | |
50 | .Sh LIBRARY | |
51 | .Lb libc | |
52 | .Sh SYNOPSIS | |
53 | .In stdio.h | |
54 | .Ft int | |
55 | .Fn fgetc "FILE *stream" | |
56 | .Ft int | |
57 | .Fn getc "FILE *stream" | |
58 | .Ft int | |
9385eb3d A |
59 | .Fn getc_unlocked "FILE *stream" |
60 | .Ft int | |
5b2abdfb A |
61 | .Fn getchar |
62 | .Ft int | |
3d9156a7 | 63 | .Fn getchar_unlocked "void" |
9385eb3d | 64 | .Ft int |
5b2abdfb A |
65 | .Fn getw "FILE *stream" |
66 | .Sh DESCRIPTION | |
67 | The | |
68 | .Fn fgetc | |
69 | function | |
70 | obtains the next input character (if present) from the stream pointed at by | |
71 | .Fa stream , | |
72 | or the next character pushed back on the stream via | |
73 | .Xr ungetc 3 . | |
74 | .Pp | |
75 | The | |
76 | .Fn getc | |
77 | function | |
78 | acts essentially identically to | |
3d9156a7 A |
79 | .Fn fgetc , |
80 | but is a macro that expands in-line. | |
5b2abdfb A |
81 | .Pp |
82 | The | |
83 | .Fn getchar | |
84 | function | |
85 | is equivalent to | |
86 | .Fn getc stdin . | |
87 | .Pp | |
88 | The | |
89 | .Fn getw | |
90 | function | |
91 | obtains the next | |
9385eb3d | 92 | .Vt int |
5b2abdfb A |
93 | (if present) |
94 | from the stream pointed at by | |
95 | .Fa stream . | |
9385eb3d A |
96 | .Pp |
97 | The | |
98 | .Fn getc_unlocked | |
99 | and | |
100 | .Fn getchar_unlocked | |
101 | functions are equivalent to | |
102 | .Fn getc | |
103 | and | |
104 | .Fn getchar | |
105 | respectively, | |
106 | except that the caller is responsible for locking the stream | |
107 | with | |
108 | .Xr flockfile 3 | |
109 | before calling them. | |
110 | These functions may be used to avoid the overhead of locking the stream | |
111 | for each character, and to avoid input being dispersed among multiple | |
112 | threads reading from the same stream. | |
5b2abdfb A |
113 | .Sh RETURN VALUES |
114 | If successful, these routines return the next requested object | |
115 | from the | |
116 | .Fa stream . | |
9385eb3d A |
117 | Character values are returned as an |
118 | .Vt "unsigned char" | |
119 | converted to an | |
120 | .Vt int . | |
5b2abdfb A |
121 | If the stream is at end-of-file or a read error occurs, |
122 | the routines return | |
123 | .Dv EOF . | |
124 | The routines | |
125 | .Xr feof 3 | |
126 | and | |
127 | .Xr ferror 3 | |
128 | must be used to distinguish between end-of-file and error. | |
129 | If an error occurs, the global variable | |
130 | .Va errno | |
131 | is set to indicate the error. | |
132 | The end-of-file condition is remembered, even on a terminal, and all | |
133 | subsequent attempts to read will return | |
134 | .Dv EOF | |
135 | until the condition is cleared with | |
136 | .Xr clearerr 3 . | |
137 | .Sh SEE ALSO | |
138 | .Xr ferror 3 , | |
9385eb3d | 139 | .Xr flockfile 3 , |
5b2abdfb A |
140 | .Xr fopen 3 , |
141 | .Xr fread 3 , | |
9385eb3d | 142 | .Xr getwc 3 , |
5b2abdfb A |
143 | .Xr putc 3 , |
144 | .Xr ungetc 3 | |
145 | .Sh STANDARDS | |
146 | The | |
147 | .Fn fgetc , | |
148 | .Fn getc | |
149 | and | |
150 | .Fn getchar | |
151 | functions | |
152 | conform to | |
153 | .St -isoC . | |
9385eb3d A |
154 | The |
155 | .Fn getc_unlocked | |
156 | and | |
157 | .Fn getchar_unlocked | |
158 | functions conform to | |
159 | .St -p1003.1-2001 . | |
5b2abdfb A |
160 | .Sh BUGS |
161 | Since | |
162 | .Dv EOF | |
163 | is a valid integer value, | |
164 | .Xr feof 3 | |
165 | and | |
166 | .Xr ferror 3 | |
167 | must be used to check for failure after calling | |
168 | .Fn getw . | |
169 | The size and byte order of an | |
9385eb3d | 170 | .Vt int |
5b2abdfb A |
171 | varies from one machine to another, and |
172 | .Fn getw | |
173 | is not recommended for portable applications. | |
174 | .Pp |