9 int glob(const char *pattern
, int flags
,
10 int (*errfunc
)(const char *epath
, int eerrno
), glob_t
*pglob
)
13 WIN32_FIND_DATA found_file
;
14 if(errfunc
)printf("glob():ERROR:Sorry errfunc not supported by this implementation\n");
15 if(flags
)printf("glob():ERROR:Sorry no flags supported by this globimplementation\n");
16 //printf("PATTERN \"%s\"\n",pattern);
18 searchhndl
= FindFirstFile( pattern
,&found_file
);
19 if(searchhndl
== INVALID_HANDLE_VALUE
)
21 if(GetLastError() == ERROR_FILE_NOT_FOUND
)
24 //printf("could not find a file matching your search criteria\n");
29 //printf("glob():ERROR:FindFirstFile: %i\n",GetLastError());
33 pglob
->gl_pathv
= malloc(sizeof(char*));
34 pglob
->gl_pathv
[0] = strdup(found_file
.cFileName
);
38 if(!FindNextFile(searchhndl
,&found_file
))
40 if(GetLastError()==ERROR_NO_MORE_FILES
)
42 //printf("glob(): no more files found\n");
47 //printf("glob():ERROR:FindNextFile:%i\n",GetLastError());
53 //printf("glob: found file %s\n",found_file.cFileName);
55 pglob
->gl_pathv
= realloc(pglob
->gl_pathv
,pglob
->gl_pathc
* sizeof(char*));
56 pglob
->gl_pathv
[pglob
->gl_pathc
-1] = strdup(found_file
.cFileName
);
59 FindClose(searchhndl
);
63 void globfree(glob_t
*pglob
)
66 for(i
=0; i
<pglob
->gl_pathc
;i
++)
68 free(pglob
->gl_pathv
[i
]);
70 free(pglob
->gl_pathv
);
77 glob( "*.jpeg",0,NULL
,&gg
);
80 for(i
=0;i
<gg
.gl_pathc
;i
++)printf("GLOBED:%i %s\n",i
,gg
.gl_pathv
[i
]);