replace_extension(3)

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

πŸ’… replace_extension(3) β€” the Allegro manual, but make it cute

okay bestie, so this one lives in the Allegro game programming library and it's literally called replace_extension. Yes, it does exactly what it says on the tin: it takes a filename+extension and swaps the extension tail for a new one. No cap. πŸŽ€


✨ NAME ✨

replace_extension β€” swaps out a filename+extension for a brand new extension tail. Part of the Allegro game programming library. πŸ’–


🌸 SYNOPSIS 🌸

#include <allegro.h>

char *replace_extension(char *dest, const char *filename, const char *ext, int size);

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the vibe: you hand it a filename (extension and all), and it replaces that extension with the new ext tail you want, writing the result into the dest buffer. It stores at most size bytes in there, so don't get bold with the buffer, bestie. πŸ’€

Now the fun part β€” if the filename has no extension at all, it just appends ext to the end of it, and it'll add a dot character if that's needed. Thoughtful. Iconic. πŸ’…

And here's the part that makes me feral: you can use the same buffer for both input and output, because Allegro internally works on a copy of the input before it ever touches dest. Go off, honestly. πŸ”₯

Example, look:

replace_extension(buf, "C:\\game\\prog.exe",
                  "dat", sizeof(buf));

see how it's giving "prog.exe β†’ prog.dat" energy? obsessed. ✨


πŸ‘‘ RETURN VALUE πŸ‘‘

It returns a copy of the dest parameter. That's it, that's the tea. 🫢


🌈 SEE ALSO 🌈


k bye bestie, go forth and rename things responsibly πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά

this has been your girl repping Allegro, version 4.4.3 β€” mwah, periodt. πŸ’œπŸ§šβ­

πŸ“¦ where this page comes from