<html><head><metacontent="HTML Tidy, see www.w3.org"name="generator"></meta><metacontent="text/html; charset=iso-8859-1"http-equiv="Content-Type"></meta><linkrel="stylesheet"type="text/css"href="style.css"></link><title>closedir</title></head><bodybgcolor="white"><script src="../jscript/codes.js"language="JavaScript"type="text/javascript"></script><script src="../../reqtools.js"language="javascript"></script><basefontsize="3"></basefont><aname="closedir"></a><aname="tag_03_81"></a><center><fontsize="2">The Open Group Base Specifications Issue 6<br></br> IEEE Std 1003.1, 2004 Edition<br></br> Copyright &copy; 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><hrnoshade="noshade"size="2"></hr><h4><aname="tag_03_81_01"></a>NAME</h4><blockquote>closedir - close a directory stream</blockquote><h4><aname="tag_03_81_02"></a>SYNOPSIS</h4><blockquoteclass="synopsis"><p><code><tt>#include <<ahref="../basedefs/dirent.h.html">dirent.h</a>><br></br><br></br> int closedir(DIR *</tt><i>dirp</i><tt>);<br></br></tt></code></p></blockquote><h4><aname="tag_03_81_03"></a>DESCRIPTION</h4><blockquote><pid="closedir.03"><spanid="closedir.01"class="req"><spanclass="reqstart"id="5a786953-6e3f-45ea-9bf8-10a9e9f14a9f"style="background-color:#FF9900">[</span><aname="req5a786953-6e3f-45ea-9bf8-10a9e9f14a9f"></a><spanclass="reqelem"id="closedir.01"attrs="{}"></span>The <i>closedir</i>() function shall close the directory stream referred to by the argument <i>dirp</i>. Upon return, the value
of <i>dirp</i> may no longer point to an accessible object of the type <b>DIR</b>.<spanclass="reqend"id="5a786953-6e3f-45ea-9bf8-10a9e9f14a9f"style="background-color:#FF9900">]</span></span><spanid="closedir.03"class="req"><spanclass="reqstart"id="1c54aa48-29bd-4e0a-adaf-6a433512b451"style="background-color:#FF9900">[</span><aname="req1c54aa48-29bd-4e0a-adaf-6a433512b451"></a><spanclass="reqelem"id="closedir.03"attrs="{}"></span>If a file descriptor is used to implement type <b>DIR</b>, that file descriptor shall be closed.<spanclass="reqend"id="1c54aa48-29bd-4e0a-adaf-6a433512b451"style="background-color:#FF9900">]</span></span></p></blockquote><h4><aname="tag_03_81_04"></a>RETURN VALUE</h4><blockquote><p><spanid="closedir.04"class="req"><spanclass="reqstart"id="8148b4fd-3cdc-4a75-9006-79b191c6e35b"style="background-color:#FF9900">[</span><aname="req8148b4fd-3cdc-4a75-9006-79b191c6e35b"></a><spanclass="reqelem"id="closedir.04"attrs="{}"></span>Upon successful completion, <i>closedir</i>() shall return 0;<spanclass="reqend"id="8148b4fd-3cdc-4a75-9006-79b191c6e35b"style="background-color:#FF9900">]</span></span><spanid="closedir.05"class="req"><spanclass="reqstart"id="cb5f7cd6-05df-41f5-9ada-cad467d2eb4d"style="background-color:#FF9900">[</span><aname="reqcb5f7cd6-05df-41f5-9ada-cad467d2eb4d"></a><spanclass="reqelem"id="closedir.05"attrs="{}"></span>otherwise, -1 shall be returned and <i>errno</i> set to indicate
the error.<spanclass="reqend"id="cb5f7cd6-05df-41f5-9ada-cad467d2eb4d"style="background-color:#FF9900">]</span></span></p></blockquote><h4><aname="tag_03_81_05"></a>ERRORS</h4><blockquote><pid="closedir.90"title="MAY:POSIX_CLOSEDIR"class="req"><spanclass="reqstart"id="956b7999-af1e-4828-a1d3-fdfe1dcec64b"style="background-color:#FF9900">[</span><aname="req956b7999-af1e-4828-a1d3-fdfe1dcec64b"></a><spanclass="reqelem"id="closedir.90"attrs="{}"></span>The <i>closedir</i>() function may fail if:<spanclass="reqend"id="956b7999-af1e-4828-a1d3-fdfe1dcec64b"style="background-color:#FF9900">]</span></p><dlcompact="compact"><spanid="closedir.90.01"class="req"><spanclass="reqstart"id="291606d5-d76a-4779-8f59-d3b975404b99"style="background-color:#FF9900">[</span><aname="req291606d5-d76a-4779-8f59-d3b975404b99"></a><spanclass="reqelem"id="closedir.90.01"attrs="{}"></span><dt>[EBADF]</dt><dd>The <i>dirp</i> argument does not refer to an open directory stream.</dd><spanclass="reqend"id="291606d5-d76a-4779-8f59-d3b975404b99"style="background-color:#FF9900">]</span></span><br></br><spanid="closedir.90.02"class="req"><spanclass="reqstart"id="43e045ae-b400-4745-b57f-2543c8bb956f"style="background-color:#FF9900">[</span><aname="req43e045ae-b400-4745-b57f-2543c8bb956f"></a><spanclass="reqelem"id="closedir.90.02"attrs="{}"></span><dt>[EINTR]</dt><dd>The <i>closedir</i>() function was interrupted by a signal.</dd><spanclass="reqend"id="43e045ae-b400-4745-b57f-2543c8bb956f"style="background-color:#FF9900">]</span></span></dl></blockquote><hr></hr><divclass="box"><em>The following sections are informative.</em></div><h4><aname="tag_03_81_06"></a>EXAMPLES</h4><blockquote><h5><aname="tag_03_81_06_01"></a>Closing a Directory Stream</h5><p>The following program fragment demonstrates how the <i>closedir</i>() function is used.</p><pre><tt>...
DIR *dir;
struct dirent *dp;
...
if ((dir = opendir (".")) == NULL) {
...
} <br></br> while ((dp = readdir (dir)) != NULL) {
...
} <br></br> closedir(dir);
... </tt></pre></blockquote><h4><aname="tag_03_81_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><aname="tag_03_81_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><aname="tag_03_81_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><aname="tag_03_81_10"></a>SEE ALSO</h4><blockquote><p><ahref="opendir.html"><i>opendir</i>()</a>, the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <ahref="../basedefs/dirent.h.html"><i><dirent.h></i></a></p></blockquote><h4><aname="tag_03_81_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 2.</p></blockquote><h4><aname="tag_03_81_12"></a>Issue 6</h4><blockquote><p>In the SYNOPSIS, the optional include of the <ahref="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> header is
removed.</p><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>The requirement to include <ahref="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> has been removed. Although <ahref="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> was required for conforming implementations of previous POSIX
specifications, it was not required for UNIX applications.</p></li><li><p>The [EINTR] error condition is added as an optional error condition.</p></li></ul></blockquote><divclass="box"><em>End of informative text.</em></div><hrnoshade="noshade"size="2"></hr><center><fontsize="2"> UNIX &reg; is a registered Trademark of The Open Group.<br></br> POSIX &reg; is a registered Trademark of The IEEE.<br></br> [ <ahref="../mindex.html">Main Index</a> | <ahref="../basedefs/contents.html">XBD</a> | <ahref="../utilities/contents.html">XCU</a> | <ahref="../functions/contents.html">XSH</a> | <ahref="../xrat/contents.html">XRAT</a> ]</font></center><hrnoshade="noshade"size="2"></hr></body></html>