# HG changeset patch # User Dmitry V. Levin # Date 1353199218 -14400 # Node ID 72f4bab621be0d6d08dfdab405f81100f653a9af # Parent 52e3cf91ff219e09c2fedc61c88b193165d95941 fts: introduce FTS_VERBATIM This gives clients the option to disable stripping of trailing slashes from input path names during fts_open initialization. The recent change v0.0-7611-g3a9002d that made fts_open strip trailing slashes from input path names had a negative impact on findutils that relies on the old fts_open behavior to implement POSIX requirement that each path operand of the find utility shall be evaluated unaltered as it was provided, including all trailing slash characters. * lib/fts_.h (FTS_VERBATIM): New bit flag. (FTS_OPTIONMASK, FTS_NAMEONLY, FTS_STOP): Adjust. * lib/fts.c (fts_open): Honor it. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2012-11-17 Dmitry V. Levin + + fts: introduce FTS_VERBATIM + * lib/fts_.h (FTS_VERBATIM): New bit flag. + (FTS_OPTIONMASK, FTS_NAMEONLY, FTS_STOP): Adjust. + * lib/fts.c (fts_open): Honor it. + 2012-11-09 Pádraig Brady getlogin-tests: allow errno == ENXIO diff --git a/lib/fts.c b/lib/fts.c --- a/lib/fts.c +++ b/lib/fts.c @@ -488,12 +488,15 @@ /* *Do* allow zero-length file names. */ size_t len = strlen(*argv); - /* If there are two or more trailing slashes, trim all but one, - but don't change "//" to "/", and do map "///" to "/". */ - char const *v = *argv; - if (2 < len && v[len - 1] == '/') - while (1 < len && v[len - 2] == '/') - --len; + if ( ! (options & FTS_VERBATIM)) + { + /* If there are two or more trailing slashes, trim all but one, + but don't change "//" to "/", and do map "///" to "/". */ + char const *v = *argv; + if (2 < len && v[len - 1] == '/') + while (1 < len && v[len - 2] == '/') + --len; + } if ((p = fts_alloc(sp, *argv, len)) == NULL) goto mem3; diff --git a/lib/fts_.h b/lib/fts_.h --- a/lib/fts_.h +++ b/lib/fts_.h @@ -145,10 +145,14 @@ # define FTS_NOATIME 0x0800 /* use O_NOATIME during traversal */ -# define FTS_OPTIONMASK 0x0fff /* valid user option mask */ + /* Use this flag to disable stripping of trailing slashes + from input path names during fts_open initialization. */ +# define FTS_VERBATIM 0x1000 -# define FTS_NAMEONLY 0x1000 /* (private) child names only */ -# define FTS_STOP 0x2000 /* (private) unrecoverable error */ +# define FTS_OPTIONMASK 0x1fff /* valid user option mask */ + +# define FTS_NAMEONLY 0x2000 /* (private) child names only */ +# define FTS_STOP 0x4000 /* (private) unrecoverable error */ int fts_options; /* fts_open options, global flags */ /* Map a directory's device number to a boolean. The boolean is