al_for_each_fs_entry(3)

πŸ“¦
version 5.2.11.3 Β· 3 versions
, in arch rolling

✨ 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 callback returns ALLEGRO_FOR_EACH_FS_ENTRY_STOP or ALLEGRO_FOR_EACH_FS_ENTRY_ERROR, iteration stops immediately and al_for_each_fs_entry(3) returns the value the callback returned. Bye, loop. πŸ’€
  • If callback returns ALLEGRO_FOR_EACH_FS_ENTRY_OK, iteration continues normally. And if the ALLEGRO_FS_ENTRY(3) parameter of callback is 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 callback returns ALLEGRO_FOR_EACH_FS_ENTRY_SKIP, iteration continues, but al_for_each_fs_entry(3) will NOT recurse into the ALLEGRO_FS_ENTRY(3) parameter of callback even 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 use al_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 making callback return 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