blob: 0e7585dda49c07f1f7eb2e3407fef21229259a86 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#ifndef DIR_H
#define DIR_H
# include <dirent.h>
# include <sys/stat.h>
# include <unistd.h>
struct ffblk
{
char *ff_name;
};
#if defined(MAC)
char separator = ':';
# define SEPSTR ":"
#else
char separator = '/';
# define SEPSTR "/"
#endif
DIR *dirp;
struct dirent *dir;
char directory[300];
int findnext(struct ffblk *ffb)
{
struct stat statbuf;
char filename[300];
for (dir = readdir(dirp); dir; dir = readdir(dirp))
{
ffb->ff_name = dir->d_name;
strcpy(filename, directory);
strcat(filename, SEPSTR);
strcat(filename, dir->d_name);
stat(filename,&statbuf);
if ((statbuf.st_mode & S_IFDIR) == 0) // Skip directories
return 0; // not done
}
return 1; // done
}
int findfirst(char *path, struct ffblk *ffb, int first)
{
int i;
char *ptr;
/* Localize Directory Separators */
for(i=0; i<strlen(path); i++)
{
if ((path[i] == '/') || (path[i] == '\\'))
{
path[i] = separator;
}
else
path[i] = tolower(path[i]);
}
strcpy(directory,path);
/* Remove any trailing separators (and anything after them) */
if ( (ptr = strrchr(directory, separator)) )
*ptr = 0;
dirp = opendir(directory);
if (!dirp)
return 1; // done
return findnext(ffb);
}
#endif /* DIR_H */
|