canonicalize_filename(3)

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

πŸ’– 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