]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/symlink.2
symlink.2: CONFORMING TO: symlink() is in POSIX.1-2008
[thirdparty/man-pages.git] / man2 / symlink.2
CommitLineData
fea681da 1.\" This manpage is Copyright (C) 1992 Drew Eckhardt;
ac56b6a8 2.\" and Copyright (C) 1993 Michael Haardt, Ian Jackson.
e7bb1f63 3.\" and Copyright (C) 2006, 2014 Michael Kerrisk
fea681da 4.\"
93015253 5.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
c13182ef 14.\"
fea681da
MK
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.
c13182ef 22.\"
fea681da
MK
23.\" Formatted or processed versions of this manual, if unaccompanied by
24.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 25.\" %%%LICENSE_END
fea681da
MK
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>
c11b1abf 31.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 32.\"
e7bb1f63 33.TH SYMLINK 2 2014-02-21 "Linux" "Linux Programmer's Manual"
fea681da 34.SH NAME
e7bb1f63 35symlink, symlinkat \- make a new name for a file
fea681da 36.SH SYNOPSIS
e7bb1f63 37.nf
fea681da
MK
38.B #include <unistd.h>
39.sp
bcd49f31 40.BI "int symlink(const char *" target ", const char *" linkpath );
cc4615cc 41.sp
e7bb1f63
MK
42.BR "#include <fcntl.h> " "/* Definition of AT_* constants */"
43.B #include <unistd.h>
44.sp
45.BI "int symlinkat(const char *" target ", int " newdirfd \
46", const char *" linkpath );
47.sp
48.fi
cc4615cc
MK
49.in -4n
50Feature Test Macro Requirements for glibc (see
51.BR feature_test_macros (7)):
52.in
53.sp
54.ad l
55.BR symlink ():
cde2506f
MK
56.RS 4
57_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
58_XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED || _POSIX_C_SOURCE\ >=\ 200112L
59.RE
e7bb1f63
MK
60.sp
61.BR symlinkat ():
62.PD 0
63.ad l
64.RS 4
65.TP 4
66Since glibc 2.10:
67_XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
68.TP
69Before glibc 2.10:
70_ATFILE_SOURCE
71.RE
cc4615cc 72.ad b
e7bb1f63 73.PD
fea681da 74.SH DESCRIPTION
e511ffb6 75.BR symlink ()
fea681da 76creates a symbolic link named
f2ae6dde 77.I linkpath
fea681da 78which contains the string
bcd49f31 79.IR target .
fea681da 80
cf50118f 81Symbolic links are interpreted at run time as if the contents of the
fea681da
MK
82link had been substituted into the path being followed to find a file or
83directory.
84
85Symbolic links may contain
836f07c1 86.I ..
fea681da
MK
87path components, which (if used at the start of the link) refer to the
88parent directories of that in which the link resides.
89
90A symbolic link (also known as a soft link) may point to an existing
91file or to a nonexistent one; the latter case is known as a dangling
92link.
93
94The permissions of a symbolic link are irrelevant; the ownership is
95ignored when following the link, but is checked when removal or
96renaming of the link is requested and the link is in a directory with
97the sticky bit
98.RB ( S_ISVTX )
99set.
100
101If
f2ae6dde 102.I linkpath
fea681da
MK
103exists it will
104.I not
105be overwritten.
e7bb1f63
MK
106.SS symlinkat()
107The
108.BR symlinkat ()
109system call operates in exactly the same way as
110.BR symlink (2),
111except for the differences described here.
112
113If the pathname given in
114.I linkpath
115is relative, then it is interpreted relative to the directory
116referred to by the file descriptor
117.I newdirfd
118(rather than relative to the current working directory of
119the calling process, as is done by
120.BR symlink (2)
121for a relative pathname).
122
123If
124.I linkpath
125is relative and
126.I newdirfd
127is the special value
128.BR AT_FDCWD ,
129then
130.I linkpath
131is interpreted relative to the current working
132directory of the calling process (like
133.BR symlink (2)).
134
135If
136.I linkpath
137is absolute, then
138.I newdirfd
139is ignored.
47297adb 140.SH RETURN VALUE
c13182ef
MK
141On success, zero is returned.
142On error, \-1 is returned, and
fea681da
MK
143.I errno
144is set appropriately.
145.SH ERRORS
146.TP
147.B EACCES
148Write access to the directory containing
f2ae6dde 149.I linkpath
fea681da 150is denied, or one of the directories in the path prefix of
f2ae6dde 151.I linkpath
fea681da
MK
152did not allow search permission.
153(See also
ad7cc990 154.BR path_resolution (7).)
fea681da 155.TP
a1f01685 156.B EDQUOT
9ee4a2b6 157The user's quota of resources on the filesystem has been exhausted.
28955f15
SP
158The resources could be inodes or disk blocks, depending on the filesystem
159implementation.
a1f01685 160.TP
fea681da 161.B EEXIST
f2ae6dde 162.I linkpath
fea681da
MK
163already exists.
164.TP
165.B EFAULT
bcd49f31 166.IR target " or " linkpath " points outside your accessible address space."
fea681da
MK
167.TP
168.B EIO
169An I/O error occurred.
170.TP
171.B ELOOP
172Too many symbolic links were encountered in resolving
f2ae6dde 173.IR linkpath .
fea681da
MK
174.TP
175.B ENAMETOOLONG
bcd49f31 176.IR target " or " linkpath " was too long."
fea681da
MK
177.TP
178.B ENOENT
179A directory component in
f2ae6dde 180.I linkpath
fea681da 181does not exist or is a dangling symbolic link, or
bcd49f31 182.I target
fea681da
MK
183is the empty string.
184.TP
185.B ENOMEM
186Insufficient kernel memory was available.
187.TP
188.B ENOSPC
189The device containing the file has no room for the new directory
190entry.
191.TP
192.B ENOTDIR
193A component used as a directory in
f2ae6dde 194.I linkpath
fea681da
MK
195is not, in fact, a directory.
196.TP
197.B EPERM
9ee4a2b6 198The filesystem containing
f2ae6dde 199.I linkpath
fea681da
MK
200does not support the creation of symbolic links.
201.TP
202.B EROFS
f2ae6dde 203.I linkpath
9ee4a2b6 204is on a read-only filesystem.
e7bb1f63
MK
205.PP
206The following additional errors can occur for
207.BR symlinkat ():
208.TP
209.B EBADF
210.I newdirfd
211is not a valid file descriptor.
212.TP
213.B ENOTDIR
214.I linkpath
215is relative and
216.I newdirfd
217is a file descriptor referring to a file other than a directory.
218.SH VERSIONS
219.BR symlinkat ()
220was added to Linux in kernel 2.6.16;
221library support was added to glibc in version 2.4.
47297adb 222.SH CONFORMING TO
e7bb1f63 223.BR symlink ():
dc3884b8 224SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
2dd578fd
MK
225.\" SVr4 documents additional error codes EDQUOT and ENOSYS.
226.\" See
227.\" .BR open (2)
228.\" re multiple files with the same name, and NFS.
e7bb1f63
MK
229
230.BR symlinkat ():
231POSIX.1-2008.
fea681da
MK
232.SH NOTES
233No checking of
bcd49f31 234.I target
fea681da
MK
235is done.
236
237Deleting the name referred to by a symlink will actually delete the
7c93fec0 238file (unless it also has other hard links).
d9bfdb9c 239If this behavior is not desired, use
0bfa087b 240.BR link (2).
47297adb 241.SH SEE ALSO
fea681da 242.BR ln (1),
a3bf8022 243.BR lchown (2),
fea681da
MK
244.BR link (2),
245.BR lstat (2),
246.BR open (2),
fea681da
MK
247.BR readlink (2),
248.BR rename (2),
0c2b92ba 249.BR unlink (2),
a9cfde1d 250.BR path_resolution (7),
ad22ad55 251.BR symlink (7)