1 /* Globbing functions for descent. Calls the relevant system handlers... */
10 //added 05/17/99 Matt Mueller
14 #if defined(__DJGPP__) || defined(__linux__)
17 int d_glob(const char *pattern, d_glob_t *g)
26 r=glob(pattern,0,NULL,&a);
27 g->gl_pathc=a.gl_pathc;
28 g->gl_pathv=a.gl_pathv;
32 void d_globfree(d_glob_t *g)
34 #ifndef __linux__ // Linux doesn't believe in freeing glob structures... :-)
40 a.gl_pathc=g->gl_pathc;
41 a.gl_pathv=g->gl_pathv;
47 #elif defined(__WINDOWS__)
51 #define MAX_GLOB_FILES 500
53 /* Using a global variable stops this from being reentrant, but in descent,
55 static char *globfiles[MAX_GLOB_FILES];
57 int d_glob(const char *pattern, d_glob_t *g)
65 if ((wfh=FindFirstFile(pattern,&wfd))!=INVALID_HANDLE_VALUE)
68 LPSTR sz = wfd.cAlternateFileName;
69 if (sz == NULL || sz [0] == '\0')
71 globfiles[c] = d_strdup (*wfd.cAlternateFileName ?
72 wfd.cAlternateFileName : wfd.cFileName);
74 c++; // Ho ho ho... :-)
75 if (c>=MAX_GLOB_FILES) return 0;
76 } while (FindNextFile(wfh,&wfd));
81 g->gl_pathv = globfiles;
85 void d_globfree(d_glob_t *g)
89 for (i=0; i < g->gl_pathc; i++) {
90 if (globfiles[i]) d_free(globfiles[i]);
94 #else // Must be good old Watcom C.
95 #error "FIXME: Globbing isn't yet supported under Watcom C. Look at misc/d_glob.c"