diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c
index 353bdd658abd358ed7fa2b800be0d0a572ebf6ee..55e4bfc42240ba1bd53a1dd2a81b7eed73d4680f 100644
--- a/src/xpdev/dirwrap.c
+++ b/src/xpdev/dirwrap.c
@@ -573,7 +573,7 @@ BOOL DLLCALL fexistcase(char *path)
 #endif
 }
 
-#ifndef _WIN32
+#ifdef __unix__
 int removecase(char *path)
 {
 	char inpath[MAX_PATH+1];
@@ -581,20 +581,22 @@ int removecase(char *path)
 	char tmp[5];
 	char *p;
 	int  i;
-	
+
+	if(strchr(path,'?') || strchr(path,'*'))
+		return(-1);
 	SAFECOPY(inpath,path);
 	p=getfname(inpath);
-	SAFECOPY(fname,p);
-	*p=0;
+	if(p>inpath)
+		*(p-1)=0;
 	fname[0]=0;
-	p++;
-	for(;*p;p++)  {
-		if(isalpha(*p))
-			sprintf(tmp,"[%c%c]",toupper(*p),tolower(*p));
+	for(i=0;p[i];i++)  {
+		if(isalpha(p[i]))
+			sprintf(tmp,"[%c%c]",toupper(p[i]),tolower(p[i]));
 		else
-			sprintf(tmp,"%c",*p);
+			sprintf(tmp,"%c",p[i]);
 		strncat(fname,tmp,MAX_PATH*4);
 	}
+	*p=0;
 
 	return(delfiles(inpath,fname)?-1:0);
 }