rmdir

delete an empty directory

Synopsis:

#include <sys/types.h>
#include <unistd.h>
int rmdir( const char *path );

Description:

The rmdir() function removes (deletes) the specified directory. The directory must not contain any files or directories. The path can be either relative to the current working directory, or it can be an absolute path name.

If the directory is the root directory or the current working directory of any process, the effect of this function is implementation-defined.

If the directory's link count becomes zero and no process has the directory open, the space occupied by the directory is freed, and the directory is no longer 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 it have been closed.

Upon successful completion, the rmdir() function will mark for update the st_ctime and st_mtime fields of the parent directory.

Returns:

0
Success
(-1)
An error occurred. errno is set to indicate the error.

Errors:

EACCES
Search permission is denied for a component of path, or write permission is denied on the parent directory of the directory to be removed.
EBUSY
The directory named by the path argument cannot be removed because it is being used by another process, and the implementation considers this to be an error.
EEXIST
The path argument names a directory that isn't empty.
ENAMETOOLONG
The argument path exceeds PATH_MAX in length, or a pathname component is longer than NAME_MAX.
ENOENT
The specified path does not exist, or path is an empty string.
ENOTDIR
A component of path is not a directory.
ENOTEMPTY
The path argument names a directory that is not empty.
EROFS
The directory entry to be removed resides on a read-only file system.

See also:

chdir(), chmod(), errno, getcwd(), mkdir(), stat()

Examples:

To remove the directory called /home/terry

#include <sys/types.h>
#include <sys/stat.h>

void main()
  {
    rmdir( "/home/terry" );
  }

Classification:

POSIX 1003.1

Systems:

All (except Netware, DOS/PM)