diff options
-rw-r--r-- | include/fts.h | 5 | ||||
-rw-r--r-- | lib/libc/gen/fts.c | 30 |
2 files changed, 25 insertions, 10 deletions
diff --git a/include/fts.h b/include/fts.h index 41f1ffc9ed0..fdb89c58c1e 100644 --- a/include/fts.h +++ b/include/fts.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fts.h,v 1.4 1999/10/03 19:22:22 millert Exp $ */ +/* $OpenBSD: fts.h,v 1.5 1999/10/03 20:39:52 millert Exp $ */ /* $NetBSD: fts.h,v 1.5 1994/12/28 01:41:50 mycroft Exp $ */ /* @@ -58,7 +58,8 @@ typedef struct { #define FTS_SEEDOT 0x0020 /* return dot and dot-dot */ #define FTS_XDEV 0x0040 /* don't cross devices */ #define FTS_WHITEOUT 0x0080 /* return whiteout information */ -#define FTS_OPTIONMASK 0x00ff /* valid user option mask */ +#define FTS_CHDIRROOT 0x0100 /* chdir to root of tree not orig cwd */ +#define FTS_OPTIONMASK 0x0fff /* valid user option mask */ #define FTS_NAMEONLY 0x1000 /* (private) child names only */ #define FTS_STOP 0x2000 /* (private) unrecoverable error */ diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 26d67fff3f9..790d665a64f 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $ */ +/* $OpenBSD: fts.c,v 1.23 1999/10/03 20:39:53 millert Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; #else -static char rcsid[] = "$OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $"; +static char rcsid[] = "$OpenBSD: fts.c,v 1.23 1999/10/03 20:39:53 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -373,9 +373,16 @@ next: tmp = p; * the root of the tree), and load the paths for the next root. */ if (p->fts_level == FTS_ROOTLEVEL) { - if (FCHDIR(sp, sp->fts_rfd)) { - SET(FTS_STOP); - return (NULL); + if ((sp->fts_options & FTS_CHDIRROOT)) { + if (chdir(p->fts_accpath)) { + SET(FTS_STOP); + return (NULL); + } + } else { + if (FCHDIR(sp, sp->fts_rfd)) { + SET(FTS_STOP); + return (NULL); + } } fts_load(sp, p); return (sp->fts_cur = p); @@ -430,9 +437,16 @@ name: t = sp->fts_path + NAPPEND(p->fts_parent); * one directory. */ if (p->fts_level == FTS_ROOTLEVEL) { - if (FCHDIR(sp, sp->fts_rfd)) { - SET(FTS_STOP); - return (NULL); + if ((sp->fts_options & FTS_CHDIRROOT)) { + if (chdir(p->fts_accpath)) { + SET(FTS_STOP); + return (NULL); + } + } else { + if (FCHDIR(sp, sp->fts_rfd)) { + SET(FTS_STOP); + return (NULL); + } } } else if (p->fts_flags & FTS_SYMFOLLOW) { if (FCHDIR(sp, p->fts_symfd)) { |