]> icculus.org git repositories - btb/d2x.git/blob - arch/linux/findfile.c
fix a couple of defines
[btb/d2x.git] / arch / linux / findfile.c
1 /* $Id: findfile.c,v 1.7 2003-03-13 00:20:21 btb Exp $ */
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   if (! glob_a.gl_pathc) return 1;
36
37   glob_whichfile = 0;
38   
39   t = strrchr(glob_a.gl_pathv[glob_whichfile], '/');
40   if (t == NULL) t = glob_a.gl_pathv[glob_whichfile]; else t++;
41   strncpy(ffstruct->name, t, 255);
42   ffstruct->size = strlen(ffstruct->name); 
43   
44   return 0;
45 }
46
47 int FileFindNext(FILEFINDSTRUCT *ffstruct)
48 {
49   char *t;
50   
51   glob_whichfile++;
52
53   if (glob_whichfile >= glob_a.gl_pathc) return -1;
54
55   t = strrchr(glob_a.gl_pathv[glob_whichfile], '/');
56   if (t == NULL) t = glob_a.gl_pathv[glob_whichfile]; else t++;
57   strncpy(ffstruct->name, t, 255);
58   ffstruct->size = strlen(ffstruct->name); 
59   return 0;
60 }
61
62 int FileFindClose(void)
63 {
64  globfree(&glob_a);
65  return 0;
66 }