Mercurial > mplayer.hg
comparison osdep/glob-win.c @ 9983:14c92818ab75
alternative timer and glob emulation code for mingw32 port
author | faust3 |
---|---|
date | Fri, 25 Apr 2003 10:00:18 +0000 |
parents | |
children | 7b0bc557987b |
comparison
equal
deleted
inserted
replaced
9982:cd76f332bdee | 9983:14c92818ab75 |
---|---|
1 #include <sys/types.h> | |
2 #include <stdio.h> | |
3 | |
4 #include "../config.h" | |
5 | |
6 #ifndef HAVE_GLOB | |
7 #ifdef __MINGW32__ | |
8 #undef DATADIR | |
9 #include <windows.h> | |
10 #include "glob.h" | |
11 | |
12 int glob(const char *pattern, int flags, | |
13 int (*errfunc)(const char *epath, int eerrno), glob_t *pglob) | |
14 { | |
15 HANDLE searchhndl; | |
16 WIN32_FIND_DATA found_file; | |
17 if(errfunc)printf("glob():ERROR:Sorry errfunc not supported by this implementation\n"); | |
18 if(flags)printf("glob():ERROR:Sorry no flags supported by this globimplementation\n"); | |
19 //printf("PATTERN \"%s\"\n",pattern); | |
20 pglob->gl_pathc = 0; | |
21 searchhndl = FindFirstFile( pattern,&found_file); | |
22 if(searchhndl == INVALID_HANDLE_VALUE) | |
23 { | |
24 if(GetLastError() == ERROR_FILE_NOT_FOUND) | |
25 { | |
26 pglob->gl_pathc = 0; | |
27 //printf("could not find a file matching your search criteria\n"); | |
28 return 1; | |
29 } | |
30 else | |
31 { | |
32 //printf("glob():ERROR:FindFirstFile: %i\n",GetLastError()); | |
33 return 1; | |
34 } | |
35 } | |
36 pglob->gl_pathv = malloc(sizeof(char*)); | |
37 pglob->gl_pathv[0] = strdup(found_file.cFileName); | |
38 pglob->gl_pathc++; | |
39 while(1) | |
40 { | |
41 if(!FindNextFile(searchhndl,&found_file)) | |
42 { | |
43 if(GetLastError()==ERROR_NO_MORE_FILES) | |
44 { | |
45 //printf("glob(): no more files found\n"); | |
46 break; | |
47 } | |
48 else | |
49 { | |
50 //printf("glob():ERROR:FindNextFile:%i\n",GetLastError()); | |
51 return 1; | |
52 } | |
53 } | |
54 else | |
55 { | |
56 //printf("glob: found file %s\n",found_file.cFileName); | |
57 pglob->gl_pathc++; | |
58 pglob->gl_pathv = realloc(pglob->gl_pathv,pglob->gl_pathc * sizeof(char*)); | |
59 pglob->gl_pathv[pglob->gl_pathc-1] = strdup(found_file.cFileName); | |
60 } | |
61 } | |
62 FindClose(searchhndl); | |
63 return 0; | |
64 } | |
65 | |
66 void globfree(glob_t *pglob) | |
67 { | |
68 int i; | |
69 for(i=0; i <pglob->gl_pathc ;i++) | |
70 { | |
71 free(pglob->gl_pathv[i]); | |
72 } | |
73 free(pglob->gl_pathv); | |
74 } | |
75 #endif /*__MINGW32__*/ | |
76 #endif /*HAVE_GLOB*/ | |
77 | |
78 #if 0 | |
79 int main(){ | |
80 glob_t gg; | |
81 printf("globtest\n"); | |
82 glob( "*.jpeg",0,NULL,&gg ); | |
83 { | |
84 int i; | |
85 for(i=0;i<gg.gl_pathc;i++)printf("GLOBED:%i %s\n",i,gg.gl_pathv[i]); | |
86 } | |
87 globfree(&gg); | |
88 | |
89 return 0; | |
90 } | |
91 #endif |