author | Jan Vrany <jan.vrany@labware.com> |
Wed, 22 Mar 2023 13:57:18 +0000 | |
branch | jv |
changeset 25445 | 1623217d2268 |
parent 23107 | 40173e082cbc |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
23107 | 3 |
COPYRIGHT (c) 2017 Jan Vrany |
155 | 4 |
All Rights Reserved |
1 | 5 |
|
6 |
This software is furnished under a license and may be used |
|
7 |
only in accordance with the terms of that license and with the |
|
8 |
inclusion of the above copyright notice. This software may not |
|
9 |
be provided or otherwise made available to, or used by, any |
|
10 |
other person. No title to or ownership of the software is |
|
11 |
hereby transferred. |
|
12 |
" |
|
7826 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
17287 | 15 |
"{ NameSpace: Smalltalk }" |
16 |
||
1 | 17 |
FileStream subclass:#DirectoryStream |
1664 | 18 |
instanceVariableNames:'dirPointer readAheadEntry' |
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
19 |
classVariableNames:'' |
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
20 |
poolDictionaries:'' |
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
21 |
category:'Streams-External' |
1 | 22 |
! |
23 |
||
217 | 24 |
!DirectoryStream primitiveDefinitions! |
1 | 25 |
%{ |
17076 | 26 |
#include "stxOSDefs.h" |
27 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19651
diff
changeset
|
28 |
#if defined(__win32__) |
1631 | 29 |
# undef UNIX_LIKE |
16297 | 30 |
#else |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19651
diff
changeset
|
31 |
# if defined(__transputer__) |
16297 | 32 |
# undef UNIX_LIKE |
33 |
# else |
|
34 |
# define UNIX_LIKE |
|
35 |
# endif |
|
2896 | 36 |
#endif |
37 |
||
1631 | 38 |
#ifdef UNIX_LIKE |
7955
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
39 |
# if defined(__GLIBC__) && (__GLIBC__ == 2) |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
40 |
# if defined(__GLIBC_MINOR__) && (__GLIBC_MINOR__ == 1) |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
41 |
/* there is a bug there, preventing 64bit readdir. */ |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
42 |
# undef __USE_FILE_OFFSET64 |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
43 |
# undef __USE_LARGEFILE64 |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
44 |
# endif |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
45 |
# endif |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
46 |
|
1631 | 47 |
# include <stdio.h> |
48 |
# define _STDIO_H_INCLUDED_ |
|
49 |
||
50 |
# include <errno.h> |
|
51 |
# define _ERRNO_H_INCLUDED_ |
|
10 | 52 |
|
2896 | 53 |
# include <sys/types.h> |
54 |
# include <sys/stat.h> |
|
1631 | 55 |
|
2896 | 56 |
# ifdef HAS_OPENDIR |
57 |
# include <sys/types.h> |
|
58 |
# ifdef NEXT |
|
59 |
# include <sys/dir.h> |
|
8881
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
60 |
# define DIRENT_STRUCT struct direct |
2896 | 61 |
# else |
62 |
# include <dirent.h> |
|
8881
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
63 |
# define DIRENT_STRUCT struct dirent |
1 | 64 |
# endif |
65 |
# endif |
|
223 | 66 |
|
67 |
/* |
|
68 |
* on some systems errno is a macro ... check for it here |
|
69 |
*/ |
|
1631 | 70 |
# ifndef errno |
71 |
extern errno; |
|
72 |
# endif |
|
2896 | 73 |
|
1631 | 74 |
#endif /* UNIX_LIKE */ |
75 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19651
diff
changeset
|
76 |
#ifdef __win32__ |
1631 | 77 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
78 |
# ifdef __i386__ |
1631 | 79 |
# define _X86_ |
80 |
# endif |
|
81 |
||
82 |
# undef INT |
|
14644 | 83 |
# undef UINT |
1631 | 84 |
# undef Array |
85 |
# undef Number |
|
86 |
# undef Method |
|
87 |
# undef Point |
|
88 |
# undef Context |
|
89 |
# undef Rectangle |
|
1989 | 90 |
# undef Block |
4298 | 91 |
# undef Time |
92 |
# undef Date |
|
10342 | 93 |
# undef Message |
94 |
# undef Process |
|
95 |
# undef Processor |
|
96 |
# undef INT |
|
1631 | 97 |
|
2685 | 98 |
/* # include <types.h> /* */ |
1989 | 99 |
# include <stdarg.h> /* */ |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4526
diff
changeset
|
100 |
# include <errno.h> |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4526
diff
changeset
|
101 |
# define _ERRNO_H_INCLUDED_ |
1989 | 102 |
# include <windef.h> /* */ |
103 |
# include <winbase.h> /* */ |
|
4298 | 104 |
/* # include <wingdi.h> /* */ |
105 |
/* # include <winuser.h> /* */ |
|
1631 | 106 |
|
107 |
# ifdef __DEF_Array |
|
108 |
# define Array __DEF_Array |
|
109 |
# endif |
|
110 |
# ifdef __DEF_Number |
|
111 |
# define Number __DEF_Number |
|
112 |
# endif |
|
113 |
# ifdef __DEF_Method |
|
114 |
# define Method __DEF_Method |
|
115 |
# endif |
|
116 |
# ifdef __DEF_Point |
|
117 |
# define Point __DEF_Point |
|
118 |
# endif |
|
1989 | 119 |
# ifdef __DEF_Block |
120 |
# define Block __DEF_Block |
|
121 |
# endif |
|
1631 | 122 |
# ifdef __DEF_Context |
123 |
# define Context __DEF_Context |
|
124 |
# endif |
|
4298 | 125 |
# ifdef __DEF_Date |
126 |
# define Date __DEF_Date |
|
127 |
# endif |
|
128 |
# ifdef __DEF_Time |
|
129 |
# define Time __DEF_Time |
|
130 |
# endif |
|
10342 | 131 |
# ifdef __DEF_Message |
132 |
# define Message __DEF_Message |
|
133 |
# endif |
|
134 |
# ifdef __DEF_Process |
|
135 |
# define Process __DEF_Process |
|
136 |
# endif |
|
137 |
# ifdef __DEF_Processor |
|
138 |
# define Processor __DEF_Processor |
|
139 |
# endif |
|
14644 | 140 |
|
141 |
# define INT STX_INT |
|
142 |
# define UINT STX_UINT |
|
1631 | 143 |
|
2999
b0e55440cf12
eliminate MKOBJ & MKCP (use MKEXTERNALADDRESS & externalAddressVal)
Claus Gittinger <cg@exept.de>
parents:
2982
diff
changeset
|
144 |
# define __HANDLEVal(o) (HANDLE)__externalAddressVal(o) |
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
145 |
// extern OBJ FileTimeToOsTime(); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
146 |
extern OBJ FileTimeToOsTime1970(); |
20488 | 147 |
#endif /* __win32__ */ |
1631 | 148 |
|
12714 | 149 |
#include "stxOSDefs.h" |
1 | 150 |
%} |
206 | 151 |
! ! |
1 | 152 |
|
438 | 153 |
!DirectoryStream primitiveFunctions! |
154 |
%{ |
|
2896 | 155 |
|
156 |
#ifndef HAS_OPENDIR |
|
7955
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
157 |
|
2896 | 158 |
# if defined(__VMS__) |
159 |
||
3816
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
160 |
# define lib$find_file LIB$FIND_FILE |
438 | 161 |
|
162 |
/* |
|
163 |
** VMS readdir() routines. |
|
164 |
** Written by Rich $alz, <rsalz@bbn.com> in August, 1990. |
|
165 |
** This code has no copyright. |
|
166 |
*/ |
|
167 |
||
8881
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
168 |
/* 12-NOV-1990 added d_namlen field and special case "." name -GJC@MITECH.COM |
438 | 169 |
*/ |
170 |
||
2896 | 171 |
# ifndef _STDIO_H_INCLUDED_ |
172 |
# include <stdio.h> |
|
173 |
# define _STDIO_H_INCLUDED_ |
|
174 |
# endif |
|
438 | 175 |
|
2896 | 176 |
# ifndef _CTYPE_H_INCLUDED_ |
177 |
# include <ctype.h> |
|
178 |
# define _CTYPE_H_INCLUDED_ |
|
179 |
# endif |
|
438 | 180 |
|
2896 | 181 |
# ifndef _ERRNO_H_INCLUDED_ |
182 |
# include <errno.h> |
|
183 |
# define _ERRNO_H_INCLUDED_ |
|
184 |
# endif |
|
438 | 185 |
|
2896 | 186 |
# ifndef _DESCRIP_H_INCLUDED_ |
187 |
# include <descrip.h> |
|
188 |
# define _DESCRIP_H_INCLUDED_ |
|
189 |
# endif |
|
438 | 190 |
|
2896 | 191 |
# ifndef _RMSDEF_H_INCLUDED_ |
192 |
# include <rmsdef.h> |
|
193 |
# define _RMSDEF_H_INCLUDED_ |
|
194 |
# endif |
|
438 | 195 |
|
196 |
/* |
|
197 |
* actually, the following has to go into dirent.h ... |
|
198 |
*/ |
|
2896 | 199 |
/* BEGIN included dirent.h |
438 | 200 |
* |
201 |
** Header file for VMS readdir() routines. |
|
202 |
** Written by Rich $alz, <rsalz@bbn.com> in August, 1990. |
|
203 |
** This code has no copyright. |
|
204 |
** |
|
205 |
** You must #include <descrip.h> before this file. |
|
206 |
*/ |
|
207 |
||
208 |
/* 12-NOV-1990 added d_namlen field -GJC@MITECH.COM */ |
|
209 |
||
210 |
/* Data structure returned by READDIR(). */ |
|
211 |
struct dirent { |
|
212 |
char d_name[100]; /* File name */ |
|
213 |
int d_namlen; |
|
2957 | 214 |
int vms_verscount; /* Number of versions */ |
215 |
int vms_versions[20]; /* Version numbers */ |
|
438 | 216 |
}; |
217 |
||
218 |
/* Handle returned by opendir(), used by the other routines. You |
|
219 |
* are not supposed to care what's inside this structure. */ |
|
220 |
typedef struct _dirdesc { |
|
221 |
long context; |
|
2957 | 222 |
int vms_wantversions; |
438 | 223 |
char *pattern; |
224 |
struct dirent entry; |
|
225 |
struct dsc$descriptor_s pat; |
|
226 |
} DIR; |
|
227 |
||
228 |
||
229 |
#define rewinddir(dirp) seekdir((dirp), 0L) |
|
230 |
||
231 |
||
232 |
extern DIR *opendir(); |
|
233 |
extern struct dirent *readdir(); |
|
234 |
extern long telldir(); |
|
235 |
extern void seekdir(); |
|
236 |
extern void closedir(); |
|
237 |
extern void vmsreaddirversions(); |
|
238 |
/* |
|
239 |
* END dirent.h |
|
240 |
*/ |
|
2896 | 241 |
#define _DIRENT_H_INCLUDED_ |
438 | 242 |
|
243 |
||
244 |
/* Number of elements in vms_versions array */ |
|
245 |
#define VERSIZE(e) (sizeof e->vms_versions / sizeof e->vms_versions[0]) |
|
246 |
||
247 |
/* Linked in later. */ |
|
248 |
extern char *strrchr(); |
|
249 |
extern char *strcpy(); |
|
250 |
/* Don't need this when all these programs are lumped together. RLD |
|
251 |
extern char *malloc(); |
|
252 |
*/ |
|
253 |
||
254 |
/* |
|
255 |
** Open a directory, return a handle for later use. |
|
256 |
*/ |
|
257 |
DIR * |
|
258 |
opendir(name) |
|
259 |
char *name; |
|
260 |
{ |
|
261 |
DIR *dd; |
|
262 |
||
263 |
/* Get memory for the handle, and the pattern. */ |
|
264 |
if ((dd = (DIR *)malloc(sizeof *dd)) == NULL) { |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4526
diff
changeset
|
265 |
__threadErrno = ENOMEM; |
438 | 266 |
return NULL; |
267 |
} |
|
268 |
||
269 |
if (strcmp(".",name) == 0) name = ""; |
|
270 |
||
271 |
dd->pattern = malloc((unsigned int)(strlen(name) + sizeof "*.*" + 1)); |
|
272 |
if (dd->pattern == NULL) { |
|
273 |
free((char *)dd); |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4526
diff
changeset
|
274 |
__threadErrno = ENOMEM; |
438 | 275 |
return NULL; |
276 |
} |
|
277 |
||
278 |
/* Fill in the fields; mainly playing with the descriptor. */ |
|
279 |
(void)sprintf(dd->pattern, "%s*.*", name); |
|
280 |
dd->context = 0; |
|
281 |
dd->vms_wantversions = 0; |
|
282 |
dd->pat.dsc$a_pointer = dd->pattern; |
|
283 |
dd->pat.dsc$w_length = strlen(dd->pattern); |
|
284 |
dd->pat.dsc$b_dtype = DSC$K_DTYPE_T; |
|
285 |
dd->pat.dsc$b_class = DSC$K_CLASS_S; |
|
286 |
||
287 |
return dd; |
|
288 |
} |
|
289 |
||
290 |
/* |
|
291 |
** Set the flag to indicate we want versions or not. |
|
292 |
*/ |
|
293 |
void |
|
294 |
vmsreaddirversions(dd, flag) |
|
295 |
DIR *dd; |
|
296 |
int flag; |
|
297 |
{ |
|
298 |
dd->vms_wantversions = flag; |
|
299 |
} |
|
300 |
||
301 |
/* |
|
302 |
** Free up an opened directory. |
|
303 |
*/ |
|
304 |
void |
|
305 |
closedir(dd) |
|
306 |
DIR *dd; |
|
307 |
{ |
|
308 |
free(dd->pattern); |
|
309 |
free((char *)dd); |
|
310 |
} |
|
311 |
||
312 |
/* |
|
313 |
** Collect all the version numbers for the current file. |
|
314 |
*/ |
|
315 |
static void |
|
316 |
collectversions(dd) |
|
317 |
DIR *dd; |
|
318 |
{ |
|
319 |
struct dsc$descriptor_s pat; |
|
320 |
struct dsc$descriptor_s res; |
|
321 |
struct dirent *e; |
|
322 |
char *p; |
|
323 |
char buff[sizeof dd->entry.d_name]; |
|
324 |
int i; |
|
325 |
char *text; |
|
326 |
long context; |
|
327 |
||
328 |
/* Convenient shorthand. */ |
|
329 |
e = &dd->entry; |
|
330 |
||
331 |
/* Add the version wildcard, ignoring the "*.*" put on before */ |
|
332 |
i = strlen(dd->pattern); |
|
333 |
text = malloc((unsigned int)(i + strlen(e->d_name)+ 2 + 1)); |
|
334 |
if (text == NULL) |
|
335 |
return; |
|
336 |
(void)strcpy(text, dd->pattern); |
|
337 |
(void)sprintf(&text[i - 3], "%s;*", e->d_name); |
|
338 |
||
339 |
/* Set up the pattern descriptor. */ |
|
340 |
pat.dsc$a_pointer = text; |
|
341 |
pat.dsc$w_length = strlen(text); |
|
342 |
pat.dsc$b_dtype = DSC$K_DTYPE_T; |
|
343 |
pat.dsc$b_class = DSC$K_CLASS_S; |
|
344 |
||
345 |
/* Set up result descriptor. */ |
|
346 |
res.dsc$a_pointer = buff; |
|
347 |
res.dsc$w_length = sizeof buff - 2; |
|
348 |
res.dsc$b_dtype = DSC$K_DTYPE_T; |
|
349 |
res.dsc$b_class = DSC$K_CLASS_S; |
|
350 |
||
351 |
/* Read files, collecting versions. */ |
|
352 |
for (context = 0; e->vms_verscount < VERSIZE(e); e->vms_verscount++) { |
|
353 |
if (lib$find_file(&pat, &res, &context) == RMS$_NMF || context == 0) |
|
354 |
break; |
|
355 |
buff[sizeof buff - 1] = '\0'; |
|
356 |
if (p = strchr(buff, ';')) |
|
357 |
e->vms_versions[e->vms_verscount] = atoi(p + 1); |
|
358 |
else |
|
359 |
e->vms_versions[e->vms_verscount] = -1; |
|
360 |
} |
|
361 |
||
362 |
free(text); |
|
363 |
} |
|
364 |
||
365 |
/* |
|
366 |
** Read the next entry from the directory. |
|
367 |
*/ |
|
368 |
struct dirent * |
|
369 |
readdir(dd) |
|
2957 | 370 |
DIR *dd; |
438 | 371 |
{ |
2957 | 372 |
struct dsc$descriptor_s res; |
373 |
char *p; |
|
2982 | 374 |
char buff[sizeof dd->entry.d_name + 10]; |
2957 | 375 |
int i; |
438 | 376 |
|
377 |
/* Set up result descriptor, and get next file. */ |
|
378 |
res.dsc$a_pointer = buff; |
|
379 |
res.dsc$w_length = sizeof buff - 2; |
|
380 |
res.dsc$b_dtype = DSC$K_DTYPE_T; |
|
381 |
res.dsc$b_class = DSC$K_CLASS_S; |
|
382 |
if (lib$find_file(&dd->pat, &res, &dd->context) == RMS$_NMF |
|
383 |
|| dd->context == 0L) |
|
384 |
/* None left... */ |
|
385 |
return NULL; |
|
386 |
||
387 |
/* Force the buffer to end with a NUL. */ |
|
388 |
buff[sizeof buff - 1] = '\0'; |
|
389 |
for (p = buff; !isspace(*p); p++) |
|
390 |
; |
|
391 |
*p = '\0'; |
|
392 |
||
393 |
/* Skip any directory component and just copy the name. */ |
|
394 |
if (p = strchr(buff, ']')) |
|
395 |
(void)strcpy(dd->entry.d_name, p + 1); |
|
396 |
else |
|
397 |
(void)strcpy(dd->entry.d_name, buff); |
|
398 |
||
399 |
/* Clobber the version. */ |
|
400 |
if (p = strchr(dd->entry.d_name, ';')) |
|
401 |
*p = '\0'; |
|
402 |
||
2982 | 403 |
/* claus: empty dirs seems to leave *.* in the buffer ... */ |
404 |
if (strcmp(dd->entry.d_name, "*.*") == 0) { |
|
405 |
return NULL; |
|
406 |
} |
|
407 |
||
438 | 408 |
dd->entry.d_namlen = strlen(dd->entry.d_name); |
409 |
||
410 |
dd->entry.vms_verscount = 0; |
|
411 |
if (dd->vms_wantversions) |
|
412 |
collectversions(dd); |
|
413 |
return &dd->entry; |
|
414 |
} |
|
415 |
||
416 |
/* |
|
417 |
** Return something that can be used in a seekdir later. |
|
418 |
*/ |
|
419 |
long |
|
420 |
telldir(dd) |
|
2957 | 421 |
DIR *dd; |
438 | 422 |
{ |
423 |
return dd->context; |
|
424 |
} |
|
425 |
||
426 |
/* |
|
427 |
** Return to a spot where we used to be. |
|
428 |
*/ |
|
429 |
void |
|
430 |
seekdir(dd, pos) |
|
2957 | 431 |
DIR *dd; |
432 |
long pos; |
|
438 | 433 |
{ |
434 |
dd->context = pos; |
|
435 |
} |
|
436 |
||
2896 | 437 |
# define HAS_OPENDIR |
438 |
||
439 |
# endif /* __VMS__ */ |
|
440 |
#endif /* not HAS_OPENDIR */ |
|
438 | 441 |
%} |
442 |
! ! |
|
443 |
||
613 | 444 |
!DirectoryStream class methodsFor:'documentation'! |
445 |
||
446 |
copyright |
|
447 |
" |
|
448 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
23107 | 449 |
COPYRIGHT (c) 2017 Jan Vrany |
613 | 450 |
All Rights Reserved |
1 | 451 |
|
613 | 452 |
This software is furnished under a license and may be used |
453 |
only in accordance with the terms of that license and with the |
|
454 |
inclusion of the above copyright notice. This software may not |
|
455 |
be provided or otherwise made available to, or used by, any |
|
456 |
other person. No title to or ownership of the software is |
|
457 |
hereby transferred. |
|
458 |
" |
|
459 |
! |
|
360 | 460 |
|
613 | 461 |
documentation |
462 |
" |
|
463 |
Instances of DirectoryStream allow reading a file-directory, |
|
464 |
as if it was a stream of filenames. |
|
465 |
Basically, its an interface to opendir, readdir and closedir. |
|
8881
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
466 |
Notice: |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
467 |
DirectoryStream is an ST/X special; |
2957 | 468 |
for portability, we recommend the use of Filename protocol. |
1295 | 469 |
|
470 |
[author:] |
|
1631 | 471 |
Claus Gittinger |
2957 | 472 |
|
473 |
[see also:] |
|
474 |
Filename |
|
613 | 475 |
" |
1 | 476 |
! ! |
477 |
||
478 |
!DirectoryStream class methodsFor:'instance creation'! |
|
479 |
||
480 |
directoryNamed:dirName |
|
7826 | 481 |
"return a DirectoryStream for directory named dirName, aString |
482 |
Raises an openError, if the directory does not exists." |
|
1 | 483 |
|
484 |
|newStream| |
|
485 |
||
8775 | 486 |
newStream := (self basicNew) text; pathName:dirName. |
1 | 487 |
newStream openForReading isNil ifTrue:[^nil]. |
488 |
^ newStream |
|
7826 | 489 |
|
490 |
" |
|
8881
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
491 |
self directoryNamed:'adadasd' |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
492 |
self directoryNamed:'.' |
7826 | 493 |
" |
1 | 494 |
! ! |
495 |
||
5245 | 496 |
!DirectoryStream methodsFor:'access-reading'! |
1 | 497 |
|
12909 | 498 |
contents |
499 |
"answer all of the directory entries as an OrderedCollection" |
|
500 |
||
501 |
|contents| |
|
502 |
||
503 |
contents := OrderedCollection new. |
|
13778 | 504 |
[self atEnd] whileFalse:[ |
505 |
|l| |
|
506 |
l := self nextLine. |
|
507 |
l isNil ifTrue:[ |
|
508 |
^ contents |
|
509 |
]. |
|
510 |
contents add:l |
|
12909 | 511 |
]. |
512 |
^ contents |
|
513 |
! |
|
514 |
||
1 | 515 |
nextLine |
17287 | 516 |
"return the next filename as a string or nil" |
17292 | 517 |
|
17287 | 518 |
|linkInfo| |
92 | 519 |
|
17287 | 520 |
linkInfo := self nextLinkInfo. |
521 |
linkInfo notNil ifTrue:[^ linkInfo sourcePath]. |
|
522 |
^ nil |
|
523 |
! |
|
524 |
||
525 |
nextLinkInfo |
|
526 |
"return the next FileStatusInfo or nil" |
|
92 | 527 |
|
17287 | 528 |
|nextResult resultInfo| |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
5245
diff
changeset
|
529 |
|
17302 | 530 |
(hitEOF or:[readAheadEntry isNil]) ifTrue:[ |
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
531 |
^ self pastEndRead |
17290 | 532 |
]. |
533 |
||
534 |
nextResult := OperatingSystem nextLinkInfoFrom:self dirPointer:dirPointer. |
|
535 |
nextResult isNil ifTrue:[ |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
536 |
hitEOF := true. |
16297 | 537 |
]. |
17290 | 538 |
readAheadEntry notNil ifTrue:[ |
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
539 |
resultInfo := readAheadEntry. |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
540 |
readAheadEntry := nextResult. |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
541 |
^ resultInfo |
17290 | 542 |
]. |
543 |
nextResult isNil ifTrue:[ |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
544 |
^ self pastEndRead |
17290 | 545 |
]. |
546 |
^ nextResult |
|
1 | 547 |
! ! |
548 |
||
8519 | 549 |
!DirectoryStream protectedMethodsFor:'instance release'! |
613 | 550 |
|
551 |
closeFile |
|
552 |
"low level close of a directoryStream" |
|
16299 | 553 |
|
554 |
|dp| |
|
555 |
||
556 |
dp := dirPointer. |
|
557 |
dp isNil ifTrue:[ |
|
17287 | 558 |
^ self errorNotOpen. |
16299 | 559 |
]. |
560 |
dirPointer := nil. |
|
613 | 561 |
%{ |
562 |
#ifdef HAS_OPENDIR |
|
16299 | 563 |
closedir( (DIR *)(__FILEVal(dp)) ); |
1631 | 564 |
#else |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19651
diff
changeset
|
565 |
# ifdef __win32__ |
16299 | 566 |
FindClose( __HANDLEVal(dp) ); |
1631 | 567 |
# endif |
613 | 568 |
#endif |
569 |
%} |
|
570 |
! ! |
|
571 |
||
1 | 572 |
!DirectoryStream methodsFor:'private'! |
573 |
||
574 |
openForReading |
|
575 |
"open the file for readonly" |
|
576 |
||
17287 | 577 |
|ok encodedPathName error fileSize osPathname osModTime osCrtTime osAccTime osFileAttributes | |
1 | 578 |
|
14581 | 579 |
encodedPathName := OperatingSystem encodePath:pathName. |
1 | 580 |
mode := #readonly. |
17290 | 581 |
hitEOF := false. |
17287 | 582 |
|
1 | 583 |
%{ |
21604
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
584 |
enum { |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
585 |
PASS_INITIAL = 1, |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
586 |
PASS_RETRY_AFTER_SCAVENGE = 2, |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
587 |
PASS_RETRY_AFTER_GARBAGE_COLLECT = 3, |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
588 |
PASS_FINAL = PASS_RETRY_AFTER_GARBAGE_COLLECT |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
589 |
} pass = PASS_INITIAL; |
77 | 590 |
#ifdef HAS_OPENDIR |
1 | 591 |
DIR *d; |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
592 |
OBJ path, dp; |
1 | 593 |
|
21604
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
594 |
retry: |
155 | 595 |
ok = false; |
1133 | 596 |
if (__INST(dirPointer) == nil) { |
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
597 |
if (__isStringLike(encodedPathName)) { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
598 |
__BEGIN_INTERRUPTABLE__ |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
599 |
__threadErrno = 0; |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
600 |
do { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
601 |
d = opendir((char *) __stringVal(encodedPathName)); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
602 |
} while ((d == NULL) && (__threadErrno == EINTR)); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
603 |
__END_INTERRUPTABLE__ |
92 | 604 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
605 |
if (d == NULL) { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
606 |
error = __mkSmallInteger(__threadErrno); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
607 |
} else { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
608 |
dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
609 |
ok = true; |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
610 |
} |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
611 |
} |
1 | 612 |
} |
1631 | 613 |
#else |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19651
diff
changeset
|
614 |
#ifdef __win32__ |
1631 | 615 |
HANDLE d; |
616 |
OBJ path, dp; |
|
11294 | 617 |
union { |
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
618 |
char pattern[MAXPATHLEN]; |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
619 |
wchar_t wpattern[MAXPATHLEN]; |
11294 | 620 |
} uP; |
621 |
union { |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
622 |
WIN32_FIND_DATAA data; |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
623 |
WIN32_FIND_DATAW wdata; |
11294 | 624 |
} uD; |
1631 | 625 |
|
21604
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
626 |
retry: |
1631 | 627 |
ok = false; |
628 |
if (__INST(dirPointer) == nil) { |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
629 |
path = __INST(pathName); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
630 |
if (__isStringLike(path)) { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
631 |
int l = __stringSize(path); |
17287 | 632 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
633 |
if (l < (MAXPATHLEN-4)) { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
634 |
strncpy(uP.pattern, __stringVal(path), l); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
635 |
strcpy(uP.pattern+l, "\\*"); |
3164
4f37ae9c8961
use strncpy to avoid buffer-overruns
Claus Gittinger <cg@exept.de>
parents:
2999
diff
changeset
|
636 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
637 |
do { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
638 |
__threadErrno = 0; |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
639 |
d = STX_API_NOINT_CALL2( "FindFirstFileA", FindFirstFileA, uP.pattern, &uD.data ); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
640 |
} while ((d < 0) && (__threadErrno == EINTR)); |
11294 | 641 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
642 |
if (d == INVALID_HANDLE_VALUE) { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
643 |
error = __mkSmallInteger(GetLastError()); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
644 |
} else { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
645 |
dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp); |
17287 | 646 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
647 |
fileSize = __MKLARGEINT64(1, uD.data.nFileSizeLow, uD.data.nFileSizeHigh ); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
648 |
osPathname = __MKSTRING( uD.data.cFileName ); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
649 |
osFileAttributes = __mkSmallInteger( uD.data.dwFileAttributes ); |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
5245
diff
changeset
|
650 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
651 |
osCrtTime = FileTimeToOsTime1970(&uD.data.ftCreationTime); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
652 |
osAccTime = FileTimeToOsTime1970(&uD.data.ftLastAccessTime); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
653 |
osModTime = FileTimeToOsTime1970(&uD.data.ftLastWriteTime); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
654 |
ok = true; |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
655 |
} |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
656 |
} |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
657 |
} |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
658 |
else if (__isUnicode16String(path)) { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
659 |
int l = __unicode16StringSize(path); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
660 |
int i; |
17287 | 661 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
662 |
if (l < (MAXPATHLEN-4)) { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
663 |
for (i=0; i<l; i++) { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
664 |
uP.wpattern[i] = __unicode16StringVal(path)[i]; |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
665 |
} |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
666 |
uP.wpattern[i++] = '\\'; |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
667 |
uP.wpattern[i++] = '*'; |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
668 |
uP.wpattern[i] = 0; |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
5245
diff
changeset
|
669 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
670 |
do { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
671 |
__threadErrno = 0; |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
672 |
d = STX_API_NOINT_CALL2( "FindFirstFileW", FindFirstFileW, uP.wpattern, &uD.wdata ); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
673 |
} while ((d < 0) && (__threadErrno == EINTR)); |
17287 | 674 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
675 |
if (d == INVALID_HANDLE_VALUE) { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
676 |
error = __mkSmallInteger(GetLastError()); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
677 |
} else { |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
678 |
dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp); |
11294 | 679 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
680 |
fileSize = __MKLARGEINT64(1, uD.wdata.nFileSizeLow, uD.wdata.nFileSizeHigh ); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
681 |
osPathname = __MKU16STRING( uD.wdata.cFileName ); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
682 |
osFileAttributes = __mkSmallInteger( uD.data.dwFileAttributes ); |
11294 | 683 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
684 |
osCrtTime = FileTimeToOsTime1970(&uD.wdata.ftCreationTime); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
685 |
osAccTime = FileTimeToOsTime1970(&uD.wdata.ftLastAccessTime); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
686 |
osModTime = FileTimeToOsTime1970(&uD.wdata.ftLastWriteTime); |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
687 |
ok = true; |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
688 |
} |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
689 |
} |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
690 |
} |
1631 | 691 |
} |
17287 | 692 |
#endif |
1 | 693 |
#endif |
21604
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
694 |
/* |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
695 |
* If no filedescriptors available, try to finalize |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
696 |
* possibly collected fd's and try again. |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
697 |
*/ |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
698 |
if ((__threadErrno == ENFILE || __threadErrno == EMFILE) && pass < PASS_FINAL) { |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
699 |
switch (pass) { |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
700 |
case PASS_INITIAL: |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
701 |
{ |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
702 |
pass = PASS_RETRY_AFTER_SCAVENGE; |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
703 |
__SSEND0(@global(ObjectMemory), @symbol(scavenge), 0); |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
704 |
__SSEND0(@global(ObjectMemory), @symbol(finalize), 0); |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
705 |
} |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
706 |
goto retry; |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
707 |
case PASS_RETRY_AFTER_SCAVENGE: |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
708 |
{ |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
709 |
pass = PASS_RETRY_AFTER_GARBAGE_COLLECT; |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
710 |
__SSEND0(@global(ObjectMemory), @symbol(garbageCollect), 0); |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
711 |
__SSEND0(@global(ObjectMemory), @symbol(finalize), 0); |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
712 |
} |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
713 |
goto retry; |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
714 |
case PASS_RETRY_AFTER_GARBAGE_COLLECT: |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
715 |
/* Should never be reached */ |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
716 |
goto getOutOfHere; |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
717 |
} |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
718 |
} |
10256dd38558
Improved handling of `EMFILE` / `ENFILE` when opening files / directories
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20578
diff
changeset
|
719 |
getOutOfHere:; |
155 | 720 |
%}. |
17287 | 721 |
|
722 |
ok == true ifTrue:[ |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
723 |
self registerForFinalization. |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
724 |
osPathname isNil ifTrue:[ |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
725 |
"UNIX: does not automatically provide the first entry" |
17291 | 726 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
727 |
StreamError handle:[:ex | |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
728 |
self close. |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
729 |
ex reject. |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
730 |
] do:[ |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
731 |
readAheadEntry := OperatingSystem nextLinkInfoFrom:self dirPointer:dirPointer. |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
732 |
]. |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
733 |
] ifFalse:[ |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
734 |
"Windows already provides the first entry's info" |
17291 | 735 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
736 |
readAheadEntry := OperatingSystem |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
737 |
linkInfoFor:osPathname |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
738 |
fileSize:fileSize |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
739 |
fileAttributes:osFileAttributes |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
740 |
osCrtTime:osCrtTime |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
741 |
osAccTime:osAccTime |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
742 |
osModTime:osModTime |
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
743 |
]. |
17287 | 744 |
|
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
745 |
^ self |
1 | 746 |
]. |
155 | 747 |
|
17287 | 748 |
ok notNil ifTrue:[ |
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
749 |
dirPointer notNil ifTrue:[^ self errorAlreadyOpen]. |
1 | 750 |
]. |
16297 | 751 |
error notNil ifTrue:[ |
19651
59a06f7e5116
avoid largeinteger arithmetic in osTime handling
Claus Gittinger <cg@exept.de>
parents:
18780
diff
changeset
|
752 |
^ self openError:(lastErrorNumber := error). |
16297 | 753 |
]. |
1 | 754 |
^ nil |
755 |
! |
|
756 |
||
757 |
reOpen |
|
8604 | 758 |
"USERS WILL NEVER INVOKE THIS METHOD |
759 |
sent after snapin to reopen streams." |
|
38 | 760 |
|
2 | 761 |
dirPointer := nil. |
762 |
super reOpen |
|
1 | 763 |
! ! |
764 |
||
765 |
!DirectoryStream methodsFor:'testing'! |
|
766 |
||
767 |
atEnd |
|
768 |
"return true, if position is at end" |
|
769 |
||
17302 | 770 |
^ readAheadEntry == nil |
2945
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
771 |
! |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
772 |
|
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
773 |
isEmpty |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
774 |
"test for if the unread portion of the directory stream is empty. |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
775 |
This query changes the readPointer of the DirectoryStream" |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
776 |
|
2957 | 777 |
|entry| |
2945
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
778 |
|
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
779 |
[self atEnd] whileFalse:[ |
3816
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
780 |
entry := self nextLine. |
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
781 |
entry asFilename isImplicit ifFalse:[ |
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
782 |
^ false. |
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
783 |
] |
2945
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
784 |
]. |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
785 |
^ true |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
786 |
|
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
787 |
|
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
788 |
" |
3816
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
789 |
(DirectoryStream directoryNamed:'/') isEmpty |
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
790 |
(DirectoryStream directoryNamed:'/var/tmp') isEmpty |
2945
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
791 |
" |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
792 |
|
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
793 |
"Modified: 18.9.1997 / 18:05:31 / stefan" |
16299 | 794 |
! |
795 |
||
796 |
isOpen |
|
797 |
^ dirPointer notNil. |
|
1 | 798 |
! ! |
799 |
||
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
800 |
!DirectoryStream class methodsFor:'documentation'! |
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
801 |
|
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
802 |
version |
18780 | 803 |
^ '$Header$' |
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
804 |
! |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
805 |
|
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
806 |
version_CVS |
18780 | 807 |
^ '$Header$' |
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
808 |
! ! |