View | Details | Raw Unified | Return to bug 262038 | Differences between
and this patch

Collapse All | Expand All

(-)b/lib/libc/gen/fts-compat.c (-3 / +28 lines)
Lines 610-615 __fts_set_clientptr_44bsd(FTS *sp, void *clientptr) Link Here
610
	sp->fts_clientptr = clientptr;
610
	sp->fts_clientptr = clientptr;
611
}
611
}
612
612
613
static struct freebsd11_dirent *
614
fts_safe_readdir(DIR *dirp, int *readdir_errno)
615
{
616
	struct freebsd11_dirent *ret;
617
618
	errno = 0;
619
	if (!dirp)
620
		return (NULL);
621
	ret = freebsd11_readdir(dirp);
622
	*readdir_errno = errno;
623
	return (ret);
624
}
625
613
/*
626
/*
614
 * This is the tricky part -- do not casually change *anything* in here.  The
627
 * This is the tricky part -- do not casually change *anything* in here.  The
615
 * idea is to build the linked list of entries that are used by fts_children
628
 * idea is to build the linked list of entries that are used by fts_children
Lines 634-640 fts_build(FTS *sp, int type) Link Here
634
	DIR *dirp;
647
	DIR *dirp;
635
	void *oldaddr;
648
	void *oldaddr;
636
	int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno,
649
	int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno,
637
	    nostat, doadjust, dnamlen;
650
	    nostat, doadjust, dnamlen, readdir_errno;
638
	char *cp;
651
	char *cp;
639
652
640
	/* Set current node pointer. */
653
	/* Set current node pointer. */
Lines 738-745 fts_build(FTS *sp, int type) Link Here
738
751
739
	/* Read the directory, attaching each entry to the `link' pointer. */
752
	/* Read the directory, attaching each entry to the `link' pointer. */
740
	doadjust = 0;
753
	doadjust = 0;
754
	readdir_errno = 0;
741
	for (head = tail = NULL, nitems = 0;
755
	for (head = tail = NULL, nitems = 0;
742
	    dirp && (dp = freebsd11_readdir(dirp));) {
756
	    (dp = fts_safe_readdir(dirp, &readdir_errno));) {
743
		dnamlen = dp->d_namlen;
757
		dnamlen = dp->d_namlen;
744
		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
758
		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
745
			continue;
759
			continue;
Lines 839-844 mem1: saved_errno = errno; Link Here
839
		}
853
		}
840
		++nitems;
854
		++nitems;
841
	}
855
	}
856
857
	if (readdir_errno) {
858
		cur->fts_errno = readdir_errno;
859
		/*
860
		 * If we've not read any items yet, treat
861
		 * the error as if we can't access the dir.
862
		 */
863
		cur->fts_info = nitems ? FTS_ERR : FTS_DNR;
864
	}
865
842
	if (dirp)
866
	if (dirp)
843
		(void)closedir(dirp);
867
		(void)closedir(dirp);
844
868
Lines 877-883 mem1: saved_errno = errno; Link Here
877
901
878
	/* If didn't find anything, return NULL. */
902
	/* If didn't find anything, return NULL. */
879
	if (!nitems) {
903
	if (!nitems) {
880
		if (type == BREAD)
904
		if (type == BREAD &&
905
		    cur->fts_info != FTS_DNR && cur->fts_info != FTS_ERR)
881
			cur->fts_info = FTS_DP;
906
			cur->fts_info = FTS_DP;
882
		return (NULL);
907
		return (NULL);
883
	}
908
	}
(-)b/lib/libc/gen/fts-compat11.c (-3 / +29 lines)
Lines 607-612 freebsd11_fts_set_clientptr(FTS11 *sp, void *clientptr) Link Here
607
	sp->fts_clientptr = clientptr;
607
	sp->fts_clientptr = clientptr;
608
}
608
}
609
609
610
static struct freebsd11_dirent *
611
fts_safe_readdir(DIR *dirp, int *readdir_errno)
612
{
613
	struct freebsd11_dirent *ret;
614
615
	errno = 0;
616
	if (!dirp)
617
		return (NULL);
618
	ret = freebsd11_readdir(dirp);
619
	*readdir_errno = errno;
620
	return (ret);
621
}
622
610
/*
623
/*
611
 * This is the tricky part -- do not casually change *anything* in here.  The
624
 * This is the tricky part -- do not casually change *anything* in here.  The
612
 * idea is to build the linked list of entries that are used by fts_children
625
 * idea is to build the linked list of entries that are used by fts_children
Lines 630-636 fts_build(FTS11 *sp, int type) Link Here
630
	DIR *dirp;
643
	DIR *dirp;
631
	void *oldaddr;
644
	void *oldaddr;
632
	char *cp;
645
	char *cp;
633
	int cderrno, descend, oflag, saved_errno, nostat, doadjust;
646
	int cderrno, descend, oflag, saved_errno, nostat, doadjust,
647
	    readdir_errno;
634
	long level;
648
	long level;
635
	long nlinks;	/* has to be signed because -1 is a magic value */
649
	long nlinks;	/* has to be signed because -1 is a magic value */
636
	size_t dnamlen, len, maxlen, nitems;
650
	size_t dnamlen, len, maxlen, nitems;
Lines 736-743 fts_build(FTS11 *sp, int type) Link Here
736
750
737
	/* Read the directory, attaching each entry to the `link' pointer. */
