SYMLINK(3POSIX)
π SYMLINK(3POSIX) β POSIX Programmer's Manual π
okay bestie, gather round, we're doing symlink today and it's honestly iconic. this is the POSIX Programmer's Manual page for symlink and symlinkat, so like, the spec version, not necessarily your Linux box's version.
π¨ PROLOG π¨
this page is literally part of the POSIX Programmer's Manual. heads up though:
the Linux implementation of this interface may differ (go check the corresponding Linux manual page for the actual Linux tea β), or honestly the interface might not even be implemented on Linux at all. no cap.
β¨ NAME β¨
symlink, symlinkat β make a symbolic link π¦
πΈ SYNOPSIS πΈ
#include <unistd.h>
int symlink(const char *path1, const char *path2);
#include <fcntl.h>
int symlinkat(const char *path1, int fd, const char *path2);
π DESCRIPTION π
so symlink() shall create a symbolic link called path2 that contains the string pointed to by path1. quick decoder ring for you:
path2= the name of the symbolic link being createdpath1= the string that's contained inside the symbolic link
the string pointed to by path1 is treated only as a string and shall not be validated as a pathname. so it's giving "just vibes, no verification" β¨
if symlink() fails for any reason other than [EIO], any file named by path2 shall be unaffected. phew.
if path2 names a symbolic link, symlink() shall fail and set errno to [EEXIST]. sorry bestie, it already exists.
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 st_mode field of the stat structure is unspecified. π it's unspecified bestie, we don't make the rules.
upon successful completion, symlink() 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. timestamps are getting their little glow-up π
now, symlinkat() shall be equivalent to the symlink() function except in the case where path2 specifies a relative path. in that case the symbolic link is created relative to the directory associated with the file descriptor fd instead of the current working directory. if the access mode of the open file description associated with the file descriptor is not O_SEARCH, the function shall check whether directory searches are permitted using the current permissions of the directory underlying the file descriptor. if the access mode is O_SEARCH, the function shall not perform the check. she's efficient π
if symlinkat() is passed the special value AT_FDCWD in the fd parameter, the current working directory shall be used and the behavior shall be identical to a call to symlink(). twins fr fr π―
π RETURN VALUE π
upon successful completion, these functions shall return 0. otherwise, these functions shall return -1 and set errno to indicate the error. zero is the slay, minus one is the nay π
π ERRORS π
these functions shall fail if:
EACCESβ 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 ofpath2.EEXISTβ thepath2argument names an existing file.EIOβ an I/O error occurs while reading from or writing to the file system.ELOOPβ a loop exists in symbolic links encountered during resolution of thepath2argument.ENAMETOOLONGβ the length of a component of the pathname specified by thepath2argument is longer than{NAME_MAX}or the length of thepath1argument is longer than{SYMLINK_MAX}.ENOENTβ a component of the path prefix ofpath2does not name an existing file orpath2is an empty string.ENOENTorENOTDIRβ thepath2argument contains at least one non-<slash>character and ends with one or more trailing<slash>characters. ifpath2without the trailing<slash>characters would name an existing file, an[ENOENT]error shall not occur.ENOSPCβ 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. (three separate ways to run out of room, obsessed with the thoroughness π«Ά)ENOTDIRβ a component of the path prefix ofpath2names an existing file that is neither a directory nor a symbolic link to a directory.EROFSβ the new symbolic link would reside on a read-only file system. no writing on the read-only girlies π
the symlinkat() function shall fail if:
EACCESβ the access mode of the open file description associated withfdis notO_SEARCHand the permissions of the directory underlyingfddo not permit directory searches.EBADFβ thepath2argument does not specify an absolute path and thefdargument is neitherAT_FDCWDnor a valid file descriptor open for reading or searching.ENOTDIRβ thepath2argument is not an absolute path andfdis a file descriptor associated with a non-directory file.
these functions may fail if:
ELOOPβ more than{SYMLOOP_MAX}symbolic links were encountered during resolution of thepath2argument.ENAMETOOLONGβ the length of thepath2argument exceeds{PATH_MAX}or pathname resolution of a symbolic link in thepath2argument produced an intermediate result with a length that exceeds{PATH_MAX}.
the following sections are informative. (i.e. the fun part, the lore, the β¨contextβ¨)
π EXAMPLES π
None.
(genuinely nothing. no examples. we're on our own bestie π)
π¦ APPLICATION USAGE π¦
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 path1 argument need not exist when the link is created. she's a free spirit, she can point at nothing πΈ
a symbolic link can cross file system boundaries. main character energy, honestly.
normal permission checks are made on each component of the symbolic link pathname during its resolution. π
π RATIONALE π
the whole point of symlinkat() 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 symlink(), resulting in unspecified behavior (spooky π). by opening a file descriptor for the target directory and using the symlinkat() function it can be guaranteed that the created symbolic link is located relative to the desired directory. it's giving safety, it's giving control, we love her π₯
β FUTURE DIRECTIONS β
None.
π SEE ALSO π
fdopendir(), fstatat(), lchown(), link(), open(), readlink(), rename(), unlink()
The Base Definitions volume of POSIX.1β2017, <fcntl.h>, <unistd.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. 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 http://www.opengroup.org/unix/online.html .
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 https://www.kernel.org/doc/man-pages/reporting_bugs.html .
okay that's the whole page, you ate that π β¨ this was IEEE/The Open Group, 2017, SYMLINK(3POSIX) β mwah, go make some links bestie ππ¦π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms