1SYMLINK(2) Linux Programmer's Manual SYMLINK(2)
2
3
4
6 symlink, symlinkat - make a new name for a file
7
9 #include <unistd.h>
10
11 int symlink(const char *target, const char *linkpath);
12
13 #include <fcntl.h> /* Definition of AT_* constants */
14 #include <unistd.h>
15
16 int symlinkat(const char *target, int newdirfd, const char *linkpath);
17
18 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20 symlink():
21 _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200112L
22 || /* Glibc versions <= 2.19: */ _BSD_SOURCE
23
24 symlinkat():
25 Since glibc 2.10:
26 _POSIX_C_SOURCE >= 200809L
27 Before glibc 2.10:
28 _ATFILE_SOURCE
29
31 symlink() creates a symbolic link named linkpath which contains the
32 string target.
33
34 Symbolic links are interpreted at run time as if the contents of the
35 link had been substituted into the path being followed to find a file
36 or directory.
37
38 Symbolic links may contain .. path components, which (if used at the
39 start of the link) refer to the parent directories of that in which the
40 link resides.
41
42 A symbolic link (also known as a soft link) may point to an existing
43 file or to a nonexistent one; the latter case is known as a dangling
44 link.
45
46 The permissions of a symbolic link are irrelevant; the ownership is
47 ignored when following the link, but is checked when removal or renam‐
48 ing of the link is requested and the link is in a directory with the
49 sticky bit (S_ISVTX) set.
50
51 If linkpath exists, it will not be overwritten.
52
53 symlinkat()
54 The symlinkat() system call operates in exactly the same way as sym‐
55 link(), except for the differences described here.
56
57 If the pathname given in linkpath is relative, then it is interpreted
58 relative to the directory referred to by the file descriptor newdirfd
59 (rather than relative to the current working directory of the calling
60 process, as is done by symlink() for a relative pathname).
61
62 If linkpath is relative and newdirfd is the special value AT_FDCWD,
63 then linkpath is interpreted relative to the current working directory
64 of the calling process (like symlink()).
65
66 If linkpath is absolute, then newdirfd is ignored.
67
69 On success, zero is returned. On error, -1 is returned, and errno is
70 set appropriately.
71
73 EACCES Write access to the directory containing linkpath is denied, or
74 one of the directories in the path prefix of linkpath did not
75 allow search permission. (See also path_resolution(7).)
76
77 EDQUOT The user's quota of resources on the filesystem has been
78 exhausted. The resources could be inodes or disk blocks,
79 depending on the filesystem implementation.
80
81 EEXIST linkpath already exists.
82
83 EFAULT target or linkpath points outside your accessible address space.
84
85 EIO An I/O error occurred.
86
87 ELOOP Too many symbolic links were encountered in resolving linkpath.
88
89 ENAMETOOLONG
90 target or linkpath was too long.
91
92 ENOENT A directory component in linkpath does not exist or is a dan‐
93 gling symbolic link, or target or linkpath is an empty string.
94
95 ENOMEM Insufficient kernel memory was available.
96
97 ENOSPC The device containing the file has no room for the new directory
98 entry.
99
100 ENOTDIR
101 A component used as a directory in linkpath is not, in fact, a
102 directory.
103
104 EPERM The filesystem containing linkpath does not support the creation
105 of symbolic links.
106
107 EROFS linkpath is on a read-only filesystem.
108
109 The following additional errors can occur for symlinkat():
110
111 EBADF newdirfd is not a valid file descriptor.
112
113 ENOENT linkpath is a relative pathname and newdirfd refers to a direc‐
114 tory that has been deleted.
115
116 ENOTDIR
117 linkpath is relative and newdirfd is a file descriptor referring
118 to a file other than a directory.
119
121 symlinkat() was added to Linux in kernel 2.6.16; library support was
122 added to glibc in version 2.4.
123
125 symlink(): SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
126
127 symlinkat(): POSIX.1-2008.
128
130 No checking of target is done.
131
132 Deleting the name referred to by a symbolic link will actually delete
133 the file (unless it also has other hard links). If this behavior is
134 not desired, use link(2).
135
136 Glibc notes
137 On older kernels where symlinkat() is unavailable, the glibc wrapper
138 function falls back to the use of symlink(). When linkpath is a rela‐
139 tive pathname, glibc constructs a pathname based on the symbolic link
140 in /proc/self/fd that corresponds to the newdirfd argument.
141
143 ln(1), namei(1), lchown(2), link(2), lstat(2), open(2), readlink(2),
144 rename(2), unlink(2), path_resolution(7), symlink(7)
145
147 This page is part of release 5.07 of the Linux man-pages project. A
148 description of the project, information about reporting bugs, and the
149 latest version of this page, can be found at
150 https://www.kernel.org/doc/man-pages/.
151
152
153
154Linux 2017-09-15 SYMLINK(2)