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

Collapse All | Expand All

(-)b/lib/libc/gen/fts.c (-2 / +26 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)
609
{
610
	errno = 0;
611
	if (!dirp)
612
		return (NULL);
613
	return readdir(dirp);
614
}
615
607
/*
616
/*
608
 * This is the tricky part -- do not casually change *anything* in here.  The
617
 * 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
618
 * idea is to build the linked list of entries that are used by fts_children
Lines 733-739 fts_build(FTS *sp, int type) Link Here
733
742
734
	/* Read the directory, attaching each entry to the `link' pointer. */
743
	/* Read the directory, attaching each entry to the `link' pointer. */
735
	doadjust = 0;
744
	doadjust = 0;
736
	for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) {
745
	for (head = tail = NULL, nitems = 0; (dp = fts_safe_readdir(dirp));) {
737
		dnamlen = dp->d_namlen;
746
		dnamlen = dp->d_namlen;
738
		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
747
		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
739
			continue;
748
			continue;
Lines 819-824 mem1: saved_errno = errno; Link Here
819
		}
828
		}
820
		++nitems;
829
		++nitems;
821
	}
830
	}
831
832
	/*
833
	 * The only way to distinguish between "no more files" and readdir
834
	 * error is checking errno when readdir() returns NULL.
835
	 */
836
	if (errno) {
837
		cur->fts_errno = errno;
838
		/*
839
		 * If we've not read any items yet, treat
840
		 * the error as if we can't access the dir.
841
		 */
842
		cur->fts_info = nitems ? FTS_ERR : FTS_DNR;
843
	}
844
822
	if (dirp)
845
	if (dirp)
823
		(void)closedir(dirp);
846
		(void)closedir(dirp);
824
847
Lines 855-861 mem1: saved_errno = errno; Link Here
855
878
856
	/* If didn't find anything, return NULL. */
879
	/* If didn't find anything, return NULL. */
857
	if (!nitems) {
880
	if (!nitems) {
858
		if (type == BREAD)
881
		if (type == BREAD &&
882
			cur->fts_info != FTS_DNR && cur->fts_info != FTS_ERR)
859
			cur->fts_info = FTS_DP;
883
			cur->fts_info = FTS_DP;
860
		return (NULL);
884
		return (NULL);
861
	}
885
	}

Return to bug 262038