xref: /freebsd-14.2/lib/libc/sys/symlink.2 (revision b2c76c41)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     @(#)symlink.2	8.1 (Berkeley) 6/4/93
29.\"
30.Dd March 30, 2020
31.Dt SYMLINK 2
32.Os
33.Sh NAME
34.Nm symlink ,
35.Nm symlinkat
36.Nd make symbolic link to a file
37.Sh LIBRARY
38.Lb libc
39.Sh SYNOPSIS
40.In unistd.h
41.Ft int
42.Fn symlink "const char *name1" "const char *name2"
43.Ft int
44.Fn symlinkat "const char *name1" "int fd" "const char *name2"
45.Sh DESCRIPTION
46A symbolic link
47.Fa name2
48is created to
49.Fa name1
50.Fa ( name2
51is the name of the
52file created,
53.Fa name1
54is the string
55used in creating the symbolic link).
56Either name may be an arbitrary path name; the files need not
57be on the same file system.
58.Pp
59The
60.Fn symlinkat
61system call is equivalent to
62.Fn symlink
63except in the case where
64.Fa name2
65specifies a relative path.
66In this case the symbolic link is created relative to the directory
67associated with the file descriptor
68.Fa fd
69instead of the current working directory.
70If
71.Fn symlinkat
72is passed the special value
73.Dv AT_FDCWD
74in the
75.Fa fd
76parameter, the current working directory is used and the behavior is
77identical to a call to
78.Fn symlink .
79.Sh RETURN VALUES
80.Rv -std symlink
81.Sh ERRORS
82The symbolic link succeeds unless:
83.Bl -tag -width Er
84.It Bq Er ENOTDIR
85A component of the
86.Fa name2
87path prefix is not a directory.
88.It Bq Er ENAMETOOLONG
89A component of the
90.Fa name2
91pathname exceeded 255 characters,
92or the entire length of either path name exceeded 1023 characters.
93.It Bq Er ENOENT
94A component of the
95.Fa name2
96path prefix does not exist.
97.It Bq Er EACCES
98A component of the
99.Fa name2
100path prefix denies search permission, or write permission is denied on the
101parent directory of the file to be created.
102.It Bq Er ELOOP
103Too many symbolic links were encountered in translating the
104.Fa name2
105path name.
106.It Bq Er EEXIST
107The path name pointed at by the
108.Fa name2
109argument
110already exists.
111.It Bq Er EPERM
112The parent directory of the file named by
113.Fa name2
114has its immutable flag set, see the
115.Xr chflags 2
116manual page for more information.
117.It Bq Er EIO
118An I/O error occurred while making the directory entry for
119.Fa name2 ,
120allocating the inode for
121.Fa name2 ,
122or writing out the link contents of
123.Fa name2 .
124.It Bq Er EROFS
125The file
126.Fa name2
127would reside on a read-only file system.
128.It Bq Er ENOSPC
129The directory in which the entry for the new symbolic link is being placed
130cannot be extended because there is no space left on the file
131system containing the directory.
132.It Bq Er ENOSPC
133The new symbolic link cannot be created because
134there is no space left on the file
135system that will contain the symbolic link.
136.It Bq Er ENOSPC
137There are no free inodes on the file system on which the
138symbolic link is being created.
139.It Bq Er EDQUOT
140The directory in which the entry for the new symbolic link
141is being placed cannot be extended because the
142user's quota of disk blocks on the file system
143containing the directory has been exhausted.
144.It Bq Er EDQUOT
145The new symbolic link cannot be created because the user's
146quota of disk blocks on the file system that will
147contain the symbolic link has been exhausted.
148.It Bq Er EDQUOT
149The user's quota of inodes on the file system on
150which the symbolic link is being created has been exhausted.
151.It Bq Er EINTEGRITY
152Corrupted data was detected while reading from the file system.
153.It Bq Er EFAULT
154The
155.Fa name1
156or
157.Fa name2
158argument
159points outside the process's allocated address space.
160.El
161.Pp
162In addition to the errors returned by the
163.Fn symlink ,
164the
165.Fn symlinkat
166may fail if:
167.Bl -tag -width Er
168.It Bq Er EBADF
169The
170.Fa name2
171argument does not specify an absolute path and the
172.Fa fd
173argument is neither
174.Dv AT_FDCWD
175nor a valid file descriptor open for searching.
176.It Bq Er ENOTDIR
177The
178.Fa name2
179argument is not an absolute path and
180.Fa fd
181is neither
182.Dv AT_FDCWD
183nor a file descriptor associated with a directory.
184.El
185.Sh SEE ALSO
186.Xr ln 1 ,
187.Xr chflags 2 ,
188.Xr link 2 ,
189.Xr lstat 2 ,
190.Xr readlink 2 ,
191.Xr unlink 2 ,
192.Xr symlink 7
193.Sh STANDARDS
194The
195.Fn symlinkat
196system call follows The Open Group Extended API Set 2 specification.
197.Sh HISTORY
198The
199.Fn symlink
200system call appeared in
201.Bx 4.2 .
202The
203.Fn symlinkat
204system call appeared in
205.Fx 8.0 .
206