| 1 |
'\" t |
| 2 |
.\" Copyright 1990-1991, The Regents of the University of California. |
| 3 |
.\" Copyright 2021, Michael Kerrisk <[email protected]> |
| 4 |
.\" Copyright, the authors of the Linux man-pages project |
| 5 |
.\" |
| 6 |
.\" SPDX-License-Identifier: BSD-4-Clause-UC |
| 7 |
.\" |
| 8 |
.TH ferror 3 2026-02-08 "Linux man-pages 6.18" |
| 9 |
.SH NAME |
| 10 |
clearerr, feof, ferror \- check and reset stream status |
| 11 |
.SH LIBRARY |
| 12 |
Standard C library |
| 13 |
.RI ( libc ,\~ \-lc ) |
| 14 |
.SH SYNOPSIS |
| 15 |
.nf |
| 16 |
.B #include <stdio.h> |
| 17 |
.P |
| 18 |
.BI "void clearerr(FILE *" stream ); |
| 19 |
.BI "int feof(FILE *" stream ); |
| 20 |
.BI "int ferror(FILE *" stream ); |
| 21 |
.fi |
| 22 |
.SH DESCRIPTION |
| 23 |
The function |
| 24 |
.BR clearerr () |
| 25 |
clears the end-of-file and error indicators for the stream pointed to by |
| 26 |
.IR stream . |
| 27 |
.P |
| 28 |
The function |
| 29 |
.BR feof () |
| 30 |
tests the end-of-file indicator for the stream pointed to by |
| 31 |
.IR stream , |
| 32 |
returning nonzero if it is set. |
| 33 |
The end-of-file indicator can be cleared only by the function |
| 34 |
.BR clearerr (). |
| 35 |
.P |
| 36 |
The function |
| 37 |
.BR ferror () |
| 38 |
tests the error indicator for the stream pointed to by |
| 39 |
.IR stream , |
| 40 |
returning nonzero if it is set. |
| 41 |
The error indicator can be reset only by the |
| 42 |
.BR clearerr () |
| 43 |
function. |
| 44 |
.P |
| 45 |
For nonlocking counterparts, see |
| 46 |
.BR unlocked_stdio (3). |
| 47 |
.SH RETURN VALUE |
| 48 |
The |
| 49 |
.BR feof () |
| 50 |
function returns nonzero if the end-of-file indicator is set for |
| 51 |
.IR stream ; |
| 52 |
otherwise, it returns zero. |
| 53 |
.P |
| 54 |
The |
| 55 |
.BR ferror () |
| 56 |
function returns nonzero if the error indicator is set for |
| 57 |
.IR stream ; |
| 58 |
otherwise, it returns zero. |
| 59 |
.SH ERRORS |
| 60 |
These functions should not fail and do not set |
| 61 |
.IR errno . |
| 62 |
.SH ATTRIBUTES |
| 63 |
For an explanation of the terms used in this section, see |
| 64 |
.BR attributes (7). |
| 65 |
.TS |
| 66 |
allbox; |
| 67 |
lbx lb lb |
| 68 |
l l l. |
| 69 |
Interface Attribute Value |
| 70 |
T{ |
| 71 |
.na |
| 72 |
.nh |
| 73 |
.BR clearerr (), |
| 74 |
.BR feof (), |
| 75 |
.BR ferror () |
| 76 |
T} Thread safety MT-Safe |
| 77 |
.TE |
| 78 |
.SH STANDARDS |
| 79 |
C11, POSIX.1-2008. |
| 80 |
.SH HISTORY |
| 81 |
C89, POSIX.1-2001. |
| 82 |
.SH NOTES |
| 83 |
POSIX.1-2008 specifies |
| 84 |
.\"https://www.austingroupbugs.net/view.php?id=401 |
| 85 |
that these functions shall not change the value of |
| 86 |
.I errno |
| 87 |
if |
| 88 |
.I stream |
| 89 |
is valid. |
| 90 |
.SH CAVEATS |
| 91 |
Normally, |
| 92 |
programs should read the return value of an input function, |
| 93 |
such as |
| 94 |
.BR fgetc (3), |
| 95 |
before using functions of the |
| 96 |
.BR feof (3) |
| 97 |
family. |
| 98 |
Only when the function returned the sentinel value |
| 99 |
.B EOF |
| 100 |
it makes sense to distinguish between the end of a file or an error with |
| 101 |
.BR feof (3) |
| 102 |
or |
| 103 |
.BR ferror (3). |
| 104 |
.SH SEE ALSO |
| 105 |
.BR open (2), |
| 106 |
.BR fdopen (3), |
| 107 |
.BR fileno (3), |
| 108 |
.BR stdio (3), |
| 109 |
.BR unlocked_stdio (3) |