xref: /openbsd-src/lib/libc/stdio/getc.3 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1.\"	$OpenBSD: getc.3,v 1.7 2000/12/24 00:30:58 aaron Exp $
2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. All advertising materials mentioning features or use of this software
19.\"    must display the following acknowledgement:
20.\"	This product includes software developed by the University of
21.\"	California, Berkeley and its contributors.
22.\" 4. Neither the name of the University nor the names of its contributors
23.\"    may be used to endorse or promote products derived from this software
24.\"    without specific prior written permission.
25.\"
26.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36.\" SUCH DAMAGE.
37.\"
38.Dd June 4, 1993
39.Dt GETC 3
40.Os
41.Sh NAME
42.Nm fgetc ,
43.Nm getc ,
44.Nm getchar ,
45.Nm getw
46.Nd get next character or word from input stream
47.Sh SYNOPSIS
48.Fd #include <stdio.h>
49.Ft int
50.Fn fgetc "FILE *stream"
51.Ft int
52.Fn getc "FILE *stream"
53.Ft int
54.Fn getchar "void"
55.Ft int
56.Fn getw "FILE *stream"
57.Sh DESCRIPTION
58The
59.Fn fgetc
60function obtains the next input character (if present) from the stream
61pointed at by
62.Fa stream ,
63or the next character pushed back on the stream via
64.Xr ungetc .
65.Pp
66The
67.Fn getc
68function acts essentially identically to
69.Fn fgetc ,
70but is a macro that expands in-line.
71.Pp
72The
73.Fn getchar
74function is equivalent to
75.Fn getc
76with the argument stdin.
77.Pp
78The
79.Fn getw
80function obtains the next
81.Li int
82(if present)
83from the stream pointed at by
84.Fa stream .
85.Sh RETURN VALUES
86If successful, these routines return the next requested object from the
87.Fa stream .
88If the stream is at end-of-file or a read error occurs, the routines return
89.Dv EOF .
90The routines
91.Xr feof 3
92and
93.Xr ferror 3
94must be used to distinguish between end-of-file and error.
95If an error occurs, the global variable
96.Va errno
97is set to indicate the error.
98The end-of-file condition is remembered, even on a terminal, and all
99subsequent attempts to read will return
100.Dv EOF
101until the condition is cleared with
102.Xr clearerr .
103.Sh SEE ALSO
104.Xr ferror 3 ,
105.Xr fopen 3 ,
106.Xr fread 3 ,
107.Xr putc 3 ,
108.Xr ungetc 3
109.Sh STANDARDS
110The
111.Fn fgetc ,
112.Fn getc ,
113and
114.Fn getchar
115functions conform to
116.St -ansiC .
117.Sh BUGS
118Since
119.Dv EOF
120is a valid integer value,
121.Xr feof
122and
123.Xr ferror
124must be used to check for failure after calling
125.Fn getw .
126The size and byte order of an
127.Em int
128varies from one machine to another, and
129.Fn getw
130is not recommended for portable applications.
131