fts.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* File tree traversal functions declarations.
  2. Copyright (C) 1994-2020 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. /*
  16. * Copyright (c) 1989, 1993
  17. * The Regents of the University of California. All rights reserved.
  18. *
  19. * Redistribution and use in source and binary forms, with or without
  20. * modification, are permitted provided that the following conditions
  21. * are met:
  22. * 1. Redistributions of source code must retain the above copyright
  23. * notice, this list of conditions and the following disclaimer.
  24. * 2. Redistributions in binary form must reproduce the above copyright
  25. * notice, this list of conditions and the following disclaimer in the
  26. * documentation and/or other materials provided with the distribution.
  27. * 4. Neither the name of the University nor the names of its contributors
  28. * may be used to endorse or promote products derived from this software
  29. * without specific prior written permission.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  32. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  35. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  39. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  40. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  41. * SUCH DAMAGE.
  42. *
  43. * @(#)fts.h 8.3 (Berkeley) 8/14/94
  44. */
  45. #ifndef _FTS_H
  46. #define _FTS_H 1
  47. #include <features.h>
  48. #include <sys/types.h>
  49. typedef struct {
  50. struct _ftsent *fts_cur; /* current node */
  51. struct _ftsent *fts_child; /* linked list of children */
  52. struct _ftsent **fts_array; /* sort array */
  53. dev_t fts_dev; /* starting device # */
  54. char *fts_path; /* path for this descent */
  55. int fts_rfd; /* fd for root */
  56. int fts_pathlen; /* sizeof(path) */
  57. int fts_nitems; /* elements in the sort array */
  58. int (*fts_compar) (const void *, const void *); /* compare fn */
  59. #define FTS_COMFOLLOW 0x0001 /* follow command line symlinks */
  60. #define FTS_LOGICAL 0x0002 /* logical walk */
  61. #define FTS_NOCHDIR 0x0004 /* don't change directories */
  62. #define FTS_NOSTAT 0x0008 /* don't get stat info */
  63. #define FTS_PHYSICAL 0x0010 /* physical walk */
  64. #define FTS_SEEDOT 0x0020 /* return dot and dot-dot */
  65. #define FTS_XDEV 0x0040 /* don't cross devices */
  66. #define FTS_WHITEOUT 0x0080 /* return whiteout information */
  67. #define FTS_OPTIONMASK 0x00ff /* valid user option mask */
  68. #define FTS_NAMEONLY 0x0100 /* (private) child names only */
  69. #define FTS_STOP 0x0200 /* (private) unrecoverable error */
  70. int fts_options; /* fts_open options, global flags */
  71. } FTS;
  72. #ifdef __USE_LARGEFILE64
  73. typedef struct {
  74. struct _ftsent64 *fts_cur; /* current node */
  75. struct _ftsent64 *fts_child; /* linked list of children */
  76. struct _ftsent64 **fts_array; /* sort array */
  77. dev_t fts_dev; /* starting device # */
  78. char *fts_path; /* path for this descent */
  79. int fts_rfd; /* fd for root */
  80. int fts_pathlen; /* sizeof(path) */
  81. int fts_nitems; /* elements in the sort array */
  82. int (*fts_compar) (const void *, const void *); /* compare fn */
  83. int fts_options; /* fts_open options, global flags */
  84. } FTS64;
  85. #endif
  86. typedef struct _ftsent {
  87. struct _ftsent *fts_cycle; /* cycle node */
  88. struct _ftsent *fts_parent; /* parent directory */
  89. struct _ftsent *fts_link; /* next file in directory */
  90. long fts_number; /* local numeric value */
  91. void *fts_pointer; /* local address value */
  92. char *fts_accpath; /* access path */
  93. char *fts_path; /* root path */
  94. int fts_errno; /* errno for this node */
  95. int fts_symfd; /* fd for symlink */
  96. unsigned short fts_pathlen; /* strlen(fts_path) */
  97. unsigned short fts_namelen; /* strlen(fts_name) */
  98. ino_t fts_ino; /* inode */
  99. dev_t fts_dev; /* device */
  100. nlink_t fts_nlink; /* link count */
  101. #define FTS_ROOTPARENTLEVEL -1
  102. #define FTS_ROOTLEVEL 0
  103. short fts_level; /* depth (-1 to N) */
  104. #define FTS_D 1 /* preorder directory */
  105. #define FTS_DC 2 /* directory that causes cycles */
  106. #define FTS_DEFAULT 3 /* none of the above */
  107. #define FTS_DNR 4 /* unreadable directory */
  108. #define FTS_DOT 5 /* dot or dot-dot */
  109. #define FTS_DP 6 /* postorder directory */
  110. #define FTS_ERR 7 /* error; errno is set */
  111. #define FTS_F 8 /* regular file */
  112. #define FTS_INIT 9 /* initialized only */
  113. #define FTS_NS 10 /* stat(2) failed */
  114. #define FTS_NSOK 11 /* no stat(2) requested */
  115. #define FTS_SL 12 /* symbolic link */
  116. #define FTS_SLNONE 13 /* symbolic link without target */
  117. #define FTS_W 14 /* whiteout object */
  118. unsigned short fts_info; /* user flags for FTSENT structure */
  119. #define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */
  120. #define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */
  121. unsigned short fts_flags; /* private flags for FTSENT structure */
  122. #define FTS_AGAIN 1 /* read node again */
  123. #define FTS_FOLLOW 2 /* follow symbolic link */
  124. #define FTS_NOINSTR 3 /* no instructions */
  125. #define FTS_SKIP 4 /* discard node */
  126. unsigned short fts_instr; /* fts_set() instructions */
  127. struct stat *fts_statp; /* stat(2) information */
  128. char fts_name[1]; /* file name */
  129. } FTSENT;
  130. #ifdef __USE_LARGEFILE64
  131. typedef struct _ftsent64 {
  132. struct _ftsent64 *fts_cycle; /* cycle node */
  133. struct _ftsent64 *fts_parent; /* parent directory */
  134. struct _ftsent64 *fts_link; /* next file in directory */
  135. long fts_number; /* local numeric value */
  136. void *fts_pointer; /* local address value */
  137. char *fts_accpath; /* access path */
  138. char *fts_path; /* root path */
  139. int fts_errno; /* errno for this node */
  140. int fts_symfd; /* fd for symlink */
  141. unsigned short fts_pathlen; /* strlen(fts_path) */
  142. unsigned short fts_namelen; /* strlen(fts_name) */
  143. ino64_t fts_ino; /* inode */
  144. dev_t fts_dev; /* device */
  145. nlink_t fts_nlink; /* link count */
  146. short fts_level; /* depth (-1 to N) */
  147. unsigned short fts_info; /* user flags for FTSENT structure */
  148. unsigned short fts_flags; /* private flags for FTSENT structure */
  149. unsigned short fts_instr; /* fts_set() instructions */
  150. struct stat64 *fts_statp; /* stat(2) information */
  151. char fts_name[1]; /* file name */
  152. } FTSENT64;
  153. #endif
  154. __BEGIN_DECLS
  155. #ifndef __USE_FILE_OFFSET64
  156. FTSENT *fts_children (FTS *, int);
  157. int fts_close (FTS *);
  158. FTS *fts_open (char * const *, int,
  159. int (*)(const FTSENT **, const FTSENT **));
  160. FTSENT *fts_read (FTS *);
  161. int fts_set (FTS *, FTSENT *, int) __THROW;
  162. #else
  163. # ifdef __REDIRECT
  164. FTSENT *__REDIRECT (fts_children, (FTS *, int), fts64_children);
  165. int __REDIRECT (fts_close, (FTS *), fts64_close);
  166. FTS *__REDIRECT (fts_open, (char * const *, int,
  167. int (*)(const FTSENT **, const FTSENT **)),
  168. fts64_open);
  169. FTSENT *__REDIRECT (fts_read, (FTS *), fts64_read);
  170. int __REDIRECT_NTH (fts_set, (FTS *, FTSENT *, int), fts64_set);
  171. # else
  172. # define fts_children fts64_children
  173. # define fts_close fts64_close
  174. # define fts_open fts64_open
  175. # define fts_read fts64_read
  176. # define fts_set fts64_set
  177. # endif
  178. #endif
  179. #ifdef __USE_LARGEFILE64
  180. FTSENT64 *fts64_children (FTS64 *, int);
  181. int fts64_close (FTS64 *);
  182. FTS64 *fts64_open (char * const *, int,
  183. int (*)(const FTSENT64 **, const FTSENT64 **));
  184. FTSENT64 *fts64_read (FTS64 *);
  185. int fts64_set (FTS64 *, FTSENT64 *, int) __THROW;
  186. #endif
  187. __END_DECLS
  188. #endif /* fts.h */