@@ -138,50 +138,18 @@ static BOOL Seek_File_64(REBREQ *file)
138
138
139
139
if (!h ) {
140
140
file -> modes = 0 ;
141
- if (dir -> file .path [0 ] == 0 ) {
142
- // Reading drives.. Rebol code: read %/
143
- len = (1 + GetLogicalDriveStrings (0 , NULL )) << 1 ;
144
- h = MAKE_MEM (len );
145
- GetLogicalDriveStrings (len , h );
146
- dir -> length = len ;
147
- dir -> actual = 0 ;
148
- file -> modes = 0 ;
149
- SET_FLAG (file -> modes , RFM_DIR );
150
- } else {
151
- // Read first file entry:
152
- h = FindFirstFile (dir -> file .path , & info );
153
- if (h == INVALID_HANDLE_VALUE ) {
154
- dir -> error = - RFE_OPEN_FAIL ;
155
- return DR_ERROR ;
156
- }
157
- cp = info .cFileName ;
141
+ // Read first file entry:
142
+ h = FindFirstFile (dir -> file .path , & info );
143
+ if (h == INVALID_HANDLE_VALUE ) {
144
+ dir -> error = - RFE_OPEN_FAIL ;
145
+ return DR_ERROR ;
158
146
}
147
+ cp = info .cFileName ;
159
148
dir -> handle = h ;
160
149
CLR_FLAG (dir -> flags , RRF_DONE );
161
150
}
162
-
163
- if (dir -> length > 0 ) {
164
- // Drive names processing...
165
- cp = (REBCHR * )h + dir -> actual ;
166
- file -> file .path = cp ;
167
- if (cp [0 ] == 0 || dir -> length <= dir -> actual ) {
168
- // end
169
- FREE_MEM (dir -> handle );
170
- dir -> handle = NULL ;
171
- SET_FLAG (dir -> flags , RRF_DONE ); // no more files
172
- return DR_DONE ;
173
- }
174
- while (cp [0 ] != 0 && dir -> length > dir -> actual ) {
175
- cp ++ ; dir -> actual ++ ;
176
- }
177
- cp [-2 ] = 0 ; // the names are as: "C:\" but we want just "C", so just terminate the string sooner
178
- dir -> actual ++ ; // skip the null after current drive name
179
- return DR_DONE ;
180
- }
181
- // regular DIR processing follows...
182
151
// Skip over the . and .. dir cases:
183
152
while (cp == 0 || (cp [0 ] == '.' && (cp [1 ] == 0 || (cp [1 ] == '.' && cp [2 ] == 0 )))) {
184
-
185
153
// Read next file entry, or error:
186
154
if (!FindNextFile (h , & info )) {
187
155
dir -> error = GetLastError ();
@@ -193,7 +161,6 @@ static BOOL Seek_File_64(REBREQ *file)
193
161
return DR_DONE ;
194
162
}
195
163
cp = info .cFileName ;
196
-
197
164
}
198
165
199
166
file -> modes = 0 ;
@@ -204,6 +171,46 @@ static BOOL Seek_File_64(REBREQ *file)
204
171
return DR_DONE ;
205
172
}
206
173
174
+ /***********************************************************************
175
+ **
176
+ */ static int Read_Drives (REBREQ * dir , REBREQ * file )
177
+ /*
178
+ ** Reading list of logical drives.. Rebol code: read %/
179
+ **
180
+ ***********************************************************************/
181
+ {
182
+ HANDLE h = (HANDLE )(dir -> handle );
183
+ REBCHR * cp = 0 ;
184
+ REBCNT len ;
185
+ if (!h ) {
186
+ len = (1 + GetLogicalDriveStrings (0 , NULL )) << 1 ;
187
+ h = MAKE_MEM (len );
188
+ GetLogicalDriveStrings (len , h );
189
+ dir -> length = len ;
190
+ dir -> actual = 0 ;
191
+ dir -> handle = h ;
192
+ file -> modes = 0 ;
193
+ CLR_FLAG (dir -> flags , RRF_DONE );
194
+ }
195
+ // Drive names processing...
196
+ cp = (REBCHR * )h + dir -> actual ;
197
+ file -> file .path = cp ;
198
+ if (cp [0 ] == 0 || dir -> length <= dir -> actual ) {
199
+ // end
200
+ FREE_MEM (dir -> handle );
201
+ dir -> handle = NULL ;
202
+ SET_FLAG (dir -> flags , RRF_DONE ); // no more files
203
+ return DR_DONE ;
204
+ }
205
+ while (cp [0 ] != 0 && dir -> length > dir -> actual ) {
206
+ cp ++ ; dir -> actual ++ ;
207
+ }
208
+ // the names are as: "C:\" but we want "C/"
209
+ cp [-2 ] = '/' ;
210
+ cp [-1 ] = 0 ;
211
+ dir -> actual ++ ; // skip the null after current drive name
212
+ return DR_DONE ;
213
+ }
207
214
208
215
/***********************************************************************
209
216
**
@@ -314,7 +321,10 @@ static BOOL Seek_File_64(REBREQ *file)
314
321
***********************************************************************/
315
322
{
316
323
if (GET_FLAG (file -> modes , RFM_DIR )) {
317
- return Read_Directory (file , (REBREQ * )file -> data );
324
+ if (!GET_FLAG (file -> modes , RFM_DRIVES ))
325
+ return Read_Directory (file , (REBREQ * )file -> data );
326
+ else
327
+ return Read_Drives (file , (REBREQ * )file -> data );
318
328
}
319
329
320
330
if (!file -> handle ) {
0 commit comments