REL2ABS(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’… REL2ABS(3) β€” library functions manual, but make it cute

okay so bestie, welcome to rel2abs from the Library Functions Manual β€” she's a libpathconv girlie and she's here to turn your messy little relative path into a whole absolute main-character path. slay ✨


🌸 NAME 🌸

rel2abs β€” make an absolute path name from a relative path name. that's it, that's the whole vibe πŸŽ€


✨ SYNOPSIS ✨

library β€œlibpathconv” char *
rel2abs(const char *path, const char *base, char *result, size_t size);

yes she's a char * returner, no cap πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so the rel2abs() function takes a relative path name path, glows it up based on a directory base, and copies the resulting absolute path name into the memory that result points at. iconic behaviour honestly 🫢

the result argument must refer to a buffer capable of storing at least size character β€” like, it literally has to have room, don't set her up to fail 😭

the resulting path name may include symbolic links. also, abs2rel() doesn't check whether or not any path exists β€” so she's not doing a vibe check on your filesystem, she's just doing path math, periodt πŸ’€


πŸ”₯ RETURN VALUES πŸ”₯

  • on success, rel2abs() returns the absolute path name β€” ate and left no crumbs πŸ‘‘
  • if an error occurs, it returns NULL β€” literally the sad trombone moment πŸ™ˆ

🌈 EXAMPLES 🌈

okay here's the flex, look at this:

char result[MAXPATHLEN];
char *path = rel2abs("../../src/sys", "/usr/local/lib", result,
MAXPATHLEN);

and that yields:

path == "/usr/src/sys"

like?? she walked up out of ../../ and landed perfectly. obsessed ⭐

similarly:

path1 = rel2abs("src/sys", "/usr", result, MAXPATHLEN);
path2 = rel2abs(".", "/usr/src/sys", result, MAXPATHLEN);

yields:

path1 == "/usr/src/sys"
path2 == "/usr/src/sys"

two different inputs, same absolute slay. the way that works πŸ’–


πŸ’€ ERRORS πŸ’€

the rel2abs() function may fail and set the external variable errno to indicate the error. so yeah, check your errno, bestie, she's telling you something 🧚

  • [EINVAL] β€” the base directory isn't an absolute path name, or the size argument is zero. like babe, base has to be absolute and size can't be zero, those are the rules πŸ™ˆ
  • [ERANGE] β€” the size argument is greater than zero but smaller than the length of the pathname plus 1. so your buffer is almost big enough and that's honestly the most painful kind of fail 😭

πŸŽ€ SEE ALSO πŸŽ€

  • abs2rel(3) β€” her sister, go say hi 🫢

πŸ’œ AUTHORS πŸ’œ

Shigio Yamaguchi (shigio@tamacom.com) β€” thank you for this gift, king πŸ‘‘


and that's the page!! brought to you by Debian, dated December 13, 2025 β€” mwah, go forth and absolutise your paths πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from
  • freebsd 14.5: base 14.5
  • freebsd 15.1: base 15.1
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms