logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

ftw.3p (7043B)


  1. '\" et
  2. .TH FTW "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. ftw
  12. \(em traverse (walk) a file tree
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <ftw.h>
  17. .P
  18. int ftw(const char *\fIpath\fP, int (*\fIfn\fP)(const char *,
  19. const struct stat *\fIptr\fP, int \fIflag\fP), int \fIndirs\fP);
  20. .fi
  21. .SH DESCRIPTION
  22. The
  23. \fIftw\fR()
  24. function shall recursively descend the directory hierarchy rooted in
  25. .IR path .
  26. For each object in the hierarchy,
  27. \fIftw\fR()
  28. shall call the function pointed to by
  29. .IR fn ,
  30. passing it a pointer to a null-terminated character string containing
  31. the name of the object, a pointer to a
  32. .BR stat
  33. structure containing information about the object, filled in as if
  34. \fIstat\fR()
  35. or
  36. \fIlstat\fR()
  37. had been called to retrieve the information. Possible values of the
  38. integer, defined in the
  39. .IR <ftw.h>
  40. header, are:
  41. .IP FTW_D 10
  42. For a directory.
  43. .IP FTW_DNR 10
  44. For a directory that cannot be read.
  45. .IP FTW_F 10
  46. For a non-directory file.
  47. .IP FTW_SL 10
  48. For a symbolic link (but see also FTW_NS below).
  49. .IP FTW_NS 10
  50. For an object other than a symbolic link on which
  51. \fIstat\fR()
  52. could not successfully be executed. If the object is a symbolic link
  53. and
  54. \fIstat\fR()
  55. failed, it is unspecified whether
  56. \fIftw\fR()
  57. passes FTW_SL or FTW_NS to the user-supplied function.
  58. .P
  59. If the integer is FTW_DNR, descendants of that directory shall not be
  60. processed. If the integer is FTW_NS, the
  61. .BR stat
  62. structure contains undefined values. An example of an object that
  63. would cause FTW_NS to be passed to the function pointed to by
  64. .IR fn
  65. would be a file in a directory with read but without execute (search)
  66. permission.
  67. .P
  68. The
  69. \fIftw\fR()
  70. function shall visit a directory before visiting any of its
  71. descendants.
  72. .P
  73. The
  74. \fIftw\fR()
  75. function shall use at most one file descriptor for each level in
  76. the tree.
  77. .P
  78. The argument
  79. .IR ndirs
  80. should be in the range [1,\c
  81. {OPEN_MAX}].
  82. .P
  83. The tree traversal shall continue until either the tree is exhausted,
  84. an invocation of
  85. .IR fn
  86. returns a non-zero value, or some error, other than
  87. .BR [EACCES] ,
  88. is detected within
  89. \fIftw\fR().
  90. .P
  91. The
  92. .IR ndirs
  93. argument shall specify the maximum number of directory streams or file
  94. descriptors or both available for use by
  95. \fIftw\fR()
  96. while traversing the tree. When
  97. \fIftw\fR()
  98. returns it shall close any directory streams and file descriptors it
  99. uses not counting any opened by the application-supplied
  100. .IR fn
  101. function.
  102. .P
  103. The results are unspecified if the application-supplied
  104. .IR fn
  105. function does not preserve the current working directory.
  106. .P
  107. The
  108. \fIftw\fR()
  109. function need not be thread-safe.
  110. .SH "RETURN VALUE"
  111. If the tree is exhausted,
  112. \fIftw\fR()
  113. shall return 0. If the function pointed to by
  114. .IR fn
  115. returns a non-zero value,
  116. \fIftw\fR()
  117. shall stop its tree traversal and return whatever value was returned
  118. by the function pointed to by
  119. .IR fn .
  120. If
  121. \fIftw\fR()
  122. detects an error, it shall return \-1 and set
  123. .IR errno
  124. to indicate the error.
  125. .P
  126. If
  127. \fIftw\fR()
  128. encounters an error other than
  129. .BR [EACCES]
  130. (see FTW_DNR and FTW_NS above), it shall return \-1 and set
  131. .IR errno
  132. to indicate the error. The external variable
  133. .IR errno
  134. may contain any error value that is possible when a directory is opened
  135. or when one of the
  136. .IR stat
  137. functions is executed on a directory or file.
  138. .SH ERRORS
  139. The
  140. \fIftw\fR()
  141. function shall fail if:
  142. .TP
  143. .BR EACCES
  144. Search permission is denied for any component of
  145. .IR path
  146. or read permission is denied for
  147. .IR path .
  148. .TP
  149. .BR ELOOP
  150. A loop exists in symbolic links encountered during resolution of the
  151. .IR path
  152. argument.
  153. .TP
  154. .BR ENAMETOOLONG
  155. .br
  156. The length of a component of a pathname is longer than
  157. {NAME_MAX}.
  158. .TP
  159. .BR ENOENT
  160. A component of
  161. .IR path
  162. does not name an existing file or
  163. .IR path
  164. is an empty string.
  165. .TP
  166. .BR ENOTDIR
  167. A component of
  168. .IR path
  169. names an existing file that is neither a directory nor a symbolic link
  170. to a directory.
  171. .TP
  172. .BR EOVERFLOW
  173. A field in the
  174. .BR stat
  175. structure cannot be represented correctly in the current programming
  176. environment for one or more files found in the file hierarchy.
  177. .P
  178. The
  179. \fIftw\fR()
  180. function may fail if:
  181. .TP
  182. .BR EINVAL
  183. The value of the
  184. .IR ndirs
  185. argument is invalid.
  186. .TP
  187. .BR ELOOP
  188. More than
  189. {SYMLOOP_MAX}
  190. symbolic links were encountered during resolution of the
  191. .IR path
  192. argument.
  193. .TP
  194. .BR ENAMETOOLONG
  195. .br
  196. The length of a pathname exceeds
  197. {PATH_MAX},
  198. or pathname resolution of a symbolic link produced an intermediate
  199. result with a length that exceeds
  200. {PATH_MAX}.
  201. .P
  202. In addition, if the function pointed to by
  203. .IR fn
  204. encounters system errors,
  205. .IR errno
  206. may be set accordingly.
  207. .LP
  208. .IR "The following sections are informative."
  209. .SH EXAMPLES
  210. .SS "Walking a Directory Structure"
  211. .P
  212. The following example walks the current directory structure, calling
  213. the
  214. .IR fn
  215. function for every directory entry, using at most 10 file descriptors:
  216. .sp
  217. .RS 4
  218. .nf
  219. #include <ftw.h>
  220. \&...
  221. if (ftw(".", fn, 10) != 0) {
  222. perror("ftw"); exit(2);
  223. }
  224. .fi
  225. .P
  226. .RE
  227. .SH "APPLICATION USAGE"
  228. The
  229. \fIftw\fR()
  230. function may allocate dynamic storage during its operation. If
  231. \fIftw\fR()
  232. is forcibly terminated, such as by
  233. \fIlongjmp\fR()
  234. or
  235. \fIsiglongjmp\fR()
  236. being executed by the function pointed to by
  237. .IR fn
  238. or an interrupt routine,
  239. \fIftw\fR()
  240. does not have a chance to free that storage, so it remains
  241. permanently allocated. A safe way to handle interrupts is to store the
  242. fact that an interrupt has occurred, and arrange to have the function
  243. pointed to by
  244. .IR fn
  245. return a non-zero value at its next invocation.
  246. .P
  247. Applications should use the
  248. \fInftw\fR()
  249. function instead of the obsolescent
  250. \fIftw\fR()
  251. function.
  252. .SH RATIONALE
  253. None.
  254. .SH "FUTURE DIRECTIONS"
  255. The
  256. \fIftw\fR()
  257. function may be removed in a future version.
  258. .SH "SEE ALSO"
  259. .IR "\fIfdopendir\fR\^(\|)",
  260. .IR "\fIfstatat\fR\^(\|)",
  261. .IR "\fIlongjmp\fR\^(\|)",
  262. .IR "\fInftw\fR\^(\|)",
  263. .IR "\fIsiglongjmp\fR\^(\|)"
  264. .P
  265. The Base Definitions volume of POSIX.1\(hy2017,
  266. .IR "\fB<ftw.h>\fP",
  267. .IR "\fB<sys_stat.h>\fP"
  268. .\"
  269. .SH COPYRIGHT
  270. Portions of this text are reprinted and reproduced in electronic form
  271. from IEEE Std 1003.1-2017, Standard for Information Technology
  272. -- Portable Operating System Interface (POSIX), The Open Group Base
  273. Specifications Issue 7, 2018 Edition,
  274. Copyright (C) 2018 by the Institute of
  275. Electrical and Electronics Engineers, Inc and The Open Group.
  276. In the event of any discrepancy between this version and the original IEEE and
  277. The Open Group Standard, the original IEEE and The Open Group Standard
  278. is the referee document. The original Standard can be obtained online at
  279. http://www.opengroup.org/unix/online.html .
  280. .PP
  281. Any typographical or formatting errors that appear
  282. in this page are most likely
  283. to have been introduced during the conversion of the source files to
  284. man page format. To report such errors, see
  285. https://www.kernel.org/doc/man-pages/reporting_bugs.html .