rmdir Subroutine

Purpose

Removes a directory.

Library

Standard C Library (libc.a)

Syntax

#include <unistd.h>

int rmdir ( Path)
const char *Path;

Description

The rmdir subroutine removes the directory specified by the Path parameter. If Network File System (NFS) is installed on your system, this path can cross into another node.

For the rmdir subroutine to execute successfully, the calling process must have write access to the parent directory of the Path parameter.

In addition, if the parent directory of Path has the Sticky bit attribute (described in the sys/mode.h file), the calling process must have one of the following:

Parameters

Item Description
Path Specifies the directory path name. The directory you specify must be:
Empty
The directory contains no entries other than . (dot) and .. (dot dot).
Well-formed
If the . (dot) entry in the Path parameter exists, it must refer to the same directory as Path. Exactly one directory has a link to the Path parameter, excluding the self-referential . (dot). If the .. (dot dot) entry in Path exists, it must refer to the directory that contains an entry for Path.

Return Values

Upon successful completion, the rmdir subroutine returns a value of 0. Otherwise, a value of -1 is returned, the specified directory is not changed, and the errno global variable is set to indicate the error.

Error Codes

The rmdir subroutine fails and the directory is not deleted if the following errors occur:

Item Description
EACCES There is no search permission on a component of the path prefix, or there is no write permission on the parent directory of the directory to be removed.
EBUSY The directory is in use as a mount point.
EEXIST or ENOTEMPTY The directory named by the Path parameter is not empty.
ENAMETOOLONG The length of the Path parameter exceeds PATH_MAX; or a path-name component longer than NAME_MAX and POSIX_NO_TRUNC is in effect.
ENOENT The directory named by the Path parameter does not exist, or the Path parameter points to an empty string.
ENOTDIR A component specified by the Path parameter is not a directory.
EINVAL The directory named by the Path parameter is not well-formed.
EROFS The directory named by the Path parameter resides on a read-only file system.

The rmdir subroutine can be unsuccessful for other reasons. See Base Operating System error codes for services that require path-name resolution for a list of additional errors.

If NFS is installed on the system, the rmdir subroutine fails if the following is true:

Item Description
ETIMEDOUT The connection timed out.