replace_filename(3)

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

πŸ’– replace_filename(3) πŸ’–

okay bestie, so this one is from the Allegro manual β€” yes, the Allegro game programming library β€” and it's giving "let me swap out the tail of this path real quick" energy. replace_filename literally replaces a path+filename with a new filename tail. that's it. that's the whole vibe. ✨


✨ SYNOPSIS ✨

#include <allegro.h>

char *replace_filename(char *dest, const char *path, const char *filename, int size);

🌸 DESCRIPTION 🌸

so what it does is: it takes the path+filename you hand it and swaps in a whole new filename tail, then drops it into the dest buffer β€” but only ever writes at most size bytes there, so no overflow shenanigans, we love a safe queen πŸ’…

and here's the iconic part: you can pass the same buffer as both input and output, no cap. like, dest can literally be path. why? because Allegro is a considerate bestie and internally works on a copy of the input before it touches dest, so nothing gets mangled mid-operation. 🫢

example time, bestie:

char name[200];
...
get_executable_name(name, sizeof(name));
replace_filename(name, name, "sound.dat", sizeof(name));

see how name is doing double duty as both the source and the destination? yeah. slay. πŸ‘‘


πŸŽ€ RETURN VALUE πŸŽ€

it hands you back a copy of the dest parameter. that's it, that's the return. πŸ’–


πŸ¦‹ SEE ALSO πŸ¦‹


okay that's the whole page, no notes. this was written against Allegro version 4.4.3, and the page itself is replace_filename(3) β€” so go forth, swap those filenames, and stay hydrated πŸ’œπŸ’…βœ¨

πŸ“¦ where this page comes from