al_for_each_fs_entry(3alleg5)
π al_for_each_fs_entry β the Allegro 5 API glow-up π
ok so bestie, welcome to the al_for_each_fs_entry(3alleg5) page from the Allegro reference manual. we're about to walk a whole directory tree together and it's gonna be adorable. let's GO π§β¨
β¨ SYNOPSIS β¨
#include <allegro5/allegro.h>
int al_for_each_fs_entry(ALLEGRO_FS_ENTRY *dir,
int (*callback)(ALLEGRO_FS_ENTRY *dir, void *extra),
void *extra)
πΈ DESCRIPTION πΈ
okay so picture this: you hand this function an ALLEGRO_FS_ENTRY(3alleg5) called dir, and dir is supposed to be a directory. it goes looking for literally every other file system entry chillin' inside it. then it calls your callback function β yes, the one called callback β once for every single filesystem entry in that directory. one call per entry. no skipping, no favoritism, main character energy for every file. π
your callback has to be of type int callback(ALLEGRO_FS_ENTRY * entry, void * extra). every time it gets called, it receives a pointer to an ALLEGRO_FS_ENTRY(3alleg5) that matches one file or directory inside dir, plus the pointer you passed in through the extra parameter of al_for_each_fs_entry(3alleg5). cute, right? π
now here's the part where the return values get spicy π₯:
- when callback returns
ALLEGRO_FOR_EACH_FS_ENTRY_STOPorALLEGRO_FOR_EACH_FS_ENTRY_ERROR, iteration stops immediately, andal_for_each_fs_entry(3alleg5)hands back whatever value the callback returned. like, we're done, no more, periodt. π - when callback returns
ALLEGRO_FOR_EACH_FS_ENTRY_OK, iteration keeps going like normal. and β plot twist β if theALLEGRO_FS_ENTRY(3alleg5)parameter of callback is itself a directory,al_for_each_fs_entry(3alleg5)will call itself on that directory. so yes bestie, it recursively descends into that directory. it's giving inception. π - however!! when callback returns
ALLEGRO_FOR_EACH_FS_ENTRY_SKIP, iteration still continues, butal_for_each_fs_entry(3alleg5)will NOT recurse into theALLEGRO_FS_ENTRY(3alleg5)parameter of callback, even if it happens to be a directory. we see it, we wave, we move on. π
also, lowkey important: this function skips any files or directories named . or .. β those little guys might exist on certain platforms and might mean the current directory and the parent directory. the callback will not be called for files or directories with such a name. not today, . and ... π
π RETURN VALUE π
so what do you get back?
ALLEGRO_FOR_EACH_FS_ENTRY_OKβ slay, everything worked. βALLEGRO_FOR_EACH_FS_ENTRY_ERRORβ something went wrong while processing the directory π. in that case it will useal_set_errno(3alleg5)to indicate the type of error that occurred.ALLEGRO_FOR_EACH_FS_ENTRY_STOPβ this one shows up when iteration was stopped by making callback return that value. and in this case,al_set_errno(3alleg5)will not be used. nope, not touching it.
ngl bestie, keep those three straight in your head, because mixing upERRORandSTOPis the kind of vibe check you do not want to fail. π
π SEE ALSO π
β SINCE β
5.1.9
and that's the whole page, bestie π«Ά β this was al_for_each_fs_entry(3alleg5) from the Allegro reference manual, and yeah, it's been around since way back in 5.1.9. go forth and recurse responsibly. mwah π
π¦ where this page comes from
- debian trixie: allegro5-doc 2:5.2.10.1+dfsg-1 Β· Zlib
- ubuntu questing: allegro5-doc 2:5.2.10.1+dfsg-1build1
- ubuntu resolute: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- ubuntu stonking: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms