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