xref: /freebsd/lib/libc/stdio/ferror.3 (revision ee12faa062c04a49bf6fe4e6867bad8606e2413f)
1.\" Copyright (c) 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Chris Torek and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)ferror.3	8.2 (Berkeley) 4/19/94
33.\"
34.Dd April 2, 2022
35.Dt FERROR 3
36.Os
37.Sh NAME
38.Nm clearerr ,
39.Nm clearerr_unlocked ,
40.Nm feof ,
41.Nm feof_unlocked ,
42.Nm ferror ,
43.Nm ferror_unlocked ,
44.Nm fileno ,
45.Nm fileno_unlocked
46.Nd check and reset stream status
47.Sh LIBRARY
48.Lb libc
49.Sh SYNOPSIS
50.In stdio.h
51.Ft void
52.Fn clearerr "FILE *stream"
53.Ft void
54.Fn clearerr_unlocked "FILE *stream"
55.Ft int
56.Fn feof "FILE *stream"
57.Ft int
58.Fn feof_unlocked "FILE *stream"
59.Ft int
60.Fn ferror "FILE *stream"
61.Ft int
62.Fn ferror_unlocked "FILE *stream"
63.Ft int
64.Fn fileno "FILE *stream"
65.Ft int
66.Fn fileno_unlocked "FILE *stream"
67.Sh DESCRIPTION
68The function
69.Fn clearerr
70clears the end-of-file and error indicators for the stream pointed
71to by
72.Fa stream .
73.Pp
74The function
75.Fn feof
76tests the end-of-file indicator for the stream pointed to by
77.Fa stream ,
78returning non-zero if it is set.
79The end-of-file indicator may be cleared by explicitly calling
80.Fn clearerr ,
81or as a side-effect of other operations, e.g.\&
82.Fn fseek .
83.Pp
84The function
85.Fn ferror
86tests the error indicator for the stream pointed to by
87.Fa stream ,
88returning non-zero if it is set.
89.Pp
90The function
91.Fn fileno
92examines the argument
93.Fa stream
94and returns its integer descriptor.
95.Pp
96The
97.Fn clearerr_unlocked ,
98.Fn feof_unlocked ,
99.Fn ferror_unlocked ,
100and
101.Fn fileno_unlocked
102functions are equivalent to
103.Fn clearerr ,
104.Fn feof ,
105.Fn ferror ,
106and
107.Fn fileno
108respectively, except that the caller is responsible for locking the stream
109with
110.Xr flockfile 3
111before calling them.
112These functions may be used to avoid the overhead of locking the stream
113and to prevent races when multiple threads are operating on the same stream.
114.Sh ERRORS
115These functions should not fail and do not set the external
116variable
117.Va errno .
118.Sh SEE ALSO
119.Xr open 2 ,
120.Xr fdopen 3 ,
121.Xr flockfile 3 ,
122.Xr stdio 3
123.Sh STANDARDS
124The functions
125.Fn clearerr ,
126.Fn feof ,
127and
128.Fn ferror
129conform to
130.St -isoC .
131.Sh HISTORY
132The functions
133.Fn clearerr ,
134.Fn feof ,
135.Fn ferror ,
136and
137.Fn fileno
138first appeared in
139.At v7 .
140