Fix email address
[mplayer/greg.git] / osdep / glob-win.c
blobd1e3dd87ae18bc7c111608db40700fac495fc7f0
1 #include <sys/types.h>
2 #include <stdio.h>
4 #include "../config.h"
6 #ifndef HAVE_GLOB
7 #ifdef __MINGW32__
8 #include <windows.h>
9 #include "glob.h"
11 int glob(const char *pattern, int flags,
12 int (*errfunc)(const char *epath, int eerrno), glob_t *pglob)
14 HANDLE searchhndl;
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);
19 pglob->gl_pathc = 0;
20 searchhndl = FindFirstFile( pattern,&found_file);
21 if(searchhndl == INVALID_HANDLE_VALUE)
23 if(GetLastError() == ERROR_FILE_NOT_FOUND)
25 pglob->gl_pathc = 0;
26 //printf("could not find a file matching your search criteria\n");
27 return 1;
29 else
31 //printf("glob():ERROR:FindFirstFile: %i\n",GetLastError());
32 return 1;
35 pglob->gl_pathv = malloc(sizeof(char*));
36 pglob->gl_pathv[0] = strdup(found_file.cFileName);
37 pglob->gl_pathc++;
38 while(1)
40 if(!FindNextFile(searchhndl,&found_file))
42 if(GetLastError()==ERROR_NO_MORE_FILES)
44 //printf("glob(): no more files found\n");
45 break;
47 else
49 //printf("glob():ERROR:FindNextFile:%i\n",GetLastError());
50 return 1;
53 else
55 //printf("glob: found file %s\n",found_file.cFileName);
56 pglob->gl_pathc++;
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);
62 return 0;
65 void globfree(glob_t *pglob)
67 int i;
68 for(i=0; i <pglob->gl_pathc ;i++)
70 free(pglob->gl_pathv[i]);
72 free(pglob->gl_pathv);
74 #endif /*__MINGW32__*/
75 #endif /*HAVE_GLOB*/
77 #if 0
78 int main(){
79 glob_t gg;
80 printf("globtest\n");
81 glob( "*.jpeg",0,NULL,&gg );
83 int i;
84 for(i=0;i<gg.gl_pathc;i++)printf("GLOBED:%i %s\n",i,gg.gl_pathv[i]);
86 globfree(&gg);
88 return 0;
90 #endif