From 35f6f08173a9c9f3d1e923e80cae2d65ff12dfaa Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Wed, 23 Aug 2006 23:48:45 +0000
Subject: [PATCH] Add removecase() function/macro which deletes the filename in
 all cases that exist.  Fix to delfiles() to delete from cwd if inpath is a
 zero-length string.

---
 src/xpdev/dirwrap.c | 29 ++++++++++++++++++++++++++++-
 src/xpdev/dirwrap.h |  3 +++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c
index eb213001d5..353bdd658a 100644
--- a/src/xpdev/dirwrap.c
+++ b/src/xpdev/dirwrap.c
@@ -573,6 +573,33 @@ BOOL DLLCALL fexistcase(char *path)
 #endif
 }
 
+#ifndef _WIN32
+int removecase(char *path)
+{
+	char inpath[MAX_PATH+1];
+	char fname[MAX_PATH*4+1];
+	char tmp[5];
+	char *p;
+	int  i;
+	
+	SAFECOPY(inpath,path);
+	p=getfname(inpath);
+	SAFECOPY(fname,p);
+	*p=0;
+	fname[0]=0;
+	p++;
+	for(;*p;p++)  {
+		if(isalpha(*p))
+			sprintf(tmp,"[%c%c]",toupper(*p),tolower(*p));
+		else
+			sprintf(tmp,"%c",*p);
+		strncat(fname,tmp,MAX_PATH*4);
+	}
+
+	return(delfiles(inpath,fname)?-1:0);
+}
+#endif
+
 #if !defined(S_ISDIR)
 	#define S_ISDIR(x)	((x)&S_IFDIR)
 #endif
@@ -644,7 +671,7 @@ ulong DLLCALL delfiles(char *inpath, char *spec)
 	glob_t	g;
 
 	lastch=*lastchar(inpath);
-	if(!IS_PATH_DELIM(lastch))
+	if(!IS_PATH_DELIM(lastch) && lastch)
 		sprintf(path,"%s%c",inpath,PATH_DELIM);
 	else
 		strcpy(path,inpath);
diff --git a/src/xpdev/dirwrap.h b/src/xpdev/dirwrap.h
index cf9f52c6b6..dd7664fcd9 100644
--- a/src/xpdev/dirwrap.h
+++ b/src/xpdev/dirwrap.h
@@ -240,6 +240,9 @@ DLLEXPORT int		DLLCALL	mkdirs(const char* path);
 DLLEXPORT void DLLCALL _splitpath(const char *path, char *drive, char *dir, 
 								  char *fname, char *ext);
 DLLEXPORT char * DLLCALL _fullpath(char *target, const char *path, size_t size);
+DLLEXPORT int DLLCALL removecase(char *path);
+#else
+	#define	removecase(x)	remove(x)
 #endif
 
 #if defined(__cplusplus)
-- 
GitLab