2 /* Replacements for functions needed specifically by the 'imagex' program in
3 * Windows native builds */
6 # error "This file contains Windows code"
9 #include "imagex-win32.h"
16 /* Replacement for glob() in Windows native builds. */
17 int glob(const char *pattern, int flags,
18 int (*errfunc)(const char *epath, int eerrno),
27 /* This function does not support all functionality of the POSIX glob(),
28 * so make sure the parameters are consistent with supported
30 assert(errfunc == NULL);
31 assert((flags & GLOB_ERR) == GLOB_ERR);
32 assert((flags & ~(GLOB_NOSORT | GLOB_ERR)) == 0);
34 hFind = FindFirstFileA(pattern, &dat);
35 if (hFind == INVALID_HANDLE_VALUE) {
37 if (err == ERROR_FILE_NOT_FOUND) {
41 /* The other possible error codes for FindFirstFile()
42 * are undocumented. */
48 pglob->gl_pathv = NULL;
52 if (pglob->gl_pathc == nspaces) {
56 new_nspaces = nspaces * 2 + 1;
57 pathv = realloc(pglob->gl_pathv,
58 new_nspaces * sizeof(pglob->gl_pathv[0]));
61 pglob->gl_pathv = pathv;
62 nspaces = new_nspaces;
64 filename = strdup(dat.cFileName);
67 pglob->gl_pathv[pglob->gl_pathc++] = filename;
68 } while (FindNextFileA(hFind, &dat));
71 if (err == ERROR_NO_MORE_FILES) {
75 /* Other possible error codes for FindNextFile() are
90 void globfree(glob_t *pglob)
93 for (i = 0; i < pglob->gl_pathc; i++)
94 free(pglob->gl_pathv[i]);
95 free(pglob->gl_pathv[i]);