1UNLINKAT(2) Linux Programmer's Manual UNLINKAT(2)
2
3
4
6 unlinkat - remove a directory entry relative to a directory file
7 descriptor
8
10 #define _ATFILE_SOURCE
11 #include <fcntl.h>
12
13 int unlinkat(int dirfd, const char *pathname, int flags);
14
16 The unlinkat() system call operates in exactly the same way as either
17 unlink(2) or rmdir(2) (depending on whether or not flags includes the
18 AT_REMOVEDIR flag) except for the differences described in this manual
19 page.
20
21 If the pathname given in pathname is relative, then it is interpreted
22 relative to the directory referred to by the file descriptor dirfd
23 (rather than relative to the current working directory of the calling
24 process, as is done by unlink(2) and rmdir(2) for a relative pathname).
25
26 If the pathname given in pathname is relative and dirfd is the special
27 value AT_FDCWD, then pathname is interpreted relative to the current
28 working directory of the calling process (like unlink(2) and rmdir(2)).
29
30 If the pathname given in pathname is absolute, then dirfd is ignored.
31
32 flags is a bit mask that can either be specified as 0, or by ORing
33 together flag values that control the operation of unlinkat(). Cur‐
34 rently only one such flags is defined:
35
36 AT_REMOVEDIR
37 By default, unlinkat() performs the equivalent of unlink(2) on
38 pathname. If the AT_REMOVEDIR flag is specified, then performs
39 the equivalent of rmdir(2) on pathname.
40
42 On success, unlinkat() returns 0. On error, -1 is returned and errno
43 is set to indicate the error.
44
46 The same errors that occur for unlink(2) and rmdir(2) can also occur
47 for unlinkat(). The following additional errors can occur for
48 unlinkat():
49
50 EBADF dirfd is not a valid file descriptor.
51
52 EINVAL An invalid flag value was specified in flags.
53
54 ENOTDIR
55 pathname is relative and dirfd is a file descriptor referring to
56 a file other than a directory.
57
59 See openat(2) for an explanation of the need for unlinkat().
60
62 This system call is non-standard but is proposed for inclusion in a
63 future revision of POSIX.1. A similar system call exists on Solaris.
64
66 unlinkat() was added to Linux in kernel 2.6.16.
67
69 openat(2), path_resolution(2), rmdir(2), unlink(2)
70
71
72
73Linux 2.6.16 2006-04-10 UNLINKAT(2)