1readlink(2)                   System Calls Manual                  readlink(2)
2
3
4

NAME

6       readlink, readlinkat - read value of a symbolic link
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <unistd.h>
13
14       ssize_t readlink(const char *restrict pathname, char *restrict buf,
15                        size_t bufsiz);
16
17       #include <fcntl.h>            /* Definition of AT_* constants */
18       #include <unistd.h>
19
20       ssize_t readlinkat(int dirfd, const char *restrict pathname,
21                        char *restrict buf, size_t bufsiz);
22
23   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
24
25       readlink():
26           _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200112L
27               || /* glibc <= 2.19: */ _BSD_SOURCE
28
29       readlinkat():
30           Since glibc 2.10:
31               _POSIX_C_SOURCE >= 200809L
32           Before glibc 2.10:
33               _ATFILE_SOURCE
34

DESCRIPTION

36       readlink()  places  the  contents  of the symbolic link pathname in the
37       buffer buf, which has size bufsiz.  readlink() does not append a termi‐
38       nating  null byte to buf.  It will (silently) truncate the contents (to
39       a length of bufsiz characters), in case the buffer is too small to hold
40       all of the contents.
41
42   readlinkat()
43       The  readlinkat() system call operates in exactly the same way as read‐
44       link(), except for the differences described here.
45
46       If the pathname given in pathname is relative, then it  is  interpreted
47       relative  to  the  directory  referred  to by the file descriptor dirfd
48       (rather than relative to the current working directory of  the  calling
49       process, as is done by readlink() for a relative pathname).
50
51       If  pathname  is relative and dirfd is the special value AT_FDCWD, then
52       pathname is interpreted relative to the current  working  directory  of
53       the calling process (like readlink()).
54
55       If pathname is absolute, then dirfd is ignored.
56
57       Since  Linux 2.6.39, pathname can be an empty string, in which case the
58       call operates on the symbolic link referred to by dirfd  (which  should
59       have been obtained using open(2) with the O_PATH and O_NOFOLLOW flags).
60
61       See openat(2) for an explanation of the need for readlinkat().
62

RETURN VALUE

64       On  success, these calls return the number of bytes placed in buf.  (If
65       the returned value equals bufsiz, then truncation may  have  occurred.)
66       On error, -1 is returned and errno is set to indicate the error.
67

ERRORS

69       EACCES Search  permission is denied for a component of the path prefix.
70              (See also path_resolution(7).)
71
72       EBADF  (readlinkat()) pathname is relative but dirfd is neither  AT_FD‐
73              CWD nor a valid file descriptor.
74
75       EFAULT