diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c index 03d80cee030609935d53902100077d5a711a95b9..c788a0181a1e66f1717d4c38edb6187ca48fb56b 100644 --- a/src/xpdev/dirwrap.c +++ b/src/xpdev/dirwrap.c @@ -62,6 +62,10 @@ #endif /* __unix__ */ +#if defined(__WATCOMC__) + #include <dos.h> +#endif + #include <sys/types.h> /* _dev_t */ #include <sys/stat.h> /* struct stat */ @@ -136,6 +140,65 @@ static int glob_compare( const void *arg1, const void *arg2 ) #pragma argsused #endif +#if defined(__WATCOMC__) + +int DLLCALL glob(const char *pattern, int flags, void* unused, glob_t* glob) +{ + struct find_t ff; + size_t found=0; + char path[MAX_PATH+1]; + char* p; + char** new_pathv; + + if(!(flags&GLOB_APPEND)) { + glob->gl_pathc=0; + glob->gl_pathv=NULL; + } + + if(_dos_findfirst((char*)pattern,_A_NORMAL,&ff)!=0) + return(GLOB_NOMATCH); + + do { + if(!(flags&GLOB_ONLYDIR) || ff.attrib&_A_SUBDIR) { + if((new_pathv=realloc(glob->gl_pathv + ,(glob->gl_pathc+1)*sizeof(char*)))==NULL) { + globfree(glob); + return(GLOB_NOSPACE); + } + glob->gl_pathv=new_pathv; + + /* build the full pathname */ + SAFECOPY(path,pattern); + p=getfname(path); + *p=0; + strcat(path,ff.name); + + if((glob->gl_pathv[glob->gl_pathc]=malloc(strlen(path)+2))==NULL) { + globfree(glob); + return(GLOB_NOSPACE); + } + strcpy(glob->gl_pathv[glob->gl_pathc],path); + if(flags&GLOB_MARK && ff.attrib&_A_SUBDIR) + strcat(glob->gl_pathv[glob->gl_pathc],"/"); + + glob->gl_pathc++; + found++; + } + } while(_dos_findnext(&ff)==0); + _dos_findclose(&ff); + + if(found==0) + return(GLOB_NOMATCH); + + if(!(flags&GLOB_NOSORT)) { + qsort(glob->gl_pathv,found,sizeof(char*),glob_compare); + } + + return(0); /* success */ +} + +#else + int DLLCALL glob(const char *pattern, int flags, void* unused, glob_t* glob) { struct _finddata_t ff; @@ -193,6 +256,8 @@ int DLLCALL glob(const char *pattern, int flags, void* unused, glob_t* glob) return(0); /* success */ } +#endif + void DLLCALL globfree(glob_t* glob) { size_t i; @@ -344,7 +409,9 @@ BOOL DLLCALL fexist(const char *filespec) return(TRUE); -#elif defined(__unix__) /* portion by cmartin */ +#else /* Unix or OS/2 */ + + /* portion by cmartin */ glob_t g; int c; @@ -373,12 +440,6 @@ BOOL DLLCALL fexist(const char *filespec) globfree(&g); return FALSE; -#else - -#warning "fexist() port needs to support wildcards!" - - return(FALSE); - #endif } @@ -555,7 +616,7 @@ ulong DLLCALL getfreediskspace(const char* path) #else - #warning OS-specific code needed here + fprintf(stderr,"\n*** !Missing getfreediskspace implementation ***\n"); return(0); #endif diff --git a/src/xpdev/dirwrap.h b/src/xpdev/dirwrap.h index c5687505cb961aa5afdffb7337e1d1a4e2914f43..f903ac8d61f7a8c48eafee1a0dc2934f8843f072 100644 --- a/src/xpdev/dirwrap.h +++ b/src/xpdev/dirwrap.h @@ -137,6 +137,8 @@ extern "C" { struct dirent * readdir (DIR *__dir); int closedir (DIR *__dir); void rewinddir(DIR *__dir); +#elif defined(__WATCOMC__) + #include <direct.h> /* opendir, etc defined here in Watcom */ #else #include <dirent.h> /* POSIX directory functions */ #endif