arealpath \- canonicalize a path name
#include <pathfns.h>
char *arealpath(const char *path);
This function determines the canonical form of a path name and returns it in a buffer allocated with malloc(3), with a null terminator.
The canonical form of a path has the following properties:
o |
It is an absolute path, i.e. the first character is always "/". |
o |
No component is "." or "..". |
o |
It does not contain any consecutive "/" characters, i.e. it may contain "/" but not "//". |
o |
No prefix of the path (including the whole path) is a symbolic link. |
The path does not have to correspond to an existing file to be canonicalized, though if the "missing" parts of the path are filled in with symbolic links then the answer will be wrong.
However, if the path cannot be accessed due to any other error (e.g. permissions) then the an error is returned rather than producing a possibly-wrong canonical form for an inaccessible path.
Note that this produce canonical names for paths, not for files: on a filesystem that supports hard links, any given file might have more than one equally valid name which fits all of the above criteria.
The behaviour is undefined if path is a null pointer.
If the return value is not a null pointer then the operation succeeded and the return value is a pointer to the newly created string.
If the return value is a null pointer then the operation failed and errno is set appropriately:
ENOTDIR |
A component of path is not a directory. |
ENAMETOOLONG |
path, or a component of path, is too long. |
EACCES |
Permission denied accessing path. |
ELOOP |
path contains too many symbolic links. |
EIO |
An I/O error occurred while reading from the file system. |
ENOMEM |
Insufficient memory (provided the local malloc sets errno). |
The only errno value set directly by this function is ELOOP; all the rest only appear when they are returned by some other library function or system call. For example, ENAMETOOLONG only occurs if the operating system's filename limits are exceeded; arealpath can handle any size of filename up to available memory.)
realpath(3) performs a similar operation to this function, but limits the size of its answer to PATH_MAX, which is not acceptable.
areadlink(3), realpath(3)