chmod.2, chown.2, open.2, mkdir.2, mknod.2, readlink.2, stat.2, symlink.2, mkfifo...
[man-pages.git] / man2 / symlink.2
blobf5bf7ef2315634b93d7a9f040607e9d7a399a148
1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\"             and Copyright (C) 1993 Michael Haardt, Ian Jackson.
3 .\"             and Copyright (C) 2006, 2014 Michael Kerrisk
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" Modified 1993-07-24 by Rik Faith
28 .\" Modified 1996-04-26 by Nick Duffek <nsd@bbc.com>
29 .\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
31 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
32 .\"
33 .TH SYMLINK 2 2021-03-22 "Linux" "Linux Programmer's Manual"
34 .SH NAME
35 symlink, symlinkat \- make a new name for a file
36 .SH SYNOPSIS
37 .nf
38 .B #include <unistd.h>
39 .PP
40 .BI "int symlink(const char *" target ", const char *" linkpath );
41 .PP
42 .BR "#include <fcntl.h>           " "/* Definition of " AT_* " constants */"
43 .B #include <unistd.h>
44 .PP
45 .BI "int symlinkat(const char *" target ", int " newdirfd \
46 ", const char *" linkpath );
47 .PP
48 .fi
49 .RS -4
50 Feature Test Macro Requirements for glibc (see
51 .BR feature_test_macros (7)):
52 .RE
53 .PP
54 .BR symlink ():
55 .nf
56     _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200112L
57 .\"    || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
58         || /* Glibc <= 2.19: */ _BSD_SOURCE
59 .fi
60 .PP
61 .BR symlinkat ():
62 .nf
63     Since glibc 2.10:
64         _POSIX_C_SOURCE >= 200809L
65     Before glibc 2.10:
66         _ATFILE_SOURCE
67 .fi
68 .SH DESCRIPTION
69 .BR symlink ()
70 creates a symbolic link named
71 .I linkpath
72 which contains the string
73 .IR target .
74 .PP
75 Symbolic links are interpreted at run time as if the contents of the
76 link had been substituted into the path being followed to find a file or
77 directory.
78 .PP
79 Symbolic links may contain
80 .I ..
81 path components, which (if used at the start of the link) refer to the
82 parent directories of that in which the link resides.
83 .PP
84 A symbolic link (also known as a soft link) may point to an existing
85 file or to a nonexistent one; the latter case is known as a dangling
86 link.
87 .PP
88 The permissions of a symbolic link are irrelevant; the ownership is
89 ignored when following the link, but is checked when removal or
90 renaming of the link is requested and the link is in a directory with
91 the sticky bit
92 .RB ( S_ISVTX )
93 set.
94 .PP
96 .I linkpath
97 exists, it will
98 .I not
99 be overwritten.
100 .SS symlinkat()
102 .BR symlinkat ()
103 system call operates in exactly the same way as
104 .BR symlink (),
105 except for the differences described here.
107 If the pathname given in
108 .I linkpath
109 is relative, then it is interpreted relative to the directory
110 referred to by the file descriptor
111 .I newdirfd
112 (rather than relative to the current working directory of
113 the calling process, as is done by
114 .BR symlink ()
115 for a relative pathname).
118 .I linkpath
119 is relative and
120 .I newdirfd
121 is the special value
122 .BR AT_FDCWD ,
123 then
124 .I linkpath
125 is interpreted relative to the current working
126 directory of the calling process (like
127 .BR symlink ()).
130 .I linkpath
131 is absolute, then
132 .I newdirfd
133 is ignored.
136 .BR openat (2)
137 for an explanation of the need for
138 .BR symlinkat ().
139 .SH RETURN VALUE
140 On success, zero is returned.
141 On error, \-1 is returned, and
142 .I errno
143 is set to indicate the error.
144 .SH ERRORS
146 .B EACCES
147 Write access to the directory containing
148 .I linkpath
149 is denied, or one of the directories in the path prefix of
150 .I linkpath
151 did not allow search permission.
152 (See also
153 .BR path_resolution (7).)
155 .B EBADF
156 .RB ( symlinkat ())
157 .I linkpath
158 is relative but
159 .I newdirfd
160 is neither
161 .B AT_FDCWD
162 nor a valid file descriptor.
164 .B EDQUOT
165 The user's quota of resources on the filesystem has been exhausted.
166 The resources could be inodes or disk blocks, depending on the filesystem
167 implementation.
169 .B EEXIST
170 .I linkpath
171 already exists.
173 .B EFAULT
174 .IR target " or " linkpath " points outside your accessible address space."
176 .B EIO
177 An I/O error occurred.
179 .B ELOOP
180 Too many symbolic links were encountered in resolving
181 .IR linkpath .
183 .B ENAMETOOLONG
184 .IR target " or " linkpath " was too long."
186 .B ENOENT
187 A directory component in
188 .I linkpath
189 does not exist or is a dangling symbolic link, or
190 .I target
192 .I linkpath
193 is an empty string.
195 .B ENOENT
196 .RB ( symlinkat ())
197 .I linkpath
198 is a relative pathname and
199 .IR newdirfd
200 refers to a directory that has been deleted.
202 .B ENOMEM
203 Insufficient kernel memory was available.
205 .B ENOSPC
206 The device containing the file has no room for the new directory
207 entry.
209 .B ENOTDIR
210 A component used as a directory in
211 .I linkpath
212 is not, in fact, a directory.
214 .B ENOTDIR
215 .RB ( symlinkat ())
216 .I linkpath
217 is relative and
218 .I newdirfd
219 is a file descriptor referring to a file other than a directory.
221 .B EPERM
222 The filesystem containing
223 .I linkpath
224 does not support the creation of symbolic links.
226 .B EROFS
227 .I linkpath
228 is on a read-only filesystem.
229 .SH VERSIONS
230 .BR symlinkat ()
231 was added to Linux in kernel 2.6.16;
232 library support was added to glibc in version 2.4.
233 .SH CONFORMING TO
234 .BR symlink ():
235 SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
236 .\" SVr4 documents additional error codes EDQUOT and ENOSYS.
237 .\" See
238 .\" .BR open (2)
239 .\" re multiple files with the same name, and NFS.
241 .BR symlinkat ():
242 POSIX.1-2008.
243 .SH NOTES
244 No checking of
245 .I target
246 is done.
248 Deleting the name referred to by a symbolic link will actually delete the
249 file (unless it also has other hard links).
250 If this behavior is not desired, use
251 .BR link (2).
252 .SS Glibc notes
253 On older kernels where
254 .BR symlinkat ()
255 is unavailable, the glibc wrapper function falls back to the use of
256 .BR symlink ().
257 When
258 .I linkpath
259 is a relative pathname,
260 glibc constructs a pathname based on the symbolic link in
261 .IR /proc/self/fd
262 that corresponds to the
263 .IR newdirfd
264 argument.
265 .SH SEE ALSO
266 .BR ln (1),
267 .BR namei (1),
268 .BR lchown (2),
269 .BR link (2),
270 .BR lstat (2),
271 .BR open (2),
272 .BR readlink (2),
273 .BR rename (2),
274 .BR unlink (2),
275 .BR path_resolution (7),
276 .BR symlink (7)