1SYMLINK(2)                 Linux Programmer's Manual                SYMLINK(2)
2
3
4

NAME

6       symlink, symlinkat - make a new name for a file
7

SYNOPSIS

9       #include <unistd.h>
10
11       int symlink(const char *target, const char *linkpath);
12
13       #include <fcntl.h>           /* Definition of AT_* constants */
14       #include <unistd.h>
15
16       int symlinkat(const char *target, int newdirfd, const char *linkpath);
17
18   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20       symlink():
21           _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200112L
22               || /* Glibc <= 2.19: */ _BSD_SOURCE
23
24       symlinkat():
25           Since glibc 2.10:
26               _POSIX_C_SOURCE >= 200809L
27           Before glibc 2.10:
28               _ATFILE_SOURCE
29

DESCRIPTION

31       symlink()  creates  a  symbolic  link named linkpath which contains the
32       string target.
33
34       Symbolic links are interpreted at run time as if the  contents  of  the
35       link  had  been substituted into the path being followed to find a file
36       or directory.
37
38       Symbolic links may contain ..  path components, which (if used  at  the
39       start of the link) refer to the parent directories of that in which the
40       link resides.
41
42       A symbolic link (also known as a soft link) may point  to  an  existing
43       file  or  to  a nonexistent one; the latter case is known as a dangling
44       link.
45
46       The permissions of a symbolic link are irrelevant; the ownership is ig‐
47       nored  when following the link, but is checked when removal or renaming
48       of the link is requested and the link is in a directory with the sticky
49       bit (S_ISVTX) set.
50
51       If linkpath exists, it will not be overwritten.
52
53   symlinkat()
54       The  symlinkat()  system  call operates in exactly the same way as sym‐
55       link(), except for the differences described here.
56
57       If the pathname given in linkpath is relative, then it  is  interpreted
58       relative  to  the directory referred to by the file descriptor newdirfd
59       (rather than relative to the current working directory of  the  calling
60       process, as is done by symlink() for a relative pathname).
61
62       If  linkpath  is  relative  and newdirfd is the special value AT_FDCWD,
63       then linkpath is interpreted relative to the current working  directory
64       of the calling process (like symlink()).
65
66       If linkpath is absolute, then newdirfd is ignored.
67
68       See openat(2) for an explanation of the need for symlinkat().
69

RETURN VALUE

71       On  success,  zero is returned.  On error, -1 is returned, and errno is
72       set to indicate the error.
73

ERRORS

75       EACCES Write access to the directory containing linkpath is denied,  or
76              one  of  the  directories in the path prefix of linkpath did not
77              allow search permission.  (See also path_resolution(7).)
78
79       EBADF  (symlinkat()) linkpath  is  relative  but  newdirfd  is  neither
80              AT_FDCWD nor a valid file descriptor.
81
82       EDQUOT The  user's  quota  of  resources on the filesystem has been ex‐
83              hausted.  The resources could be inodes or disk blocks,  depend‐
84              ing on the filesystem implementation.
85
86       EEXIST linkpath already exists.
87
88       EFAULT target or linkpath points outside your accessible address space.
89
90       EIO    An I/O error occurred.
91
92       ELOOP  Too many symbolic links were encountered in resolving linkpath.
93
94       ENAMETOOLONG
95              target or linkpath was too long.
96
97       ENOENT A  directory  component  in linkpath does not exist or is a dan‐
98              gling symbolic link, or target or linkpath is an empty string.
99
100       ENOENT (symlinkat()) linkpath  is  a  relative  pathname  and  newdirfd
101              refers to a directory that has been deleted.
102
103       ENOMEM Insufficient kernel memory was available.
104
105       ENOSPC The device containing the file has no room for the new directory
106              entry.
107
108       ENOTDIR
109              A component used as a directory in linkpath is not, in  fact,  a
110              directory.
111
112       ENOTDIR
113              (symlinkat())  linkpath  is  relative and newdirfd is a file de‐
114              scriptor referring to a file other than a directory.
115
116       EPERM  The filesystem containing linkpath does not support the creation
117              of symbolic links.
118
119       EROFS  linkpath is on a read-only filesystem.
120

VERSIONS

122       symlinkat()  was  added  to Linux in kernel 2.6.16; library support was
123       added to glibc in version 2.4.
124

CONFORMING TO

126       symlink(): SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
127
128       symlinkat(): POSIX.1-2008.
129

NOTES

131       No checking of target is done.
132
133       Deleting the name referred to by a symbolic link will  actually  delete
134       the  file  (unless  it also has other hard links).  If this behavior is
135       not desired, use link(2).
136
137   Glibc notes
138       On older kernels where symlinkat() is unavailable,  the  glibc  wrapper
139       function  falls back to the use of symlink().  When linkpath is a rela‐
140       tive pathname, glibc constructs a pathname based on the  symbolic  link
141       in /proc/self/fd that corresponds to the newdirfd argument.
142

SEE ALSO

144       ln(1),  namei(1),  lchown(2),  link(2), lstat(2), open(2), readlink(2),
145       rename(2), unlink(2), path_resolution(7), symlink(7)
146

COLOPHON

148       This page is part of release 5.13 of the Linux  man-pages  project.   A
149       description  of  the project, information about reporting bugs, and the
150       latest    version    of    this    page,    can     be     found     at
151       https://www.kernel.org/doc/man-pages/.
152
153
154
155Linux                             2021-08-27                        SYMLINK(2)
Impressum