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