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 the . and .. entries, 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, containing) 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.

If a directory is in use (e.g. being read by ls, or is some process's current directory, etc.) when it is removed, all further accesses to it should be rejected (with ENOENT). Like a file deleted while in use, it should only be fully removed when all remaining references to it are dropped.

The removal must be atomic, both with respect to other running processes, and (if implementing a recoverable file system) with respect to crash recovery.

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 a . or .. entry.
ENOTEMPTYThe 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.