1/* walk.c
2   Walk a directory tree.  */
3
4#include "uucp.h"
5
6#include "uudefs.h"
7#include "sysdep.h"
8#include "system.h"
9
10#if HAVE_FTW_H
11#include <ftw.h>
12#endif
13
14static int iswalk_dir P((const char *zname, const struct stat *qstat,
15			 int iflag));
16
17/* Walk a directory tree.  */
18
19static size_t cSlen;
20static void (*puSfn) P((const char *zfull, const char *zrelative,
21			pointer pinfo));
22static pointer pSinfo;
23
24boolean
25usysdep_walk_tree (zdir, pufn, pinfo)
26     const char *zdir;
27     void (*pufn) P((const char *zfull, const char *zrelative,
28		     pointer pinfo));
29     pointer pinfo;
30{
31  cSlen = strlen (zdir) + 1;
32  puSfn = pufn;
33  pSinfo = pinfo;
34  return ftw ((char *) zdir, iswalk_dir, 5) == 0;
35}
36
37/* Pass a file found in the directory tree to the system independent
38   function.  */
39
40/*ARGSUSED*/
41static int
42iswalk_dir (zname, qstat, iflag)
43     const char *zname;
44     const struct stat *qstat ATTRIBUTE_UNUSED;
45     int iflag;
46{
47  char *zcopy;
48
49  if (iflag != FTW_F)
50    return 0;
51
52  zcopy = zbufcpy (zname + cSlen);
53
54  (*puSfn) (zname, zcopy, pSinfo);
55
56  ubuffree (zcopy);
57
58  return 0;
59}
60