OS/161 Reference Manual


readlink - fetch symbolic link contents


Standard C Library (libc, -lc)


#include <unistd.h>

readlink(const char *path, char *buf, size_t len);


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.


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.