READLINK(2) | System Calls Manual | READLINK(2) |
readlink
,
readlinkat
— read value of a
symbolic link
#include
<unistd.h>
ssize_t
readlink
(const
char *restrict path, char
*restrict buf, size_t
bufsiz);
#include <fcntl.h>
#include <unistd.h>
ssize_t
readlinkat
(int
fd, const char
*path, char *buf,
size_t bufsiz);
The
readlink
()
function places the contents of the symbolic link path
in the buffer buf, which has size
bufsiz. readlink
() does not
append a NUL
character to
buf.
The
readlinkat
()
function is equivalent to readlink
() except that
where path specifies a relative path, the symbolic
link whose contents are read is determined relative to the directory
associated with file descriptor fd instead of the
current working directory.
If
readlinkat
()
is passed the special value AT_FDCWD
(defined in
<fcntl.h>
) in the
fd parameter, the current working directory is used
and the behavior is identical to a call to
readlink
().
The call returns the count of characters placed in the buffer if it succeeds, or a -1 if an error occurs, placing the error code in the global variable errno.
readlink
() and
readlinkat
() will fail if:
ENOTDIR
]ENAMETOOLONG
]NAME_MAX
characters, or an entire pathname (including the terminating NUL) exceeded
PATH_MAX
bytes.ENOENT
]EACCES
]ELOOP
]EINVAL
]EIO
]EFAULT
]Additionally, readlinkat
() will fail
if:
EBADF
]AT_FDCWD
nor a valid file descriptor.ENOTDIR
]EACCES
]The readlink
() and
readlinkat
() functions conform to
IEEE Std 1003.1-2008 (“POSIX.1”).
The readlink
() system call first appeared
in 4.1cBSD. The readlinkat
()
system call has been available since OpenBSD
5.0.
May 31, 2015 | OpenBSD-6.8 |