1RMDIR(3P) POSIX Programmer's Manual RMDIR(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 rmdir — remove a directory
14
16 #include <unistd.h>
17
18 int rmdir(const char *path);
19
21 The rmdir() function shall remove a directory whose name is given by
22 path. The directory shall be removed only if it is an empty directory.
23
24 If the directory is the root directory or the current working directory
25 of any process, it is unspecified whether the function succeeds, or
26 whether it shall fail and set errno to [EBUSY].
27
28 If path names a symbolic link, then rmdir() shall fail and set errno to
29 [ENOTDIR].
30
31 If the path argument refers to a path whose final component is either
32 dot or dot-dot, rmdir() shall fail.
33
34 If the directory's link count becomes 0 and no process has the direc‐
35 tory open, the space occupied by the directory shall be freed and the
36 directory shall no longer be accessible. If one or more processes have
37 the directory open when the last link is removed, the dot and dot-dot
38 entries, if present, shall be removed before rmdir() returns and no new
39 entries may be created in the directory, but the directory shall not be
40 removed until all references to the directory are closed.
41
42 If the directory is not an empty directory, rmdir() shall fail and set
43 errno to [EEXIST] or [ENOTEMPTY].
44
45 Upon successful completion, rmdir() shall mark for update the last data
46 modification and last file status change timestamps of the parent
47 directory.
48
50 Upon successful completion, the function rmdir() shall return 0. Other‐
51 wise, −1 shall be returned, and errno set to indicate the error. If −1
52 is returned, the named directory shall not be changed.
53
55 The rmdir() function shall fail if:
56
57 EACCES Search permission is denied on a component of the path prefix,
58 or write permission is denied on the parent directory of the
59 directory to be removed.
60
61 EBUSY The directory to be removed is currently in use by the system or
62 some process and the implementation considers this to be an
63 error.
64
65 [EEXIST] or [ENOTEMPTY]
66 The path argument names a directory that is not an empty
67 directory, or there are hard links to the directory other
68 than dot or a single entry in dot-dot.
69
70 EINVAL The path argument contains a last component that is dot.
71
72 EIO A physical I/O error has occurred.
73
74 ELOOP A loop exists in symbolic links encountered during resolu‐
75 tion of the path argument.
76
77 ENAMETOOLONG
78 The length of a component of a pathname is longer than
79 {NAME_MAX}.
80
81 ENOENT A component of path does not name an existing file, or the
82 path argument names a nonexistent directory or points to an
83 empty string.
84
85 ENOTDIR A component of path names an existing file that is neither
86 a directory nor a symbolic link to a directory.
87
88 [EPERM] or [EACCES]
89 The S_ISVTX flag is set on the directory containing the
90 file referred to by the path argument and the process does
91 not satisfy the criteria specified in the Base Definitions
92 volume of POSIX.1‐2008, Section 4.2, Directory Protection.
93
94 EROFS The directory entry to be removed resides on a read-only
95 file system.
96
97 The rmdir() function may fail if:
98
99 ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during
100 resolution of the path argument.
101
102 ENAMETOOLONG
103 The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
104 tion of a symbolic link produced an intermediate result with a
105 length that exceeds {PATH_MAX}.
106
107 The following sections are informative.
108
110 Removing a Directory
111 The following example shows how to remove a directory named
112 /home/cnd/mod1.
113
114 #include <unistd.h>
115
116 int status;
117 ...
118 status = rmdir("/home/cnd/mod1");
119
121 None.
122
124 The rmdir() and rename() functions originated in 4.2 BSD, and they used
125 [ENOTEMPTY] for the condition when the directory to be removed does not
126 exist or new already exists. When the 1984 /usr/group standard was pub‐
127 lished, it contained [EEXIST] instead. When these functions were
128 adopted into System V, the 1984 /usr/group standard was used as a ref‐
129 erence. Therefore, several existing applications and implementations
130 support/use both forms, and no agreement could be reached on either
131 value. All implementations are required to supply both [EEXIST] and
132 [ENOTEMPTY] in <errno.h> with distinct values, so that applications can
133 use both values in C-language case statements.
134
135 The meaning of deleting pathname/dot is unclear, because the name of
136 the file (directory) in the parent directory to be removed is not
137 clear, particularly in the presence of multiple links to a directory.
138
139 The POSIX.1‐1990 standard was silent with regard to the behavior of
140 rmdir() when there are multiple hard links to the directory being
141 removed. The requirement to set errno to [EEXIST] or [ENOTEMPTY] clari‐
142 fies the behavior in this case.
143
144 If the current working directory of the process is being removed, that
145 should be an allowed error.
146
147 Virtually all existing implementations detect [ENOTEMPTY] or the case
148 of dot-dot. The text in Section 2.3, Error Numbers about returning any
149 one of the possible errors permits that behavior to continue. The
150 [ELOOP] error may be returned if more than {SYMLOOP_MAX} symbolic links
151 are encountered during resolution of the path argument.
152
154 None.
155
157 Section 2.3, Error Numbers, mkdir(), remove(), rename(), unlink()
158
159 The Base Definitions volume of POSIX.1‐2008, Section 4.2, Directory
160 Protection, <unistd.h>
161
163 Portions of this text are reprinted and reproduced in electronic form
164 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
165 -- Portable Operating System Interface (POSIX), The Open Group Base
166 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
167 cal and Electronics Engineers, Inc and The Open Group. (This is
168 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
169 event of any discrepancy between this version and the original IEEE and
170 The Open Group Standard, the original IEEE and The Open Group Standard
171 is the referee document. The original Standard can be obtained online
172 at http://www.unix.org/online.html .
173
174 Any typographical or formatting errors that appear in this page are
175 most likely to have been introduced during the conversion of the source
176 files to man page format. To report such errors, see https://www.ker‐
177 nel.org/doc/man-pages/reporting_bugs.html .
178
179
180
181IEEE/The Open Group 2013 RMDIR(3P)