xref: /openbsd-src/lib/libc/stdio/getc.3 (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1.\"	$OpenBSD: getc.3,v 1.12 2007/05/31 19:19:31 jmc 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 $Mdocdate: May 31 2007 $
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
73.Em stdin .
74.Pp
75The
76.Fn getw
77function obtains the next
78.Li int
79(if present)
80from the stream pointed at by
81.Fa stream .
82.Sh RETURN VALUES
83If successful, these routines return the next requested object from the
84.Fa stream .
85If the stream is at end-of-file or a read error occurs, the routines return
86.Dv EOF .
87The routines
88.Xr feof 3
89and
90.Xr ferror 3
91must be used to distinguish between end-of-file and error.
92If an error occurs, the global variable
93.Va errno
94is set to indicate the error.
95The end-of-file condition is remembered, even on a terminal, and all
96subsequent attempts to read will return
97.Dv EOF
98until the condition is cleared with
99.Xr clearerr 3 .
100.Sh SEE ALSO
101.Xr ferror 3 ,
102.Xr fopen 3 ,
103.Xr fread 3 ,
104.Xr putc 3 ,
105.Xr ungetc 3
106.Sh STANDARDS
107The
108.Fn fgetc ,
109.Fn getc ,
110and
111.Fn getchar
112functions conform to
113.St -ansiC .
114.Sh BUGS
115Since
116.Dv EOF
117is a valid integer value,
118.Xr feof 3
119and
120.Xr ferror 3
121must be used to check for failure after calling
122.Fn getw .
123.Pp
124Since the size and byte order of an
125.Vt int
126may vary from one machine to another,
127.Fn getw
128is not recommended for portable applications.
129