]> icculus.org git repositories - btb/d2x.git/blob - arch/linux/findfile.c
This commit was generated by cvs2svn to compensate for changes in r2,
[btb/d2x.git] / arch / linux / findfile.c
1 #include <conf.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <glob.h>
5 #include "findfile.h"
6 #include "u_mem.h"
7 #include "error.h"
8
9 /* KLUDGE ALERT: evil globals */
10 static glob_t glob_a;
11 static int glob_whichfile;
12
13 int FileFindFirst(char *search_str, FILEFINDSTRUCT *ffstruct)
14 {
15   int r;
16   char *t;
17
18   Assert(search_str != NULL);
19   Assert(ffstruct != NULL);
20
21   r = glob(search_str, 0, NULL, &glob_a);
22   if (r == GLOB_NOMATCH) return -1;
23
24   glob_whichfile = 0;
25   
26   t = strrchr(glob_a.gl_pathv[glob_whichfile], '/');
27   if (t == NULL) t = glob_a.gl_pathv[glob_whichfile]; else t++;
28   strncpy(ffstruct->name, t, 255);
29   ffstruct->size = strlen(ffstruct->name); 
30   
31   return 0;
32 }
33
34 int FileFindNext(FILEFINDSTRUCT *ffstruct)
35 {
36   char *t;
37   
38   glob_whichfile++;
39
40   if (glob_whichfile >= glob_a.gl_pathc) return -1;
41
42   t = strrchr(glob_a.gl_pathv[glob_whichfile], '/');
43   if (t == NULL) t = glob_a.gl_pathv[glob_whichfile]; else t++;
44   strncpy(ffstruct->name, t, 255);
45   ffstruct->size = strlen(ffstruct->name); 
46   return 0;
47 }
48
49 int FileFindClose(void)
50 {
51  globfree(&glob_a);
52  return 0;
53 }