rename.2: wfix
[man-pages.git] / man2 / symlink.2
blob87c25d5f483d86de187101b4b0ffc1d3bb52c38f
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.
134 .SH RETURN VALUE
135 On success, zero is returned.
136 On error, \-1 is returned, and
137 .I errno
138 is set to indicate the error.
139 .SH ERRORS
141 .B EACCES
142 Write access to the directory containing
143 .I linkpath
144 is denied, or one of the directories in the path prefix of
145 .I linkpath
146 did not allow search permission.
147 (See also
148 .BR path_resolution (7).)
150 .B EDQUOT
151 The user's quota of resources on the filesystem has been exhausted.
152 The resources could be inodes or disk blocks, depending on the filesystem
153 implementation.
155 .B EEXIST
156 .I linkpath
157 already exists.
159 .B EFAULT
160 .IR target " or " linkpath " points outside your accessible address space."
162 .B EIO
163 An I/O error occurred.
165 .B ELOOP
166 Too many symbolic links were encountered in resolving
167 .IR linkpath .
169 .B ENAMETOOLONG
170 .IR target " or " linkpath " was too long."
172 .B ENOENT
173 A directory component in
174 .I linkpath
175 does not exist or is a dangling symbolic link, or
176 .I target
178 .I linkpath
179 is an empty string.
181 .B ENOMEM
182 Insufficient kernel memory was available.
184 .B ENOSPC
185 The device containing the file has no room for the new directory
186 entry.
188 .B ENOTDIR
189 A component used as a directory in
190 .I linkpath
191 is not, in fact, a directory.
193 .B EPERM
194 The filesystem containing
195 .I linkpath
196 does not support the creation of symbolic links.
198 .B EROFS
199 .I linkpath
200 is on a read-only filesystem.
202 The following additional errors can occur for
203 .BR symlinkat ():
205 .B EBADF
206 .I newdirfd
207 is not a valid file descriptor.
209 .B ENOENT
210 .I linkpath
211 is a relative pathname and
212 .IR newdirfd
213 refers to a directory that has been deleted.
215 .B ENOTDIR
216 .I linkpath
217 is relative and
218 .I newdirfd
219 is a file descriptor referring to a file other than a directory.
220 .SH VERSIONS
221 .BR symlinkat ()
222 was added to Linux in kernel 2.6.16;
223 library support was added to glibc in version 2.4.
224 .SH CONFORMING TO
225 .BR symlink ():
226 SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
227 .\" SVr4 documents additional error codes EDQUOT and ENOSYS.
228 .\" See
229 .\" .BR open (2)
230 .\" re multiple files with the same name, and NFS.
232 .BR symlinkat ():
233 POSIX.1-2008.
234 .SH NOTES
235 No checking of
236 .I target
237 is done.
239 Deleting the name referred to by a symbolic link will actually delete the
240 file (unless it also has other hard links).
241 If this behavior is not desired, use
242 .BR link (2).
243 .SS Glibc notes
244 On older kernels where
245 .BR symlinkat ()
246 is unavailable, the glibc wrapper function falls back to the use of
247 .BR symlink ().
248 When
249 .I linkpath
250 is a relative pathname,
251 glibc constructs a pathname based on the symbolic link in
252 .IR /proc/self/fd
253 that corresponds to the
254 .IR newdirfd
255 argument.
256 .SH SEE ALSO
257 .BR ln (1),
258 .BR namei (1),
259 .BR lchown (2),
260 .BR link (2),
261 .BR lstat (2),
262 .BR open (2),
263 .BR readlink (2),
264 .BR rename (2),
265 .BR unlink (2),
266 .BR path_resolution (7),
267 .BR symlink (7)