get_filename(3)

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

πŸ’– get_filename β€” bestie edition πŸ’–

okay so this is a page from the Allegro manual, the game programming library, and we're talking about get_filename(3) β€” the little function that hands you a pointer to the filename part of a path. πŸŽ€


✨ NAME ✨

get_filename β€” returns a pointer to the filename portion of a path. it's giving Allegro game programming library realness πŸ¦‹


🌸 SYNOPSIS 🌸

#include <allegro.h>

char *get_filename(const char *path);

πŸ’… DESCRIPTION πŸ’…

so what this does is: it finds the filename portion of a completely specified file path. like, full path in, filename out. iconic.

now here's the tea on separators β€” both \ and / count as directory separators when you're under DOS and Windows. but under every other platform? only / counts. so no cap, the backslash thing is a Windows/DOS-only situation. πŸ’€

example, look:

get_executable_name(name, sizeof(name));
allegro_message("Running `%s'\n", get_filename(name));
✨ important note: Allegro does not perform any IO operations during the verification. none. zero. it's just vibing with the string.

and the way that matters is: if you have /a/path/like/this/ β€” which doesn't have a filename β€” the function returns a pointer to the trailing null character. but if you have /a/path/like/this (no trailing slash), Allegro returns a pointer to this, even if it is a valid directory. no peeking at the filesystem, no checking if it's real, just vibes. πŸ™ˆ


🫢 RETURN VALUE 🫢

returns a pointer to the portion of path where the filename starts β€” or the beginning of path if no valid filename is found (eg. you are processing a path with backslashes under Unix, which lowkey will not work for you there bestie 😭).


🌈 SEE ALSO 🌈


and that's the whole page, periodt. πŸ’…βœ¨ this was Allegro, version 4.4.3 β€” shoutout to the Allegro girlies for keeping the docs alive, ily, go read get_extension(3) next bestie πŸ’–πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from