home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / uucp-1.04 / unix / walk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-13  |  1.1 KB  |  60 lines

  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.  
  14. static int iswalk_dir P((const char *zname, const struct stat *qstat,
  15.              int iflag));
  16.  
  17. /* Walk a directory tree.  */
  18.  
  19. static size_t cSlen;
  20. static void (*puSfn) P((const char *zfull, const char *zrelative,
  21.             pointer pinfo));
  22. static pointer pSinfo;
  23.  
  24. boolean
  25. usysdep_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*/
  41. static int
  42. iswalk_dir (zname, qstat, iflag)
  43.      const char *zname;
  44.      const struct stat *qstat;
  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.