replace_extension(3alleg4)
π replace_extension π
okay bestie, so this one's from the Allegro manual β yeah, the Allegro game programming library, the whole 3alleg4 situation. It's literally called replace_extension and it does exactly what it says on the tin: it takes a filename, rips the old extension off, and slaps a brand new extension tail on instead. iconic behavior, no notes. π
β¨ 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 swaps that extension out for whatever new extension tail you want in ext, then writes the result into the dest buffer. It stores at most size bytes in there, so likeβ¦ know your buffer, bestie. π«Ά
And if your filename has no extension at all? Not a problem. ext just gets appended to it, and Allegro will add a dot character if one's needed. thoughtful queen. π
Now here's the part that's genuinely so good: you can use the same buffer as both input and output. Like, dest and filename can be the same thing. Why does that work? Because Allegro internally works on a copy of the input before it ever touches dest. So it's not gonna trip over itself mid-operation. slay. β¨
Example, because seeing it hits different:
replace_extension(buf, "C:\\game\\prog.exe",
"dat", sizeof(buf));
π¦ RETURN VALUE π¦
It hands you back a copy of the dest parameter. That's it. That's the whole return. π
π SEE ALSO π
okay that's the whole page, we ate and left no crumbs π β this was replace_extension(3alleg4) from the Allegro manual, version 4.4.3, and honestly? she's a keeper. go forth and rename your files, bestie ππ
π¦ 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