fts.c (8870) | fts.c (17141) |
---|---|
1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 42 unchanged lines hidden (view full) --- 51static void fts_lfree __P((FTSENT *)); 52static void fts_load __P((FTS *, FTSENT *)); 53static size_t fts_maxarglen __P((char * const *)); 54static void fts_padjust __P((FTS *, void *)); 55static int fts_palloc __P((FTS *, size_t)); 56static FTSENT *fts_sort __P((FTS *, FTSENT *, int)); 57static u_short fts_stat __P((FTS *, FTSENT *, int)); 58 | 1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 42 unchanged lines hidden (view full) --- 51static void fts_lfree __P((FTSENT *)); 52static void fts_load __P((FTS *, FTSENT *)); 53static size_t fts_maxarglen __P((char * const *)); 54static void fts_padjust __P((FTS *, void *)); 55static int fts_palloc __P((FTS *, size_t)); 56static FTSENT *fts_sort __P((FTS *, FTSENT *, int)); 57static u_short fts_stat __P((FTS *, FTSENT *, int)); 58 |
59#define ISDOT(a) (a[0] == '.' && (!a[1] || a[1] == '.' && !a[2])) | 59#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])) ) |
60 61#define ISSET(opt) (sp->fts_options & opt) 62#define SET(opt) (sp->fts_options |= opt) 63 64#define CHDIR(sp, path) (!ISSET(FTS_NOCHDIR) && chdir(path)) 65#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) 66 67/* fts_build flags */ --- 231 unchanged lines hidden (view full) --- 299 p->fts_flags |= FTS_SYMFOLLOW; 300 return (p); 301 } 302 303 /* Directory in pre-order. */ 304 if (p->fts_info == FTS_D) { 305 /* If skipped or crossed mount point, do post-order visit. */ 306 if (instr == FTS_SKIP || | 60 61#define ISSET(opt) (sp->fts_options & opt) 62#define SET(opt) (sp->fts_options |= opt) 63 64#define CHDIR(sp, path) (!ISSET(FTS_NOCHDIR) && chdir(path)) 65#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) 66 67/* fts_build flags */ --- 231 unchanged lines hidden (view full) --- 299 p->fts_flags |= FTS_SYMFOLLOW; 300 return (p); 301 } 302 303 /* Directory in pre-order. */ 304 if (p->fts_info == FTS_D) { 305 /* If skipped or crossed mount point, do post-order visit. */ 306 if (instr == FTS_SKIP || |
307 ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev) { | 307 (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev) ) { |
308 if (p->fts_flags & FTS_SYMFOLLOW) 309 (void)close(p->fts_symfd); 310 if (sp->fts_child) { 311 fts_lfree(sp->fts_child); 312 sp->fts_child = NULL; 313 } 314 p->fts_info = FTS_DP; 315 return (p); --- 33 unchanged lines hidden (view full) --- 349 } 350 p = sp->fts_child; 351 sp->fts_child = NULL; 352 goto name; 353 } 354 355 /* Move to the next node on this level. */ 356next: tmp = p; | 308 if (p->fts_flags & FTS_SYMFOLLOW) 309 (void)close(p->fts_symfd); 310 if (sp->fts_child) { 311 fts_lfree(sp->fts_child); 312 sp->fts_child = NULL; 313 } 314 p->fts_info = FTS_DP; 315 return (p); --- 33 unchanged lines hidden (view full) --- 349 } 350 p = sp->fts_child; 351 sp->fts_child = NULL; 352 goto name; 353 } 354 355 /* Move to the next node on this level. */ 356next: tmp = p; |
357 if (p = p->fts_link) { | 357 if ( (p = p->fts_link) ) { |
358 free(tmp); 359 360 /* 361 * If reached the top, return to the original directory, and 362 * load the paths for the next root. 363 */ 364 if (p->fts_level == FTS_ROOTLEVEL) { 365 if (!ISSET(FTS_NOCHDIR) && FCHDIR(sp, sp->fts_rfd)) { --- 269 unchanged lines hidden (view full) --- 635 cp = sp->fts_path + len; 636 *cp++ = '/'; 637 } 638 639 level = cur->fts_level + 1; 640 641 /* Read the directory, attaching each entry to the `link' pointer. */ 642 adjaddr = NULL; | 358 free(tmp); 359 360 /* 361 * If reached the top, return to the original directory, and 362 * load the paths for the next root. 363 */ 364 if (p->fts_level == FTS_ROOTLEVEL) { 365 if (!ISSET(FTS_NOCHDIR) && FCHDIR(sp, sp->fts_rfd)) { --- 269 unchanged lines hidden (view full) --- 635 cp = sp->fts_path + len; 636 *cp++ = '/'; 637 } 638 639 level = cur->fts_level + 1; 640 641 /* Read the directory, attaching each entry to the `link' pointer. */ 642 adjaddr = NULL; |
643 for (head = tail = NULL, nitems = 0; dp = readdir(dirp);) { | 643 for (head = tail = NULL, nitems = 0; (dp = readdir(dirp)); ) { |
644 if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) 645 continue; 646 647 if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL) 648 goto mem1; 649 if (dp->d_namlen > maxlen) { 650 if (fts_palloc(sp, (size_t)dp->d_namlen)) { 651 /* --- 23 unchanged lines hidden (view full) --- 675 if (nlinks) { 676 p->fts_info = FTS_NS; 677 p->fts_errno = cderrno; 678 } else 679 p->fts_info = FTS_NSOK; 680 p->fts_accpath = cur->fts_accpath; 681 } else if (nlinks == 0 682#ifdef DT_DIR | 644 if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) 645 continue; 646 647 if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL) 648 goto mem1; 649 if (dp->d_namlen > maxlen) { 650 if (fts_palloc(sp, (size_t)dp->d_namlen)) { 651 /* --- 23 unchanged lines hidden (view full) --- 675 if (nlinks) { 676 p->fts_info = FTS_NS; 677 p->fts_errno = cderrno; 678 } else 679 p->fts_info = FTS_NSOK; 680 p->fts_accpath = cur->fts_accpath; 681 } else if (nlinks == 0 682#ifdef DT_DIR |
683 || nlinks > 0 && 684 dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN | 683 || (nlinks > 0 && 684 dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN) |
685#endif 686 ) { 687 p->fts_accpath = 688 ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; 689 p->fts_info = FTS_NSOK; 690 } else { 691 /* Build a file name for fts_stat to stat. */ 692 if (ISSET(FTS_NOCHDIR)) { --- 211 unchanged lines hidden (view full) --- 904 905static void 906fts_lfree(head) 907 register FTSENT *head; 908{ 909 register FTSENT *p; 910 911 /* Free a linked list of structures. */ | 685#endif 686 ) { 687 p->fts_accpath = 688 ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; 689 p->fts_info = FTS_NSOK; 690 } else { 691 /* Build a file name for fts_stat to stat. */ 692 if (ISSET(FTS_NOCHDIR)) { --- 211 unchanged lines hidden (view full) --- 904 905static void 906fts_lfree(head) 907 register FTSENT *head; 908{ 909 register FTSENT *p; 910 911 /* Free a linked list of structures. */ |
912 while (p = head) { | 912 while ( (p = head) ) { |
913 head = head->fts_link; 914 free(p); 915 } 916} 917 918/* 919 * Allow essentially unlimited paths; find, rm, ls should all work on any tree. 920 * Most systems will allow creation of paths much longer than MAXPATHLEN, even --- 51 unchanged lines hidden --- | 913 head = head->fts_link; 914 free(p); 915 } 916} 917 918/* 919 * Allow essentially unlimited paths; find, rm, ls should all work on any tree. 920 * Most systems will allow creation of paths much longer than MAXPATHLEN, even --- 51 unchanged lines hidden --- |