REL2ABS(3)
π 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]β thebasedirectory isn't an absolute path name, or thesizeargument is zero. like babe,basehas to be absolute andsizecan't be zero, those are the rules π[ERANGE]β thesizeargument 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
- Copyright (c) 1997 Shigio Yamaguchi. All rights reserved
- Copyright (c) 1999 Tama Communications Corporation. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms