realpath() — Resolve path name
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2
Single UNIX Specification, Version 3 |
both |
Format
#define _XOPEN_SOURCE_EXTENDED 1
#include <stdlib.h>
char *realpath(const char *__restrict__file_name, char *__restrict__resolved_name);
General description
The realpath() function derives, from the path name pointed to by file_name, an absolute path name that names the same file, whose resolution does not involve ".","..", or symbolic links. The generated path name is stored, up to a maximum of PATH_MAX bytes, in the buffer pointed to by resolved_name.
Returned value
If successful, realpath() returns a pointer to the resolved name.
If unsuccessful, the
contents of the buffer pointed to by resolved_name are
undefined, realpath() returns a NULL pointer and sets errno to one
of the following values:
- Error Code
- Description
- 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
- Too many symbolic links were encountered in resolving path
- ENAMETOOLONG
- Path name is longer that PATH_MAX characters, or some component of path name is longer that NAME_MAX characters while _POSIX_NO_TRUNC is in effect. For symbolic links, the length of the path name string substituted for a symbolic link exceeds PATH_MAX. The PATH_MAX and NAME_MAX values are determined using pathconf().
- 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.
- ERANGE
- File system will return ERANGE if the result to be stored in 'resolved_name' is larger than PATH_MAX.