rmdir - remove a directory
#include <unistd.h> int rmdir(const char *path);
The rmdir() function removes a directory whose name is given by path. The directory is removed only if it is an empty directory.If the directory is the root directory or the current working directory of any process, it is unspecified whether the function succeeds, or whether it fails and sets errno to [EBUSY].
If path names a symbolic link, then rmdir() fails and sets errno to [ENOTDIR].
If the directory's link count becomes 0 and no process has the directory open, the space occupied by the directory will be freed and the directory will no longer be accessible. If one or more processes have the directory open when the last link is removed, the dot and dot-dot entries, if present, are removed before rmdir() returns and no new entries may be created in the directory, but the directory is not removed until all references to the directory are closed.
Upon successful completion, the rmdir() function marks for update the st_ctime and st_mtime fields of the parent directory.
Upon successful completion, the function rmdir() returns 0. Otherwise, -1 is returned, and errno is set to indicate the error. If -1 is returned, the named directory is not changed.
The rmdir() function will fail if:
- [EACCES]
- Search permission is denied on a component of the path prefix, or write permission is denied on the parent directory of the directory to be removed.
- [EBUSY]
- The directory to be removed is currently in use by the system or another process and the implementation considers this to be an error.
- [EEXIST] or [ENOTEMPTY]
- The path argument names a directory that is not an empty directory.
- [EIO]
- A physical I/O error has occurred.
- [ELOOP]
- Too many symbolic links were encountered in resolving path.
- [ENAMETOOLONG]
- The length of the path argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.
- [ENOENT]
- A component of path does not name an existing file, or the path argument names a non-existent directory or points to an empty string.
- [ENOTDIR]
- A component of the path is not a directory.
- [EPERM] or [EACCES]
- The S_ISVTX flag is set on the parent directory of the directory to be removed and the caller is not the owner of the directory to be removed, nor is the caller the owner of the parent directory, nor does the caller have the appropriate privileges.
- [EROFS]
- The directory entry to be removed resides on a read-only file system.
The rmdir() function may fail if:
- [ENAMETOOLONG]
- Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.
None.
None.
None.
mkdir(), remove(), unlink(), <unistd.h>.
Derived from the POSIX.1-1988 standard.