bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] fts: reduce two or more trailing spaces to just one, usually


From: Jim Meyering
Subject: Re: [PATCH] fts: reduce two or more trailing spaces to just one, usually
Date: Tue, 04 Sep 2012 13:05:55 +0200

Eric Blake wrote:
> On 09/04/2012 04:57 AM, Eric Blake wrote:
>>> * lib/fts.c (fts_open): Upon initialization, if a name ends in two
>>> or more slashes, trim all but the final one.  But if a name consists
>>> solely of two or more slashes, reduce it to "//", not to "/".
>>>
>>
>> For two slashes, that is correct.  But trimming "///" to "//" is a
>> violation of POSIX and fails on cygwin; "///" must be the same as "/",
>> not "///".
>>
>>> +++ b/lib/fts.c
>>> @@ -487,6 +487,14 @@ fts_open (char * const *argv,
>>>          for (root = NULL, nitems = 0; *argv != NULL; ++argv, ++nitems) {
>>>                  /* *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 "/".  */
>>> +                char const *v = *argv;
>>> +                if (2 < len && v[len - 1] == '/')
>>> +                  while (2 < len && v[len - 2] == '/')
>>> +                    --len;
>
> I think that this would do the right thing, though (notice that it
> strips all but 1 slash for anything longer than "//" to begin with):
>
> +                char const *v = *argv;
> +                if (2 < len && v[len - 1] == '/')
> +                  while (1 < len && v[len - 1] == '/')
> +                    --len;

Precisely what I'd just written.  Thanks.

diff --git a/lib/fts.c b/lib/fts.c
index a9db89a..36f7e0d 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -489,10 +489,10 @@ fts_open (char * const *argv,
                 size_t len = strlen(*argv);

                 /* If there are two or more trailing slashes, trim all but one,
-                   but don't change "//" to "/".  */
+                   but don't change "//" to "/", and do map "///" to "/".  */
                 char const *v = *argv;
                 if (2 < len && v[len - 1] == '/')
-                  while (2 < len && v[len - 2] == '/')
+                  while (1 < len && v[len - 2] == '/')
                     --len;

                 if ((p = fts_alloc(sp, *argv, len)) == NULL)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]