From c056391ce2a47c61026abb5ab612b69059f650ad Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Sun, 12 Aug 2007 06:19:16 +0000
Subject: [PATCH] Turn wildmatch into a recursive function.

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

Reported by Cyan.
---
 src/xpdev/dirwrap.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c
index ddd99bcc21..6591fb0e4f 100644
--- a/src/xpdev/dirwrap.c
+++ b/src/xpdev/dirwrap.c
@@ -939,10 +939,12 @@ BOOL DLLCALL isfullpath(const char* filename)
 /* Matches file name against filespec										*/
 /* Optionally not allowing * to match PATH_DELIM (for paths)				*/
 /****************************************************************************/
+
 BOOL DLLCALL wildmatch(const char *fname, const char *spec, BOOL path)
 {
 	char *specp;
 	char *fnamep;
+	char *wildend;
 
 	specp=(char *)spec;
 	fnamep=(char *)fname;
@@ -959,10 +961,21 @@ BOOL DLLCALL wildmatch(const char *fname, const char *spec, BOOL path)
 			case '*':
 				while(*specp=='*')
 					specp++;
-				for(;*fnamep!=*specp && *fnamep;fnamep++) {
-					if(path && IS_PATH_DELIM(*fnamep))
-						return(FALSE);
+				if(path) {
+					for(wildend=fnamep; *wildend; wildend++) {
+						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:
 				if(*specp != *fnamep)
 					return(FALSE);
-- 
GitLab