al_for_each_fs_entry(3)
β¨ NAME β¨
al_for_each_fs_entry β Allegro 5 API. You're on the al_for_each_fs_entry(3) page from the Allegro reference manual, bestie, and it's giving "let's walk a directory tree together" main character energy π
π¦ 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 here's the vibe: al_for_each_fs_entry(3) takes the ALLEGRO_FS_ENTRY(3) dir β which should represent a directory β and looks for any other file system entries that are in it. Then it calls the callback function callback once for every filesystem entry in the directory dir. Obsessed? Same. π
The callback callback must be of type int callback(ALLEGRO_FS_ENTRY * entry, void * extra). It gets called with a pointer to an ALLEGRO_FS_ENTRY(3) that matches one file or directory in dir, plus the pointer passed in the extra parameter to al_for_each_fs_entry(3). No cap, that's the whole handoff. π«Ά
Now the return-value vibe check, because this is where the recursion drama happens:
- If
callbackreturnsALLEGRO_FOR_EACH_FS_ENTRY_STOPorALLEGRO_FOR_EACH_FS_ENTRY_ERROR, iteration stops immediately andal_for_each_fs_entry(3)returns the value the callback returned. Bye, loop. π - If
callbackreturnsALLEGRO_FOR_EACH_FS_ENTRY_OK, iteration continues normally. And if theALLEGRO_FS_ENTRY(3)parameter ofcallbackis a directory,al_for_each_fs_entry(3)will call itself on that directory β so yes, it recursively descends into that directory. It's giving recursion, periodt. π₯ - If
callbackreturnsALLEGRO_FOR_EACH_FS_ENTRY_SKIP, iteration continues, butal_for_each_fs_entry(3)will NOT recurse into theALLEGRO_FS_ENTRY(3)parameter ofcallbackeven if it is a directory. Skip means skip, bestie. π
Also important: this function will skip any files or directories named . or .., which may exist on certain platforms and may signify the current and the parent directory. The callback will not be called for files or directories with such a name. π
Returns, because yes there are layers:
ALLEGRO_FOR_EACH_FS_ENTRY_OKβ returns this if successful. Slay. βALLEGRO_FOR_EACH_FS_ENTRY_ERRORβ returns this if something went wrong in processing the directory. In that case it will useal_set_errno(3)to indicate the type of error which occurred. So check that errno, bestie. πALLEGRO_FOR_EACH_FS_ENTRY_STOPβ returns this in case iteration was stopped by makingcallbackreturn that value. In this case,al_set_errno(3)will not be used. Important distinction, iykyk. β
π SEE ALSO π
πΈ SINCE πΈ
5.1.9 β iconic since then, fr fr. π
π okay that's the whole page, bestie! from the Allegro reference manual, all about al_for_each_fs_entry(3); the footer date is whatever your local copy says, and we're not inventing one β mwah π
π¦ where this page comes from
- arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms