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 tothisβ 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. πβ¨
π¦ where this page comes from
- debian bookworm: allegro4-doc 2:4.4.3.1-3 Β· Allegro-gift-ware
- debian trixie: allegro4-doc 2:4.4.3.1-5 Β· Allegro-gift-ware
- ubuntu jammy: allegro4-doc 2:4.4.3.1-2 Β· Allegro-gift-ware
- ubuntu noble: allegro4-doc 2:4.4.3.1-4.1build3 Β· Allegro-gift-ware
- ubuntu questing: allegro4-doc 2:4.4.3.1-6
- ubuntu resolute: allegro4-doc 2:4.4.3.1-7 Β· Allegro-gift-ware
- ubuntu stonking: allegro4-doc 2:4.4.3.1-9 Β· Allegro-gift-ware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms