SYMLINK(2)
π SYMLINK(2) π β the symlink glow-up, from your fave syscall bestie
okay so. you opened the System Calls Manual (that's the manual name, it lives in section 2, syscalls only, no cap) and you landed on symlink. bestie, you are about to make a link that is literally symbolic. not a hard link. a vibe. let's go. π¦
β¨ NAME β¨
symlink, symlinkat β make symbolic link to a file
π LIBRARY π
Standard C Library (libc, -lc)
πΈ SYNOPSIS πΈ
like, here's the whole thing, copy it exactly, don't freestyle:
#include <unistd.h>
int
symlink(const char *name1, const char *name2);
int
symlinkat(const char *name1, int fd, const char *name2);
π DESCRIPTION π
So. A symbolic link name2 is created to name1. And before you get confused (everyone does, it's fine, breathe): name2 is the name of the file being created, and name1 is the string used in creating the symbolic link. The way that the "new thing" is name2 and the "thing it points at" is name1? iconic. slightly chaotic. we love her. π
Either name can be an arbitrary path name β go feral, no rules β and the files do not have to live on the same file system. cross-filesystem? she doesn't care. main character energy. β¨
Now. symlinkat() is the same girl as symlink() except in one specific case: when name2 specifies a relative path. In that case, the symbolic link gets created relative to the directory associated with the file descriptor fd instead of the current working directory. cute, right? π
And if you pass symlinkat() the special value AT_FDCWD in the fd parameter? Then the current working directory is used and the behavior is identical to a call to symlink(). fr fr, same thing.
π₯ RETURN VALUES π₯
symlink() returns the value 0 if it ate and left no crumbs (successful). Otherwise the value -1 comes back and the global variable errno is set to indicate the error. π the -1 is never good news.
π ERRORS π
The symbolic link succeeds unless β and girl, there are so many unlesses:
[ENOTDIR]β a component of thename2path prefix is not a directory. rude.[ENAMETOOLONG]β a component of thename2pathname exceeded 255 characters, or the entire length of either path name exceeded 1023 characters. she said too long, bestie π[ENOENT]β a component of thename2path prefix does not exist. she's not there. ghosted.[EACCES]β a component of thename2path prefix denies search permission, or write permission is denied on the parent directory of the file to be created.[ELOOP]β too many symbolic links were encountered in translating thename2path name. it's giving infinite hallway π΅π«[EEXIST]β the path name pointed at by thename2argument already exists. she's taken!![EPERM]β the parent directory of the file named byname2has its immutable flag set. see thechflags(2)manual page for more information. that directory is not accepting applications. π«[EIO]β an I/O error occurred while making the directory entry forname2, allocating the inode forname2, or writing out the link contents ofname2.[EROFS]β the filename2would reside on a read-only file system. no writes allowed, periodt.[ENOSPC]β the directory in which the entry for the new symbolic link is being placed cannot be extended because there is no space left on the file system containing the directory.[ENOSPC]β the new symbolic link cannot be created because there is no space left on the file system that will contain the symbolic link.[ENOSPC]β there are no free inodes on the file system on which the symbolic link is being created. (yes, three separateENOSPCsituations. she contains multitudes.)[EDQUOT]β the directory in which the entry for the new symbolic link is being placed cannot be extended because the user's quota of disk blocks on the file system containing the directory has been exhausted.[EDQUOT]β the new symbolic link cannot be created because the user's quota of disk blocks on the file system that will contain the symbolic link has been exhausted.[EDQUOT]β the user's quota of inodes on the file system on which the symbolic link is being created has been exhausted. quota said enough π«Ά[EINTEGRITY]β corrupted data was detected while reading from the file system. she's not okay, and neither is the disk. π[EFAULT]β thename1orname2argument points outside the process's allocated address space. out of bounds, out of pocket.
On top of all the errors symlink() returns, symlinkat() may also fail if:
[EBADF]β thename2argument does not specify an absolute path and thefdargument is neitherAT_FDCWDnor a valid file descriptor open for searching.[ENOTDIR]β thename2argument is not an absolute path andfdis neitherAT_FDCWDnor a file descriptor associated with a directory.
pro tip from your girl:errnois the group chat. read it immediately after the-1or the messages get marked as read and you'll never know what happened. π
π SEE ALSO π
ln(1), chflags(2), link(2), lstat(2), readlink(2), unlink(2), symlink(7)
iykyk, go read them, they're all besties.
β STANDARDS β
The symlinkat() system call follows The Open Group Extended API Set 2 specification. she's certified. she's got paperwork. π
π HISTORY π
- The
symlink()system call appeared in4.2BSD. an elder. a legend. π - The
symlinkat()system call appeared inFreeBSD 8.0.
and that's the whole page, bestie. no cap, every flag, every errno, every vibe β all preserved. this gorgeous little page came to you via Debian and is dated March 30, 2020, and it's the SYMLINK(2) entry in the System Calls Manual. go make some links. slay. πβ¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1983, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms