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