## rmdir

#### OS/161 Reference Manual

### Name

rmdir - remove directory

### Library

Standard C Library (libc, -lc)

### Synopsis

#include <unistd.h>
int
rmdir(const char *pathname);

### Description

rmdir removes the directory named by pathname. The directory (and all the components in its path prefix) must exist. The directory must be empty, except for "." and "..", and may not be the root directory of the filesystem.

It is invalid to attempt to remove the "." or ".." entries in a directory. What rmdir actually removes is a name in some (other) directory; removing the "." or ".." names would make a mess. It is not invalid for a process to remove its own current directory, but it does not work to do so by calling rmdir(".").

It is impossible in any event to remove a directory named with "..", because it is impossible to name a directory with ".." unless it is not empty.

You must decide what happens if an attempt is made to remove a directory that is presently in use (e.g., is being read by ls, or is some process's current directory, etc.)

The removal must be atomic.

### Return Values

On success, rmdir returns 0. On error, -1 is returned, and errno is set according to the error encountered.

### Errors

The following error codes should be returned under the conditions given. Other error codes may be returned for other errors not mentioned here.

> ENODEV | The device prefix of filename did not exist.
> ENOTDIR | A non-final component of pathname was not a directory.
> ENOTDIR | pathname referred to an object that was not a directory.
> ENOENT | The target directory did not exist.
> EINVAL | An attempt was made to remove "."
> ENOTEMPTY | The target directory was not empty.
> EIO | A hard I/O error occurred.
> EFAULT | pathname was an invalid pointer.

Attempts to remove ".." may generate either EINVAL or ENOTEMPTY.