X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f NNTP-Posting-Date: Thu, 30 Nov 2006 00:32:27 -0600 From: "Alexei A. Frounze" Newsgroups: comp.os.msdos.djgpp References: <456dad03$0$486$cc7c7865 AT news DOT luth DOT se> <200611291634 DOT kATGYcbw010800 AT envy DOT delorie DOT com> Subject: Re: fnmatch("\\\\", "\\", 0) == 1 ??? Date: Wed, 29 Nov 2006 22:31:24 -0800 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962 Message-ID: Lines: 51 NNTP-Posting-Host: 24.18.54.10 X-Trace: sv3-8e6yh+5z6CotmU9Dwr/BRrwtelRqNhqT8vXf95/UIwxLfft8omKgtE6uNufBS+944eJO7YimMeXJFpZ!WNQHsAxU7zTP9aETRuiuHDUm+adhJPIUueEVuOnTBYb8VEZaxrhnNz2p6J878njUui6hFcpZDro4!+BSh6JyToA== X-Complaints-To: abuse AT comcast DOT net X-DMCA-Complaints-To: dmca AT comcast DOT net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Brian Inglis wrote: > fOn Wed, 29 Nov 2006 11:34:38 -0500 in comp.os.msdos.djgpp, DJ Delorie > wrote: > >> >>> This function indicates if STRING matches the PATTERN. ..." >>> >>> So DJGPP says that "\" doesn't match "\\" while Linux says it does. >>> >>> Well, I say DJGPP is right as the pattern says there should be two >>> backslashes and you only provide one. >> >> Except that PATTERN is a regex influenced by FNM_NOESCAPE and >> FNM_PATHNAME, and STRING isn't. So a pattern of "\\" is a single >> escaped backslash, whereas a string of "\" is a single backslash. >> They should match. > > switch ((c = *pattern++)) > { > ... > ... > ... > case '\\': > /*+++ pattern already post-incremented to point to next char */ > if (!(flags & FNM_NOESCAPE) && pattern[1] && strchr("*?[\\", > pattern[1])) > /*+++ should be: > if (!(flags & FNM_NOESCAPE) && strchr("*?[\\", *pattern)) > *+++ as end of input pattern will match end char in escapes string */ > { > /*+++ end of input pattern might be clearer with ! or == '\0' */ > if ((c = *pattern++) == 0) > { > c = '\\'; > --pattern; > } > if (c != *string++) > return FNM_NOMATCH; > break; > } I don't think the above is enough. There's another problem. With the above code you'd never see (c = *pattern++) == 0. My bet is that the intent was to treat the slash in the last character of pattern as an ordinary character. That would explain the {c = '\\'; --pattern;} thing along with the fallthrough behavior. But the code is broken in this place. Dunno if it was tested against the single unix spec or just a little bit to see that it seems to work (in some basic cases). Alex