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