751
	/* Read the directory, attaching each entry to the `link' pointer. */
738
	doadjust = 0;
752
	doadjust = 0;
753
	readdir_errno = 0;
739
	for (head = tail = NULL, nitems = 0;
754
	for (head = tail = NULL, nitems = 0;
740
	    dirp && (dp = freebsd11_readdir(dirp));) {
755
	    (dp = fts_safe_readdir(dirp, &readdir_errno));) {
741
		dnamlen = dp->d_namlen;
756
		dnamlen = dp->d_namlen;
742
		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
757
		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
743
			continue;
758
			continue;
Lines 823-828 mem1: saved_errno = errno; Link Here
823
		}
838
		}
824
		++nitems;
839
		++nitems;
825
	}
840
	}
841
842
	if (readdir_errno) {
843
		cur->fts_errno = readdir_errno;
844
		/*
845
		 * If we've not read any items yet, treat
846
		 * the error as if we can't access the dir.
847
		 */
848
		cur->fts_info = nitems ? FTS_ERR : FTS_DNR;
849
	}
850
826
	if (dirp)
851
	if (dirp)
827
		(void)closedir(dirp);
852
		(void)closedir(dirp);
828
853
Lines 859-865 mem1: saved_errno = errno; Link Here
859
884
860
	/* If didn't find anything, return NULL. */
885
	/* If didn't find anything, return NULL. */
861
	if (!nitems) {
886
	if (!nitems) {
862
		if (type == BREAD)
887
		if (type == BREAD &&
888
		    cur->fts_info != FTS_DNR && cur->fts_info != FTS_ERR)
863
			cur->fts_info = FTS_DP;
889
			cur->fts_info = FTS_DP;
864
		return (NULL);
890
		return (NULL);
865
	}
891
	}
(-)b/lib/libc/gen/fts.c (-3 / +30 lines)
Lines 604-609 fts_set_clientptr(FTS *sp, void *clientptr) Link Here
604
	sp->fts_clientptr = clientptr;
604
	sp->fts_clientptr = clientptr;
605
}
605
}
606
606
607
static struct dirent *
608
fts_safe_readdir(DIR *dirp, int *readdir_errno)
609
{
610
	struct dirent *ret;
611
612
	errno = 0;
613
	if (!dirp)
614
		return (NULL);
615
	ret = readdir(dirp);
616
	*readdir_errno = errno;
617
	return (ret);
618
}
619
607
/*
620
/*
608
 * This is the tricky part -- do not casually change *anything* in here.  The
621
 * This is the tricky part -- do not casually change *anything* in here.  The
609
 * idea is to build the linked list of entries that are used by fts_children
622
 * idea is to build the linked list of entries that are used by fts_children
Lines 627-633 fts_build(FTS *sp, int type) Link Here
627
	DIR *dirp;
640
	DIR *dirp;
628
	void *oldaddr;
641
	void *oldaddr;
629
	char *cp;
642
	char *cp;
630
	int cderrno, descend, oflag, saved_errno, nostat, doadjust;
643
	int cderrno, descend, oflag, saved_errno, nostat, doadjust,
644
	    readdir_errno;
631
	long level;
645
	long level;
632
	long nlinks;	/* has to be signed because -1 is a magic value */
646
	long nlinks;	/* has to be signed because -1 is a magic value */
633
	size_t dnamlen, len, maxlen, nitems;
647
	size_t dnamlen, len, maxlen, nitems;
Lines 733-739 fts_build(FTS *sp, int type) Link Here
733
747
734
	/* Read the directory, attaching each entry to the `link' pointer. */
748
	/* Read the directory, attaching each entry to the `link' pointer. */
735
	doadjust = 0;
749
	doadjust = 0;
736
	for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) {
750
	readdir_errno = 0;
751
	for (head = tail = NULL, nitems = 0;
752
	    (dp = fts_safe_readdir(dirp, &readdir_errno));) {
737
		dnamlen = dp->d_namlen;
753
		dnamlen = dp->d_namlen;
738
		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
754
		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
739
			continue;
755
			continue;
Lines 819-824 mem1: saved_errno = errno; Link Here
819
		}
835
		}
820
		++nitems;
836
		++nitems;
821
	}
837
	}
838
839
	if (readdir_errno) {
840
		cur->fts_errno = readdir_errno;
841
		/*
842
		 * If we've not read any items yet, treat
843
		 * the error as if we can't access the dir.
844
		 */
845
		cur->fts_info = nitems ? FTS_ERR : FTS_DNR;
846
	}
847
822
	if (dirp)
848
	if (dirp)
823
		(void)closedir(dirp);
849
		(void)closedir(dirp);
824
850
Lines 855-861 mem1: saved_errno = errno; Link Here
855
881
856
	/* If didn't find anything, return NULL. */
882
	/* If didn't find anything, return NULL. */
857
	if (!nitems) {
883
	if (!nitems) {
858
		if (type == BREAD)
884
		if (type == BREAD &&
885
		    cur->fts_info != FTS_DNR && cur->fts_info != FTS_ERR)
859
			cur->fts_info = FTS_DP;
886
			cur->fts_info = FTS_DP;
860
		return (NULL);
887
		return (NULL);
861
	}
888
	}

Return to bug 262038