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