[BACK]Return to compat_fts.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/compat_fts.c between version 1.3 and 1.6

version 1.3, 2014/08/16 19:00:01 version 1.6, 2014/12/11 18:20:07
Line 6  int dummy;
Line 6  int dummy;
   
 #else  #else
   
   /*      $Id$    */
 /*      $OpenBSD$       */  /*      $OpenBSD$       */
   
 /*-  /*-
Line 61  static unsigned short  fts_stat(FTS *, FTSENT *);
Line 62  static unsigned short  fts_stat(FTS *, FTSENT *);
 static int       fts_safe_changedir(FTS *, FTSENT *, int, const char *);  static int       fts_safe_changedir(FTS *, FTSENT *, int, const char *);
   
 #define ISDOT(a)        (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))  #define ISDOT(a)        (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
   #define MAX(a,b)        (((a)>(b))?(a):(b))
   #ifndef O_DIRECTORY
   #define O_DIRECTORY     0
   #endif
   
 #define CLR(opt)        (sp->fts_options &= ~(opt))  #define CLR(opt)        (sp->fts_options &= ~(opt))
 #define ISSET(opt)      (sp->fts_options & (opt))  #define ISSET(opt)      (sp->fts_options & (opt))
Line 145  fts_open(char * const *argv, int options, void *dummy)
Line 150  fts_open(char * const *argv, int options, void *dummy)
          * and ".." are all fairly nasty problems.  Note, if we can't get the           * and ".." are all fairly nasty problems.  Note, if we can't get the
          * descriptor we run anyway, just more slowly.           * descriptor we run anyway, just more slowly.
          */           */
         if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = open(".", O_RDONLY, 0)) < 0)          if (!ISSET(FTS_NOCHDIR) &&
               (sp->fts_rfd = open(".", O_RDONLY | O_CLOEXEC)) < 0)
                 SET(FTS_NOCHDIR);                  SET(FTS_NOCHDIR);
   
         if (nitems == 0)          if (nitems == 0)
Line 405  fts_build(FTS *sp)
Line 411  fts_build(FTS *sp)
         DIR *dirp;          DIR *dirp;
         void *oldaddr;          void *oldaddr;
         size_t dlen, len, maxlen;          size_t dlen, len, maxlen;
         int nitems, cderrno, descend, level, nlinks, nostat, doadjust;          int nitems, cderrno, descend, level, doadjust;
         int saved_errno;          int saved_errno;
         char *cp;          char *cp;
   
Line 423  fts_build(FTS *sp)
Line 429  fts_build(FTS *sp)
         }          }
   
         /*          /*
          * Nlinks is the number of possible entries of type directory in the  
          * directory if we're cheating on stat calls, 0 if we're not doing  
          * any stat calls at all, -1 if we're doing stats on everything.  
          */  
         nlinks = -1;  
         nostat = 0;  
   
         /*  
          * If we're going to need to stat anything or we want to descend           * If we're going to need to stat anything or we want to descend
          * and stay in the directory, chdir.  If this fails we keep going,           * and stay in the directory, chdir.  If this fails we keep going,
          * but set a flag so we don't chdir after the post-order visit.           * but set a flag so we don't chdir after the post-order visit.
Line 447  fts_build(FTS *sp)
Line 445  fts_build(FTS *sp)
          */           */
         cderrno = 0;          cderrno = 0;
         if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {          if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {
                 if (nlinks)                  cur->fts_errno = errno;
                         cur->fts_errno = errno;  
                 cur->fts_flags |= FTS_DONTCHDIR;                  cur->fts_flags |= FTS_DONTCHDIR;
                 descend = 0;                  descend = 0;
                 cderrno = errno;                  cderrno = errno;
Line 489  fts_build(FTS *sp)
Line 486  fts_build(FTS *sp)
                 if (ISDOT(dp->d_name))                  if (ISDOT(dp->d_name))
                         continue;                          continue;
   
 #ifdef HAVE_DIRENT_NAMLEN  #if HAVE_DIRENT_NAMLEN
                 dlen = dp->d_namlen;                  dlen = dp->d_namlen;
 #else  #else
                 dlen = strlen(dp->d_name);                  dlen = strlen(dp->d_name);
Line 543  mem1:    saved_errno = errno;
Line 540  mem1:    saved_errno = errno;
                 }                  }
   
                 if (cderrno) {                  if (cderrno) {
                         if (nlinks) {                          p->fts_info = FTS_NS;
                                 p->fts_info = FTS_NS;                          p->fts_errno = cderrno;
                                 p->fts_errno = cderrno;  
                         } else  
                                 p->fts_info = FTS_NSOK;  
                         p->fts_accpath = cur->fts_accpath;                          p->fts_accpath = cur->fts_accpath;
                 } else if (nlinks == 0  
 #ifdef DT_DIR  
                     || (nostat &&  
                     dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)  
 #endif  
                     ) {  
                         p->fts_accpath =  
                             ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;  
                         p->fts_info = FTS_NSOK;  
                 } else {                  } else {
                         /* Build a file name for fts_stat to stat. */                          /* Build a file name for fts_stat to stat. */
                         if (ISSET(FTS_NOCHDIR)) {                          if (ISSET(FTS_NOCHDIR)) {
Line 567  mem1:    saved_errno = errno;
Line 552  mem1:    saved_errno = errno;
                                 p->fts_accpath = p->fts_name;                                  p->fts_accpath = p->fts_name;
                         /* Stat it. */                          /* Stat it. */
                         p->fts_info = fts_stat(sp, p);                          p->fts_info = fts_stat(sp, p);
   
                         /* Decrement link count if applicable. */  
                         if (nlinks > 0 && (p->fts_info == FTS_D ||  
                             p->fts_info == FTS_DC || p->fts_info == FTS_DOT))  
                                 --nlinks;  
                 }                  }
   
                 /* We walk in directory order so "ls -f" doesn't get upset. */                  /* We walk in directory order so "ls -f" doesn't get upset. */
Line 802  fts_safe_changedir(FTS *sp, FTSENT *p, int fd, const c
Line 782  fts_safe_changedir(FTS *sp, FTSENT *p, int fd, const c
         newfd = fd;          newfd = fd;
         if (ISSET(FTS_NOCHDIR))          if (ISSET(FTS_NOCHDIR))
                 return (0);                  return (0);
         if (fd < 0 && (newfd = open(path, O_RDONLY, 0)) < 0)          if (fd < 0 && (newfd = open(path, O_RDONLY|O_DIRECTORY|O_CLOEXEC)) < 0)
                 return (-1);                  return (-1);
         if (fstat(newfd, &sb)) {          if (fstat(newfd, &sb)) {
                 ret = -1;                  ret = -1;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.6

CVSweb