symlink()

NAME

symlink() - create symbolic link to a file

SYNOPSIS

#include <unistd.h>

int symlink(const char *path1, const char *path2)

DESCRIPTION

The symlink(2) function creates a symbolic link, with the pathname path2, with the contents path1. There must be no existing file or symbolic link with the name path2.

RETURN VALUE

Upon sucess, symlink(2) returns 0; otherwise it returns -1 and sets the value of errno.

ERRORS

The symlink(2) function can fail for the following reasons:

[EACCES]
Process does not have write permission in the directory where the symbolic link is being created or does not have search permission for some component of path2.
[EEXIST]
The path2 argument names a file or link that exists.
[EIO]
An I/O error occurred.
[EINVAL]
The underlying device doesn't support the operation.
[ELOOP]
While resolving path2, the system encountered too many symbolic links.
[ENAMETOOLONG]
Either a pathname component is longer than {NAME_MAX}, or the length of path2 is longer than {PATH_MAX}.
[ENOENT]
Either path2 is an empty string or some component does not name an existing file.
[ENOSPC]
There is no space on the file system, so the directory containing the link cannot be extended or the link cannot be created, or the system is out of file allocation resources.
[ENOTDIR]
Some component of the path prefix of path2 is not a directory.
[EROFS]
The new symbolic link would be on a read-only filesystem.

NOTES

Remember that unlike a hard link the presence of a symbolic link does not guarantee the existence of path1, not even when the link is created. Also unlike hard links, a symbolic link can point to a directory and it can cross file system boundaries.

SEE ALSO

lchown(2)

link(2)

lstat(2)

open(2)

readlink(2)