man-pages/man2/symlink.2.html
2021-03-31 01:06:50 +01:00

411 lines
8.1 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SYMLINK</TITLE>
</HEAD><BODY>
<H1>SYMLINK</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
symlink, symlinkat - make a new name for a file
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/unistd.h">unistd.h</A>&gt;</B>
<B>int symlink(const char *</B><I>target</I><B>, const char *</B><I>linkpath</I><B>);</B>
<B>#include &lt;<A HREF="file:///usr/include/fcntl.h">fcntl.h</A>&gt; </B>/* Definition of AT_* constants */
<B>#include &lt;<A HREF="file:///usr/include/unistd.h">unistd.h</A>&gt;</B>
<B>int symlinkat(const char *</B><I>target</I><B>, int </B><I>newdirfd</I><B>, const char *</B><I>linkpath</I><B>);</B>
</PRE>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>symlink</B>():
<DL COMPACT><DT id="1"><DD>
_XOPEN_SOURCE&nbsp;&gt;=&nbsp;500 || _POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200112L
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Glibc&nbsp;versions&nbsp;&lt;=&nbsp;2.19:&nbsp;*/&nbsp;_BSD_SOURCE
</DL>
<P>
<B>symlinkat</B>():
<DL COMPACT><DT id="2"><DD>
<DL COMPACT>
<DT id="3">Since glibc 2.10:<DD>
_POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200809L
<DT id="4">Before glibc 2.10:<DD>
_ATFILE_SOURCE
</DL>
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>symlink</B>()
creates a symbolic link named
<I>linkpath</I>
which contains the string
<I>target</I>.
<P>
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.
<P>
Symbolic links may contain
<I>..</I>
path components, which (if used at the start of the link) refer to the
parent directories of that in which the link resides.
<P>
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.
<P>
The permissions of a symbolic link are irrelevant; the ownership is
ignored when following the link, but is checked when removal or
renaming of the link is requested and the link is in a directory with
the sticky bit
(<B>S_ISVTX</B>)
set.
<P>
If
<I>linkpath</I>
exists, it will
<I>not</I>
be overwritten.
<A NAME="lbAE">&nbsp;</A>
<H3>symlinkat()</H3>
The
<B>symlinkat</B>()
system call operates in exactly the same way as
<B>symlink</B>(),
except for the differences described here.
<P>
If the pathname given in
<I>linkpath</I>
is relative, then it is interpreted relative to the directory
referred to by the file descriptor
<I>newdirfd</I>
(rather than relative to the current working directory of
the calling process, as is done by
<B>symlink</B>()
for a relative pathname).
<P>
If
<I>linkpath</I>
is relative and
<I>newdirfd</I>
is the special value
<B>AT_FDCWD</B>,
then
<I>linkpath</I>
is interpreted relative to the current working
directory of the calling process (like
<B>symlink</B>()).
<P>
If
<I>linkpath</I>
is absolute, then
<I>newdirfd</I>
is ignored.
<A NAME="lbAF">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, zero is returned.
On error, -1 is returned, and
<I>errno</I>
is set appropriately.
<A NAME="lbAG">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="5"><B>EACCES</B>
<DD>
Write access to the directory containing
<I>linkpath</I>
is denied, or one of the directories in the path prefix of
<I>linkpath</I>
did not allow search permission.
(See also
<B><A HREF="/cgi-bin/man/man2html?7+path_resolution">path_resolution</A></B>(7).)
<DT id="6"><B>EDQUOT</B>
<DD>
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.
<DT id="7"><B>EEXIST</B>
<DD>
<I>linkpath</I>
already exists.
<DT id="8"><B>EFAULT</B>
<DD>
<I>target</I> or <I>linkpath</I> points outside your accessible address space.
<DT id="9"><B>EIO</B>
<DD>
An I/O error occurred.
<DT id="10"><B>ELOOP</B>
<DD>
Too many symbolic links were encountered in resolving
<I>linkpath</I>.
<DT id="11"><B>ENAMETOOLONG</B>
<DD>
<I>target</I> or <I>linkpath</I> was too long.
<DT id="12"><B>ENOENT</B>
<DD>
A directory component in
<I>linkpath</I>
does not exist or is a dangling symbolic link, or
<I>target</I>
or
<I>linkpath</I>
is an empty string.
<DT id="13"><B>ENOMEM</B>
<DD>
Insufficient kernel memory was available.
<DT id="14"><B>ENOSPC</B>
<DD>
The device containing the file has no room for the new directory
entry.
<DT id="15"><B>ENOTDIR</B>
<DD>
A component used as a directory in
<I>linkpath</I>
is not, in fact, a directory.
<DT id="16"><B>EPERM</B>
<DD>
The filesystem containing
<I>linkpath</I>
does not support the creation of symbolic links.
<DT id="17"><B>EROFS</B>
<DD>
<I>linkpath</I>
is on a read-only filesystem.
</DL>
<P>
The following additional errors can occur for
<B>symlinkat</B>():
<DL COMPACT>
<DT id="18"><B>EBADF</B>
<DD>
<I>newdirfd</I>
is not a valid file descriptor.
<DT id="19"><B>ENOENT</B>
<DD>
<I>linkpath</I>
is a relative pathname and
<I>newdirfd</I>
refers to a directory that has been deleted.
<DT id="20"><B>ENOTDIR</B>
<DD>
<I>linkpath</I>
is relative and
<I>newdirfd</I>
is a file descriptor referring to a file other than a directory.
</DL>
<A NAME="lbAH">&nbsp;</A>
<H2>VERSIONS</H2>
<B>symlinkat</B>()
was added to Linux in kernel 2.6.16;
library support was added to glibc in version 2.4.
<A NAME="lbAI">&nbsp;</A>
<H2>CONFORMING TO</H2>
<B>symlink</B>():
SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
<P>
<B>symlinkat</B>():
POSIX.1-2008.
<A NAME="lbAJ">&nbsp;</A>
<H2>NOTES</H2>
No checking of
<I>target</I>
is done.
<P>
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
<B><A HREF="/cgi-bin/man/man2html?2+link">link</A></B>(2).
<A NAME="lbAK">&nbsp;</A>
<H3>Glibc notes</H3>
On older kernels where
<B>symlinkat</B>()
is unavailable, the glibc wrapper function falls back to the use of
<B>symlink</B>().
When
<I>linkpath</I>
is a relative pathname,
glibc constructs a pathname based on the symbolic link in
<I>/proc/self/fd</I>
that corresponds to the
<I>newdirfd</I>
argument.
<A NAME="lbAL">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+ln">ln</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?1+namei">namei</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?2+lchown">lchown</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+link">link</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+lstat">lstat</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+readlink">readlink</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+rename">rename</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+unlink">unlink</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?7+path_resolution">path_resolution</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+symlink">symlink</A></B>(7)
<A NAME="lbAM">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="21"><A HREF="#lbAB">NAME</A><DD>
<DT id="22"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="23"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DL>
<DT id="24"><A HREF="#lbAE">symlinkat()</A><DD>
</DL>
<DT id="25"><A HREF="#lbAF">RETURN VALUE</A><DD>
<DT id="26"><A HREF="#lbAG">ERRORS</A><DD>
<DT id="27"><A HREF="#lbAH">VERSIONS</A><DD>
<DT id="28"><A HREF="#lbAI">CONFORMING TO</A><DD>
<DT id="29"><A HREF="#lbAJ">NOTES</A><DD>
<DL>
<DT id="30"><A HREF="#lbAK">Glibc notes</A><DD>
</DL>
<DT id="31"><A HREF="#lbAL">SEE ALSO</A><DD>
<DT id="32"><A HREF="#lbAM">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:35 GMT, March 31, 2021
</BODY>
</HTML>