Subject: Re: [PATCH v2 5/6] msvc: opendir: handle paths ending with a slash

From: René Scharfe <[email-masked]>
Date: Tue, 23 Nov 2010 21:16:44 +0100

Am 23.11.2010 20:48, schrieb Erik Faye-Lund:
> On Tue, Nov 23, 2010 at 8:31 PM, René Scharfe
> <[email-masked]> wrote:
>> Am 23.11.2010 19:38, schrieb Erik Faye-Lund:
>>> Signed-off-by: Erik Faye-Lund <[email-masked]>
>>> ---
>>>  compat/msvc.c |    2 ++
>>>  1 files changed, 2 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/compat/msvc.c b/compat/msvc.c
>>> index 199eb22..fdbfb70 100644
>>> --- a/compat/msvc.c
>>> +++ b/compat/msvc.c
>>> @@ -23,6 +23,8 @@ DIR *opendir(const char *name)
>>>
>>>       /* check that the pattern won't be too long for FindFirstFileA */
>>>       len = strlen(name);
>>> +     if (is_dir_sep(name[len - 1]))
>>
>> Perhaps extend this thus, and handle multiple slashes?
>>
>>        while (len > 0 && is_dir_sep(name[len - 1]))
>>
>>> +             len--;
>>>       if (len + 2 >= MAX_PATH) {
>>>               errno = ENAMETOOLONG;
>>>               return NULL;
> 
> Sure, it could be done. But the reason why I didn't do that myself was
> that I got a bit worried about this being a slippery slope towards
> full path-normalization. FindFirstFileA() does handle non-normalized
> paths, as long as they are below MAX_PATH in length.
> 
> I just didn't want to add a slash if there was already one there,
> which is something different than trying to fix the input-path.
> 
> In other words, I'm not entirely sure if fixing up such a case is a
> task that belongs to opendir.

Okay; based on the subject of the patch I had assumed that opendir()
wasn't working at all on paths with trailing slashes.

René