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