1UNLINK(2) Linux Programmer's Manual UNLINK(2)
2
3
4
6 unlink, unlinkat - delete a name and possibly the file it refers to
7
9 #include <unistd.h>
10
11 int unlink(const char *pathname);
12
13 #include <fcntl.h> /* Definition of AT_* constants */
14 #include <unistd.h>
15
16 int unlinkat(int dirfd, const char *pathname, int flags);
17
18 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20 unlinkat():
21 Since glibc 2.10:
22 _POSIX_C_SOURCE >= 200809L
23 Before glibc 2.10:
24 _ATFILE_SOURCE
25
27 unlink() deletes a name from the filesystem. If that name was the last
28 link to a file and no processes have the file open, the file is deleted
29 and the space it was using is made available for reuse.
30
31 If the name was the last link to a file but any processes still have
32 the file open, the file will remain in existence until the last file
33 descriptor referring to it is closed.
34
35 If the name referred to a symbolic link, the link is removed.
36
37 If the name referred to a socket, FIFO, or device, the name for it is
38 removed but processes which have the object open may continue to use
39 it.
40
41 unlinkat()
42 The unlinkat() system call operates in exactly the same way as either
43 unlink() or rmdir(2) (depending on whether or not flags includes the
44 AT_REMOVEDIR flag) except for the differences described here.
45
46 If the pathname given in pathname is relative, then it is interpreted
47 relative to the directory referred to by the file descriptor dirfd
48 (rather than relative to the current working directory of the calling
49 process, as is done by unlink() and rmdir(2) for a relative pathname).
50
51 If the pathname given in pathname is relative and dirfd is the special
52 value AT_FDCWD, then pathname is interpreted relative to the current
53 working directory of the calling process (like unlink() and rmdir(2)).
54
55 If the pathname given in pathname is absolute, then dirfd is ignored.
56
57 flags is a bit mask that can either be specified as 0, or by ORing to‐
58 gether flag values that control the operation of unlinkat(). Cur‐
59 rently, only one such flag is defined:
60
61 AT_REMOVEDIR
62 By default, unlinkat() performs the equivalent of unlink() on
63 pathname. If the AT_REMOVEDIR flag is specified, then performs
64 the equivalent of rmdir(2) on pathname.
65
66 See openat(2) for an explanation of the need for unlinkat().
67
69 On success, zero is returned. On error, -1 is returned, and errno is
70 set to indicate the error.
71
73 EACCES Write access to the directory containing pathname is not allowed
74 for the process's effective UID, or one of the directories in
75 pathname did not allow search permission. (See also path_reso‐
76 lution(7).)