1READLINK(2) Linux Programmer's Manual READLINK(2)
2
3
4
6 readlink, readlinkat - read value of a symbolic link
7
9 #include <unistd.h>
10
11 ssize_t readlink(const char *restrict pathname, char *restrict buf,
12 size_t bufsiz);
13
14 #include <fcntl.h> /* Definition of AT_* constants */
15 #include <unistd.h>
16
17 ssize_t readlinkat(int dirfd, const char *restrict pathname,
18 char *restrict buf, size_t bufsiz);
19
20 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21
22 readlink():
23 _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200112L
24 || /* Glibc <= 2.19: */ _BSD_SOURCE
25
26 readlinkat():
27 Since glibc 2.10:
28 _POSIX_C_SOURCE >= 200809L
29 Before glibc 2.10:
30 _ATFILE_SOURCE
31
33 readlink() places the contents of the symbolic link pathname in the
34 buffer buf, which has size bufsiz. readlink() does not append a termi‐
35 nating null byte to buf. It will (silently) truncate the contents (to
36 a length of bufsiz characters), in case the buffer is too small to hold
37 all of the contents.
38
39 readlinkat()
40 The readlinkat() system call operates in exactly the same way as read‐
41 link(), except for the differences described here.
42
43 If the pathname given in pathname is relative, then it is interpreted
44 relative to the directory referred to by the file descriptor dirfd
45 (rather than relative to the current working directory of the calling
46 process, as is done by readlink() for a relative pathname).
47
48 If pathname is relative and dirfd is the special value AT_FDCWD, then
49 pathname is interpreted relative to the current working directory of
50 the calling process (like readlink()).
51
52 If pathname is absolute, then dirfd is ignored.
53
54 Since Linux 2.6.39, pathname can be an empty string, in which case the
55 call operates on the symbolic link referred to by dirfd (which should
56 have been obtained using open(2) with the O_PATH and O_NOFOLLOW flags).
57
58 See openat(2) for an explanation of the need for readlinkat().
59
61 On success, these calls return the number of bytes placed in buf. (If
62 the returned value equals bufsiz, then truncation may have occurred.)
63 On error, -1 is returned and errno is set to indicate the error.
64
66 EACCES Search permission is denied for a component of the path prefix.
67 (See also path_resolution(7).)
68
69 EBADF (readlinkat()) pathname is relative but dirfd is neither AT_FD‐
70 CWD nor a valid file descriptor.
71
72 EFAULT buf extends outside the process's allocated address space.
7