abs2rel3
Make a relative path name from an absolute path name
Usage
library “libpathconv”
char *
abs2rel(const char *path, const char *base, char *result, size_t size);
Overview
The abs2rel() function makes a relative path name from an absolute 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 characters.
The resulting path name may include symbolic links. The abs2rel() function doesn't check whether or not any path exists.
Return values
The abs2rel() function returns relative path name on success. If an error occurs, it returns NULL.
Examples
char result[MAXPATHLEN];
char *path = abs2rel("/usr/src/sys", "/usr/local/lib", result, MAXPATHLEN);
yields:
path == "../../src/sys"
Similarly,
path1 = abs2rel("/usr/src/sys", "/usr", result, MAXPATHLEN);
path2 = abs2rel("/usr/src/sys", "/usr/src/sys", result, MAXPATHLEN);
yields:
path1 == "src/sys"
path2 == "."
Errors
The abs2rel() 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.