1unlink(2)                     System Calls Manual                    unlink(2)
2
3
4

NAME

6       unlink, unlinkat - delete a name and possibly the file it refers to
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <unistd.h>
13
14       int unlink(const char *pathname);
15
16       #include <fcntl.h>           /* Definition of AT_* constants */
17       #include <unistd.h>
18
19       int unlinkat(int dirfd, const char *pathname, int flags);
20
21   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
22
23       unlinkat():
24           Since glibc 2.10:
25               _POSIX_C_SOURCE >= 200809L
26           Before glibc 2.10:
27               _ATFILE_SOURCE
28

DESCRIPTION

30       unlink() deletes a name from the filesystem.  If that name was the last
31       link to a file and no processes have the file open, the file is deleted
32       and the space it was using is made available for reuse.
33
34       If  the  name  was the last link to a file but any processes still have
35       the file open, the file will remain in existence until  the  last  file
36       descriptor referring to it is closed.
37
38       If the name referred to a symbolic link, the link is removed.
39
40       If  the  name referred to a socket, FIFO, or device, the name for it is
41       removed but processes which have the object open may  continue  to  use
42       it.
43
44   unlinkat()
45       The  unlinkat()  system call operates in exactly the same way as either
46       unlink() or rmdir(2) (depending on whether or not  flags  includes  the
47       AT_REMOVEDIR flag) except for the differences described here.
48
49       If  the  pathname given in pathname is relative, then it is interpreted
50       relative to the directory referred to  by  the  file  descriptor  dirfd
51       (rather  than  relative to the current working directory of the calling
52       process, as is done by unlink() and rmdir(2) for a relative pathname).
53
54       If the pathname given in pathname is relative and dirfd is the  special
55       value  AT_FDCWD,  then  pathname is interpreted relative to the current
56       working directory of the calling process (like unlink() and rmdir(2)).
57
58       If the pathname given in pathname is absolute, then dirfd is ignored.
59
60       flags is a bit mask that can either be specified as 0, or by ORing  to‐
61       gether  flag  values  that  control  the operation of unlinkat().  Cur‐
62       rently, only one such flag is defined:
63
64       AT_REMOVEDIR
65              By default, unlinkat() performs the equivalent  of  unlink()  on
66              pathname.   If the AT_REMOVEDIR flag is specified, then performs
67              the equivalent of rmdir(2) on pathname.
68
69       See openat(2) for an explanation of the need for unlinkat().
70

RETURN VALUE

72       On success, zero is returned.  On error, -1 is returned, and  errno  is
73       set to indicate the error.
74

ERRORS

76       EACCES Write access to the directory containing pathname is not allowed
77              for the process's effective UID, or one of  the  directories