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