1LINKAT(2) Linux Programmer's Manual LINKAT(2)
2
3
4
6 linkat - create a file link relative to directory file descriptors
7
9 #include <fcntl.h> /* Definition of AT_* constants */
10 #include <unistd.h>
11
12 int linkat(int olddirfd, const char *oldpath,
13 int newdirfd, const char *newpath, int flags);
14
15 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17 linkat():
18 Since glibc 2.10:
19 _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
20 Before glibc 2.10:
21 _ATFILE_SOURCE
22
24 The linkat() system call operates in exactly the same way as link(2),
25 except for the differences described in this manual page.
26
27 If the pathname given in oldpath is relative, then it is interpreted
28 relative to the directory referred to by the file descriptor olddirfd
29 (rather than relative to the current working directory of the calling
30 process, as is done by link(2) for a relative pathname).
31
32 If oldpath is relative and olddirfd is the special value AT_FDCWD, then
33 oldpath is interpreted relative to the current working directory of the
34 calling process (like link(2)).
35
36 If oldpath is absolute, then olddirfd is ignored.
37
38 The interpretation of newpath is as for oldpath, except that a relative
39 pathname is interpreted relative to the directory referred to by the
40 file descriptor newdirfd.
41
42 The following values can be biwise ORed in flags:
43
44 AT_EMPTY_PATH (since Linux 2.6.39)
45 If oldpath is an empty string, create a link to the file refer‐
46 enced by olddirfd (which may have been obtained using the
47 open(2) O_PATH flag). In this case, olddirfd can refer to any
48 type of file, not just a directory. The caller must have the
49 CAP_DAC_READ_SEARCH capability in order to use this flag; this
50 prevents arbitrary users from creating hard links using file
51 descriptors received via a UNIX domain socket (see the discus‐
52 sion of SCM_RIGHTS in unix(7)).
53
54 AT_SYMLINK_FOLLOW (since Linux 2.6.18)
55 By default, linkat(), does not dereference oldpath if it is a
56 symbolic link (like link(2)). The flag AT_SYMLINK_FOLLOW can be
57 specified in flags to cause oldpath to be dereferenced if it is
58 a symbolic link.
59
60 Before kernel 2.6.18, the flags argument was unused, and had to be
61 specified as 0.
62
64 On success, linkat() returns 0. On error, -1 is returned and errno is
65 set to indicate the error.
66
68 The same errors that occur for link(2) can also occur for linkat().
69 The following additional errors can occur for linkat():
70
71 EBADF olddirfd or newdirfd is not a valid file descriptor.
72
73 ENOENT AT_EMPTY_PATH was specified in flags, but the caller did not
74 have the CAP_DAC_READ_SEARCH capability.
75
76 ENOTDIR
77
78 ENOTDIR
79 oldpath is relative and olddirfd is a file descriptor referring
80 to a file other than a directory; or similar for newpath and
81 newdirfd
82
84 linkat() was added to Linux in kernel 2.6.16; library support was added
85 to glibc in version 2.4.
86
88 POSIX.1-2008.
89
91 See openat(2) for an explanation of the need for linkat().
92
94 link(2), openat(2), path_resolution(7), symlink(7)
95
97 This page is part of release 3.53 of the Linux man-pages project. A
98 description of the project, and information about reporting bugs, can
99 be found at http://www.kernel.org/doc/man-pages/.
100
101
102
103Linux 2013-07-21 LINKAT(2)