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