## readlink

#### OS/161 Reference Manual

### Name

readlink - fetch symbolic link contents

### Library

Standard C Library (libc, -lc)

### Synopsis

`#include <unistd.h>`
`int`
`readlink(const char *`path`, char *`buf`, size_t` len`);`

### Description

`readlink` retrieves the contents of the symbolic link named by path and places them in the buffer buf. At most len bytes are written.

`readlink` does not include a null terminator in buf.

The call (like all system calls) should be atomic. Note that the kernel is not obliged to (and generally cannot) make the read atomic with respect to other threads in the same process accessing the buffer during the operation.

### Return Values

`readlink` returns the number of characters transferred. If an error occurs, -1 is returned, and errno is set according to the error encountered.

### Errors

The following error codes should be returned under the conditions given. Other error codes may be returned for other cases not mentioned here.

| ENODEV | The device prefix of filename did not exist.
ENOTDIR | A non-final component of path was not a directory.
ENOENT | The named file does not exist.
EINVAL | The named file is not a symlink.
EIO | A hard I/O error occurred.
EFAULT | buf or path points to an invalid address.