-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcedir.c
120 lines (94 loc) · 2.37 KB
/
cedir.c
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// cedir.c
//
// Time-stamp: <27/08/01 12:50:30 [email protected]>
#include <windows.h>
#include <errno.h>
#include <sys/stat.h>
#include <malloc.h>
#include "ndir.h"
#define MAXPATHLEN 255
static struct direct dir_static;
#define IS_DIRECTORY_SEP(x) (x == '\\' || x == '/')
DIR *
xceopendir (char *fname)
{
DIR *dirp;
struct xcestat statbuf;
char filename[MAXPATHLEN];
char *p, *d;
XCETrace("opendir(%s)", fname);
if(strcmp(fname, ".") == 0)
XCEGetCurrentDirectoryA(sizeof(filename), filename);
else
XCEFixPathA(fname, filename);
XCETrace("opendir2(%s)", filename);
if(xcestat(filename, &statbuf) < 0)
return NULL;
if(!(statbuf.st_mode & S_IFDIR))
return NULL;
if (!(dirp = (DIR *) malloc (sizeof (DIR))))
{
errno = ENOMEM;
return NULL;
}
dirp->dd_handle = INVALID_HANDLE_VALUE;
dirp->dd_isfat = 1;
dirp->dd_fd = 0;
dirp->dd_loc = 0;
dirp->dd_size = 0;
strcpy(dirp->dd_path, filename);
return dirp;
}
void
xceclosedir (DIR *dirp)
{
if (dirp->dd_handle != INVALID_HANDLE_VALUE)
{
FindClose ((HANDLE)dirp->dd_handle);
}
free ((char *) dirp);
}
struct direct *
xcereaddir (DIR *dirp)
{
WIN32_FIND_DATA find_data;
#ifdef UNDER_CE
if(dirp->dd_loc == 0)
{
strcpy(find_data.cFileName, ".");
}
else if(dirp->dd_loc == 1)
{
strcpy(find_data.cFileName, "..");
}
else
#endif
if (dirp->dd_handle == INVALID_HANDLE_VALUE)
{
char filename[MAXNAMLEN + 3];
int ln;
XCEFixPathA(dirp->dd_path, filename);
ln = strlen (filename) - 1;
if (!IS_DIRECTORY_SEP (filename[ln]))
strcat (filename, "\\");
strcat (filename, "*");
// printf("FindFirstFile: %s\n", filename);
dirp->dd_handle = (HANDLE)XCEFindFirstFileA (filename, &find_data);
if (dirp->dd_handle == INVALID_HANDLE_VALUE)
return NULL;
}
else
{
if (!XCEFindNextFileA ((HANDLE)dirp->dd_handle, &find_data))
return NULL;
}
dir_static.d_ino = 1;
#ifdef UNDER_CE
dirp->dd_loc++;
#endif
dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 +
dir_static.d_namlen - dir_static.d_namlen % 4;
dir_static.d_namlen = strlen (find_data.cFileName);
strcpy (dir_static.d_name, find_data.cFileName);
return &dir_static;
}