rel2abs(3)

rel2abs3

Make an absolute path name from a relative path name

Usage

library “libpathconv”

char *

rel2abs(const char *path, const char *base, char *result, size_t size);

Overview

The rel2abs() function makes an absolute path name from a relative path name path based on a directory base and copies the resulting path name into the memory referenced by result. The result argument must refer to a buffer capable of storing at least size character

The resulting path name may include symbolic links. abs2rel() doesn't check whether or not any path exists.

Return values

The rel2abs() function returns absolute path name on success. If an error occurs, it returns NULL.

Examples

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

yields:

path == "/usr/src/sys"

Similarly,

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

yields:

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

Errors

The rel2abs() function may fail and set the external variable errno to indicate the error.

[EINVAL]

The base directory isn't an absolute path name or the size argument is zero.

[ERANGE]

The size argument is greater than zero but smaller than the length of the pathname plus 1

Releases

20 releases since FreeBSD 12.0-RELEASE; the text changed 12 times.

  1. 12.0
  2. 12.1
  3. 12.2
  4. 12.3
  5. 12.4
  6. 13.0–13.1
  7. 13.2
  8. 13.3–14.2
  9. 14.3–14.4
  10. 14.5
  11. 15.0
  12. 15.1
  13. 16.0

Authors

Shigio Yamaguchi ⟨[email protected]⟩

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.