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

Return to bug 262038