annotate win/dirent.c @ 1601:71e0a3ad07f7

Enable level 3 warnings in DEBUG mode with Visual C to show deprecation warnings. Source code cleanup to eliminate the warnings now generated on this level.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 26 Feb 2012 09:21:35 +0000
parents 6baf177f335c
children f8d1da63fb77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1 #include <stdio.h>
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2 #include <stdlib.h>
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3 #include <string.h>
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4 #include <ctype.h>
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6 #include <windows.h>
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7
1594
6baf177f335c Rename compat.c/h dwcompat.c/h and configure option to --with-dwcompat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1362
diff changeset
8 #include "dwcompat.h"
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
9 #include <errno.h>
1362
412af8059331 Attempt to get it building with Mingw again... builds but crashes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 572
diff changeset
10 #include <direct.h>
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
11
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
12 #define error(rc) errno = 255
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
13
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
14 struct _dirdescr {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
15 HANDLE handle; /* DosFindFirst handle */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
16 char fstype; /* filesystem type */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
17 long count; /* valid entries in <ffbuf> */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
18 long number; /* absolute number of next entry */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
19 int index; /* relative number of next entry */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
20 char name[MAXPATHLEN+3]; /* directory name */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
21 unsigned attrmask; /* attribute mask for seekdir */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
22 struct dirent entry; /* buffer for directory entry */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
23 WIN32_FIND_DATA data;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
24 };
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
25
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
26 /*
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
27 * Return first char of filesystem type, or 0 if unknown.
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
28 */
527
e0ea29c3d1eb Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 260
diff changeset
29 static char API getFSType(const char *path)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
30 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
31 static char cache[1+26];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
32 char drive[3];
1601
71e0a3ad07f7 Enable level 3 warnings in DEBUG mode with Visual C to show deprecation warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1594
diff changeset
33 UCHAR unit;
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
34 char r;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
35
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
36 if (isalpha(path[0]) && path[1] == ':') {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
37 unit = toupper(path[0]) - '@';
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
38 path += 2;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
39 } else {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
40 return 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
41 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
42
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
43 if ((path[0] == '\\' || path[0] == '/')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
44 && (path[1] == '\\' || path[1] == '/'))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
45 return 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
46
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
47 if (cache [unit])
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
48 return cache [unit];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
49
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
50 drive[0] = '@' + unit;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
51 drive[1] = ':';
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
52 drive[2] = '\0';
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
53
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
54 r = GetDriveType(drive);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
55
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
56 return cache [unit] = r;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
57 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
58
527
e0ea29c3d1eb Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 260
diff changeset
59 char * API abs_path(const char *name, char *buffer, int len)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
60 {
260
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
61 LPTSTR file;
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
62
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
63 if(isalpha(name[0]) && name[1] == ':' && name[2] == '\0')
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
64 {
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
65 int drive = _getdrive();
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
66 char newdrive = toupper(name[0]);
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
67
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
68 _chdrive((newdrive - 'A')+1);
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
69
1601
71e0a3ad07f7 Enable level 3 warnings in DEBUG mode with Visual C to show deprecation warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1594
diff changeset
70 if(_getcwd(buffer, len))
260
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
71 {
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
72 _chdrive(drive);
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
73 return buffer;
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
74 }
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
75 _chdrive(drive);
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
76 return NULL;
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
77 }
260
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
78 if(GetFullPathName(name, len, buffer, &file))
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
79 return buffer;
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
80 return NULL;
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
81 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
82
527
e0ea29c3d1eb Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 260
diff changeset
83 DIR * API openxdir(const char *path, unsigned att_mask)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
84 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
85 DIR *dir;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
86 char name[MAXPATHLEN+3];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
87
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
88 dir = malloc(sizeof(DIR));
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
89 if (dir == NULL) {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
90 errno = ENOMEM;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
91 return NULL;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
92 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
93
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
94 strncpy(name, path, MAXPATHLEN);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
95 name[MAXPATHLEN] = '\0';
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
96 switch (name[strlen(name)-1]) {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
97 default:
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
98 strcat(name, "\\");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
99 case '\\':
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
100 case '/':
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
101 case ':':
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
102 ;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
103 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
104 strcat(name, ".");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
105 if (!abs_path(name, dir->name, MAXPATHLEN+1))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
106 strcpy(dir->name, name);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
107 if (dir->name[strlen(dir->name)-1] == '\\')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
108 strcat(dir->name, "*");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
109 else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
110 strcat(dir->name, "\\*");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
111
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
112 dir->fstype = getFSType(dir->name);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
113 dir->attrmask = att_mask | A_DIR;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
114
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
115 dir->count = 100;
184
4ec906d40ce2 FindFirstFile returns INVALID_HANDLE_VALUE on error, not NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 3
diff changeset
116 if((dir->handle = FindFirstFile(dir->name, &dir->data))==INVALID_HANDLE_VALUE)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
117 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
118 free(dir);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
119 error(rc);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
120 return NULL;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
121 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
122
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
123 dir->number = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
124 dir->index = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
125
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
126 return (DIR *)dir;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
127 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
128
527
e0ea29c3d1eb Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 260
diff changeset
129 DIR * API opendir(const char *pathname)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
130 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
131 return openxdir(pathname, 0);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
132 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
133
527
e0ea29c3d1eb Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 260
diff changeset
134 struct dirent * API readdir(DIR *dir)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
135 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
136 static int dummy_ino = 2;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
137
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
138 if (dir->number)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
139 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
140 dir->count = 100;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
141 if(!FindNextFile(dir->handle, &(dir->data)))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
142 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
143 error(rc);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
144 return NULL;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
145 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
146
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
147 dir->index = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
148 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
149
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
150 strcpy(dir->entry.d_name, dir->data.cFileName);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
151 dir->entry.d_ino = dummy_ino++;
1601
71e0a3ad07f7 Enable level 3 warnings in DEBUG mode with Visual C to show deprecation warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1594
diff changeset
152 dir->entry.d_reclen = (int)strlen(dir->data.cFileName);
71e0a3ad07f7 Enable level 3 warnings in DEBUG mode with Visual C to show deprecation warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1594
diff changeset
153 dir->entry.d_namlen = (int)strlen(dir->data.cFileName);
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
154 dir->entry.d_size = dir->data.nFileSizeLow;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
155 dir->entry.d_attribute = dir->data.dwFileAttributes;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
156 #if 0
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
157 dir->entry.d_time = *(USHORT *)&dir->next->ftimeLastWrite;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
158 dir->entry.d_date = *(USHORT *)&dir->next->fdateLastWrite;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
159 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
160
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
161 dir->number++;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
162 dir->index++;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
163 return &dir->entry;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
164 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
165
527
e0ea29c3d1eb Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 260
diff changeset
166 long API telldir(DIR *dir)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
167 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
168 return dir->number;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
169 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
170
527
e0ea29c3d1eb Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 260
diff changeset
171 void API seekdir(DIR *dir, long off)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
172 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
173 if (dir->number > off) {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
174 char name[MAXPATHLEN+2];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
175
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
176 FindClose(dir->handle);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
177
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
178 strcpy(name, dir->name);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
179 strcat(name, "*");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
180
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
181 if((dir->handle = FindFirstFile(name, &(dir->data)))==NULL)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
182 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
183 error(rc);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
184 return;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
185 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
186
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
187 dir->number = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
188 dir->index = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
189 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
190
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
191 while (dir->number < off && readdir(dir))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
192 ;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
193 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
194
527
e0ea29c3d1eb Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 260
diff changeset
195 void API closedir(DIR *dir)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
196 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
197 FindClose(dir->handle);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
198 free(dir);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
199 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
200
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
201 /*****************************************************************************/
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
202
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
203 #ifdef TEST
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
204
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
205 main(int argc, char **argv)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
206 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
207 int i;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
208 DIR *dir;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
209 struct dirent *ep;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
210
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
211 for (i = 1; i < argc; ++i) {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
212 dir = opendir(argv[i]);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
213 if (!dir)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
214 continue;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
215 while (ep = readdir(dir))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
216 if (strchr("\\/:", argv[i] [strlen(argv[i]) - 1]))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
217 printf("%s%s\n", argv[i], ep->d_name);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
218 else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
219 printf("%s/%s\n", argv[i], ep->d_name);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
220 closedir(dir);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
221 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
222
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
223 return 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
224 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
225
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
226 #endif