29
29
int glob(const char *pattern, int flags,
30
int (*errfunc)(const char *epath, int eerrno), glob_t *pglob)
30
int (*errfunc)(const char *epath, int eerrno), glob_t *pglob)
33
33
WIN32_FIND_DATA found_file;
34
if(errfunc)printf("glob():ERROR:Sorry errfunc not supported by this implementation\n");
35
if(flags)printf("glob():ERROR:Sorry no flags supported by this globimplementation\n");
36
//printf("PATTERN \"%s\"\n",pattern);
38
searchhndl = FindFirstFile( pattern,&found_file);
39
if(searchhndl == INVALID_HANDLE_VALUE)
41
if(GetLastError() == ERROR_FILE_NOT_FOUND)
44
//printf("could not find a file matching your search criteria\n");
49
//printf("glob():ERROR:FindFirstFile: %i\n",GetLastError());
53
pglob->gl_pathv = malloc(sizeof(char*));
35
printf("glob():ERROR:Sorry errfunc not supported by this implementation\n");
37
printf("glob():ERROR:Sorry no flags supported by this globimplementation\n");
38
//printf("PATTERN \"%s\"\n",pattern);
40
searchhndl = FindFirstFile(pattern, &found_file);
41
if (searchhndl == INVALID_HANDLE_VALUE) {
42
if (GetLastError() == ERROR_FILE_NOT_FOUND) {
44
//printf("could not find a file matching your search criteria\n");
47
//printf("glob():ERROR:FindFirstFile: %i\n",GetLastError());
51
pglob->gl_pathv = malloc(sizeof(char *));
54
52
pglob->gl_pathv[0] = strdup(found_file.cFileName);
58
if(!FindNextFile(searchhndl,&found_file))
60
if(GetLastError()==ERROR_NO_MORE_FILES)
62
//printf("glob(): no more files found\n");
55
if (!FindNextFile(searchhndl, &found_file)) {
56
if (GetLastError() == ERROR_NO_MORE_FILES) {
57
//printf("glob(): no more files found\n");
67
//printf("glob():ERROR:FindNextFile:%i\n",GetLastError());
60
//printf("glob():ERROR:FindNextFile:%i\n",GetLastError());
73
64
//printf("glob: found file %s\n",found_file.cFileName);
75
pglob->gl_pathv = realloc(pglob->gl_pathv,pglob->gl_pathc * sizeof(char*));
76
pglob->gl_pathv[pglob->gl_pathc-1] = strdup(found_file.cFileName);
66
pglob->gl_pathv = realloc(pglob->gl_pathv, pglob->gl_pathc * sizeof(char *));
67
pglob->gl_pathv[pglob->gl_pathc - 1] = strdup(found_file.cFileName);
79
70
FindClose(searchhndl);
83
74
void globfree(glob_t *pglob)
86
for(i=0; i <pglob->gl_pathc ;i++)
88
free(pglob->gl_pathv[i]);
90
free(pglob->gl_pathv);
77
for (i = 0; i < pglob->gl_pathc; i++)
78
free(pglob->gl_pathv[i]);
79
free(pglob->gl_pathv);
97
glob( "*.jpeg",0,NULL,&gg );
87
glob("*.jpeg", 0, NULL, &gg);
100
for(i=0;i<gg.gl_pathc;i++)printf("GLOBED:%i %s\n",i,gg.gl_pathv[i]);
90
for (i = 0; i < gg.gl_pathc; i++)
91
printf("GLOBED:%i %s\n", i, gg.gl_pathv[i]);