Skip to content
Snippets Groups Projects
Commit c056391c authored by deuce's avatar deuce
Browse files

Turn wildmatch into a recursive function.

Fixes incorrect FALSE in the case of wildmatch("ttest.txt","*test.txt",x)

Reported by Cyan.
parent ee816a12
No related branches found
No related tags found
No related merge requests found
...@@ -939,10 +939,12 @@ BOOL DLLCALL isfullpath(const char* filename) ...@@ -939,10 +939,12 @@ BOOL DLLCALL isfullpath(const char* filename)
/* Matches file name against filespec */ /* Matches file name against filespec */
/* Optionally not allowing * to match PATH_DELIM (for paths) */ /* Optionally not allowing * to match PATH_DELIM (for paths) */
/****************************************************************************/ /****************************************************************************/
BOOL DLLCALL wildmatch(const char *fname, const char *spec, BOOL path) BOOL DLLCALL wildmatch(const char *fname, const char *spec, BOOL path)
{ {
char *specp; char *specp;
char *fnamep; char *fnamep;
char *wildend;
specp=(char *)spec; specp=(char *)spec;
fnamep=(char *)fname; fnamep=(char *)fname;
...@@ -959,10 +961,21 @@ BOOL DLLCALL wildmatch(const char *fname, const char *spec, BOOL path) ...@@ -959,10 +961,21 @@ BOOL DLLCALL wildmatch(const char *fname, const char *spec, BOOL path)
case '*': case '*':
while(*specp=='*') while(*specp=='*')
specp++; specp++;
for(;*fnamep!=*specp && *fnamep;fnamep++) { if(path) {
if(path && IS_PATH_DELIM(*fnamep)) for(wildend=fnamep; *wildend; wildend++) {
return(FALSE); if(IS_PATH_DELIM(*wildend)) {
wildend--;
break;
}
}
}
else
wildend=strchr(fnamep, 0);
for(;wildend >= fnamep;wildend--) {
if(wildmatch(wildend, specp, path))
return(TRUE);
} }
return(FALSE);
default: default:
if(*specp != *fnamep) if(*specp != *fnamep)
return(FALSE); return(FALSE);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment