when load the paths for the next root. test case is "du d1/d1d1 d2/d2d1",
the second root will not be in the right directory.
SCCS-vsn: lib/libc/gen/fts.c 5.41
*/
#if defined(LIBC_SCCS) && !defined(lint)
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fts.c 5.40 (Berkeley) %G%";
+static char sccsid[] = "@(#)fts.c 5.41 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
if (p = p->fts_link) {
free(tmp);
if (p = p->fts_link) {
free(tmp);
- /* If reached the top, load the paths for the next root. */
+ /*
+ * If reached the top, return to the original directory, and
+ * load the paths for the next root.
+ */
if (p->fts_level == FTS_ROOTLEVEL) {
if (p->fts_level == FTS_ROOTLEVEL) {
+ if (!ISSET(FTS_NOCHDIR) && FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
fts_load(sp, p);
return (sp->fts_cur = p);
}
fts_load(sp, p);
return (sp->fts_cur = p);
}
* needed sorted entries or stat information, they had better be
* checking FTS_NS on the returned nodes.
*/
* needed sorted entries or stat information, they had better be
* checking FTS_NS on the returned nodes.
*/
if (nlinks || type == BREAD)
if (FCHDIR(sp, dirfd(dirp))) {
if (nlinks && type == BREAD)
if (nlinks || type == BREAD)
if (FCHDIR(sp, dirfd(dirp))) {
if (nlinks && type == BREAD)
cur->fts_flags |= FTS_DONTCHDIR;
descend = 0;
cderrno = errno;
cur->fts_flags |= FTS_DONTCHDIR;
descend = 0;
cderrno = errno;