returns the canonicalized absolute
char *pathname, char
function resolves all symbolic links, extra “/” characters and
references to /./ and /../
in pathname, and copies the resulting absolute
pathname into the memory referenced by resolved. The
to a buffer capable of storing at least
characters, or be
function will resolve both absolute and relative paths and return the
absolute pathname corresponding to pathname. All
components of pathname must exist when
realpath() is called.
realpath() function returns
resolved on success. If resolved
NULL and no error occurred, then
realpath() returns a NUL-terminated string in a
newly allocated buffer. If an error occurs,
the contents of resolved are undefined.
realpath() will fail if:
- Read or search permission was denied for a component of pathname.
- The pathname argument is a null pointer.
- An error occurred while reading from the file system.
- Too many symbolic links were encountered in translating pathname.
- A component of pathname exceeded
NAME_MAXcharacters, or the entire pathname (including the terminating NUL) exceeded
- Pathname resolution of a symbolic link produced an intermediate result
whose length exceeds
- A component of pathname does not name an existing file or pathname points to an empty string.
- A component of the path prefix is not a directory.
- Sufficient storage space is unavailable for allocation.
readlink(1), realpath(1), getcwd(3)
realpath() function conforms to
IEEE Std 1003.1-2008 (“POSIX.1”).
realpath() function call first
appeared in 4.4BSD.
In OpenBSD 6.6, it was reimplemented on
top of the
__realpath() system call. Its calling
convention differs from the standard function by requiring
resolved to not be
NULL and by
returning an integer, zero on success, and -1 with corresponding errno on
failure. This is visible in the output of