Commit ce74d0e0 authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Introduce case-insensitive version of glob(): globi()

glob() is case-insensitive on Windows already, so create a work-alike for *nix.
parent 479bd24c
......@@ -305,7 +305,29 @@ void globfree(glob_t* glob)
glob->gl_pathc=0;
}
#endif /* !defined(__unix__) */
#else /* __unix__ */
// Case-insensitive version of glob()
int globi(const char *p, int flags,
int (*errfunc) (const char *epath, int eerrno),
glob_t *g)
{
char pattern[MAX_PATH * 2] = "";
int len = 0;
if(p != NULL) {
while(*p != '\0' && len < MAX_PATH) {
if(IS_ALPHA(*p))
len += sprintf(pattern + len, "[%c%c]", toupper(*p), tolower(*p));
else
pattern[len++] = *p;
}
}
pattern[len] = '\0';
return glob(pattern, flags, errfunc, g);
}
#endif
/****************************************************************************/
/* Returns number of files and/or sub-directories in directory (path) */
......
......@@ -50,6 +50,10 @@ extern "C" {
#include <sys/types.h>
#include <sys/stat.h>
#include <glob.h> /* POSIX.2 directory pattern matching function */
// Case-insensitive glob
int globi(const char *pattern, int flags, int (*errfunc) (const char *epath, int eerrno), glob_t *pglob);
#define MKDIR(dir) mkdir(dir,0777)
#if defined(__CYGWIN__)
......@@ -107,6 +111,7 @@ extern "C" {
DLLEXPORT int glob(const char *pattern, int flags, void* unused, glob_t*);
DLLEXPORT void globfree(glob_t*);
#define globi(a,b,c,d) glob(a,b,c,d)
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment