REALPATH(3) Library Functions Manual REALPATH(3)

realpathresolve a pathname


#include <stdlib.h>

char *realpath(const char *restrict file_name,
       char *restrict resolved_name);

The realpath () function shall derive, from the pathname pointed to by file_name, an absolute pathname that names the same file, whose resolution does not involve ‘’., ‘..’, or symbolic links. The generated pathname shall be stored as a null-terminated string, up to a maximum of {PATH_MAX} bytes, in the buffer pointed to by resolved_name.

If resolved_name is a null pointer, the behavior of realpath () is implementation-defined.

Upon successful completion, realpath () shall return a pointer to the resolved name. Otherwise, realpath () shall return a null pointer and set to indicate the error, and the contents of the buffer pointed to by resolved_name are undefined.

The realpath () function shall fail if:

Read or search permission was denied for a component of file_name .
The file_name argument is a null pointer.
An error occurred while reading from the file system.
A loop exists in symbolic links encountered during resolution of the file_name argument.
The length of the file_name argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.
A component of file_name does not name an existing file or file_name points to an empty string.
A component of the path prefix is not a directory.

The realpath () function may fail if:

More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the file_name argument.
Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.
Insufficient storage space is available.

The following example generates an absolute pathname for the file identified by the argument. The generated pathname is stored in the array.

#include <stdlib.h>
...
char *symlinkpath = "/tmp/symlink/file";
char actualpath [PATH_MAX+1];
char *ptr;


ptr = realpath(symlinkpath, actualpath);

None.

Since the maximum pathname length is arbitrary unless {PATH_MAX} is defined, an application generally cannot supply a resolved_name buffer with size {{PATH_MAX}+1}.

In the future, passing a null pointer to realpath () for the resolved_name argument may be defined to have realpath () allocate space for the generated pathname.

getcwd(3), sysconf(3), the Base Definitions volume of IEEE Std 1003.1-2001 (“POSIX.1”), <stdlib.h>

First released in Issue 4, Version 2.

Moved from X/OPEN UNIX extension to BASE.

The keyword is added to the realpath () prototype for alignment with the ISO/IEC 9899:1999 (“ISO C99”) standard.

The wording of the mandatory [ELOOP] error condition is updated, and a second optional [ELOOP] error condition is added.

IEEE Std 1003.1-2001 (“POSIX.1”)/Cor 1-2002, item XSH/TC1/D6/51 is applied, adding new text to the DESCRIPTION for the case when resolved_name is a null pointer, changing the [EINVAL] error text, adding text to the RATIONALE, and adding text to FUTURE DIRECTIONS.

IEEE Std 1003.1-2001 (“POSIX.1”)/Cor 2-2004, item XSH/TC2/D6/110 is applied, updating the ERRORS section to refer to the file_name argument, rather than a non-existent argument.

footer end

January 1, 2004 posix.fail