al_findnext(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸ’– al_findnext πŸ’–

okay bestie, so you know al_findfirst(3)? the one that kicks off a whole search for files? yeah. this is its ride-or-die sequel β€” the function that keeps the party going and grabs the next file in a search that al_findfirst() already started. it's part of the Allegro game programming library, iykyk. πŸ¦‹


✨ SYNOPSIS ✨

#include <allegro.h>

int al_findnext(struct al_ffblk *info);

like. that's it. one include, one call. so clean. πŸŽ€


🌸 DESCRIPTION 🌸

so the way this works is: this finds the next file in a search that was started by al_findfirst(). that's literally the whole vibe. it's the "and then???" of file searching. πŸ’…

here's what it looks like in the wild, no cap:

if (al_findfirst("*.pcx", &info, 0) != 0)
   return;

do {
   /* Do something useful here with info.name. */
} while (al_findnext(&info) == 0);

al_findclose(&info);

see how it loops? al_findfirst() gets you the first hit, al_findnext() keeps feeding you more until it can't anymore, and then al_findclose() cleans up after you. main character loop behavior fr. πŸ‘‘

quick PSA: notice how info.name is the thing you actually use inside the loop β€” that's where the current filename lives. go do something iconic with it. 🌈

🫢 RETURN VALUE 🫢

  • returns zero if a match is found β€” slay, keep going ✨
  • returns non-zero if no match is found, or if an error happened
  • and in that error case, it sets errno accordingly so you can figure out what went wrong 😭

so like, == 0 means "yay more files", anything else means "we're done here". simple. periodt. πŸ’œ


πŸ”₯ SEE ALSO πŸ”₯


and that's the whole thing! πŸ¦‹ this page is from the Allegro manual, version 4.4.3 β€” so if you're out here searching files, go off, you got this. mwah. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from