readlink()

NAME

readlink () - read the contents of a symbolic link

SYNOPSIS

#include <unistd.h>

int readlink(const char *path, char *buf, size_t bufsize)

DESCRIPTION

The readlink(2) function stores the contents of the symbolic link file path in the buffer buf, which is of size bufsize. On INTERIX, the contents of buf are null-terminated, though portable programs should not assume this is so.

If the symlink data are longer than bufsiz, then only the first bufsiz bytes of the symlink data are written into the buffer, and the value bufsiz is returned; errno is not set.

However, if you lstat(2) the symbolic link, then the st_size field is set to the total number of bytes of symlink data.

RETURN VALUE

On success, the readlink(2) call returns the number of bytes stored in bufsize; otherwise it returns -1 and sets errno.

ERRORS

The readlink(2) call can fail for the following reasons:

[EACCES]
Process does not have permission to search some directory in the path.
[EINVAL]
The path is not a symbolic link file, or the file is on a device that does not support the operation.
[EIO]
An I/O error occurred while reading from the filesystem.
[ENOENT]
Either path is an empty string or some component of path does not exist.
[ELOOP]
Too many symbolic links were encountered in resolving path.
[ENAMETOOLONG]
The path is longer than {PATH_MAX} or some component of path is longer than {NAME_MAX}, or the pathname resolution of a symbolic link produced some intermediate result that was longer than {PATH_MAX}.
[ENOTDIR]
Some component of the prefix in path is not a directory.

SEE ALSO