Fix vf_tcdump's compilation
[mplayer/kovensky.git] / osdep / glob-win.c
blob6cf29efd5f81f699694e7fae16bc56926db96e0d
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <sys/types.h>
20 #include <stdio.h>
22 #include "config.h"
24 #include <windows.h>
25 #include "glob.h"
27 int glob(const char *pattern, int flags,
28 int (*errfunc)(const char *epath, int eerrno), glob_t *pglob)
30 HANDLE searchhndl;
31 WIN32_FIND_DATA found_file;
32 if(errfunc)printf("glob():ERROR:Sorry errfunc not supported by this implementation\n");
33 if(flags)printf("glob():ERROR:Sorry no flags supported by this globimplementation\n");
34 //printf("PATTERN \"%s\"\n",pattern);
35 pglob->gl_pathc = 0;
36 searchhndl = FindFirstFile( pattern,&found_file);
37 if(searchhndl == INVALID_HANDLE_VALUE)
39 if(GetLastError() == ERROR_FILE_NOT_FOUND)
41 pglob->gl_pathc = 0;
42 //printf("could not find a file matching your search criteria\n");
43 return 1;
45 else
47 //printf("glob():ERROR:FindFirstFile: %i\n",GetLastError());
48 return 1;
51 pglob->gl_pathv = malloc(sizeof(char*));
52 pglob->gl_pathv[0] = strdup(found_file.cFileName);
53 pglob->gl_pathc++;
54 while(1)
56 if(!FindNextFile(searchhndl,&found_file))
58 if(GetLastError()==ERROR_NO_MORE_FILES)
60 //printf("glob(): no more files found\n");
61 break;
63 else
65 //printf("glob():ERROR:FindNextFile:%i\n",GetLastError());
66 return 1;
69 else
71 //printf("glob: found file %s\n",found_file.cFileName);
72 pglob->gl_pathc++;
73 pglob->gl_pathv = realloc(pglob->gl_pathv,pglob->gl_pathc * sizeof(char*));
74 pglob->gl_pathv[pglob->gl_pathc-1] = strdup(found_file.cFileName);
77 FindClose(searchhndl);
78 return 0;
81 void globfree(glob_t *pglob)
83 int i;
84 for(i=0; i <pglob->gl_pathc ;i++)
86 free(pglob->gl_pathv[i]);
88 free(pglob->gl_pathv);
91 #if 0
92 int main(void){
93 glob_t gg;
94 printf("globtest\n");
95 glob( "*.jpeg",0,NULL,&gg );
97 int i;
98 for(i=0;i<gg.gl_pathc;i++)printf("GLOBED:%i %s\n",i,gg.gl_pathv[i]);
100 globfree(&gg);
102 return 0;
104 #endif