Section: POSIX Programmer's Manual (3P)
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
--- make a symbolic link relative to directory file descriptor
int symlink(const char *path1, const char *path2);
int symlinkat(const char *path1, int fd, const char *path2);
function shall create a symbolic link called
that contains the string pointed to by
is the name of the symbolic link created,
is the string contained in the symbolic link).
The string pointed to by
shall be treated only as a character string and shall not be validated
as a pathname.
function fails for any reason other than
any file named by
shall be unaffected.
names a symbolic link,
shall fail and set
The symbolic link's user ID shall be set to the process' effective
user ID. The symbolic link's group ID shall be set to the group
ID of the parent directory or to the effective group ID of the
process. Implementations shall provide a way to initialize the symbolic
link's group ID to the group ID of the parent directory. Implementations
may, but need not, provide an implementation-defined way to initialize the
symbolic link's group ID to the effective group ID of the calling process.
The values of the file mode bits for the created symbolic link are
unspecified. All interfaces specified by POSIX.1-2008 shall behave as if the
contents of symbolic links can always be read, except that the value of
the file mode bits returned in the
field of the
structure is unspecified.
Upon successful completion,
shall mark for update the last data access, last data modification,
and last file status change timestamps of the symbolic link. Also,
the last data modification and last file status change timestamps of
the directory that contains the new entry shall be marked for update.
function shall be equivalent to the
function except in the case where
specifies a relative path. In this case the symbolic link is created
relative to the directory associated with the file descriptor
instead of the current working directory. If the file descriptor was
opened without O_SEARCH, the function shall check whether directory
searches are permitted using the current permissions of the directory
underlying the file descriptor. If the file descriptor was opened with
O_SEARCH, the function shall not perform the check.
is passed the special value AT_FDCWD in the
parameter, the current working directory shall be used and the behavior
shall be identical to a call to
Upon successful completion, these functions shall return 0.
Otherwise, these functions shall return -1 and set
to indicate the error.
These functions shall fail if:
Write permission is denied in the directory where the symbolic link is
being created, or search permission is denied for a component of the
path prefix of
argument names an existing file.
An I/O error occurs while reading from or writing to the file system.
A loop exists in symbolic links encountered during resolution of the
The length of a component of the pathname specified by the
argument is longer than
or the length of the
argument is longer than
A component of the path prefix of
does not name an existing file or
is an empty string.
The directory in which the entry for the new symbolic link is being
placed cannot be extended because no space is left on the file system
containing the directory, or the new symbolic link cannot be created
because no space is left on the file system which shall contain the
link, or the file system is out of file-allocation resources.
A component of the path prefix of
names an existing file that is neither a directory nor a symbolic link
to a directory.
The new symbolic link would reside on a read-only file system.
function shall fail if:
was not opened with O_SEARCH and the permissions of the directory
do not permit directory searches.
argument does not specify an absolute path and the
argument is neither AT_FDCWD nor a valid file descriptor open for reading
argument is not an absolute path and
is a file descriptor associated with a non-directory file.
These functions may fail if:
symbolic links were encountered during resolution of the
The length of the
or pathname resolution of a symbolic link in the
argument produced an intermediate result with a length that exceeds
The following sections are informative.
Like a hard link, a symbolic link allows a file to have multiple
logical names. The presence of a hard link guarantees the existence of
a file, even after the original name has been removed. A symbolic link
provides no such assurance; in fact, the file named by the
argument need not exist when the link is created. A symbolic link can
cross file system boundaries.
Normal permission checks are made on each component of the symbolic
link pathname during its resolution.
The purpose of the
function is to create symbolic links in directories other than the
current working directory without exposure to race conditions. Any part
of the path of a file could be changed in parallel to a call to
resulting in unspecified behavior. By opening a file descriptor for
the target directory and using the
function it can be guaranteed that the created symbolic link is located
relative to the desired directory.
The Base Definitions volume of POSIX.1-2008,
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see