Add missing #include, fixes the warning:
[mplayer/greg.git] / osdep / glob-win.c
blobf0764bba37b20e0338b71fa37ded1c5f01b4642b
1 #include <sys/types.h>
2 #include <stdio.h>
4 #include "config.h"
6 #include <windows.h>
7 #include "glob.h"
9 int glob(const char *pattern, int flags,
10 int (*errfunc)(const char *epath, int eerrno), glob_t *pglob)
12 HANDLE searchhndl;
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);
17 pglob->gl_pathc = 0;
18 searchhndl = FindFirstFile( pattern,&found_file);
19 if(searchhndl == INVALID_HANDLE_VALUE)
21 if(GetLastError() == ERROR_FILE_NOT_FOUND)
23 pglob->gl_pathc = 0;
24 //printf("could not find a file matching your search criteria\n");
25 return 1;
27 else
29 //printf("glob():ERROR:FindFirstFile: %i\n",GetLastError());
30 return 1;
33 pglob->gl_pathv = malloc(sizeof(char*));
34 pglob->gl_pathv[0] = strdup(found_file.cFileName);
35 pglob->gl_pathc++;
36 while(1)
38 if(!FindNextFile(searchhndl,&found_file))
40 if(GetLastError()==ERROR_NO_MORE_FILES)
42 //printf("glob(): no more files found\n");
43 break;
45 else
47 //printf("glob():ERROR:FindNextFile:%i\n",GetLastError());
48 return 1;
51 else
53 //printf("glob: found file %s\n",found_file.cFileName);
54 pglob->gl_pathc++;
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);
60 return 0;
63 void globfree(glob_t *pglob)
65 int i;
66 for(i=0; i <pglob->gl_pathc ;i++)
68 free(pglob->gl_pathv[i]);
70 free(pglob->gl_pathv);
73 #if 0
74 int main(void){
75 glob_t gg;
76 printf("globtest\n");
77 glob( "*.jpeg",0,NULL,&gg );
79 int i;
80 for(i=0;i<gg.gl_pathc;i++)printf("GLOBED:%i %s\n",i,gg.gl_pathv[i]);
82 globfree(&gg);
84 return 0;
86 #endif