OpenBSD manual page server

Manual Page Search Parameters

REALPATH(3) Library Functions Manual REALPATH(3)

realpathreturns the canonicalized absolute pathname

#include <limits.h>
#include <stdlib.h>

char *
realpath(const char *pathname, char *resolved);

The () 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 refer to a buffer capable of storing at least PATH_MAX characters, or be NULL.

The () 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.

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:

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_MAX characters, or the entire pathname (including the terminating NUL) exceeded PATH_MAX.
Pathname resolution of a symbolic link produced an intermediate result whose length exceeds PATH_MAX.
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)

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).

October 13, 2021 OpenBSD-current