{"id":5304,"date":"2022-12-20T18:37:17","date_gmt":"2022-12-20T21:37:17","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/ftw-man3p\/"},"modified":"2022-12-20T18:37:17","modified_gmt":"2022-12-20T21:37:17","slug":"ftw-man3p","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/ftw-man3p\/","title":{"rendered":"FTW (man3p)"},"content":{"rendered":"<h1 align=\"center\">FTW<\/h1>\n<p> <a href=\"#PROLOG\">PROLOG<\/a><br \/> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#APPLICATION USAGE\">APPLICATION USAGE<\/a><br \/> <a href=\"#RATIONALE\">RATIONALE<\/a><br \/> <a href=\"#FUTURE DIRECTIONS\">FUTURE DIRECTIONS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>PROLOG <a name=\"PROLOG\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual page is part of the POSIX Programmer\u2019s Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">ftw \u2014 traverse (walk) a file tree<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <ftw.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int ftw(const char *<i>path<\/i>, int (*<i>fn<\/i>)(const char *, <br \/> const struct stat *<i>ptr<\/i>, int <i>flag<\/i>), int <i>ndirs<\/i>);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">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, filled in as if <i>stat<\/i>() or <i>lstat<\/i>() had been called to retrieve the information. Possible values of the integer, defined in the <i><ftw.h><\/i> header, are:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p>FTW_D<\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"74%\">\n<p>For a directory.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p>FTW_DNR<\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"74%\">\n<p>For a directory that cannot be read.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p>FTW_F<\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"74%\">\n<p>For a non-directory file.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p>FTW_SL<\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"74%\">\n<p>For a symbolic link (but see also FTW_NS below).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p>FTW_NS<\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"74%\">\n<p>For an object other than a symbolic link on which <i>stat<\/i>() could not successfully be executed. If the object is a symbolic link and <i>stat<\/i>() failed, it is unspecified whether <i>ftw<\/i>() passes FTW_SL or FTW_NS to the user-supplied function.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">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>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>ftw<\/i>() function shall visit a directory before visiting any of its descendants.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>ftw<\/i>() function shall use at most one file descriptor for each level in the tree.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The argument <i>ndirs<\/i> should be in the range [1,{OPEN_MAX}].<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">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 <b>[EACCES]<\/b>, is detected within <i>ftw<\/i>().<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">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>\n<p style=\"margin-left:11%; margin-top: 1em\">The results are unspecified if the application-supplied <i>fn<\/i> function does not preserve the current working directory.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>ftw<\/i>() function need not be thread-safe.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">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 \u22121 and set <i>errno<\/i> to indicate the error.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If <i>ftw<\/i>() encounters an error other than <b>[EACCES]<\/b> (see FTW_DNR and FTW_NS above), it shall return \u22121 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>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>ftw<\/i>() function shall fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p style=\"margin-top: 1em\"><b>EACCES<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p style=\"margin-top: 1em\">Search permission is denied for any component of <i>path<\/i> or read permission is denied for <i>path<\/i>.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ELOOP<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>A loop exists in symbolic links encountered during resolution of the <i>path<\/i> argument.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENAMETOOLONG<\/b><\/p>\n<p style=\"margin-left:22%;\">The length of a component of a pathname is longer than {NAME_MAX}.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ENOENT<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>A component of <i>path<\/i> does not name an existing file or <i>path<\/i> is an empty string.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENOTDIR<\/b><\/p>\n<p style=\"margin-left:22%;\">A component of <i>path<\/i> names an existing file that is neither a directory nor a symbolic link to a directory.<\/p>\n<p style=\"margin-left:11%;\"><b>EOVERFLOW<\/b><\/p>\n<p style=\"margin-left:22%;\">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.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>ftw<\/i>() function may fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EINVAL<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The value of the <i>ndirs<\/i> argument is invalid.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ELOOP<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the <i>path<\/i> argument.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENAMETOOLONG<\/b><\/p>\n<p style=\"margin-left:22%;\">The length of a pathname exceeds {PATH_MAX}, or pathname resolution of a symbolic link produced an intermediate result with a length that exceeds {PATH_MAX}.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In addition, if the function pointed to by <i>fn<\/i> encounters system errors, <i>errno<\/i> may be set accordingly.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>The following sections are informative.<\/i><\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i><b>Walking a Directory Structure<\/b><\/i> <br \/> 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>\n<p style=\"margin-left:17%; margin-top: 1em\">#include <ftw.h> <br \/> &#8230; <br \/> if (ftw(&#8220;.&#8221;, fn, 10) != 0) { <br \/> perror(&#8220;ftw&#8221;); exit(2); <br \/> }<\/p>\n<h2>APPLICATION USAGE <a name=\"APPLICATION USAGE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>ftw<\/i>() function may allocate dynamic storage during its operation. If <i>ftw<\/i>() is forcibly terminated, such as by <i>longjmp<\/i>() or <i>siglongjmp<\/i>() 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>\n<p style=\"margin-left:11%; margin-top: 1em\">Applications should use the <i>nftw<\/i>() function instead of the obsolescent <i>ftw<\/i>() function.<\/p>\n<h2>RATIONALE <a name=\"RATIONALE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>FUTURE DIRECTIONS <a name=\"FUTURE DIRECTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>ftw<\/i>() function may be removed in a future version.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>fdopendir<\/i>(), <i>fstatat<\/i>(), <i>longjmp<\/i>(), <i>nftw<\/i>(), <i>siglongjmp<\/i>()<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The Base Definitions volume of POSIX.1-2017, <b><ftw.h><\/b>, <b><sys_stat.h><\/b><\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology &#8212; Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http:\/\/www.opengroup.org\/unix\/online.html .<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https:\/\/www.kernel.org\/doc\/man-pages\/reporting_bugs.html .<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  ftw \u2014 traverse (walk) a file tree <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3779,1],"tags":[2193,1594],"class_list":["post-5304","post","type-post","status-publish","format-standard","hentry","category-3pm-perl-llamadas-de-bibliotecas","category-sin-categoria","tag-ftw","tag-man3p"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=5304"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5304\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=5304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=5304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=5304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}