2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
44 .\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
46 .TH FGETC 3C "Oct 15, 2003"
48 fgetc, getc, getc_unlocked, getchar, getchar_unlocked, getw \- get a byte from
55 \fBint\fR \fBfgetc\fR(\fBFILE *\fR\fIstream\fR);
60 \fBint\fR \fBgetc\fR(\fBFILE *\fR\fIstream\fR);
65 \fBint\fR \fBgetc_unlocked\fR(\fBFILE *\fR\fIstream\fR);
70 \fBint\fR \fBgetchar\fR(\fBvoid\fR);
75 \fBint\fR \fBgetchar_unlocked\fR(\fBvoid\fR);
80 \fBint\fR \fBgetw\fR(\fBFILE *\fR\fIstream\fR);
86 The \fBfgetc()\fR function obtains the next byte (if present) as an \fBunsigned
87 char\fR converted to an \fBint\fR, from the input stream pointed to by
88 \fIstream\fR, and advances the associated file position indicator for the
92 For standard-conforming (see \fBstandards\fR(5)) applications, if the
93 end-of-file indicator for the stream is set, \fBfgetc()\fR returns \fBEOF\fR
94 whether or not a next byte is present.
97 The \fBfgetc()\fR function may mark the \fBst_atime\fR field of the file
98 associated with \fIstream\fR for update. The \fBst_atime\fR field will be
99 marked for update by the first successful execution of \fBfgetc()\fR,
100 \fBfgets\fR(3C), \fBfread\fR(3C), \fBfscanf\fR(3C), \fBgetc()\fR,
101 \fBgetchar()\fR, \fBgets\fR(3C) or \fBscanf\fR(3C) using \fIstream\fR that
102 returns data not supplied by a prior call to \fBungetc\fR(3C) or
106 The \fBgetc()\fR function is functionally identical to \fBfgetc()\fR, except
107 that it is implemented as a macro. It runs faster than \fBfgetc()\fR, but it
108 takes up more space per invocation and its name cannot be passed as an argument
112 The \fBgetchar()\fR routine is equivalent to \fBgetc(stdin)\fR. It is
113 implemented as a macro.
116 The \fBgetc_unlocked()\fR and \fBgetchar_unlocked()\fR routines are variants of
117 \fBgetc()\fR and \fBgetchar()\fR, respectively, that do not lock the stream.
118 It is the caller's responsibility to acquire the stream lock before calling
119 these routines and releasing the lock afterwards; see \fBflockfile\fR(3C) and
120 \fBstdio\fR(3C). These routines are implemented as macros.
123 The \fBgetw()\fR function reads the next word from the \fIstream\fR. The size
124 of a word is the size of an \fBint\fR and may vary from environment to
125 environment. The \fBgetw()\fR function presumes no special alignment in the
129 The \fBgetw()\fR function may mark the \fBst_atime\fR field of the file
130 associated with \fIstream\fR for update. The \fBst_atime\fR field will be
131 marked for update by the first successful execution of \fBfgetc()\fR,
132 \fBfgets\fR(3C), \fBfread\fR(3C), \fBgetc()\fR, \fBgetchar()\fR,
133 \fBgets\fR(3C), \fBfscanf\fR(3C) or \fBscanf\fR(3C) using \fIstream\fR that
134 returns data not supplied by a prior call to \fBungetc\fR(3C).
138 Upon successful completion, \fBfgetc()\fR, \fBgetc()\fR, \fBgetc_unlocked()\fR,
139 \fBgetchar()\fR, \fBgetchar_unlocked()\fR, and \fBgetw()\fR return the next
140 byte from the input stream pointed to by \fIstream\fR. If the stream is at
141 end-of-file, the end-of-file indicator for the stream is set and these
142 functions return \fBEOF\fR. For standard-conforming (see \fBstandards\fR(5))
143 applications, if the end-of-file indicator for the stream is set, these
144 functions return \fBEOF\fR whether or not the stream is at end-of-file. If a
145 read error occurs, the error indicator for the stream is set, \fBEOF\fR is
146 returned, and \fBerrno\fR is set to indicate the error.
150 The \fBfgetc()\fR, \fBgetc()\fR, \fBgetc_unlocked()\fR, \fBgetchar()\fR,
151 \fBgetchar_unlocked()\fR, and \fBgetw()\fR functions will fail if data needs to
159 The \fBO_NONBLOCK\fR flag is set for the file descriptor underlying
160 \fIstream\fR and the process would be delayed in the \fBfgetc()\fR operation.
169 The file descriptor underlying \fIstream\fR is not a valid file descriptor open
179 The read operation was terminated due to the receipt of a signal, and no data
189 A physical I/O error has occurred, or the process is in a background process
190 group attempting to read from its controlling terminal, and either the process
191 is ignoring or blocking the \fBSIGTTIN\fR signal or the process group is
192 orphaned. This error may also be generated for implementation-dependent
199 \fB\fBEOVERFLOW\fR\fR
202 The file is a regular file and an attempt was made to read at or beyond the
203 offset maximum associated with the corresponding stream.
208 The \fBfgetc()\fR, \fBgetc()\fR, \fBgetc_unlocked()\fR, \fBgetchar()\fR,
209 \fBgetchar_unlocked()\fR, and \fBgetw()\fR functions may fail if:
216 Insufficient storage space is available.
225 A request was made of a non-existent device, or the request was outside the
226 capabilities of the device.
232 If the integer value returned by \fBfgetc()\fR, \fBgetc()\fR,
233 \fBgetc_unlocked()\fR, \fBgetchar()\fR, \fBgetchar_unlocked()\fR, and
234 \fBgetw()\fR is stored into a variable of type \fBchar\fR and then compared
235 against the integer constant EOF, the comparison may never succeed, because
236 sign-extension of a variable of type \fBchar\fR on widening to integer is
237 implementation-dependent.
240 The \fBferror\fR(3C) or \fBfeof\fR(3C) functions must be used to distinguish
241 between an error condition and an end-of-file condition.
244 Functions exist for the \fBgetc()\fR, \fBgetc_unlocked()\fR, \fBgetchar()\fR,
245 and \fBgetchar_unlocked()\fR macros. To get the function form, the macro name
246 must be undefined (for example, \fB#undef getc\fR).
249 When the macro forms are used, \fBgetc()\fR and \fBgetc_unlocked()\fR evaluate
250 the \fIstream\fR argument more than once. In particular,
251 \fBgetc(*\fR\fIf++\fR\fB);\fR does not work sensibly. The \fBfgetc()\fR
252 function should be used instead when evaluating the \fIstream\fR argument has
256 Because of possible differences in word length and byte ordering, files written
257 using \fBgetw()\fR are machine-dependent, and may not be read using
258 \fBgetw()\fR on a different processor.
261 The \fBgetw()\fR function is inherently byte stream-oriented and is not tenable
262 in the context of either multibyte character streams or wide-character streams.
263 Application programmers are recommended to use one of the character-based input
268 See \fBattributes\fR(5) for descriptions of the following attributes:
276 ATTRIBUTE TYPE ATTRIBUTE VALUE
278 Interface Stability T{
279 \fBfgetc()\fR, \fBgetc()\fR, \fBgetc_unlocked()\fR, \fBgetchar()\fR, and \fBgetchar_unlocked()\fR are Standard.
282 MT-Level See \fBNOTES\fR below.
288 \fBIntro\fR(3), \fB__fsetlocking\fR(3C), \fBfclose\fR(3C), \fBfeof\fR(3C),
289 \fBfgets\fR(3C), \fBfgetwc\fR(3C), \fBfgetws\fR(3C), \fBflockfile\fR(3C),
290 \fBfopen\fR(3C), \fBfread\fR(3C), \fBfscanf\fR(3C), \fBgets\fR(3C),
291 \fBputc\fR(3C), \fBscanf\fR(3C), \fBstdio\fR(3C), \fBungetc\fR(3C),
292 \fBungetwc\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)
296 The \fBfgetc()\fR, \fBgetc()\fR, \fBgetchar()\fR, and \fBgetw()\fR routines are
297 MT-Safe in multithreaded applications. The \fBgetc_unlocked()\fR and
298 \fBgetchar_unlocked()\fR routines are unsafe in multithreaded applications.