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

Make removecase() handle dirs as well as files through the use of a new
static delfiles_and_or_dirs() function which is basically delfiles()
with an option to remove() dirs too.
delfiles() simply calls this function now.
parent e8308f29
No related branches found
No related tags found
No related merge requests found
...@@ -573,33 +573,6 @@ BOOL DLLCALL fexistcase(char *path) ...@@ -573,33 +573,6 @@ BOOL DLLCALL fexistcase(char *path)
#endif #endif
} }
#ifdef __unix__
int removecase(char *path)
{
char inpath[MAX_PATH+1];
char fname[MAX_PATH*4+1];
char tmp[5];
char *p;
int i;
if(strchr(path,'?') || strchr(path,'*'))
return(-1);
SAFECOPY(inpath,path);
p=getfname(inpath);
fname[0]=0;
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[i]);
strncat(fname,tmp,MAX_PATH*4);
}
*p=0;
return(delfiles(inpath,fname)?-1:0);
}
#endif
#if !defined(S_ISDIR) #if !defined(S_ISDIR)
#define S_ISDIR(x) ((x)&S_IFDIR) #define S_ISDIR(x) ((x)&S_IFDIR)
#endif #endif
...@@ -660,10 +633,7 @@ int DLLCALL getfattr(const char* filename) ...@@ -660,10 +633,7 @@ int DLLCALL getfattr(const char* filename)
#endif #endif
} }
/****************************************************************************/ static ulong delfiles_and_or_dirs(char *inpath, char *spec, int dirs)
/* Deletes all files in dir 'path' that match file spec 'spec' */
/****************************************************************************/
ulong DLLCALL delfiles(char *inpath, char *spec)
{ {
char path[MAX_PATH+1]; char path[MAX_PATH+1];
char lastch; char lastch;
...@@ -678,8 +648,10 @@ ulong DLLCALL delfiles(char *inpath, char *spec) ...@@ -678,8 +648,10 @@ ulong DLLCALL delfiles(char *inpath, char *spec)
strcat(path,spec); strcat(path,spec);
glob(path,0,NULL,&g); glob(path,0,NULL,&g);
for(i=0;i<g.gl_pathc;i++) { for(i=0;i<g.gl_pathc;i++) {
if(!dirs) {
if(isdir(g.gl_pathv[i])) if(isdir(g.gl_pathv[i]))
continue; continue;
}
CHMOD(g.gl_pathv[i],S_IWRITE); /* Incase it's been marked RDONLY */ CHMOD(g.gl_pathv[i],S_IWRITE); /* Incase it's been marked RDONLY */
if(remove(g.gl_pathv[i])==0) if(remove(g.gl_pathv[i])==0)
files++; files++;
...@@ -688,6 +660,41 @@ ulong DLLCALL delfiles(char *inpath, char *spec) ...@@ -688,6 +660,41 @@ ulong DLLCALL delfiles(char *inpath, char *spec)
return(files); return(files);
} }
#ifdef __unix__
int removecase(char *path)
{
char inpath[MAX_PATH+1];
char fname[MAX_PATH*4+1];
char tmp[5];
char *p;
int i;
if(strchr(path,'?') || strchr(path,'*'))
return(-1);
SAFECOPY(inpath,path);
p=getfname(inpath);
fname[0]=0;
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[i]);
strncat(fname,tmp,MAX_PATH*4);
}
*p=0;
return(delfiles_and_or_dirs(inpath,fname,TRUE)?-1:0);
}
#endif
/****************************************************************************/
/* Deletes all files in dir 'path' that match file spec 'spec' */
/****************************************************************************/
ulong DLLCALL delfiles(char *inpath, char *spec)
{
return(delfiles_and_or_dirs(inpath,spec,FALSE));
}
/****************************************************************************/ /****************************************************************************/
/* Return free disk space in bytes (up to a maximum of 4GB) */ /* Return free disk space in bytes (up to a maximum of 4GB) */
/****************************************************************************/ /****************************************************************************/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment