11 int glob(const char *pattern
, int flags
,
12 int (*errfunc
)(const char *epath
, int eerrno
), glob_t
*pglob
)
15 WIN32_FIND_DATA found_file
;
16 if(errfunc
)printf("glob():ERROR:Sorry errfunc not supported by this implementation\n");
17 if(flags
)printf("glob():ERROR:Sorry no flags supported by this globimplementation\n");
18 //printf("PATTERN \"%s\"\n",pattern);
20 searchhndl
= FindFirstFile( pattern
,&found_file
);
21 if(searchhndl
== INVALID_HANDLE_VALUE
)
23 if(GetLastError() == ERROR_FILE_NOT_FOUND
)
26 //printf("could not find a file matching your search criteria\n");
31 //printf("glob():ERROR:FindFirstFile: %i\n",GetLastError());
35 pglob
->gl_pathv
= malloc(sizeof(char*));
36 pglob
->gl_pathv
[0] = strdup(found_file
.cFileName
);
40 if(!FindNextFile(searchhndl
,&found_file
))
42 if(GetLastError()==ERROR_NO_MORE_FILES
)
44 //printf("glob(): no more files found\n");
49 //printf("glob():ERROR:FindNextFile:%i\n",GetLastError());
55 //printf("glob: found file %s\n",found_file.cFileName);
57 pglob
->gl_pathv
= realloc(pglob
->gl_pathv
,pglob
->gl_pathc
* sizeof(char*));
58 pglob
->gl_pathv
[pglob
->gl_pathc
-1] = strdup(found_file
.cFileName
);
61 FindClose(searchhndl
);
65 void globfree(glob_t
*pglob
)
68 for(i
=0; i
<pglob
->gl_pathc
;i
++)
70 free(pglob
->gl_pathv
[i
]);
72 free(pglob
->gl_pathv
);
74 #endif /*__MINGW32__*/
81 glob( "*.jpeg",0,NULL
,&gg
);
84 for(i
=0;i
<gg
.gl_pathc
;i
++)printf("GLOBED:%i %s\n",i
,gg
.gl_pathv
[i
]);