OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man2 / symlink.2
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 2014-08-19 "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 .sp
40 .BI "int symlink(const char *" target ", const char *" linkpath );
41 .sp
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
49 .in -4n
50 Feature Test Macro Requirements for glibc (see
51 .BR feature_test_macros (7)):
52 .in
53 .sp
54 .ad l
55 .BR symlink ():
56 .RS 4
57 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
58 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED || _POSIX_C_SOURCE\ >=\ 200112L
59 .RE
60 .sp
61 .BR symlinkat ():
62 .PD 0
63 .ad l
64 .RS 4
65 .TP 4
66 Since glibc 2.10:
67 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
68 .TP
69 Before glibc 2.10:
70 _ATFILE_SOURCE
71 .RE
72 .ad b
73 .PD
74 .SH DESCRIPTION
75 .BR symlink ()
76 creates a symbolic link named
77 .I linkpath
78 which contains the string
79 .IR target .
80
81 Symbolic links are interpreted at run time as if the contents of the
82 link had been substituted into the path being followed to find a file or
83 directory.
84
85 Symbolic links may contain
86 .I ..
87 path components, which (if used at the start of the link) refer to the
88 parent directories of that in which the link resides.
89
90 A symbolic link (also known as a soft link) may point to an existing
91 file or to a nonexistent one; the latter case is known as a dangling
92 link.
93
94 The permissions of a symbolic link are irrelevant; the ownership is
95 ignored when following the link, but is checked when removal or
96 renaming of the link is requested and the link is in a directory with
97 the sticky bit
98 .RB ( S_ISVTX )
99 set.
100
101 If
102 .I linkpath
103 exists, it will
104 .I not
105 be overwritten.
106 .SS symlinkat()
107 The
108 .BR symlinkat ()
109 system call operates in exactly the same way as
110 .BR symlink (),
111 except for the differences described here.
112
113 If the pathname given in
114 .I linkpath
115 is relative, then it is interpreted relative to the directory
116 referred to by the file descriptor
117 .I newdirfd
118 (rather than relative to the current working directory of
119 the calling process, as is done by
120 .BR symlink ()
121 for a relative pathname).
122
123 If
124 .I linkpath
125 is relative and
126 .I newdirfd
127 is the special value
128 .BR AT_FDCWD ,
129 then
130 .I linkpath
131 is interpreted relative to the current working
132 directory of the calling process (like
133 .BR symlink ()).
134
135 If
136 .I linkpath
137 is absolute, then
138 .I newdirfd
139 is ignored.
140 .SH RETURN VALUE
141 On success, zero is returned.
142 On error, \-1 is returned, and
143 .I errno
144 is set appropriately.
145 .SH ERRORS
146 .TP
147 .B EACCES
148 Write access to the directory containing
149 .I linkpath
150 is denied, or one of the directories in the path prefix of
151 .I linkpath
152 did not allow search permission.
153 (See also
154 .BR path_resolution (7).)
155 .TP
156 .B EDQUOT
157 The user's quota of resources on the filesystem has been exhausted.
158 The resources could be inodes or disk blocks, depending on the filesystem
159 implementation.
160 .TP
161 .B EEXIST
162 .I linkpath
163 already exists.
164 .TP
165 .B EFAULT
166 .IR target " or " linkpath " points outside your accessible address space."
167 .TP
168 .B EIO
169 An I/O error occurred.
170 .TP
171 .B ELOOP
172 Too many symbolic links were encountered in resolving
173 .IR linkpath .
174 .TP
175 .B ENAMETOOLONG
176 .IR target " or " linkpath " was too long."
177 .TP
178 .B ENOENT
179 A directory component in
180 .I linkpath
181 does not exist or is a dangling symbolic link, or
182 .I target
183 is the empty string.
184 .TP
185 .B ENOMEM
186 Insufficient kernel memory was available.
187 .TP
188 .B ENOSPC
189 The device containing the file has no room for the new directory
190 entry.
191 .TP
192 .B ENOTDIR
193 A component used as a directory in
194 .I linkpath
195 is not, in fact, a directory.
196 .TP
197 .B EPERM
198 The filesystem containing
199 .I linkpath
200 does not support the creation of symbolic links.
201 .TP
202 .B EROFS
203 .I linkpath
204 is on a read-only filesystem.
205 .PP
206 The following additional errors can occur for
207 .BR symlinkat ():
208 .TP
209 .B EBADF
210 .I newdirfd
211 is not a valid file descriptor.
212 .TP
213 .B ENOENT
214 .I linkpath
215 is a relative pathname and
216 .IR newdirfd
217 refers to a directory that has been deleted.
218 .TP
219 .B ENOTDIR
220 .I linkpath
221 is relative and
222 .I newdirfd
223 is a file descriptor referring to a file other than a directory.
224 .SH VERSIONS
225 .BR symlinkat ()
226 was added to Linux in kernel 2.6.16;
227 library support was added to glibc in version 2.4.
228 .SH CONFORMING TO
229 .BR symlink ():
230 SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
231 .\" SVr4 documents additional error codes EDQUOT and ENOSYS.
232 .\" See
233 .\" .BR open (2)
234 .\" re multiple files with the same name, and NFS.
235
236 .BR symlinkat ():
237 POSIX.1-2008.
238 .SH NOTES
239 No checking of
240 .I target
241 is done.
242
243 Deleting the name referred to by a symbolic link will actually delete the
244 file (unless it also has other hard links).
245 If this behavior is not desired, use
246 .BR link (2).
247 .SS Glibc notes
248 On older kernels where
249 .BR symlinkat ()
250 is unavailable, the glibc wrapper function falls back to the use of
251 .BR symlink (2).
252 When
253 .I linkpath
254 is a relative pathname,
255 glibc constructs a pathname based on the symbolic link in
256 .IR /proc/self/fd
257 that corresponds to the
258 .IR newdirfd
259 argument.
260 .SH SEE ALSO
261 .BR ln (1),
262 .BR lchown (2),
263 .BR link (2),
264 .BR lstat (2),
265 .BR open (2),
266 .BR readlink (2),
267 .BR rename (2),
268 .BR unlink (2),
269 .BR path_resolution (7),
270 .BR symlink (7)
271 .SH COLOPHON
272 This page is part of release 3.79 of the Linux
273 .I man-pages
274 project.
275 A description of the project,
276 information about reporting bugs,
277 and the latest version of this page,
278 can be found at
279 \%http://www.kernel.org/doc/man\-pages/.