get_filename(3alleg4)

✨ get_filename β€” Allegro manual, section 3alleg4 ✨

okay bestie, listen up, this one's a lil function from the Allegro game programming library called get_filename(3alleg4) and it does exactly one thing but it does it flawlessly. πŸ’…


πŸ¦‹ NAME πŸ¦‹

get_filename β€” hands you a pointer to the filename portion of a path. part of the Allegro game programming library, iykyk. πŸ‘‘


🌸 SYNOPSIS 🌸

#include <allegro.h>

char *get_filename(const char *path);

that's it. one include, one function, no drama. ✨


πŸ’– DESCRIPTION πŸ’–

okay so picture this: you've got a whole entire file path, fully specified, the works. get_filename finds out which part of it is actually the filename portion and points at it. no cap. πŸ”₯

now here's the separator tea β˜• β€” under DOS and Windows, both \ and / get recognized as directory separators. but under every other platform? only / counts. so if you're on Unix and you hand it backslashes, bestie, it's gonna be confused. 😭

example time, look at this gorgeousness:

get_executable_name(name, sizeof(name));
allegro_message("Running `%s'\n", get_filename(name));

see how cute that is? it grabs the executable name, then asks for just the filename part, then prints it. iconic behavior honestly. 🫢

⚠️ important warning moment: Allegro does not perform any IO operations during the verification. none. zero. not a single disk touch. which means: - if you've got /a/path/like/this/, which has no filename at the end, the function returns a pointer to the trailing null character. - but if you've got /a/path/like/this (no trailing slash), Allegro returns a pointer to this β€” even if it's a valid directory. yes. even then. it does not check. it does not care. πŸ’€

πŸŽ€ RETURN VALUE πŸŽ€

it returns a pointer to the portion of path where the filename starts. and if no valid filename is found? it gives you a pointer to the beginning of path instead. (example: you're processing a path with backslashes under Unix. classic. πŸ™ˆ)


🌈 SEE ALSO 🌈

go read those too, they're the friend group. 🧚


and that's the whole page, bestie!! this was Allegro, version 4.4.3, manual section 3alleg4, for the one and only get_filename. mwah πŸ’– stay slay, stay portable, and remember: no trailing slash means no filename, periodt. πŸ‘‘βœ¨