8999 SMBIOS: cleanup 32-bit specific code
[unleashed.git] / usr / src / man / man3c / fgetc.3c
blobe5ae39b779768b32556dfcef3e65a8cd4736816d
1 '\" te
2 .\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.  Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
4 .\" http://www.opengroup.org/bookstore/.
5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
6 .\"  This notice shall appear on any product containing this material.
7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
10 .TH FGETC 3C "Oct 15, 2003"
11 .SH NAME
12 fgetc, getc, getc_unlocked, getchar, getchar_unlocked, getw \- get a byte from
13 a stream
14 .SH SYNOPSIS
15 .LP
16 .nf
17 #include <stdio.h>
19 \fBint\fR \fBfgetc\fR(\fBFILE *\fR\fIstream\fR);
20 .fi
22 .LP
23 .nf
24 \fBint\fR \fBgetc\fR(\fBFILE *\fR\fIstream\fR);
25 .fi
27 .LP
28 .nf
29 \fBint\fR \fBgetc_unlocked\fR(\fBFILE *\fR\fIstream\fR);
30 .fi
32 .LP
33 .nf
34 \fBint\fR \fBgetchar\fR(\fBvoid\fR);
35 .fi
37 .LP
38 .nf
39 \fBint\fR \fBgetchar_unlocked\fR(\fBvoid\fR);
40 .fi
42 .LP
43 .nf
44 \fBint\fR \fBgetw\fR(\fBFILE *\fR\fIstream\fR);
45 .fi
47 .SH DESCRIPTION
48 .sp
49 .LP
50 The \fBfgetc()\fR function obtains the next byte (if present) as an \fBunsigned
51 char\fR converted to an \fBint\fR, from the input stream pointed to by
52 \fIstream\fR, and advances the associated file position indicator for the
53 stream (if defined).
54 .sp
55 .LP
56 For standard-conforming (see \fBstandards\fR(5)) applications, if the
57 end-of-file indicator for the stream is set, \fBfgetc()\fR returns \fBEOF\fR
58 whether or not a next byte is present.
59 .sp
60 .LP
61 The \fBfgetc()\fR function may mark the \fBst_atime\fR field of the file
62 associated with \fIstream\fR for update. The \fBst_atime\fR field will be
63 marked for update by the first successful execution of \fBfgetc()\fR,
64 \fBfgets\fR(3C), \fBfread\fR(3C), \fBfscanf\fR(3C), \fBgetc()\fR,
65 \fBgetchar()\fR, \fBgets\fR(3C) or \fBscanf\fR(3C) using \fIstream\fR that
66 returns data not supplied by a prior call to \fBungetc\fR(3C) or
67 \fBungetwc\fR(3C).
68 .sp
69 .LP
70 The \fBgetc()\fR function is functionally identical to \fBfgetc()\fR, except
71 that it is implemented as a macro. It runs faster than \fBfgetc()\fR, but it
72 takes up more space per invocation and its name cannot be passed as an argument
73 to a function call.
74 .sp
75 .LP
76 The \fBgetchar()\fR routine is equivalent to \fBgetc(stdin)\fR. It is
77 implemented as a macro.
78 .sp
79 .LP
80 The \fBgetc_unlocked()\fR and \fBgetchar_unlocked()\fR routines are variants of
81 \fBgetc()\fR and \fBgetchar()\fR, respectively, that do not lock the stream.
82 It is the caller's responsibility to acquire the stream lock before calling
83 these routines and releasing the lock afterwards; see \fBflockfile\fR(3C) and
84 \fBstdio\fR(3C). These routines are implemented as macros.
85 .sp
86 .LP
87 The \fBgetw()\fR function reads the next word from the \fIstream\fR. The size
88 of a word is the size of an \fBint\fR and may vary from environment to
89 environment.  The \fBgetw()\fR function presumes no special alignment in the
90 file.
91 .sp
92 .LP
93 The \fBgetw()\fR function may mark the \fBst_atime\fR field of the file
94 associated with \fIstream\fR for update. The \fBst_atime\fR field will be
95 marked for update by the first successful execution of \fBfgetc()\fR,
96 \fBfgets\fR(3C), \fBfread\fR(3C), \fBgetc()\fR, \fBgetchar()\fR,
97 \fBgets\fR(3C), \fBfscanf\fR(3C) or \fBscanf\fR(3C) using \fIstream\fR that
98 returns data not supplied by a prior call to \fBungetc\fR(3C).
99 .SH RETURN VALUES
102 Upon successful completion, \fBfgetc()\fR, \fBgetc()\fR, \fBgetc_unlocked()\fR,
103 \fBgetchar()\fR, \fBgetchar_unlocked()\fR, and \fBgetw()\fR return the next
104 byte from the input stream pointed to by \fIstream\fR. If the stream is at
105 end-of-file, the end-of-file indicator for the stream is set and these
106 functions return \fBEOF\fR. For standard-conforming (see \fBstandards\fR(5))
107 applications, if the end-of-file indicator for the stream is set, these
108 functions return \fBEOF\fR whether or not the stream is at end-of-file. If a
109 read error occurs, the error indicator for the stream is set, \fBEOF\fR is
110 returned, and \fBerrno\fR is set to indicate the error.
111 .SH ERRORS
114 The \fBfgetc()\fR, \fBgetc()\fR, \fBgetc_unlocked()\fR, \fBgetchar()\fR,
115 \fBgetchar_unlocked()\fR, and \fBgetw()\fR functions will fail if data needs to
116 be read and:
118 .ne 2
120 \fB\fBEAGAIN\fR\fR
122 .RS 13n
123 The \fBO_NONBLOCK\fR flag is set for the file descriptor underlying
124 \fIstream\fR and the process would be delayed in the \fBfgetc()\fR operation.
128 .ne 2
130 \fB\fBEBADF\fR\fR
132 .RS 13n
133 The file descriptor underlying \fIstream\fR is not a valid file descriptor open
134 for reading.
138 .ne 2
140 \fB\fBEINTR\fR\fR
142 .RS 13n
143 The read operation was terminated due to the receipt of a signal, and no data
144 was transferred.
148 .ne 2
150 \fB\fBEIO\fR\fR
152 .RS 13n
153 A physical I/O error has occurred, or the process is in a background process
154 group attempting to read from its controlling terminal, and either the process
155 is ignoring or blocking the \fBSIGTTIN\fR signal or the process group is
156 orphaned. This error may also be generated for implementation-dependent
157 reasons.
161 .ne 2
163 \fB\fBEOVERFLOW\fR\fR
165 .RS 13n
166 The file is a regular file and an attempt was made to read at or beyond the
167 offset maximum associated with the corresponding stream.
172 The \fBfgetc()\fR, \fBgetc()\fR, \fBgetc_unlocked()\fR, \fBgetchar()\fR,
173 \fBgetchar_unlocked()\fR, and \fBgetw()\fR functions may fail if:
175 .ne 2
177 \fB\fBENOMEM\fR\fR
179 .RS 10n
180 Insufficient storage space is available.
184 .ne 2
186 \fB\fBENXIO\fR\fR
188 .RS 10n
189 A request was made of a non-existent device, or the request was outside the
190 capabilities of the device.
193 .SH USAGE
196 If the integer value returned by \fBfgetc()\fR, \fBgetc()\fR,
197 \fBgetc_unlocked()\fR, \fBgetchar()\fR, \fBgetchar_unlocked()\fR, and
198 \fBgetw()\fR is stored into a variable of type \fBchar\fR and then compared
199 against the integer constant EOF, the comparison may never succeed, because
200 sign-extension of a variable of type \fBchar\fR on widening to integer is
201 implementation-dependent.
204 The \fBferror\fR(3C) or \fBfeof\fR(3C) functions must be used to distinguish
205 between an error condition and an end-of-file condition.
208 Functions exist for the \fBgetc()\fR, \fBgetc_unlocked()\fR, \fBgetchar()\fR,
209 and \fBgetchar_unlocked()\fR macros. To get the function form, the macro name
210 must be undefined (for example, \fB#undef getc\fR).
213 When the macro forms are used, \fBgetc()\fR and \fBgetc_unlocked()\fR evaluate
214 the \fIstream\fR argument more than once. In particular,
215 \fBgetc(*\fR\fIf++\fR\fB);\fR does not work sensibly.  The \fBfgetc()\fR
216 function should be used instead when evaluating the \fIstream\fR argument has
217 side effects.
220 Because of possible differences in word length and byte ordering, files written
221 using \fBgetw()\fR are machine-dependent, and may not be read using
222 \fBgetw()\fR on a different processor.
225 The \fBgetw()\fR function is inherently byte stream-oriented and is not tenable
226 in the context of either multibyte character streams or wide-character streams.
227 Application programmers are recommended to use one of the character-based input
228 functions instead.
229 .SH ATTRIBUTES
232 See \fBattributes\fR(5) for descriptions of the following attributes:
237 box;
238 c | c
239 l | l .
240 ATTRIBUTE TYPE  ATTRIBUTE VALUE
242 Interface Stability     T{
243 \fBfgetc()\fR, \fBgetc()\fR, \fBgetc_unlocked()\fR, \fBgetchar()\fR, and \fBgetchar_unlocked()\fR are Standard.
246 MT-Level        See \fBNOTES\fR below.
249 .SH SEE ALSO
252 \fBIntro\fR(3), \fB__fsetlocking\fR(3C), \fBfclose\fR(3C), \fBfeof\fR(3C),
253 \fBfgets\fR(3C), \fBfgetwc\fR(3C), \fBfgetws\fR(3C), \fBflockfile\fR(3C),
254 \fBfopen\fR(3C), \fBfread\fR(3C), \fBfscanf\fR(3C), \fBgets\fR(3C),
255 \fBputc\fR(3C), \fBscanf\fR(3C), \fBstdio\fR(3C), \fBungetc\fR(3C),
256 \fBungetwc\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)
257 .SH NOTES
260 The \fBfgetc()\fR, \fBgetc()\fR, \fBgetchar()\fR, and \fBgetw()\fR routines are
261 MT-Safe in multithreaded applications.  The \fBgetc_unlocked()\fR and
262 \fBgetchar_unlocked()\fR routines are unsafe in multithreaded applications.