canonicalize_filename(3alleg4)
π canonicalize_filename β Allegro manual, but make it cute π
okay bestie, buckle up, this one's a little function from the Allegro game programming library and it's here to make your filenames behave. no cap.
β¨ SYNOPSIS β¨
#include <allegro.h>
char *canonicalize_filename(char *dest, const char *filename, int size);
πΈ DESCRIPTION πΈ
So what does it do? It takes any filename and turns it into its canonical form, which is basically the glow-up version: the minimal absolute filename that describes the exact same file, and it also fixes up any incorrect forward/backward slashes so they match whatever platform you're actually on. iconic behavior honestly.
It stores at most size bytes into the dest buffer. π
And here's the part that lowkey slays: you can use the same buffer as both input and output, because Allegro internally works on a copy of the input before it ever touches dest. no conflict, no drama, we love a safe queen. π
Example, because a girl loves a demo:
char buf[256];
...
canonicalize_filename(buf, "~/../s22/..\\t3st///hi.c",
sizeof(buf));
/* Running this under Unix would
return: /home/t3st/hi.c */
β οΈ but bestie, real talk β this function will not work as expected if the path you're canonicalizing comes from another platform. like, a"c:\something"path will canonicalize into something really wrong under Unix:"/current/path/c:/something". it's giving chaos. don't do it. π«
π« RETURN VALUE π«
It returns a copy of the dest parameter. that's it, that's the whole vibe. π
π¦ SEE ALSO π¦
and that's the whole page, bestie!! π«Ά this was Allegro version 4.4.3, dated alongside the canonicalize_filename(3alleg4) page itself β mwah, go fix those slashes, you've got this. πβ¨
π¦ 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