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. πŸ’œβœ¨