make_relative_filename(3alleg4)

πŸ’– make_relative_filename β€” the Allegro manual page, bestie edition πŸ’–

okay so this is make_relative_filename from the Allegro manual, and it's genuinely one of those little functions that just works once you get it. She tries to make a relative filename from an absolute path and filename. slay.


✨ NAME ✨

make_relative_filename β€” tries to make a relative filename from absolute path and filename. Allegro game programming library. πŸŽ€


🌸 SYNOPSIS 🌸

#include <allegro.h>

char *make_relative_filename(char *dest, const char *path, const char
*filename, int size);

πŸ¦‹ DESCRIPTION πŸ¦‹

so basically, she attempts to make a relative filename from an absolute path and an absolute filename, storing at most size bytes into the dest buffer. πŸ’…

real talk: this function won't work if the paths are not canonical under the current platform (see canonicalize_filename()). also, dest cannot be used as input value for path or filename. not me warning you twice, it's just important bestie 😭

example, because seeing it is believing:

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 */

like, look at that glow-up. absolute path in, cute little relative path out. iconic. ✨


πŸ‘‘ RETURN VALUE πŸ‘‘

returns a copy of the dest parameter if she succeeds, or NULL if she fails (eg. under DOS, one path starts with "C:\" and another with "A:\"). periodt. πŸ’€


🌈 SEE ALSO 🌈


and that's the whole page, bestie β€” brought to you by Allegro version 4.4.3, make_relative_filename(3alleg4), mwah πŸ’‹ go make some relative paths, you got this 🫢