annotate win/dirent.c @ 2873:0bbfb19022e7

C++: GCC prior to 4.7 does not support the override keyword. So if using earlier versions of GCC, just remove override. This allows compilation on ancient GCC and GCC based Xcode. Also remove virtual from the application, I don't think it is needed and old GCC pukes on it when it is there.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 19 Dec 2022 07:42:12 +0000
parents 22e3e829be13
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1617
f8d1da63fb77 Add code to allow building DW.DLL as Unicode on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1601
diff changeset
1 #undef UNICODE
f8d1da63fb77 Add code to allow building DW.DLL as Unicode on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1601
diff changeset
2 #undef _UNICODE
f8d1da63fb77 Add code to allow building DW.DLL as Unicode on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1601
diff changeset
3
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4 #include <stdio.h>
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5 #include <stdlib.h>
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6 #include <string.h>
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7 #include <ctype.h>
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
8
1960
22e3e829be13 Win: Switch to using winsock 2.x, this will remove support for ancient versions of Windows like 95 and NT 3.5 and older...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1864
diff changeset
9 #include <winsock2.h>
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
10 #include <windows.h>
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
11
1839
22225eb286e5 Fixes for building with MINGW64 (specifically http://tdm-gcc.tdragon.net/).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1617
diff changeset
12 #define _DW_INTERNAL
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
13 #include "dwcompat.h"
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
14 #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
15 #include <direct.h>
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
16
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
17 #define error(rc) errno = 255
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
18
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
19 struct _dirdescr {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
20 HANDLE handle; /* DosFindFirst handle */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
21 char fstype; /* filesystem type */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
22 long count; /* valid entries in <ffbuf> */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
23 long number; /* absolute number of next entry */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
24 int index; /* relative number of next entry */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
25 char name[MAXPATHLEN+3]; /* directory name */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
26 unsigned attrmask; /* attribute mask for seekdir */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
27 struct dirent entry; /* buffer for directory entry */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
28 WIN32_FIND_DATA data;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
29 };
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
30
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
31 /*
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
32 * Return first char of filesystem type, or 0 if unknown.
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
33 */
1864
3816d76835e9 Some more MinGW build fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 1839
diff changeset
34 static char getFSType(const char *path)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
35 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
36 static char cache[1+26];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
37 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
38 UCHAR unit;
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
39 char r;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
40
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
41 if (isalpha(path[0]) && path[1] == ':') {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
42 unit = toupper(path[0]) - '@';
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
43 path += 2;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
44 } else {
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
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
48 if ((path[0] == '\\' || path[0] == '/')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
49 && (path[1] == '\\' || path[1] == '/'))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
50 return 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
51
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
52 if (cache [unit])
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
53 return cache [unit];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
54
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
55 drive[0] = '@' + unit;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
56 drive[1] = ':';
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
57 drive[2] = '\0';
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
58
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
59 r = GetDriveType(drive);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
60
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
61 return cache [unit] = r;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
62 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
63
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
64 char * API abs_path(const char *name, char *buffer, int len)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
65 {
260
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
66 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
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 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
69 {
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
70 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
71 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
72
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
73 _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
74
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
75 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
76 {
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
77 _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
78 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
79 }
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
80 _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
81 return NULL;
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
82 }
260
e320dc29bfcd Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 184
diff changeset
83 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
84 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
85 return NULL;
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
86 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
87
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
88 DIR * API openxdir(const char *path, unsigned att_mask)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
89 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
90 DIR *dir;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
91 char name[MAXPATHLEN+3];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
92
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
93 dir = malloc(sizeof(DIR));
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
94 if (dir == NULL) {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
95 errno = ENOMEM;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
96 return NULL;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
97 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
98
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
99 strncpy(name, path, MAXPATHLEN);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
100 name[MAXPATHLEN] = '\0';
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
101 switch (name[strlen(name)-1]) {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
102 default:
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
103 strcat(name, "\\");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
104 case '\\':
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
105 case '/':
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
106 case ':':
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
107 ;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
108 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
109 strcat(name, ".");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
110 if (!abs_path(name, dir->name, MAXPATHLEN+1))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
111 strcpy(dir->name, name);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
112 if (dir->name[strlen(dir->name)-1] == '\\')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
113 strcat(dir->name, "*");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
114 else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
115 strcat(dir->name, "\\*");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
116
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
117 dir->fstype = getFSType(dir->name);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
118 dir->attrmask = att_mask | A_DIR;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
119
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
120 dir->count = 100;
184
4ec906d40ce2 FindFirstFile returns INVALID_HANDLE_VALUE on error, not NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 3
diff changeset
121 if((dir->handle = FindFirstFile(dir->name, &dir->data))==INVALID_HANDLE_VALUE)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
122 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
123 free(dir);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
124 error(rc);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
125 return NULL;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
126 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
127
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
128 dir->number = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
129 dir->index = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
130
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
131 return (DIR *)dir;
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 DIR * API opendir(const char *pathname)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
135 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
136 return openxdir(pathname, 0);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
137 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
138
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
139 struct dirent * API readdir(DIR *dir)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
140 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
141 static int dummy_ino = 2;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
142
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
143 if (dir->number)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
144 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
145 dir->count = 100;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
146 if(!FindNextFile(dir->handle, &(dir->data)))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
147 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
148 error(rc);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
149 return NULL;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
150 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
151
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
152 dir->index = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
153 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
154
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
155 strcpy(dir->entry.d_name, dir->data.cFileName);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
156 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
157 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
158 dir->entry.d_namlen = (int)strlen(dir->data.cFileName);
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
159 dir->entry.d_size = dir->data.nFileSizeLow;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
160 dir->entry.d_attribute = dir->data.dwFileAttributes;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
161 #if 0
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
162 dir->entry.d_time = *(USHORT *)&dir->next->ftimeLastWrite;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
163 dir->entry.d_date = *(USHORT *)&dir->next->fdateLastWrite;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
164 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
165
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
166 dir->number++;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
167 dir->index++;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
168 return &dir->entry;
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 long API telldir(DIR *dir)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
172 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
173 return dir->number;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
174 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
175
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
176 void API seekdir(DIR *dir, long off)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
177 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
178 if (dir->number > off) {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
179 char name[MAXPATHLEN+2];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
180
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
181 FindClose(dir->handle);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
182
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
183 strcpy(name, dir->name);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
184 strcat(name, "*");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
185
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
186 if((dir->handle = FindFirstFile(name, &(dir->data)))==NULL)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
187 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
188 error(rc);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
189 return;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
190 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
191
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
192 dir->number = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
193 dir->index = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
194 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
195
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
196 while (dir->number < off && readdir(dir))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
197 ;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
198 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
199
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
200 void API closedir(DIR *dir)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
201 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
202 FindClose(dir->handle);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
203 free(dir);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
204 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
205
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
206 /*****************************************************************************/
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
207
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
208 #ifdef TEST
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
209
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
210 main(int argc, char **argv)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
211 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
212 int i;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
213 DIR *dir;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
214 struct dirent *ep;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
215
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
216 for (i = 1; i < argc; ++i) {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
217 dir = opendir(argv[i]);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
218 if (!dir)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
219 continue;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
220 while (ep = readdir(dir))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
221 if (strchr("\\/:", argv[i] [strlen(argv[i]) - 1]))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
222 printf("%s%s\n", argv[i], ep->d_name);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
223 else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
224 printf("%s/%s\n", argv[i], ep->d_name);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
225 closedir(dir);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
226 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
227
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
228 return 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
229 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
230
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
231 #endif