NAME
realpath — resolve
a pathname
SYNOPSIS
char *realpath(const char *restrict file_name,
char *restrict resolved_name);
DESCRIPTION
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.
RETURN VALUE
Upon successful completion, realpath ()
shall return a pointer to the resolved name. Otherwise,
realpath () shall return a null pointer and set
errno to
indicate the error, and the contents of the buffer pointed to by
resolved_name are undefined.
ERRORS
The realpath () function shall fail
if:
- [EACCES]
- Read or search permission was denied for a component of file_name .
- [EINVAL]
- Either the file_name or resolved_name argument is a null pointer.
- [EIO]
- An error occurred while reading from the file system.
- [ELOOP]
- A loop exists in symbolic links encountered during resolution of the path argument.
- [ENAMETOOLONG]
- The length of the file_name argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.
- [ENOENT]
- A component of file_name does not name an existing file or file_name points to an empty string.
- [ENOTDIR]
- A component of the path prefix is not a directory.
The realpath () function may fail if:
- [ELOOP]
- More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the path argument.
- [ENAMETOOLONG]
- Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.
- [ENOMEM]
- Insufficient storage space is available.
EXAMPLES
Generating an Absolute Pathname
The following example generates an absolute pathname for the file identified by the symlinkpath argument. The generated pathname is stored in the actualpath array.
#include <stdlib.h> ... char *symlinkpath = "/tmp/symlink/file"; char actualpath [PATH_MAX+1]; char *ptr; ptr = realpath(symlinkpath, actualpath);
APPLICATION USAGE
None.
RATIONALE
None.
FUTURE DIRECTIONS
None.
SEE ALSO
getcwd(3) , sysconf(3) , the Base Definitions volume of IEEE Std 1003.1-2001 (“POSIX.1”), <stdlib.h>
CHANGE HISTORY
First released in Issue 4, Version 2.
Issue 5
Moved from X/OPEN UNIX extension to BASE.
Issue 6
The
restrict
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.
End of informative text. footer end