📄 rmdir.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>rmdir</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="rmdir"></a> <a name="tag_03_613"></a><!-- rmdir --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_613_01"></a>NAME</h4><blockquote>rmdir - remove a directory</blockquote><h4><a name="tag_03_613_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include <<a href="../basedefs/unistd.h.html">unistd.h</a>><br><br> int rmdir(const char *</tt><i>path</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_613_03"></a>DESCRIPTION</h4><blockquote><p>The <i>rmdir</i>() function shall remove a directory whose name is given by <i>path</i>. The directory shall be removed only ifit is an empty directory.</p><p>If the directory is the root directory or the current working directory of any process, it is unspecified whether the functionsucceeds, or whether it shall fail and set <i>errno</i> to [EBUSY].</p><p>If <i>path</i> names a symbolic link, then <i>rmdir</i>() shall fail and set <i>errno</i> to [ENOTDIR].</p><p>If the <i>path</i> argument refers to a path whose final component is either dot or dot-dot, <i>rmdir</i>() shall fail.</p><p>If the directory's link count becomes 0 and no process has the directory open, the space occupied by the directory shall befreed and the directory shall no longer be accessible. If one or more processes have the directory open when the last link isremoved, the dot and dot-dot entries, if present, shall be removed before <i>rmdir</i>() returns and no new entries may be createdin the directory, but the directory shall not be removed until all references to the directory are closed.</p><p>If the directory is not an empty directory, <i>rmdir</i>() shall fail and set <i>errno</i> to [EEXIST] or [ENOTEMPTY].</p><p>Upon successful completion, the <i>rmdir</i>() function shall mark for update the <i>st_ctime</i> and <i>st_mtime</i> fields ofthe parent directory.</p></blockquote><h4><a name="tag_03_613_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, the function <i>rmdir</i>() shall return 0. Otherwise, -1 shall be returned, and <i>errno</i> set toindicate the error. If -1 is returned, the named directory shall not be changed.</p></blockquote><h4><a name="tag_03_613_05"></a>ERRORS</h4><blockquote><p>The <i>rmdir</i>() function shall fail if:</p><dl compact><dt>[EACCES]</dt><dd>Search permission is denied on a component of the path prefix, or write permission is denied on the parent directory of thedirectory to be removed.</dd><dt>[EBUSY]</dt><dd>The directory to be removed is currently in use by the system or some process and the implementation considers this to be anerror.</dd><dt>[EEXIST] or [ENOTEMPTY]</dt><dd>The <i>path</i> argument names a directory that is not an empty directory, or there are hard links to the directory other than dotor a single entry in dot-dot.</dd><dt>[EINVAL]</dt><dd>The <i>path</i> argument contains a last component that is dot.</dd><dt>[EIO]</dt><dd>A physical I/O error has occurred.</dd><dt>[ELOOP]</dt><dd>A loop exists in symbolic links encountered during resolution of the <i>path</i> argument.</dd><dt>[ENAMETOOLONG]</dt><dd>The length of the <i>path</i> argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.</dd><dt>[ENOENT]</dt><dd>A component of <i>path</i> does not name an existing file, or the <i>path</i> argument names a nonexistent directory or pointsto an empty string.</dd><dt>[ENOTDIR]</dt><dd>A component of <i>path</i> is not a directory.</dd><dt>[EPERM] or [EACCES]</dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"><br>The S_ISVTX flag is set on the parent directory of the directory to be removed and the caller is not the owner of the directory tobe removed, nor is the caller the owner of the parent directory, nor does the caller have the appropriate privileges. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>[EROFS]</dt><dd>The directory entry to be removed resides on a read-only file system.</dd></dl><p>The <i>rmdir</i>() function may fail if:</p><dl compact><dt>[ELOOP]</dt><dd>More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the <i>path</i> argument.</dd><dt>[ENAMETOOLONG]</dt><dd>As a result of encountering a symbolic link in resolution of the <i>path</i> argument, the length of the substituted pathnamestring exceeded {PATH_MAX}.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_613_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_613_06_01"></a>Removing a Directory</h5><p>The following example shows how to remove a directory named <b>/home/cnd/mod1</b>.</p><pre><tt>#include <unistd.h><br>int status;...status = rmdir("/home/cnd/mod1");</tt></pre></blockquote><h4><a name="tag_03_613_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_613_08"></a>RATIONALE</h4><blockquote><p>The <i>rmdir</i>() and <a href="../functions/rename.html"><i>rename</i>()</a> functions originated in 4.2 BSD, and they used[ENOTEMPTY] for the condition when the directory to be removed does not exist or <i>new</i> already exists. When the 1984/usr/group standard was published, it contained [EEXIST] instead. When these functions were adopted into System V, the 1984/usr/group standard was used as a reference. Therefore, several existing applications and implementations support/use both forms,and no agreement could be reached on either value. All implementations are required to supply both [EEXIST] and [ENOTEMPTY] in <ahref="../basedefs/errno.h.html"><i><errno.h></i></a> with distinct values, so that applications can use both values inC-language <b>case</b> statements.</p><p>The meaning of deleting <i>pathname</i> <b>/dot</b> is unclear, because the name of the file (directory) in the parent directoryto be removed is not clear, particularly in the presence of multiple links to a directory.</p><p>The POSIX.1-1990 standard was silent with regard to the behavior of <i>rmdir</i>() when there are multiple hard links to thedirectory being removed. The requirement to set <i>errno</i> to [EEXIST] or [ENOTEMPTY] clarifies the behavior in this case.</p><p>If the process' current working directory is being removed, that should be an allowed error.</p><p>Virtually all existing implementations detect [ENOTEMPTY] or the case of dot-dot. The text in <a href="xsh_chap02_03.html#tag_02_03"><i>Error Numbers</i></a> about returning any one of the possible errors permits that behavior tocontinue. The [ELOOP] error may be returned if more than {SYMLOOP_MAX} symbolic links are encountered during resolution of the<i>path</i> argument.</p></blockquote><h4><a name="tag_03_613_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_613_10"></a>SEE ALSO</h4><blockquote><p><a href="xsh_chap02_03.html#tag_02_03"><i>Error Numbers</i></a> , <a href="mkdir.html"><i>mkdir</i>()</a> , <a href="remove.html"><i>remove</i>()</a> , <a href="unlink.html"><i>unlink</i>()</a> , the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/unistd.h.html"><i><unistd.h></i></a></p></blockquote><h4><a name="tag_03_613_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 3. Included for alignment with the POSIX.1-1988 standard.</p></blockquote><h4><a name="tag_03_613_12"></a>Issue 6</h4><blockquote><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>The DESCRIPTION is updated to indicate the results of naming a symbolic link in <i>path</i>.</p></li><li><p>The [EIO] mandatory error condition is added.</p></li><li><p>The [ELOOP] mandatory error condition is added.</p></li><li><p>A second [ENAMETOOLONG] is added as an optional error condition.</p></li></ul><p>The following changes were made to align with the IEEE P1003.1a draft standard:</p><ul><li><p>The [ELOOP] optional error condition is added.</p></li></ul></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -