canonicalize_filename(3)
π canonicalize_filename(3) β Allegro manual π
okay bestie, gather round, because this one is so useful and also lowkey cursed if you use it wrong. it's from the Allegro game programming library, and it's here to make your filenames behave. π
β¨ NAME β¨
canonicalize_filename β Converts any filename into its canonical form. Allegro game programming library.
like, it takes whatever chaotic little path string you hand it and gives you back the one true version. π
πΈ SYNOPSIS πΈ
#include <allegro.h>
char *canonicalize_filename(char *dest, const char *filename, int size);
π¦ DESCRIPTION π¦
so here's the vibe: this function converts any filename into its canonical form, aka the minimal absolute filename that describes the exact same file. it also fixes up any incorrect forward/backward slashes so they match whatever platform you're actually on. π
it stores at most size bytes into the dest buffer. and here's the cute part β you can totally use the same buffer for both input and output, because Allegro internally works on a copy of the input before it ever touches dest. no cap. π«Ά
example, bestie:
char buf[256];
...
canonicalize_filename(buf, "~/../s22/..\\t3st///hi.c",
sizeof(buf));
/* Running this under Unix would
return: /home/t3st/hi.c */
see how messy that input was?? slashes everywhere, .. doing the most, and it still pulled out /home/t3st/hi.c. iconic behavior honestly. πβ¨
β οΈ BUT. huge warning, pay attention: this function won't work as expected if the path you're canonicalizing comes from another platform. example, a"c:\something"path will canonicalize into something really wrong under Unix:"/current/path/c:/something". it's giving chaos. so don't do that. π
π RETURN VALUE π
returns a copy of the dest parameter. that's it, that's the whole thing. she returns herself. main character energy. π
π₯ SEE ALSO π₯
Allegro, version 4.4.3 β and yeah the header/footer says canonicalize_filename(3) twice because the manpage said so, we don't make the rules. mwah, go canonicalize something, bestie π§π
π¦ where this page comes from
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms