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>
27 int glob(const char *pattern
, int flags
,
28 int (*errfunc
)(const char *epath
, int eerrno
), glob_t
*pglob
)
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);
36 searchhndl
= FindFirstFile( pattern
,&found_file
);
37 if(searchhndl
== INVALID_HANDLE_VALUE
)
39 if(GetLastError() == ERROR_FILE_NOT_FOUND
)
42 //printf("could not find a file matching your search criteria\n");
47 //printf("glob():ERROR:FindFirstFile: %i\n",GetLastError());
51 pglob
->gl_pathv
= malloc(sizeof(char*));
52 pglob
->gl_pathv
[0] = strdup(found_file
.cFileName
);
56 if(!FindNextFile(searchhndl
,&found_file
))
58 if(GetLastError()==ERROR_NO_MORE_FILES
)
60 //printf("glob(): no more files found\n");
65 //printf("glob():ERROR:FindNextFile:%i\n",GetLastError());
71 //printf("glob: found file %s\n",found_file.cFileName);
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
);
81 void globfree(glob_t
*pglob
)
84 for(i
=0; i
<pglob
->gl_pathc
;i
++)
86 free(pglob
->gl_pathv
[i
]);
88 free(pglob
->gl_pathv
);
95 glob( "*.jpeg",0,NULL
,&gg
);
98 for(i
=0;i
<gg
.gl_pathc
;i
++)printf("GLOBED:%i %s\n",i
,gg
.gl_pathv
[i
]);