Update to MPlayer SVN rev 28800 and FFmpeg SVN rev 17752.
[vaapi:mplayer.git] / osdep / glob-win.c
1 /*
2  * This file is part of MPlayer.
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #include <sys/types.h>
20 #include <stdio.h>
21
22 #include "config.h"
23
24 #include <windows.h>
25 #include "glob.h"
26
27 int glob(const char *pattern, int flags,
28           int (*errfunc)(const char *epath, int eerrno), glob_t *pglob)
29 {
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)
38         {
39                 if(GetLastError() == ERROR_FILE_NOT_FOUND)
40                 {
41                         pglob->gl_pathc = 0;
42                     //printf("could not find a file matching your search criteria\n");
43                 return 1;
44                 }
45                 else 
46                 {
47                         //printf("glob():ERROR:FindFirstFile: %i\n",GetLastError());
48                         return 1;
49                 }
50          }
51     pglob->gl_pathv = malloc(sizeof(char*));
52     pglob->gl_pathv[0] = strdup(found_file.cFileName);
53     pglob->gl_pathc++;
54     while(1)
55     {
56                 if(!FindNextFile(searchhndl,&found_file))
57                 {
58                         if(GetLastError()==ERROR_NO_MORE_FILES)
59                         {
60                                 //printf("glob(): no more files found\n");
61                 break;
62                         }
63                         else
64                         {
65                                 //printf("glob():ERROR:FindNextFile:%i\n",GetLastError());
66                                 return 1;
67                         }
68                 }
69                 else
70                 {
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);       
75                 }
76     }
77     FindClose(searchhndl);
78     return 0;
79 }
80
81 void globfree(glob_t *pglob)
82 {
83         int i;
84         for(i=0; i <pglob->gl_pathc ;i++)
85         {
86                 free(pglob->gl_pathv[i]);
87         }
88         free(pglob->gl_pathv);
89 }
90
91 #if 0
92 int main(void){
93    glob_t        gg;
94    printf("globtest\n");
95    glob( "*.jpeg",0,NULL,&gg );
96    {
97         int i;
98         for(i=0;i<gg.gl_pathc;i++)printf("GLOBED:%i %s\n",i,gg.gl_pathv[i]);
99     }
100    globfree(&gg);
101    
102    return 0;
103 }
104 #endif