al_feof(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ al_feof β€” Allegro 5 API ✨

okay bestie, welcome to the al_feof(3alleg5) page, you're gonna eat this one up πŸ’…


🌸 SYNOPSIS 🌸

#include <allegro5/allegro.h>

bool al_feof(ALLEGRO_FILE *f)

πŸ’– DESCRIPTION πŸ’–

So like. al_feof returns true if the end-of-file indicator has been set on the file, i.e. we have attempted to read past the end of the file. πŸŽ€

NOT ME GETTING THIS WRONG FOR YEARSβ€” it does not return true just because you're simply at the end of the file. like, being at the end and having tried to read past the end are two completely different vibes, and this function only cares about the second one. 😭

the following code correctly reads two bytes, even when the file contains exactly two bytes:

int b1 = al_fgetc(f);
int b2 = al_fgetc(f);
if (al_feof(f)) {
   /* At least one byte was unsuccessfully read. */
   report_error();
}

so yeah, you can read exactly two bytes out of a two-byte file and not trip the EOF flag, because both reads succeeded. the flag only pops when a read actually fails. it's giving "last one to leave doesn't get flagged, only the one who tried to go past the exit" πŸšͺ✨


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page, no cap 🫢 Allegro reference manual, al_feof(3alleg5) β€” go slay your file reads, queen πŸ‘‘πŸ’œ

πŸ“¦ where this page comes from