325 lines
10 KiB
HTML
325 lines
10 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>nftw</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="nftw"></a> <a name="tag_03_405"></a><!-- nftw -->
|
|
<!--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_405_01"></a>NAME</h4>
|
|
|
|
<blockquote>nftw - walk a file tree</blockquote>
|
|
|
|
<h4><a name="tag_03_405_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 nftw(const char *</tt><i>path</i><tt>, int (*</tt><i>fn</i><tt>)(const char *,<br>
|
|
const struct stat *, int, struct FTW *), int</tt> <i>depth</i><tt>, int</tt>
|
|
<i>flags</i><tt>);<br>
|
|
<img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_405_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>nftw</i>() function shall recursively descend the directory hierarchy rooted in <i>path</i>. The <i>nftw</i>() function
|
|
has a similar effect to <a href="../functions/ftw.html"><i>ftw</i>()</a> except that it takes an additional argument <i>flags</i>,
|
|
which is a bitwise-inclusive OR of zero or more of the following flags:</p>
|
|
|
|
<dl compact>
|
|
<dt>FTW_CHDIR</dt>
|
|
|
|
<dd>If set, <i>nftw</i>() shall change the current working directory to each directory as it reports files in that directory. If
|
|
clear, <i>nftw</i>() shall not change the current working directory.</dd>
|
|
|
|
<dt>FTW_DEPTH</dt>
|
|
|
|
<dd>If set, <i>nftw</i>() shall report all files in a directory before reporting the directory itself. If clear, <i>nftw</i>()
|
|
shall report any directory before reporting the files in that directory.</dd>
|
|
|
|
<dt>FTW_MOUNT</dt>
|
|
|
|
<dd>If set, <i>nftw</i>() shall only report files in the same file system as <i>path</i>. If clear, <i>nftw</i>() shall report all
|
|
files encountered during the walk.</dd>
|
|
|
|
<dt>FTW_PHYS</dt>
|
|
|
|
<dd>If set, <i>nftw</i>() shall perform a physical walk and shall not follow symbolic links.</dd>
|
|
</dl>
|
|
|
|
<p>If FTW_PHYS is clear and FTW_DEPTH is set, <i>nftw</i>() shall follow links instead of reporting them, but shall not report any
|
|
directory that would be a descendant of itself. If FTW_PHYS is clear and FTW_DEPTH is clear, <i>nftw</i>() shall follow links
|
|
instead of reporting them, but shall not report the contents of any directory that would be a descendant of itself.</p>
|
|
|
|
<p>At each file it encounters, <i>nftw</i>() shall call the user-supplied function <i>fn</i> with four arguments:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The first argument is the pathname of the object.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The second argument is a pointer to the <b>stat</b> buffer containing information on the object.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The third argument is an integer giving additional information. Its value is one of the following:</p>
|
|
|
|
<dl compact>
|
|
<dt>FTW_F</dt>
|
|
|
|
<dd>The object is a file.</dd>
|
|
|
|
<dt>FTW_D</dt>
|
|
|
|
<dd>The object is a directory.</dd>
|
|
|
|
<dt>FTW_DP</dt>
|
|
|
|
<dd>The object is a directory and subdirectories have been visited. (This condition shall only occur if the FTW_DEPTH flag is
|
|
included in <i>flags</i>.)</dd>
|
|
|
|
<dt>FTW_SL</dt>
|
|
|
|
<dd>The object is a symbolic link. (This condition shall only occur if the FTW_PHYS flag is included in <i>flags</i>.)</dd>
|
|
|
|
<dt>FTW_SLN</dt>
|
|
|
|
<dd>The object is a symbolic link that does not name an existing file. (This condition shall only occur if the FTW_PHYS flag is not
|
|
included in <i>flags</i>.)</dd>
|
|
|
|
<dt>FTW_DNR</dt>
|
|
|
|
<dd>The object is a directory that cannot be read. The <i>fn</i> function shall not be called for any of its descendants.</dd>
|
|
|
|
<dt>FTW_NS</dt>
|
|
|
|
<dd>The <a href="../functions/stat.html"><i>stat</i>()</a> function failed on the object because of lack of appropriate permission.
|
|
The <b>stat</b> buffer passed to <i>fn</i> is undefined. Failure of <a href="../functions/stat.html"><i>stat</i>()</a> for any
|
|
other reason is considered an error and <i>nftw</i>() shall return -1.</dd>
|
|
</dl>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The fourth argument is a pointer to an <b>FTW</b> structure. The value of <b>base</b> is the offset of the object's filename in
|
|
the pathname passed as the first argument to <i>fn</i>. The value of <b>level</b> indicates depth relative to the root of the walk,
|
|
where the root level is 0.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The results are unspecified if the application-supplied <i>fn</i> function does not preserve the current working directory.</p>
|
|
|
|
<p>The argument <i>depth</i> sets the maximum number of file descriptors that shall be used by <i>nftw</i>() while traversing the
|
|
file tree. At most one file descriptor shall be used for each directory level.</p>
|
|
|
|
<p>The <i>nftw</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_405_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>nftw</i>() function shall continue until the first of the following conditions occurs:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>An invocation of <i>fn</i> shall return a non-zero value, in which case <i>nftw</i>() shall return that value.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The <i>nftw</i>() function detects an error other than [EACCES] (see FTW_DNR and FTW_NS above), in which case <i>nftw</i>()
|
|
shall return -1 and set <i>errno</i> to indicate the error.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The tree is exhausted, in which case <i>nftw</i>() shall return 0.</p>
|
|
</li>
|
|
</ul>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_405_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>nftw</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>, or <i>fn</i> returns
|
|
-1 and does not reset <i>errno</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>nftw</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>[EMFILE]</dt>
|
|
|
|
<dd>{OPEN_MAX} file descriptors are currently open in the calling process.</dd>
|
|
|
|
<dt>[ENAMETOOLONG]</dt>
|
|
|
|
<dd>
|
|
Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.</dd>
|
|
|
|
<dt>[ENFILE]</dt>
|
|
|
|
<dd>Too many files are currently open in the system.</dd>
|
|
</dl>
|
|
|
|
<p>In addition, <i>errno</i> may be set if the function pointed to by <i>fn</i> causes <i>errno</i> to be set.</p>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_405_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>The following example walks the <b>/tmp</b> directory and its subdirectories, calling the <i>nftw</i>() function for every
|
|
directory entry, to a maximum of 5 levels deep.</p>
|
|
|
|
<pre>
|
|
<tt>#include <ftw.h>
|
|
...
|
|
int nftwfunc(const char *, const struct stat *, int, struct FTW *);
|
|
<br>
|
|
int nftwfunc(const char *filename, const struct stat *statptr,
|
|
int fileflags, struct FTW *pfwt)
|
|
{
|
|
return 0;
|
|
}
|
|
...
|
|
char *startpath = "/tmp";
|
|
int depth = 5;
|
|
int flags = FTW_CHDIR | FTW_DEPTH | FTW_MOUNT;
|
|
int ret;
|
|
<br>
|
|
ret = nftw(startpath, nftwfunc, depth, flags);
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_405_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_405_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_405_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_405_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="lstat.html"><i>lstat</i>()</a> , <a href="opendir.html"><i>opendir</i>()</a> , <a href=
|
|
"readdir.html"><i>readdir</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></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_405_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 4, Version 2.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_405_12"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>Moved from X/OPEN UNIX extension to BASE.</p>
|
|
|
|
<p>In the DESCRIPTION, the definition of the <i>depth</i> argument is clarified.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_405_13"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>The Open Group Base Resolution bwg97-003 is applied.</p>
|
|
|
|
<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>nftw</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>
|
|
|