263 lines
9.6 KiB
HTML
263 lines
9.6 KiB
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 The Open Group, All Rights Reserved -->
|
|
<title>ftw</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="ftw"></a> <a name="tag_03_201"></a><!-- ftw -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_201_01"></a>NAME</h4>
|
|
|
|
<blockquote>ftw - traverse (walk) a file tree</blockquote>
|
|
|
|
<h4><a name="tag_03_201_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt=
|
|
"[Option Start]" border="0"> #include <<a href="../basedefs/ftw.h.html">ftw.h</a>><br>
|
|
<br>
|
|
int ftw(const char *</tt><i>path</i><tt>, int (*</tt><i>fn</i><tt>)(const char *,<br>
|
|
const struct stat *</tt><i>ptr</i><tt>, int</tt> <i>flag</i><tt>), int</tt>
|
|
<i>ndirs</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div>
|
|
|
|
<tt><br>
|
|
</tt></blockquote>
|
|
|
|
<h4><a name="tag_03_201_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>ftw</i>() function shall recursively descend the directory hierarchy rooted in <i>path</i>. For each object in the
|
|
hierarchy, <i>ftw</i>() shall call the function pointed to by <i>fn</i>, passing it a pointer to a null-terminated character string
|
|
containing the name of the object, a pointer to a <b>stat</b> structure containing information about the object, and an integer.
|
|
Possible values of the integer, defined in the <a href="../basedefs/ftw.h.html"><i><ftw.h></i></a> header, are:</p>
|
|
|
|
<dl compact>
|
|
<dt>FTW_D</dt>
|
|
|
|
<dd>For a directory.</dd>
|
|
|
|
<dt>FTW_DNR</dt>
|
|
|
|
<dd>For a directory that cannot be read.</dd>
|
|
|
|
<dt>FTW_F</dt>
|
|
|
|
<dd>For a file.</dd>
|
|
|
|
<dt>FTW_SL</dt>
|
|
|
|
<dd>For a symbolic link (but see also FTW_NS below).</dd>
|
|
|
|
<dt>FTW_NS</dt>
|
|
|
|
<dd>For an object other than a symbolic link on which <a href="../functions/stat.html"><i>stat</i>()</a> could not successfully be
|
|
executed. If the object is a symbolic link and <a href="../functions/stat.html"><i>stat</i>()</a> failed, it is unspecified whether
|
|
<i>ftw</i>() passes FTW_SL or FTW_NS to the user-supplied function.</dd>
|
|
</dl>
|
|
|
|
<p>If the integer is FTW_DNR, descendants of that directory shall not be processed. If the integer is FTW_NS, the <b>stat</b>
|
|
structure contains undefined values. An example of an object that would cause FTW_NS to be passed to the function pointed to by
|
|
<i>fn</i> would be a file in a directory with read but without execute (search) permission.</p>
|
|
|
|
<p>The <i>ftw</i>() function shall visit a directory before visiting any of its descendants.</p>
|
|
|
|
<p>The <i>ftw</i>() function shall use at most one file descriptor for each level in the tree.</p>
|
|
|
|
<p>The argument <i>ndirs</i> should be in the range [1, {OPEN_MAX}].</p>
|
|
|
|
<p>The tree traversal shall continue until either the tree is exhausted, an invocation of <i>fn</i> returns a non-zero value, or
|
|
some error, other than [EACCES], is detected within <i>ftw</i>().</p>
|
|
|
|
<p>The <i>ndirs</i> argument shall specify the maximum number of directory streams or file descriptors or both available for use by
|
|
<i>ftw</i>() while traversing the tree. When <i>ftw</i>() returns it shall close any directory streams and file descriptors it uses
|
|
not counting any opened by the application-supplied <i>fn</i> function.</p>
|
|
|
|
<p>The results are unspecified if the application-supplied <i>fn</i> function does not preserve the current working directory.</p>
|
|
|
|
<p>The <i>ftw</i>() function need not be reentrant. A function that is not required to be reentrant is not required to be
|
|
thread-safe.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_201_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>If the tree is exhausted, <i>ftw</i>() shall return 0. If the function pointed to by <i>fn</i> returns a non-zero value,
|
|
<i>ftw</i>() shall stop its tree traversal and return whatever value was returned by the function pointed to by <i>fn</i>. If
|
|
<i>ftw</i>() detects an error, it shall return -1 and set <i>errno</i> to indicate the error.</p>
|
|
|
|
<p>If <i>ftw</i>() encounters an error other than [EACCES] (see FTW_DNR and FTW_NS above), it shall return -1 and set <i>errno</i>
|
|
to indicate the error. The external variable <i>errno</i> may contain any error value that is possible when a directory is opened
|
|
or when one of the <i>stat</i> functions is executed on a directory or file.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_201_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>ftw</i>() function shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EACCES]</dt>
|
|
|
|
<dd>Search permission is denied for any component of <i>path</i> or read permission is denied for <i>path</i>.</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 <i>path</i> is an empty string.</dd>
|
|
|
|
<dt>[ENOTDIR]</dt>
|
|
|
|
<dd>A component of <i>path</i> is not a directory.</dd>
|
|
|
|
<dt>[EOVERFLOW]</dt>
|
|
|
|
<dd>A field in the <b>stat</b> structure cannot be represented correctly in the current programming environment for one or more
|
|
files found in the file hierarchy.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>ftw</i>() function may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd>The value of the <i>ndirs</i> argument is invalid.</dd>
|
|
|
|
<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>
|
|
Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.</dd>
|
|
</dl>
|
|
|
|
<p>In addition, if the function pointed to by <i>fn</i> encounters system errors, <i>errno</i> may be set accordingly.</p>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_201_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<h5><a name="tag_03_201_06_01"></a>Walking a Directory Structure</h5>
|
|
|
|
<p>The following example walks the current directory structure, calling the <i>fn</i> function for every directory entry, using at
|
|
most 10 file descriptors:</p>
|
|
|
|
<pre>
|
|
<tt>#include <ftw.h>
|
|
...
|
|
if (ftw(".", fn, 10) != 0) {
|
|
perror("ftw"); exit(2);
|
|
}
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_201_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>ftw</i>() function may allocate dynamic storage during its operation. If <i>ftw</i>() is forcibly terminated, such as by
|
|
<a href="../functions/longjmp.html"><i>longjmp</i>()</a> or <a href="../functions/siglongjmp.html"><i>siglongjmp</i>()</a> being
|
|
executed by the function pointed to by <i>fn</i> or an interrupt routine, <i>ftw</i>() does not have a chance to free that storage,
|
|
so it remains permanently allocated. A safe way to handle interrupts is to store the fact that an interrupt has occurred, and
|
|
arrange to have the function pointed to by <i>fn</i> return a non-zero value at its next invocation.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_201_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_201_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_201_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="longjmp.html"><i>longjmp</i>()</a> , <a href="lstat.html"><i>lstat</i>()</a> , <a href=
|
|
"malloc.html"><i>malloc</i>()</a> , <a href="nftw.html"><i>nftw</i>()</a> , <a href="opendir.html"><i>opendir</i>()</a> , <a href=
|
|
"siglongjmp.html"><i>siglongjmp</i>()</a> , <a href="stat.html"><i>stat</i>()</a> , the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/ftw.h.html"><i><ftw.h></i></a>, <a href=
|
|
"../basedefs/sys/stat.h.html"><i><sys/stat.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_201_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 1. Derived from Issue 1 of the SVID.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_201_12"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>UX codings in the DESCRIPTION, RETURN VALUE, and ERRORS sections are changed to EX.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_201_13"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>The ERRORS section is updated as follows:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The wording of the mandatory [ELOOP] error condition is updated.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>A second optional [ELOOP] error condition is added.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The [EOVERFLOW] mandatory error condition is added.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>Text is added to the DESCRIPTION to say that the <i>ftw</i>() function need not be reentrant and that the results are
|
|
unspecified if the application-supplied <i>fn</i> function does not preserve the current working directory.</p>
|
|
</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>
|
|
|