make_relative_filename(3)
π make_relative_filename β the Allegro manual, but make it make sense π
okay bestie, this one lives in the Allegro game programming library, and it's genuinely so useful once you get the vibe. no cap. π«Ά
β¨ NAME β¨
make_relative_filename β she tries to make a relative filename out of an absolute path and an absolute filename. part of the Allegro game programming library, periodt. π
πΈ SYNOPSIS πΈ
#include <allegro.h>
char *make_relative_filename(char *dest, const char *path, const char
*filename, int size);
like. look at her. iconic signature fr fr. π
π¦ DESCRIPTION π¦
so what she's doing is: you hand her an absolute path and an absolute filename, and she attempts to cook up a relative filename for you, storing at most size bytes into the dest buffer. that's the whole assignment. she ate. π₯
β οΈ two things you NEED to know before you go off, bestie: - she won't work if the paths aren't canonical under the current platform β go checkcanonicalize_filename()for that, iykyk -destcannot be used as the input value forpathorfilename. do not do it. it's giving chaos. π
here's the example, verbatim, don't touch her:
char base[] = "/long/absolute/path/program.exe";
char user_input[] = "/nice/and/short.txt";
...
make_relative_filename(buf, base, user_input, sizeof(buf));
/* Under Unix buf would contain:
../../../nice/and/short.txt */
the way that ../../../nice/and/short.txt is literally a glow-up from that giant absolute path... we love a transformation arc. β¨π
π RETURN VALUE π
she returns a copy of the dest parameter when she succeeds. if she fails, you get NULL. π«
and lowkey the failure case is messy β for example, under DOS, if one path starts with "C:\" and another starts with "A:\", bestie there is simply no relative path between those two worlds. two different drives, two different universes. π
π SEE ALSO π
make_absolute_filename(3)β the reverse girly πis_relative_filename(3)β the vibe check βcanonicalize_filename(3)β go here first if your paths are acting uncanonical π
that's the whole page, bestie β no notes, she's perfect. this little love letter comes straight out of the Allegro manual, version 4.4.3, and the page you just read is make_relative_filename(3). go forth and compute, queen. πβ¨πΈπ¦ππ
π¦ 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