ferror(3)
๐ ferror(3) โ the girlies' guide to checking & resetting stream status ๐
okay so bestie, this is a page from the Library Functions Manual, and it's about three little functions that all live in <stdio.h> and are lowkey the bouncers of your file streams. they check the vibes. they reset the vibes. let's get into it. โจ
๐ธ NAME ๐ธ
clearerr, feof, ferror โ check and reset stream status, bestie. that's it. that's the job. ๐
๐ LIBRARY ๐
Standard C library, aka libc, link it with -lc. iconic, standard, we love her. ๐ซถ
โจ SYNOPSIS โจ
#include <stdio.h>
void clearerr(FILE *stream);
int feof(FILE *stream);
int ferror(FILE *stream);
look at them. three little icons. ๐
๐ DESCRIPTION ๐
so here's the tea, one function at a time:
clearerr()โ this one clears the end-of-file indicator and the error indicator for the stream thatstreampoints to. it's the factory reset. the clean slate. the "we don't talk about that anymore" button. ๐งนfeof()โ this one tests the end-of-file indicator for the stream thatstreampoints to, and it returns nonzero if that indicator is set. and here's the important part: that end-of-file indicator can only be cleared byclearerr(). nobody else. not you, not your other functions, onlyclearerr(). periodt. ๐ferror()โ this one tests the error indicator for the stream thatstreampoints to, returning nonzero if it's set. and same energy as above: the error indicator can be reset only by theclearerr()function. she's the only one with the keys. ๐
and if you're out here looking for the nonlocking counterparts of these? go check unlocked_stdio(3), bestie. that's where they live. ๐ฆ
๐ฏ RETURN VALUE ๐ฏ
feof()returns nonzero if the end-of-file indicator is set forstream, otherwise it returns zero. simple as that. โจferror()returns nonzero if the error indicator is set forstream, otherwise it returns zero. also simple. also slay. ๐
๐ซ ERRORS ๐ซ
these functions should not fail, and they do not set errno. like, at all. they're too chill for that. ๐
๐ฅ ATTRIBUTES ๐ฅ
for an explanation of the terms used in this section, go peek at attributes(7). (yes, we're citing our sources, we're academic like that ๐)
so the interface here is clearerr(), feof(), ferror() โ and its attribute:
- Thread safety:
MT-Safe๐งตโจ
that's the whole table, bestie. one row, one vibe: safe to use across threads. no cap. ๐ฅ
๐ STANDARDS ๐
C11, POSIX.1-2008. she's certified. she's compliant. she passed the vibe check. โ
๐ฐ๏ธ HISTORY ๐ฐ๏ธ
C89, POSIX.1-2001. she's been around since before you were born and she's still serving. a true legacy icon. ๐
๐ NOTES ๐
POSIX.1-2008 specifies that these functions shall not change the value of errno if stream is valid. so if your stream is valid, your errno stays exactly where you left her. untouched. unbothered. ๐
โ ๏ธ CAVEATS โ ๏ธ
okay this one actually matters so listen up bestie, no scrolling past this one. ๐
normally, programs should read the return value of an input function, like fgetc(3), before using functions from the feof(3) family. like, read the actual result first. do not come for feof() before you've even asked the input function what happened.
only when that function returned the sentinel value EOF does it make sense to distinguish between the end of a file or an error, using feof(3) or ferror(3).
so the order is: call the input function โ get EOF โ then ask feof() or ferror() what's up. checking too early is giving main character energy in the wrong way. ๐
๐ SEE ALSO ๐
go read them. they're all part of the family. ๐
and that's the whole page, bestie!! ๐ before you go: this was Linux man-pages 6.20, dated 2026-02-08, and it's page ferror(3) in case you need to cite her. mwah, go read your streams properly, ily ๐๐ฆโจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: BSD-4-Clause-UC
- Copyright 1990-1991, The Regents of the University of California
- Copyright 2021, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms