| LINK(2) | System Calls Manual | LINK(2) | 
link —
#include <unistd.h>
int
  
  link(const
    char *name1, const char
    *name2);
#include
  <fcntl.h>
int
  
  linkat(int
    fd1, const char
    *name1, int fd2,
    const char *name2,
    int flags);
link() function call atomically creates the
  specified directory entry (hard link) name2 with the
  attributes of the underlying object pointed at by name1.
  If the link is successful: the link count of the underlying object is
  incremented; name1 and name2 share
  equal access and rights to the underlying object.
If name1 is removed, the file name2 is not deleted and the link count of the underlying object is decremented.
name1 must exist for the hard link to succeed and both name1 and name2 must be in the same file system. name1 may not be a directory unless the caller is the super-user and the file system containing it supports linking to directories.
linkat() works the same way as
    link() except if name1 (resp.
    name2) is relative. In that case, it is looked up from
    a directory whose file descriptor was passed as fd1
    (resp. fd2). Search permission is required on the
    directories named by fd1 and
    fd2. fd1 or
    fd2 can be set to AT_FDCWD in
    order to specify the current directory.
When operating on a symlink, link()
    resolves the symlink and creates a hard link on the target.
    linkat() will do the same if
    AT_SYMLINK_FOLLOW is set in
    flags, but it will link on the symlink itself if the
    flag is clear.
link() and linkat()
  functions return the value 0 if successful; otherwise the
  value -1 is returned and the global variable
  errno is set to indicate the error.
link() and linkat() will fail
  and no link will be created if:
EACCES]EDQUOT]EEXIST]EFAULT]EIO]ELOOP]EMLINK]LINK_MAX}.ENAMETOOLONG]NAME_MAX}
      characters, or an entire path name exceeded
      {PATH_MAX} characters.ENOENT]ENOSPC]ENOTDIR]EOPNOTSUPP]EPERM]link() on a
      directory.EROFS]EXDEV]In addition, linkat() will fail if:
EBADF]AT_FDCWD nor a valid file descriptor open for
      reading or searching.ENOTDIR]link() function conforms to IEEE
  Std 1003.1-1990 (“POSIX.1”).
  linkat() conforms to IEEE Std
  1003.1-2008 (“POSIX.1”).
link() function appeared in
  Version 1 AT&T UNIX.
| September 1, 2019 | NetBSD 9.4 |