33 #if defined(LIBC_SCCS) && !defined(lint)
34 static char sccsid[] =
"@(#)fts.c 8.6 (Berkeley) 8/14/94";
38 #include <sys/param.h>
39 #include <include/sys/stat.h>
48 #if defined(__UCLIBC__)
49 # define __fxstat64(_stat_ver, _fd, _sbp) fstat((_fd), (_sbp))
51 #if defined(hpux) || defined(__hpux)
52 # define _INCLUDE_POSIX_SOURCE
53 # define __errno_location() (&errno)
54 # define dirfd(dirp) -1
57 # define __fxstat64(_stat_ver, _fd, _sbp) fstat((_fd), (_sbp))
58 # define _D_EXACT_NAMLEN(d) ((d)->d_namlen)
60 #if defined(sun) || defined(RPM_OS_UNIXWARE)
61 # define __errno_location() (&errno)
62 # define dirfd(dirp) -1
64 # define __fxstat64(_stat_ver, _fd, _sbp) fstat((_fd), (_sbp))
66 #if defined(__APPLE__)
67 # include <sys/stat.h>
68 # define __errno_location() (__error())
69 #ifndef __DARWIN_STRUCT_STAT64
73 #ifndef __DARWIN_STRUCT_STAT64
74 # define __fxstat64(_stat_ver, _fd, _sbp) fstat((_fd), (_sbp))
76 # define __fxstat64(_stat_ver, _fd, _sbp) fstat64((_fd), (_sbp))
79 #if defined(__CYGWIN__) || defined(__MINGW32__)
80 # include <sys/stat.h>
81 #if defined(__CYGWIN__)
82 # define __errno_location() (__errno())
84 # define __errno_location() (_errno())
86 # define __errno_location() (&errno)
90 # define __fxstat64(_stat_ver, _fd, _sbp) fstat((_fd), (_sbp))
92 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
93 # define __errno_location() (&errno)
95 # define __fxstat64(_stat_ver, _fd, _sbp) fstat((_fd), (_sbp))
96 # define _D_EXACT_NAMLEN(d) ((d)->d_namlen)
99 # define __errno_location() (&errno)
100 # define dirfd(dirp) -1
103 # define __fxstat64(_stat_ver, _fd, _sbp) fstat((_fd), (_sbp))
104 # define _D_EXACT_NAMLEN(d) ((d)->d_namlen)
106 #if defined(RPM_OS_IRIX)
107 # define __errno_location() (&errno)
108 # define dirfd(dirp) -1
109 # define __fxstat64(_stat_ver, _fd, _sbp) fstat((_fd), (_sbp))
110 # define _D_EXACT_NAMLEN(d) ((d)->d_reclen)
112 #if defined(RPM_OS_AIX)
113 # define __errno_location() (&errno)
114 # define dirfd(dirp) ((dirp)->dd_fd)
116 # define __fxstat64(_stat_ver, _fd, _sbp) fstat((_fd), (_sbp))
117 # define _D_EXACT_NAMLEN(d) ((d)->d_namlen)
119 #if defined(RPM_OS_NTOQNX)
120 # define __errno_location() (&errno)
123 # define dirfd(dirp) -1
124 # define __fxstat64(_stat_ver, _fd, _sbp) fstat((_fd), (_sbp))
127 #if !defined(_D_EXACT_NAMLEN)
128 # define _D_EXACT_NAMLEN(d) (strlen((d)->d_name))
138 # define __set_errno(val) (*__errno_location ()) = (val)
140 # define __close close
141 # define __fchdir fchdir
144 #if !defined(USHRT_MAX)
145 #define USHRT_MAX 65535
151 #if defined __GNUC__ && __GNUC__ >= 2
152 # define alignof(TYPE) __alignof__ (TYPE)
154 # define alignof(TYPE) \
155 ((int) &((struct { char dummy1; TYPE dummy2; } *) 0)->dummy2)
157 #define ALIGNBYTES (alignof(long double) - 1)
161 #define ALIGN(p) (((unsigned long int) (p) + ALIGNBYTES) & ~ALIGNBYTES)
193 #define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '/' && !a[2]) || (a[1] == '.' && (!a[2] || (a[2] == '/' && !a[3])))))
195 #define CLR(opt) (sp->fts_options &= ~(opt))
196 #define ISSET(opt) (sp->fts_options & (opt))
197 #define SET(opt) (sp->fts_options |= (opt))
199 #define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && __fchdir(fd))
219 fprintf(stderr,
"--> Fts_open(%p, 0x%x, %p) av[0] %s\n", argv, options, compar, argv[0]);
231 if ((sp = (
FTS *) malloc((u_int)
sizeof(*sp))) ==
NULL)
233 memset(sp, 0,
sizeof(*sp));
234 sp->
fts_compar = (
int (*) (
const void *,
const void *)) compar;
251 #define MAXPATHLEN 1024
269 if ((len = strlen(*argv)) == 0) {
322 if (compar && nitems > 1)
386 fprintf(stderr,
"--> Fts_close(%p)\n", sp);
418 if (saved_errno != 0) {
453 if (!(fts_info >= 1 && fts_info <= 14))
455 return ftsInfoStrings[ fts_info ];
463 (p->fts_path[p->fts_pathlen - 1] == '/' \
464 ? p->fts_pathlen - 1 : p->fts_pathlen)
476 fprintf(stderr,
"--> Fts_read(%p)\n", sp);
604 __open(
".", O_RDONLY, 0)) < 0) {
671 fprintf(stderr,
"<-- Fts_read(%p) ret %p", sp, p);
692 fprintf(stderr,
"--> Fts_set(%p, %p, 0x%x)\n", sp, p, instr);
712 fprintf(stderr,
"--> Fts_children(%p, 0x%x)\n", sp, instr);
766 if ((fd =
__open(
".", O_RDONLY, 0)) < 0)
794 register struct dirent *dp;
800 int cderrno, descend,
len, level, nlinks, saved_errno,
812 #if defined FTS_WHITEOUT && 0
814 oflag = DTF_NODUP|DTF_REWIND;
816 oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND;
818 # define __opendir2(path, flag) (*sp->fts_opendir) (path)
846 (
void)printf(
"nlinks == %d (cur: %d)\n", nlinks, cur->
fts_nlink);
847 (
void)printf(
"NOSTAT %d PHYSICAL %d SEEDOT %d\n",
866 if (nlinks || type ==
BREAD) {
870 if (nlinks && type ==
BREAD)
907 for (head = tail =
NULL, nitems = 0;
923 mem1: saved_errno =
errno;
961 #if defined FTS_WHITEOUT && 0
962 if (dp->d_type == DT_WHT)
982 #
if defined DT_DIR && defined _DIRENT_HAVE_D_TYPE
984 dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)
1044 if (descend && (type ==
BCHILD || !nitems) &&
1074 struct stat *sbp, sb;
1080 #if defined FTS_WHITEOUT && 0
1084 memset(sbp,
'\0',
sizeof (*sbp));
1085 sbp->st_mode = S_IFWHT;
1098 saved_errno =
errno;
1108 err:
memset(sbp, 0,
sizeof(*sbp));
1112 if (S_ISDIR(sbp->st_mode)) {
1120 dev = p->
fts_dev = sbp->st_dev;
1121 ino = p->
fts_ino = sbp->st_ino;
1143 if (S_ISREG(sbp->st_mode))
1178 for (head = *(ap = sp->
fts_array); --nitems; ++ap)
1198 len =
sizeof(*p) + namelen;
1203 memset(p, 0,
sizeof(*p));
1207 memmove(p->
fts_name, name, namelen);
1228 while ((p = head)) {
1278 #define ADJUST(p) do { \
1279 if ((p)->fts_accpath != (p)->fts_name) { \
1280 (p)->fts_accpath = \
1281 (char *)addr + ((p)->fts_accpath - (p)->fts_path); \
1283 (p)->fts_path = addr; \
1302 if ((len = strlen(*argv)) > max)
1315 int ret, oerrno, newfd;
1325 {
const char * lpath =
NULL;
1326 int ut =
urlPath(path, &lpath);
1330 if (fd < 0 && (newfd =
__open(path, O_RDONLY, 0)) < 0)
1333 if (__fxstat64(_STAT_VER, newfd, &sb)) {
struct _ftsent * fts_cycle
qsort(mc->macroTable, mc->firstFree, sizeof(mc->macroTable[0]), compareMacroName)
static void fts_padjust(FTS *sp, FTSENT *head)
static FTSENT * fts_sort(FTS *sp, FTSENT *head, int nitems)
FTS * Fts_open(char *const *argv, int options, int(*compar)(const FTSENT **, const FTSENT **))
Create a handle for file hierarchy traversal.
static PyObject *int type
FTSENT * Fts_children(FTS *sp, int instr)
Return list of children of the current node.
static int fts_safe_changedir(FTS *sp, FTSENT *p, int fd, const char *path)
urltype urlIsURL(const char *url)
Return type of URL.
int(* fts_stat)(const char *path, struct stat *st)
DIR *(* fts_opendir)(const char *path)
int Stat(const char *path, struct stat *st)
stat(2) clone.
static FTSENT * fts_alloc(FTS *sp, const char *name, int namelen)
struct _ftsent * fts_parent
#define __opendir2(path, flag)
int(* fts_closedir)(DIR *dir)
static u_short fts_stat(FTS *sp, FTSENT *p, int follow)
#define _D_EXACT_NAMLEN(d)
static int fts_palloc(FTS *sp, size_t more)
memset(_r, 0, sizeof(*_r))
static void fts_lfree(FTSENT *head)
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
int Lstat(const char *path, struct stat *st)
lstat(2) clone.
static const char * ftsInfoStrings[]
static size_t fts_maxarglen(char *const *argv)
FTSENT * Fts_read(FTS *sp)
Return next node in the file hierarchy traversal.
static void fts_load(FTS *sp, FTSENT *p)
int Fts_set(FTS *sp, FTSENT *p, int instr)
Modify the traversal for a file set member.
static const char * ftsInfoStr(int fts_info)
urltype urlPath(const char *url, const char **pathp)
Return path component of URL.
int(* fts_lstat)(const char *path, struct stat *st)
struct dirent *(* fts_readdir)(DIR *dir)
int Fts_close(FTS *sp)
Destroy a file hierarchy traversal handle.
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
int
Save source and expand field into target.
struct _ftsent * fts_child
int(* fts_compar)(const void *, const void *)
struct _ftsent ** fts_array
struct _ftsent * fts_link
#define FTS_ROOTPARENTLEVEL
static FTSENT * fts_build(FTS *sp, int type)