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