Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

readlink, readlinkat - read contents of symbolic link

&pagelevel(4)&pagelevel

Syntax

#include <unistd.h>

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

Description

readlink() places the contents of the symbolic link referred to by path in the buffer buf, which has size bufsize. The contents of the link are not terminated with a null byte when returned.

The readlinkat() function is equivalent to the readlink() function except when the path parameter specifies a relative path. In this case the symbolic link whose content is to be read is not searched for in the current directory, but in the directory connected with the file descriptor fd. If the file descriptor was opened without O_SEARCH, the function checks whether a search is permitted in the connected file descriptor with the authorizations applicable for the directory. If the file descriptor was opened with O_SEARCH, the check is not performed.

When the value AT_FDCWD was transferred to the readlinkat() function for the fd parameter, the current directory is used.

Return val.

Number of bytes placed in the buffer


upon successful completion.

-1

if an error occurs. errno is set to indicate the error. The contents of the buffer remain unchanged.

Errors

readlink() and readlinkat() will fail if: 

 

EACCES

Search permission is denied for a component of the path prefix of path.

Too many symbolic links were encountered in resolving path.

 

EFAULT

path or buf are outside the allocated address space of the process.

 

EINVAL

path is not a symbolic link.

 

Extension

 

EINVAL

An attempt was made to access a BS2000 file. (End)

 

EIO

An I/O error occurred while reading from or writing to the file system.

 

ELOOP

Too many symbolic links were encountered in resolving path.

 

ENAMETOOLONG 

 


The length of the path argument exceeds {PATH_MAX} or the length of a path component exceeds{NAME_MAX}.


ENOENT

The named file does not exist.


ENOSYS

The file system does not support symbolic links.


ENOTDIR

One of the component of the path prefix of path is not a directory.


In addition, readlinkat() fails if the following applies:

 

EACCES

The file descriptor fd was not opened with O_SEARCH, and the authorizations applicable for the directory do not permit the directory to be searched.

 

EBADF

The path parameter does not specify an absolute pathname, and the fd parameter does not have the value AT_FDCWD, nor does it contain a valid file descriptor opened for reading or searching.

 

ENOTDIR

The path parameter does not specify an absolute pathname, and the file descriptor fd is not connected with a directory.

Notes

readlink() will only access POSIX files.

Syntax

stat(), symlink(), fcntl.h, unistd.h.