1 /* Globbing functions for descent. Calls the relevant system handlers... */
6 //added 05/17/99 Matt Mueller
10 #if defined(__DJGPP__) || defined(__LINUX__)
13 int d_glob(const char *pattern, d_glob_t *g)
22 r=glob(pattern,0,NULL,&a);
23 g->gl_pathc=a.gl_pathc;
24 g->gl_pathv=a.gl_pathv;
28 void d_globfree(d_glob_t *g)
30 #ifndef __LINUX__ // Linux doesn't believe in freeing glob structures... :-)
36 a.gl_pathc=g->gl_pathc;
37 a.gl_pathv=g->gl_pathv;
43 #elif defined(__WINDOWS__)
47 #define MAX_GLOB_FILES 500
49 /* Using a global variable stops this from being reentrant, but in descent,
51 static char *globfiles[MAX_GLOB_FILES];
53 int d_glob(const char *pattern, d_glob_t *g)
61 if ((wfh=FindFirstFile(pattern,&wfd))!=INVALID_HANDLE_VALUE)
64 LPSTR sz = wfd.cAlternateFileName;
65 if (sz == NULL || sz [0] == '\0')
67 globfiles[c] = d_strdup (*wfd.cAlternateFileName ?
68 wfd.cAlternateFileName : wfd.cFileName);
70 c++; // Ho ho ho... :-)
71 if (c>=MAX_GLOB_FILES) return 0;
72 } while (FindNextFile(wfh,&wfd));
77 g->gl_pathv = globfiles;
81 void d_globfree(d_glob_t *g)
85 for (i=0; i < g->gl_pathc; i++) {
86 if (globfiles[i]) d_free(globfiles[i]);
90 #else // Must be good old Watcom C.
91 #error "FIXME: Globbing isn't yet supported under Watcom C. Look at misc/d_glob.c"