1LINK(2)                    Linux Programmer's Manual                   LINK(2)
2
3
4

NAME

6       link, linkat - make a new name for a file
7

SYNOPSIS

9       #include <unistd.h>
10
11       int link(const char *oldpath, const char *newpath);
12
13       #include <fcntl.h>           /* Definition of AT_* constants */
14       #include <unistd.h>
15
16       int linkat(int olddirfd, const char *oldpath,
17                  int newdirfd, const char *newpath, int flags);
18
19   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21       linkat():
22           Since glibc 2.10:
23               _POSIX_C_SOURCE >= 200809L
24           Before glibc 2.10:
25               _ATFILE_SOURCE
26

DESCRIPTION

28       link()  creates  a  new link (also known as a hard link) to an existing
29       file.
30
31       If newpath exists, it will not be overwritten.
32
33       This new name may be used exactly as the old  one  for  any  operation;
34       both names refer to the same file (and so have the same permissions and
35       ownership) and it is impossible to tell which name was the "original".
36
37   linkat()
38       The linkat() system call operates in exactly the same  way  as  link(),
39       except for the differences described here.
40
41       If  the  pathname  given in oldpath is relative, then it is interpreted
42       relative to the directory referred to by the file  descriptor  olddirfd
43       (rather  than  relative to the current working directory of the calling
44       process, as is done by link() for a relative pathname).
45
46       If oldpath is relative and olddirfd is the special value AT_FDCWD, then
47       oldpath is interpreted relative to the current working directory of the
48       calling process (like link()).
49
50       If oldpath is absolute, then olddirfd is ignored.
51
52       The interpretation of newpath is as for oldpath, except that a relative
53       pathname  is  interpreted  relative to the directory referred to by the
54       file descriptor newdirfd.
55
56       The following values can be bitwise ORed in flags:
57
58       AT_EMPTY_PATH (since Linux 2.6.39)
59              If oldpath is an empty string, create a link to the file  refer‐
60              enced  by  olddirfd  (which  may  have  been  obtained using the
61              open(2) O_PATH flag).  In this case, olddirfd can refer  to  any
62              type  of  file except a directory.  This will generally not work
63              if the file has a link count of zero (files created with  O_TMP‐
64              FILE and without O_EXCL are an exception).  The caller must have
65              the CAP_DAC_READ_SEARCH capability in order to  use  this  flag.
66              This  flag  is  Linux-specific; define _GNU_SOURCE to obtain its
67              definition.
68
69       AT_SYMLINK_FOLLOW (since Linux 2.6.18)
70              By default, linkat(), does not dereference oldpath if  it  is  a
71              symbolic  link (like link()).  The flag AT_SYMLINK_FOLLOW can be
72              specified in flags to cause oldpath to be dereference