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