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
19

DESCRIPTION

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, the rmdir() function shall mark for  update
46       the st_ctime and st_mtime fields of the parent 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 direc‐
66              tory, or there are hard links to the directory other than dot or
67              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 resolution of
74              the path argument.
75
76       ENAMETOOLONG
77              The length of the path argument exceeds {PATH_MAX} or a pathname
78              component is longer than {NAME_MAX}.
79
80       ENOENT A  component of path does not name an existing file, or the path
81              argument names a nonexistent directory or  points  to  an  empty
82              string.
83
84       ENOTDIR
85              A component of path is not a directory.
86
87       EPERM or EACCES
88
89              The S_ISVTX flag is set on the parent directory of the directory
90              to be removed and the caller is not the owner of  the  directory
91              to  be removed, nor is the caller the owner of the parent direc‐
92              tory, nor does the caller have the appropriate privileges.
93
94       EROFS  The directory entry to be removed resides on  a  read-only  file
95              system.
96
97
98       The rmdir() function may fail if:
99
100       ELOOP  More  than  {SYMLOOP_MAX} symbolic links were encountered during
101              resolution of the path argument.
102
103       ENAMETOOLONG
104              As a result of encountering a symbolic link in resolution of the
105              path  argument,  the  length  of the substituted pathname string
106              exceeded {PATH_MAX}.
107
108
109       The following sections are informative.
110

EXAMPLES

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

APPLICATION USAGE

125       None.
126

RATIONALE

128       The rmdir() and rename() functions originated in 4.2 BSD, and they used
129       [ENOTEMPTY] for the condition when the directory to be removed does not
130       exist or new already exists. When the 1984 /usr/group standard was pub‐
131       lished, it contained  [EEXIST]  instead.   When  these  functions  were
132       adopted  into System V, the 1984 /usr/group standard was used as a ref‐
133       erence. Therefore, several existing  applications  and  implementations
134       support/use  both  forms,  and  no agreement could be reached on either
135       value. All implementations are required to  supply  both  [EEXIST]  and
136       [ENOTEMPTY] in <errno.h> with distinct values, so that applications can
137       use both values in C-language case statements.
138
139       The meaning of deleting pathname /dot is unclear, because the  name  of
140       the  file  (directory)  in  the  parent  directory to be removed is not
141       clear, particularly in the presence of multiple links to a directory.
142
143       The POSIX.1-1990 standard was silent with regard  to  the  behavior  of
144       rmdir()  when  there  are  multiple  hard  links to the directory being
145       removed. The requirement to set errno to [EEXIST] or [ENOTEMPTY] clari‐
146       fies the behavior in this case.
147
148       If the process' current working directory is being removed, that should
149       be an allowed error.
150
151       Virtually all existing implementations detect [ENOTEMPTY] or  the  case
152       of  dot-dot.  The  text in Error Numbers about returning any one of the
153       possible errors permits that behavior to continue.  The  [ELOOP]  error
154       may  be  returned if more than {SYMLOOP_MAX} symbolic links are encoun‐
155       tered during resolution of the path argument.
156

FUTURE DIRECTIONS

158       None.
159

SEE ALSO

161       Error Numbers, mkdir(), remove(), unlink(), the Base Definitions volume
162       of IEEE Std 1003.1-2001, <unistd.h>
163
165       Portions  of  this text are reprinted and reproduced in electronic form
166       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
167       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
168       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
169       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
170       event of any discrepancy between this version and the original IEEE and
171       The  Open Group Standard, the original IEEE and The Open Group Standard
172       is the referee document. The original Standard can be  obtained  online
173       at http://www.opengroup.org/unix/online.html .
174
175
176
177IEEE/The Open Group                  2003                            RMDIR(3P)
Impressum