1RMDIR(3P)                  POSIX Programmer's Manual                 RMDIR(3P)
2
3
4

PROLOG

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

NAME

12       rmdir — remove a directory
13

SYNOPSIS

15       #include <unistd.h>
16
17       int rmdir(const char *path);
18

DESCRIPTION

20       The rmdir() function shall remove a directory whose name  is  given  by
21       path.  The directory shall be removed only if it is an empty directory.
22
23       If the directory is the root directory or the current working directory
24       of any process, it is unspecified whether  the  function  succeeds,  or
25       whether it shall fail and set errno to [EBUSY].
26
27       If path names a symbolic link, then rmdir() shall fail and set errno to
28       [ENOTDIR].
29
30       If the path argument refers to a path whose final component  is  either
31       dot or dot-dot, rmdir() shall fail.
32
33       If  the  directory's link count becomes 0 and no process has the direc‐
34       tory open, the space occupied by the directory shall be freed  and  the
35       directory  shall no longer be accessible. If one or more processes have
36       the directory open when the last link is removed, the dot  and  dot-dot
37       entries, if present, shall be removed before rmdir() returns and no new
38       entries may be created in the directory, but the directory shall not be
39       removed until all references to the directory are closed.
40
41       If  the directory is not an empty directory, rmdir() shall fail and set
42       errno to [EEXIST] or [ENOTEMPTY].
43
44       Upon successful completion, rmdir() shall mark for update the last data
45       modification  and  last  file  status  change  timestamps of the parent
46       directory.
47

RETURN VALUE

49       Upon successful completion, the function rmdir() shall return 0. Other‐
50       wise,  -1 shall be returned, and errno set to indicate the error. If -1
51       is returned, the named directory shall not be changed.
52

ERRORS

54       The rmdir() function shall fail if:
55
56       EACCES Search permission is denied on a component of the  path  prefix,
57              or  write  permission  is  denied on the parent directory of the
58              directory to be removed.
59
60       EBUSY  The directory to be removed is currently in use by the system or
61              some  process  and  the  implementation  considers this to be an
62              error.
63
64       [EEXIST] or [ENOTEMPTY]
65                   The path argument names a directory that is  not  an  empty
66                   directory,  or  there are hard links to the directory other
67                   than dot or a single entry in dot-dot.
68
69       EINVAL      The path argument contains a last component that is dot.
70
71       EIO         A physical I/O error has occurred.
72
73       ELOOP       A loop exists in symbolic links encountered during  resolu‐
74                   tion of the path argument.
75
76       ENAMETOOLONG
77                   The  length  of  a  component  of a pathname is longer than
78                   {NAME_MAX}.
79
80       ENOENT      A component of path does not name an existing file, or  the
81                   path argument names a nonexistent directory or points to an
82                   empty string.
83
84       ENOTDIR     A component of path names an existing file that is  neither
85                   a directory nor a symbolic link to a directory.
86
87       [EPERM] or [EACCES]
88                   The  S_ISVTX  flag  is  set on the directory containing the
89                   file referred to by the path argument and the process  does
90                   not  satisfy the criteria specified in the Base Definitions
91                   volume of POSIX.1‐2017, Section 4.3, Directory Protection.
92
93       EROFS       The directory entry to be removed resides  on  a  read-only
94                   file system.
95
96       The rmdir() function may fail if:
97
98       ELOOP  More  than  {SYMLOOP_MAX} symbolic links were encountered during
99              resolution of the path argument.
100
101       ENAMETOOLONG
102              The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
103              tion  of  a symbolic link produced an intermediate result with a
104              length that exceeds {PATH_MAX}.
105
106       The following sections are informative.
107

EXAMPLES

109   Removing a Directory
110       The  following  example  shows  how  to  remove   a   directory   named
111       /home/cnd/mod1.
112
113
114           #include <unistd.h>
115
116           int status;
117           ...
118           status = rmdir("/home/cnd/mod1");
119

APPLICATION USAGE

121       None.
122

RATIONALE

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

FUTURE DIRECTIONS

154       None.
155

SEE ALSO

157       Section 2.3, Error Numbers, mkdir(), remove(), rename(), unlink()
158
159       The Base Definitions volume of  POSIX.1‐2017,  Section  4.3,  Directory
160       Protection, <unistd.h>
161
163       Portions  of  this text are reprinted and reproduced in electronic form
164       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
165       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
166       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
167       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
168       event of any discrepancy between this version and the original IEEE and
169       The  Open Group Standard, the original IEEE and The Open Group Standard
170       is the referee document. The original Standard can be  obtained  online
171       at http://www.opengroup.org/unix/online.html .
172
173       Any  typographical  or  formatting  errors that appear in this page are
174       most likely to have been introduced during the conversion of the source
175       files  to  man page format. To report such errors, see https://www.ker
176       nel.org/doc/man-pages/reporting_bugs.html .
177
178
179
180IEEE/The Open Group                  2017                            RMDIR(3P)
Impressum