[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 2

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

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:

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.

The rmdir subroutine can be unsuccessful for other reasons. See Appendix A, "Base Operating System Error Codes For Services That Require Path-Name Resolution" on page A-1 for a list of additional errors.

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

ETIMEDOUT The connection timed out.

Related Information

The chmod or fchmod subroutine, mkdir subroutine, remove (remove Subroutine) subroutine, rename (rename Subroutine) subroutine, umask (umask Subroutine) subroutine, unlink (unlink Subroutine) subroutine.

The rm command, rmdir command.

Files, Directories, and File Systems For Programmers in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]