REALPATH(3) | Library Functions Manual | REALPATH(3) |
realpath
— returns
the canonicalized absolute pathname
#include
<limits.h>
#include <stdlib.h>
char *
realpath
(const
char *pathname, char
*resolved);
The realpath
() 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
resolved argument must refer to a
buffer capable of storing at least PATH_MAX
characters, or be NULL
.
The realpath
() function will resolve both
absolute and relative paths and return the absolute pathname corresponding
to pathname. All but the last component of
pathname must exist when
realpath
() is called.
The realpath
() function returns
resolved on success. If resolved
is NULL
and no error occurred, then
realpath
() returns a NUL-terminated string in a
newly allocated buffer. If an error occurs,
realpath
() returns NULL
and
the contents of resolved are undefined.
The function realpath
() will fail if:
EACCES
]EINVAL
]EIO
]ELOOP
]ENAMETOOLONG
]NAME_MAX
characters, or the entire
pathname (including the terminating NUL) exceeded
PATH_MAX
.ENAMETOOLONG
]PATH_MAX
.ENOENT
]ENOTDIR
]ENOMEM
]The realpath
() function conforms to
IEEE Std 1003.1-2008 (“POSIX.1”).
The 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
kdump(1).
July 5, 2019 | OpenBSD-current |