[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.12 and 1.17

version 1.12, 2016/10/18 23:58:12 version 1.17, 2020/06/15 01:37:14
Line 1 
Line 1 
 #include "config.h"  
   
 #if HAVE_FTS  
   
 int dummy;  
   
 #else  
   
 /*      $Id$    */  /*      $Id$    */
 /*      $OpenBSD$       */  /*      $OpenBSD$       */
   
Line 37  int dummy;
Line 29  int dummy;
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.   * SUCH DAMAGE.
  */   */
   #include "config.h"
   
 #include <sys/stat.h>  #include <sys/stat.h>
 #include <sys/types.h>  #include <sys/types.h>
Line 62  static int  fts_palloc(FTS *, size_t);
Line 55  static int  fts_palloc(FTS *, size_t);
 static FTSENT   *fts_sort(FTS *, FTSENT *, int);  static FTSENT   *fts_sort(FTS *, FTSENT *, int);
 static unsigned short    fts_stat(FTS *, FTSENT *);  static unsigned short    fts_stat(FTS *, FTSENT *);
   
   typedef int (*qsort_compar_proto)(const void *, const void *);
   
 #define ISDOT(a)        (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))  #define ISDOT(a)        (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
 #ifndef O_DIRECTORY  
 #define O_DIRECTORY     0  
 #endif  
 #ifndef O_CLOEXEC  #ifndef O_CLOEXEC
 #define O_CLOEXEC       0  #define O_CLOEXEC       0
 #endif  #endif
 #ifndef PATH_MAX  
 #define PATH_MAX        4096  
 #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 84  fts_open(char * const *argv, int options,
Line 73  fts_open(char * const *argv, int options,
         FTS *sp;          FTS *sp;
         FTSENT *p, *root;          FTSENT *p, *root;
         int nitems;          int nitems;
         FTSENT *parent, *tmp;          FTSENT *parent, *prev;
   
         /* Options check. */          /* Options check. */
         if (options & ~FTS_OPTIONMASK) {          if (options & ~FTS_OPTIONMASK) {
Line 117  fts_open(char * const *argv, int options,
Line 106  fts_open(char * const *argv, int options,
         parent->fts_level = FTS_ROOTPARENTLEVEL;          parent->fts_level = FTS_ROOTPARENTLEVEL;
   
         /* Allocate/initialize root(s). */          /* Allocate/initialize root(s). */
         for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) {          for (root = prev = NULL, nitems = 0; *argv; ++argv, ++nitems) {
                 if ((p = fts_alloc(sp, *argv, strlen(*argv))) == NULL)                  if ((p = fts_alloc(sp, *argv, strlen(*argv))) == NULL)
                         goto mem3;                          goto mem3;
                 p->fts_level = FTS_ROOTLEVEL;                  p->fts_level = FTS_ROOTLEVEL;
Line 139  fts_open(char * const *argv, int options,
Line 128  fts_open(char * const *argv, int options,
                 } else {                  } else {
                         p->fts_link = NULL;                          p->fts_link = NULL;
                         if (root == NULL)                          if (root == NULL)
                                 tmp = root = p;                                  root = p;
                         else {                          else
                                 tmp->fts_link = p;                                  prev->fts_link = p;
                                 tmp = p;                          prev = p;
                         }  
                 }                  }
         }          }
         if (compar && nitems > 1)          if (compar && nitems > 1)
Line 580  fts_sort(FTS *sp, FTSENT *head, int nitems)
Line 568  fts_sort(FTS *sp, FTSENT *head, int nitems)
         if (nitems > sp->fts_nitems) {          if (nitems > sp->fts_nitems) {
                 struct _ftsent **a;                  struct _ftsent **a;
   
                 sp->fts_nitems = nitems + 40;  
                 if ((a = reallocarray(sp->fts_array,                  if ((a = reallocarray(sp->fts_array,
                     sp->fts_nitems, sizeof(FTSENT *))) == NULL) {                      nitems + 40, sizeof(FTSENT *))) == NULL) {
                         free(sp->fts_array);                          free(sp->fts_array);
                         sp->fts_array = NULL;                          sp->fts_array = NULL;
                         sp->fts_nitems = 0;                          sp->fts_nitems = 0;
                         return (head);                          return (head);
                 }                  }
                   sp->fts_nitems = nitems + 40;
                 sp->fts_array = a;                  sp->fts_array = a;
         }          }
         for (ap = sp->fts_array, p = head; p; p = p->fts_link)          for (ap = sp->fts_array, p = head; p; p = p->fts_link)
                 *ap++ = p;                  *ap++ = p;
         qsort(sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar);          qsort(sp->fts_array, nitems, sizeof(FTSENT *),
               (qsort_compar_proto)sp->fts_compar);
         for (head = *(ap = sp->fts_array); --nitems; ++ap)          for (head = *(ap = sp->fts_array); --nitems; ++ap)
                 ap[0]->fts_link = ap[1];                  ap[0]->fts_link = ap[1];
         ap[0]->fts_link = NULL;          ap[0]->fts_link = NULL;
Line 655  fts_palloc(FTS *sp, size_t more)
Line 644  fts_palloc(FTS *sp, size_t more)
                 errno = ENAMETOOLONG;                  errno = ENAMETOOLONG;
                 return (1);                  return (1);
         }          }
         sp->fts_pathlen += more;          p = recallocarray(sp->fts_path, sp->fts_pathlen,
         p = realloc(sp->fts_path, sp->fts_pathlen);              sp->fts_pathlen + more, 1);
         if (p == NULL) {          if (p == NULL) {
                 free(sp->fts_path);                  free(sp->fts_path);
                 sp->fts_path = NULL;                  sp->fts_path = NULL;
                 return (1);                  return (1);
         }          }
           sp->fts_pathlen += more;
         sp->fts_path = p;          sp->fts_path = p;
         return (0);          return (0);
 }  }
Line 704  fts_maxarglen(char * const *argv)
Line 694  fts_maxarglen(char * const *argv)
                         max = len;                          max = len;
         return (max + 1);          return (max + 1);
 }  }
   
 #endif  

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.17

CVSweb