REALPATH(3)

NAME
realpath - returns the canonicalized absolute pathname

SYNOPSIS
#include <limits.h>
#include <stdlib.h>
char *
realpath(const char *pathname, char *resolved);

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

RETURN VALUES
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.

ERRORS
The function realpath() will fail if:

[EACCES]
    Read or search permission was denied for a component of pathname.

[EINVAL]
    The pathname argument is a null pointer.

[EIO]
    An error occurred while reading from the file system.

[ELOOP]
    Too many symbolic links were encountered in translating pathname.

[ENAMETOOLONG]
    A component of pathname exceeded NAME_MAX characters, or the entire pathname (including the terminating NUL) exceeded PATH_MAX.

[ENAMETOOLONG]
    Pathname resolution of a symbolic link produced an intermediate result whose length exceeds PATH_MAX.

[ENOENT]
    A component of pathname does not name an existing file or pathname points to an empty string.

[ENOTDIR]
    A component of the path prefix is not a directory.

[ENOMEM]
    Sufficient storage space is unavailable for allocation.

SEE ALSO
readlink(1), getcwd(3)

STANDARDS
The realpath() function conforms to p1003.1-2008.

HISTORY
The realpath() function call first appeared in 4.4BSD.