author | Claus Gittinger <cg@exept.de> |
Thu, 11 Mar 1999 00:14:46 +0100 | |
changeset 4042 | 526c79cadbf8 |
parent 3824 | d515d22eca90 |
child 4298 | 1889f8051f69 |
permissions | -rw-r--r-- |
3746 | 1 |
" |
2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
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 |
||
13 |
ExternalStream subclass:#FileStream |
|
3755 | 14 |
instanceVariableNames:'pathName canPosition removeOnClose' |
3746 | 15 |
classVariableNames:'OpenErrorSignal' |
16 |
poolDictionaries:'' |
|
17 |
category:'Streams-External' |
|
18 |
! |
|
19 |
||
20 |
!FileStream primitiveDefinitions! |
|
21 |
%{ |
|
22 |
#ifdef __openVMS__ |
|
23 |
# undef __new |
|
24 |
#endif |
|
25 |
||
26 |
#include <stdio.h> |
|
27 |
#define _STDIO_H_INCLUDED_ |
|
28 |
||
29 |
#include <errno.h> |
|
30 |
#define _ERRNO_H_INCLUDED_ |
|
31 |
||
32 |
#ifdef transputer |
|
33 |
# include <iocntrl.h> |
|
34 |
# ifndef fileno |
|
35 |
/* kludge: inmos forgot fileno */ |
|
36 |
# define fileno(f) ((f)->__file) |
|
37 |
# endif |
|
38 |
#else |
|
39 |
# include <sys/types.h> |
|
40 |
# include <sys/stat.h> |
|
41 |
#endif |
|
42 |
||
43 |
#ifdef hpux |
|
44 |
# define fileno(f) ((f->__fileH << 8) | (f->__fileL)) |
|
45 |
#endif |
|
46 |
||
47 |
#ifndef SEEK_SET |
|
48 |
# define SEEK_SET 0 |
|
49 |
#endif |
|
50 |
#ifndef SEEK_CUR |
|
51 |
# define SEEK_CUR 1 |
|
52 |
#endif |
|
53 |
#ifndef SEEK_END |
|
54 |
# define SEEK_END 2 |
|
55 |
#endif |
|
56 |
||
57 |
/* |
|
58 |
* not all systems have off_t |
|
59 |
* explicit add of those we know to have ... |
|
60 |
*/ |
|
61 |
#ifdef __osf__ |
|
62 |
# define OFF_T off_t |
|
63 |
#endif |
|
64 |
||
65 |
#ifndef OFF_T |
|
66 |
# define OFF_T long |
|
67 |
#endif |
|
68 |
||
69 |
#ifdef __VMS__ |
|
70 |
/* |
|
71 |
* get those VMS definitions ... |
|
72 |
*/ |
|
73 |
# include <rms.h> |
|
74 |
#endif |
|
75 |
||
76 |
#ifdef WIN32 |
|
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
77 |
# if 1 |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
78 |
# define NO_STDIO |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
79 |
# else |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
80 |
# undef __BEGIN_INTERRUPTABLE__ |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
81 |
# undef __END_INTERRUPTABLE__ |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
82 |
# define __BEGIN_INTERRUPTABLE__ |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
83 |
# define __END_INTERRUPTABLE__ |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
84 |
# endif |
3746 | 85 |
# ifdef i386 |
86 |
# define _X86_ |
|
87 |
# endif |
|
88 |
||
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
89 |
# undef INT |
3746 | 90 |
# undef Array |
91 |
# undef Number |
|
92 |
# undef Method |
|
93 |
# undef Point |
|
94 |
# undef Rectangle |
|
95 |
# undef Block |
|
96 |
||
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
97 |
# define NOATOM |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
98 |
# define NOGDICAPMASKS |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
99 |
# define NOMETAFILE |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
100 |
# define NOMINMAX |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
101 |
//# define NOOPENFILE |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
102 |
# define NOSOUND |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
103 |
# define NOWH |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
104 |
//# define NOCOMM |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
105 |
# define NOKANJI |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
106 |
# define NOCRYPT |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
107 |
//# define NOMCX |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
108 |
# define WIN32_LEAN_AND_MEAN |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
109 |
# include <windows.h> |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
110 |
# include <winsock.h> /* */ |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
111 |
# if !defined(__BORLANDC__) |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
112 |
# define stat _stat |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
113 |
# endif |
3746 | 114 |
|
115 |
# ifdef __DEF_Array |
|
116 |
# define Array __DEF_Array |
|
117 |
# endif |
|
118 |
# ifdef __DEF_Number |
|
119 |
# define Number __DEF_Number |
|
120 |
# endif |
|
121 |
# ifdef __DEF_Method |
|
122 |
# define Method __DEF_Method |
|
123 |
# endif |
|
124 |
# ifdef __DEF_Point |
|
125 |
# define Point __DEF_Point |
|
126 |
# endif |
|
127 |
# ifdef __DEF_Block |
|
128 |
# define Block __DEF_Block |
|
129 |
# endif |
|
130 |
||
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
131 |
# define INT int |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
132 |
#endif /* WIN32 */ |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
133 |
|
3746 | 134 |
#ifdef NO_STDIO |
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
135 |
/*# define HFILE HANDLE*/ |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
136 |
# define HFILE FILE * |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
137 |
//# define fileno(f) f |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
138 |
|
3746 | 139 |
# define TELL(currentPosition,f,buffered) \ |
140 |
if (buffered) { \ |
|
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
141 |
currentPosition = ftell(f); \ |
3746 | 142 |
} else { \ |
143 |
OBJ rA = __INST(readAhead); \ |
|
144 |
if (rA != nil) { \ |
|
145 |
__INST(readAhead) = nil; \ |
|
146 |
currentPosition = lseek(fileno(f), -1L, SEEK_CUR); \ |
|
147 |
} \ |
|
148 |
else \ |
|
149 |
currentPosition = lseek(fileno(f), 0L, SEEK_CUR); \ |
|
150 |
} |
|
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
151 |
|
3746 | 152 |
# define SEEK(ret,f,nP,buffered) \ |
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
153 |
if (buffered) { \ |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
154 |
ret = fseek(f, nP, SEEK_SET); \ |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
155 |
} else { \ |
3746 | 156 |
OBJ rA = __INST(readAhead); \ |
157 |
if (rA != nil) { \ |
|
158 |
__INST(readAhead) = nil; \ |
|
159 |
} \ |
|
160 |
ret = lseek(fileno(f), nP, SEEK_SET); \ |
|
161 |
} |
|
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
162 |
|
3746 | 163 |
# define TOEND(ret,f,buffered) \ |
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
164 |
if (buffered) { \ |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
165 |
ret = fseek(f, 0L, SEEK_END); \ |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
166 |
} else { \ |
3746 | 167 |
OBJ rA = __INST(readAhead); \ |
168 |
if (rA != nil) { \ |
|
169 |
__INST(readAhead) = nil; \ |
|
170 |
} \ |
|
171 |
ret = lseek(fileno(f), 0L, SEEK_END); \ |
|
172 |
} |
|
173 |
#else |
|
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
174 |
# define HFILE FILE * |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
175 |
|
3746 | 176 |
# define TELL(currentPosition,f,buffered) \ |
177 |
if (buffered) { \ |
|
178 |
currentPosition = ftell(f); \ |
|
179 |
} else { \ |
|
180 |
currentPosition = lseek(fileno(f), 0L, SEEK_CUR); \ |
|
181 |
} |
|
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
182 |
|
3746 | 183 |
# define SEEK(ret,f,nP,buffered) \ |
184 |
if (buffered) { \ |
|
185 |
ret = fseek(f, nP, SEEK_SET); \ |
|
186 |
} else { \ |
|
187 |
ret = lseek(fileno(f), nP, SEEK_SET); \ |
|
188 |
} |
|
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
189 |
|
3746 | 190 |
# define TOEND(ret,f,buffered) \ |
191 |
if (buffered) { \ |
|
192 |
ret = fseek(f, 0L, SEEK_END); \ |
|
193 |
} else { \ |
|
194 |
ret = lseek(fileno(f), 0L, SEEK_END); \ |
|
195 |
} |
|
196 |
||
197 |
extern long ftell(), lseek(); |
|
198 |
#endif |
|
199 |
||
200 |
/* |
|
201 |
* on some systems errno is a macro ... check for it here |
|
202 |
*/ |
|
203 |
#ifndef errno |
|
204 |
extern errno; |
|
205 |
#endif |
|
206 |
||
207 |
%} |
|
208 |
! ! |
|
209 |
||
210 |
!FileStream class methodsFor:'documentation'! |
|
211 |
||
212 |
copyright |
|
213 |
" |
|
214 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
215 |
All Rights Reserved |
|
216 |
||
217 |
This software is furnished under a license and may be used |
|
218 |
only in accordance with the terms of that license and with the |
|
219 |
inclusion of the above copyright notice. This software may not |
|
220 |
be provided or otherwise made available to, or used by, any |
|
221 |
other person. No title to or ownership of the software is |
|
222 |
hereby transferred. |
|
223 |
" |
|
224 |
! |
|
225 |
||
226 |
documentation |
|
227 |
" |
|
228 |
This class provides access to the operating systems underlying file |
|
229 |
system (i.e. its an interface to the stdio library). |
|
230 |
||
231 |
Notice, that on some systems, the standard I/O library has performance |
|
232 |
problems when a file is opened for readwrite. |
|
233 |
For best results, open files either readonly or writeonly. |
|
234 |
||
235 |
Also notice, that some OperatingSystems do not fully support |
|
236 |
positioning a file stream. |
|
237 |
For example, poor VMS does not allow positioning onto arbitrary |
|
238 |
byte boundaries if the file is a variable-record-RMS file. |
|
239 |
(stupid enough, this is the default for textfiles as created by |
|
240 |
some tools ...) |
|
241 |
Therefore, the instance variable canPosition is set according to |
|
242 |
this and an error is raised, if a position: is attemted. |
|
243 |
I know, this is ugly, but what else could we do ? |
|
244 |
||
245 |
[instance variables:] |
|
246 |
pathName <String> the files path (if known) |
|
247 |
canPosition <Boolean> positionable - read above comment |
|
248 |
||
249 |
[author:] |
|
250 |
Claus Gittinger |
|
251 |
||
252 |
[see also:] |
|
253 |
Filename DirectoryStream PipeStream Socket |
|
254 |
" |
|
255 |
! |
|
256 |
||
257 |
examples |
|
258 |
" |
|
259 |
for VMS users only: |
|
260 |
||
261 |
The #openWithMode:attributes: entry allows additional RMS attributes |
|
262 |
to be passed in the second argument, which must be an array of strings |
|
263 |
as described in the 'creat' RTL Library documentation. |
|
264 |
||
265 |
For example, to create a file with fixed records and recordLength of 100, |
|
266 |
use: |
|
267 |
||
268 |
|newFile| |
|
269 |
||
270 |
newFile := FileStream new pathName:'<nameOfFile>'. |
|
271 |
newFile setMode:#writeonly. |
|
272 |
newFile openWithMode:'w' attributes:#('rfm=fix' 'fsz=100'). |
|
273 |
||
274 |
since all of the above is private protocol, and it is considered bad style to |
|
275 |
access these from user programs, we recommend subclassing FileStream as |
|
276 |
something like VMSFixedRecordFileStream, and redefine the instance creation |
|
277 |
method(s) there as appropriate. |
|
278 |
This will retain VMS specifics in one place and enhance maintanability. |
|
279 |
" |
|
280 |
! ! |
|
281 |
||
282 |
!FileStream class methodsFor:'initialization'! |
|
283 |
||
284 |
initialize |
|
285 |
OpenErrorSignal isNil ifTrue:[ |
|
286 |
"/ |
|
287 |
"/ this is temporary - for now allow an openError to |
|
288 |
"/ be unhandled and proceed by returning a nil from the |
|
289 |
"/ stream creation method. |
|
290 |
"/ In the future, this will be a hard signal. |
|
291 |
"/ |
|
292 |
OpenErrorSignal := QuerySignal new. |
|
293 |
OpenErrorSignal parent:(super openErrorSignal) mayProceed:true. |
|
294 |
OpenErrorSignal nameClass:self message:#openErrorSignal. |
|
295 |
OpenErrorSignal notifierString:'open error'. |
|
296 |
] |
|
297 |
||
298 |
"Modified: 8.10.1997 / 11:56:39 / cg" |
|
299 |
! ! |
|
300 |
||
301 |
!FileStream class methodsFor:'instance creation'! |
|
302 |
||
303 |
appendingOldFileNamed:filename |
|
304 |
"return a FileStream for existing file named filename, aString. |
|
305 |
The file is opened for writeonly access." |
|
306 |
||
307 |
|newStream| |
|
308 |
newStream := self new pathName:filename. |
|
309 |
newStream openForAppending isNil ifTrue:[^nil]. |
|
310 |
" |
|
311 |
this is not a good idea; I might like to read the written stuff ... |
|
312 |
||
313 |
newStream readLimit:(newStream size). |
|
314 |
" |
|
315 |
^ newStream |
|
316 |
! |
|
317 |
||
318 |
appendingOldFileNamed:filename in:aDirectory |
|
319 |
"return a FileStream for existing file named filename, aString |
|
320 |
in aDirectory, a FileDirectory. |
|
321 |
The file is opened for writeonly access." |
|
322 |
||
323 |
|newStream| |
|
324 |
newStream := self new pathName:filename in:aDirectory. |
|
325 |
newStream openForAppending isNil ifTrue:[^nil]. |
|
326 |
" |
|
327 |
this is not a good idea; I might like to read the written stuff ... |
|
328 |
||
329 |
newStream readLimit:(newStream size). |
|
330 |
" |
|
331 |
^ newStream |
|
332 |
! |
|
333 |
||
334 |
fileNamed:filename |
|
335 |
"return a stream on file filename - if the file does not |
|
336 |
already exist, create it. |
|
337 |
The file is opened for read/write access." |
|
338 |
||
339 |
|stream| |
|
340 |
||
341 |
stream := self oldFileNamed:filename. |
|
342 |
stream isNil ifTrue:[ |
|
343 |
stream := self newFileNamed:filename |
|
344 |
]. |
|
345 |
^ stream |
|
346 |
! |
|
347 |
||
348 |
fileNamed:filename in:aDirectory |
|
349 |
"return a stream on file filename - if the file does not |
|
350 |
already exist, create it. |
|
351 |
The file is opened for read/write access." |
|
352 |
||
353 |
|stream| |
|
354 |
||
355 |
stream := self oldFileNamed:filename in:aDirectory. |
|
356 |
stream isNil ifTrue:[ |
|
357 |
stream := self newFileNamed:filename in:aDirectory |
|
358 |
]. |
|
359 |
^ stream |
|
360 |
! |
|
361 |
||
362 |
newFileForWritingNamed:filename |
|
363 |
"return a FileStream for new file named filename, aString. |
|
364 |
If the file exists, it is truncated, otherwise created. |
|
365 |
The file is opened for writeonly access." |
|
366 |
||
367 |
|newStream| |
|
368 |
newStream := self new pathName:filename. |
|
369 |
newStream createForWriting isNil ifTrue:[^nil]. |
|
370 |
^ newStream |
|
371 |
! |
|
372 |
||
373 |
newFileForWritingNamed:filename in:aDirectory |
|
374 |
"return a FileStream for new file named filename, aString |
|
375 |
in aDirectory, a FileDirectory. |
|
376 |
If the file exists, it is truncated, otherwise created. |
|
377 |
The file is opened for writeonly access." |
|
378 |
||
379 |
|newStream| |
|
380 |
newStream := self new pathName:filename in:aDirectory. |
|
381 |
newStream createForWriting isNil ifTrue:[^nil]. |
|
382 |
^ newStream |
|
383 |
! |
|
384 |
||
385 |
newFileNamed:filename |
|
386 |
"return a FileStream for new file named filename, aString. |
|
387 |
If the file exists, it is truncated, otherwise created. |
|
388 |
The file is opened for read/write access." |
|
389 |
||
390 |
|newStream| |
|
391 |
newStream := self new pathName:filename. |
|
392 |
newStream createForReadWrite isNil ifTrue:[^nil]. |
|
393 |
^ newStream |
|
394 |
||
395 |
"Modified: / 28.10.1997 / 14:28:08 / cg" |
|
396 |
! |
|
397 |
||
398 |
newFileNamed:filename in:aDirectory |
|
399 |
"return a FileStream for new file named filename, aString |
|
400 |
in aDirectory, a FileDirectory. |
|
401 |
If the file exists, it is truncated, otherwise created. |
|
402 |
The file is opened for read/write access." |
|
403 |
||
404 |
|newStream| |
|
405 |
newStream := self new pathName:filename in:aDirectory. |
|
406 |
newStream createForReadWrite isNil ifTrue:[^nil]. |
|
407 |
^ newStream |
|
408 |
! |
|
409 |
||
410 |
oldFileNamed:filename |
|
411 |
"return a FileStream for existing file named filename, aString. |
|
412 |
The file is opened for read/write access." |
|
413 |
||
414 |
|newStream| |
|
415 |
||
416 |
(OperatingSystem isReadable:filename) ifFalse:[^nil]. |
|
417 |
newStream := self new pathName:filename. |
|
418 |
newStream readwrite. |
|
419 |
newStream openForReadWrite isNil ifTrue:[^nil]. |
|
420 |
" |
|
421 |
this is not a good idea; someone else might be appending ... |
|
422 |
||
423 |
newStream readLimit:(newStream size). |
|
424 |
" |
|
425 |
^ newStream |
|
426 |
! |
|
427 |
||
428 |
oldFileNamed:filename in:aDirectory |
|
429 |
"return a FileStream for existing file named filename, aString |
|
430 |
in aDirectory, a FileDirectory. |
|
431 |
The file is opened for read/write access." |
|
432 |
||
433 |
|newStream| |
|
434 |
newStream := self new pathName:filename in:aDirectory. |
|
435 |
newStream openForReadWrite isNil ifTrue:[^nil]. |
|
436 |
" |
|
437 |
this is not a good idea; someone else might be appending ... |
|
438 |
||
439 |
newStream readLimit:(newStream size). |
|
440 |
" |
|
441 |
^ newStream |
|
442 |
! |
|
443 |
||
444 |
readonlyFileNamed:filename |
|
445 |
"return a readonly FileStream for existing file named filename, aString" |
|
446 |
||
447 |
|newStream| |
|
448 |
||
449 |
(OperatingSystem isReadable:filename) ifFalse:[^nil]. |
|
450 |
||
451 |
newStream := self new pathName:filename. |
|
452 |
newStream openForReading isNil ifTrue:[^nil]. |
|
453 |
" |
|
454 |
this is not a good idea; someone else might be appending ... |
|
455 |
||
456 |
newStream readLimit:(newStream size). |
|
457 |
" |
|
458 |
^ newStream |
|
459 |
! |
|
460 |
||
461 |
readonlyFileNamed:filename in:aDirectory |
|
462 |
"return a readonly FileStream for existing file named filename, aString |
|
463 |
in aDirectory, a FileDirectory" |
|
464 |
||
465 |
|newStream| |
|
466 |
newStream := self new pathName:filename in:aDirectory. |
|
467 |
newStream openForReading isNil ifTrue:[^nil]. |
|
468 |
" |
|
469 |
this is not a good idea; someone else might be appending ... |
|
470 |
||
471 |
newStream readLimit:(newStream size). |
|
472 |
" |
|
473 |
^ newStream |
|
474 |
! ! |
|
475 |
||
476 |
!FileStream class methodsFor:'Signal constants'! |
|
477 |
||
478 |
openErrorSignal |
|
479 |
"return the FileStream specific openErrorSignal. |
|
480 |
This is different from ExternalStream>>OpenErrorSignal!!" |
|
481 |
||
482 |
^ OpenErrorSignal |
|
483 |
||
484 |
"Created: / 28.1.1998 / 14:41:18 / stefan" |
|
485 |
! ! |
|
486 |
||
487 |
!FileStream methodsFor:'Squeak compatibility'! |
|
488 |
||
489 |
fullName |
|
490 |
"Squeak compatibility: return the full pathname" |
|
491 |
||
492 |
^ pathName asFilename pathName |
|
493 |
||
494 |
"Created: 17.10.1997 / 17:04:12 / cg" |
|
495 |
"Modified: 20.10.1997 / 19:22:44 / cg" |
|
496 |
! ! |
|
497 |
||
498 |
!FileStream methodsFor:'accessing'! |
|
499 |
||
500 |
directoryName |
|
501 |
"return the name of the directory I'm in as a string" |
|
502 |
||
503 |
^ pathName asFilename directoryName |
|
504 |
! |
|
505 |
||
506 |
name |
|
507 |
"return my name without leading direcory-path (i.e. the plain fileName) |
|
508 |
as a string" |
|
509 |
||
510 |
^ pathName asFilename baseName |
|
511 |
! |
|
512 |
||
513 |
pathName |
|
514 |
"return the pathname" |
|
515 |
||
516 |
^ pathName |
|
517 |
! |
|
518 |
||
3755 | 519 |
removeOnClose:aBoolean |
520 |
"set/clear the removeOnClose flag. |
|
521 |
If set, the file will be removed when closed. |
|
522 |
Provided mostly for OS's which do not allow an |
|
523 |
open file to be removed (i.e. non unixes), |
|
524 |
and a fileStream for a tempFile is used. |
|
525 |
Especially, the CVS-SourceCodeManager returns |
|
526 |
this kind of file-handles occasionally. |
|
527 |
This is an ST/X special feature which is not portable |
|
528 |
to other systems." |
|
529 |
||
530 |
removeOnClose := aBoolean |
|
531 |
||
532 |
"Modified: / 13.8.1998 / 12:10:07 / cg" |
|
533 |
! |
|
534 |
||
3746 | 535 |
store:something |
536 |
"what really should this do" |
|
537 |
||
538 |
self nextPutAll:something storeString |
|
539 |
! ! |
|
540 |
||
541 |
!FileStream methodsFor:'error handling'! |
|
542 |
||
543 |
openError |
|
544 |
"{ Pragma: +optSpace }" |
|
545 |
||
546 |
"report an error, that file open failed" |
|
547 |
||
548 |
"/ |
|
549 |
"/ for now, error on open only raises a querySignal. |
|
550 |
"/ If its not handled, a failing open will return nil. |
|
551 |
"/ Currently, all users of fileStream check for this |
|
552 |
"/ nil return value (which is a historic leftover) |
|
553 |
"/ |
|
554 |
"/ This will change in one of the next ST/X releases - for |
|
555 |
"/ now, it is best to provide an exceptionHandler AND check the |
|
556 |
"/ return value. |
|
557 |
"/ Sorry about that. |
|
558 |
"/ |
|
559 |
LastErrorNumber := lastErrorNumber. |
|
560 |
super openError. |
|
561 |
^ nil |
|
562 |
! ! |
|
563 |
||
3755 | 564 |
!FileStream methodsFor:'instance release'! |
565 |
||
566 |
closeFile |
|
567 |
"low level close - may be redefined in subclasses" |
|
568 |
||
569 |
super closeFile. |
|
570 |
removeOnClose == true ifTrue:[ |
|
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
571 |
pathName asFilename remove. |
3755 | 572 |
] |
573 |
||
574 |
"Created: / 13.8.1998 / 12:11:22 / cg" |
|
575 |
! ! |
|
576 |
||
3746 | 577 |
!FileStream methodsFor:'positioning'! |
578 |
||
579 |
position |
|
580 |
"return the read/write position in the file - |
|
581 |
notice, in smalltalk indices start at 1 so begin of file is 1" |
|
582 |
||
583 |
%{ /* NOCONTEXT */ |
|
584 |
||
585 |
HFILE f; |
|
586 |
long currentPosition; |
|
587 |
||
588 |
if (__INST(filePointer) != nil) { |
|
589 |
f = __FILEVal(__INST(filePointer)); |
|
590 |
do { |
|
591 |
TELL(currentPosition,f,__INST(buffered) == true); |
|
592 |
} while ((currentPosition < 0) && (errno == EINTR)); |
|
593 |
if (currentPosition >= 0) { |
|
594 |
/* |
|
595 |
* notice: Smalltalk index starts at 1 |
|
596 |
*/ |
|
597 |
RETURN ( __MKSMALLINT(currentPosition + 1) ); |
|
598 |
} |
|
599 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
600 |
} |
|
601 |
%}. |
|
602 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
603 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
604 |
^ self primitiveFailed |
|
605 |
! |
|
606 |
||
607 |
position:newPos |
|
608 |
"set the read/write position in the file" |
|
609 |
||
610 |
%{ /* NOCONTEXT */ |
|
611 |
||
612 |
HFILE f; |
|
613 |
long ret; |
|
614 |
OBJ fp; |
|
615 |
long nP; |
|
616 |
||
617 |
if ((__INST(canPosition) != false) |
|
618 |
|| (newPos == __MKSMALLINT(1))) { |
|
619 |
if ((fp = __INST(filePointer)) != nil) { |
|
620 |
if (__isSmallInteger(newPos)) { |
|
621 |
f = __FILEVal(fp); |
|
622 |
nP = (long)__intVal(newPos); |
|
623 |
||
624 |
/* |
|
625 |
* notice: Smalltalk index starts at 1 |
|
626 |
*/ |
|
627 |
nP--; |
|
628 |
||
629 |
do { |
|
630 |
SEEK(ret,f,nP,__INST(buffered) == true); |
|
631 |
} while ((ret < 0) && (errno == EINTR)); |
|
632 |
if (ret >= 0) { |
|
633 |
__INST(position) = newPos; |
|
634 |
/* |
|
635 |
* just to make certain ... |
|
636 |
*/ |
|
637 |
__INST(hitEOF) = false; |
|
638 |
RETURN ( self ); |
|
639 |
} |
|
640 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
641 |
} |
|
642 |
} |
|
643 |
} |
|
644 |
%}. |
|
645 |
canPosition == false ifTrue:[ |
|
646 |
"/ position by rewinding & re-reading everything up-to |
|
647 |
"/ that point. |
|
648 |
^ self slowPosition:newPos |
|
649 |
]. |
|
650 |
lastErrorNumber notNil ifTrue:[ |
|
651 |
(OperatingSystem errorSymbolForNumber:lastErrorNumber) == #EINVAL ifTrue:[ |
|
652 |
"/ invalid position |
|
653 |
^ self positionError |
|
654 |
]. |
|
655 |
"/ assume I/O error |
|
656 |
^ self ioError |
|
657 |
]. |
|
658 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
659 |
^ self primitiveFailed |
|
660 |
! |
|
661 |
||
662 |
setToEnd |
|
663 |
"set the read/write position in the file to be at the end of the file" |
|
664 |
||
665 |
%{ |
|
666 |
HFILE f; |
|
667 |
long ret; |
|
668 |
||
669 |
if (__INST(filePointer) != nil) { |
|
670 |
f = __FILEVal(__INST(filePointer)); |
|
671 |
__INST(position) = nil; |
|
672 |
do { |
|
673 |
TOEND(ret,f,__INST(buffered) == true); |
|
674 |
} while ((ret < 0) && (errno == EINTR)); |
|
675 |
if (ret >= 0) { |
|
676 |
RETURN ( self ); |
|
677 |
} |
|
678 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
679 |
} |
|
680 |
%}. |
|
681 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
682 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
683 |
^ self primitiveFailed |
|
684 |
! |
|
685 |
||
686 |
slowPosition:newPos |
|
687 |
"position the file by re-reading everything up-to newPos. |
|
688 |
The effect is the same as that of #position:, but its much slower. |
|
689 |
This is required to reposition nonPositionable streams, such |
|
690 |
as tape-streams or variable-record-RMS files under VMS. |
|
691 |
Caveat: |
|
692 |
This should really be done transparently by the stdio library." |
|
693 |
||
694 |
|buffer amount| |
|
695 |
||
696 |
self isReadable ifFalse:[ |
|
697 |
"/ sorry |
|
698 |
^ self positionError |
|
699 |
]. |
|
700 |
||
701 |
buffer := ByteArray new:8*1024. |
|
702 |
||
703 |
(position isNil "/ i.e. unknown |
|
704 |
or:[newPos < position]) ifTrue:[ |
|
705 |
self reset. |
|
706 |
]. |
|
707 |
[position < newPos] whileTrue:[ |
|
708 |
amount := (buffer size) min:(newPos-position). |
|
709 |
(self nextBytes:amount into:buffer startingAt:1) ~~ amount ifTrue:[ |
|
710 |
^ self positionError |
|
711 |
]. |
|
712 |
]. |
|
713 |
"/ ('FileStream [info]: slow position - please convert ''' , pathName printString , ''' to streamLF format') infoPrintCR. |
|
714 |
! ! |
|
715 |
||
716 |
!FileStream methodsFor:'printing & storing'! |
|
717 |
||
718 |
printOn:aStream |
|
719 |
"append a human readable representation of the receiver to aStream" |
|
720 |
||
721 |
aStream nextPutAll:'(a FileStream for:'. |
|
722 |
aStream nextPutAll:pathName printString. |
|
723 |
aStream nextPut:$) |
|
724 |
||
725 |
"Modified: 30.7.1997 / 13:51:01 / cg" |
|
726 |
! |
|
727 |
||
728 |
storeOn:aStream |
|
729 |
"append a representation of the receiver to aStream, |
|
730 |
from which a copy can be reconstructed later." |
|
731 |
||
732 |
aStream nextPutAll:'(FileStream oldFileNamed:'. |
|
733 |
aStream nextPutAll:pathName storeString. |
|
734 |
(self position ~~ 1) ifTrue:[ |
|
735 |
aStream nextPutAll:'; position:'. |
|
736 |
self position storeOn:aStream |
|
737 |
]. |
|
738 |
aStream nextPut:$) |
|
739 |
||
740 |
"Modified: 30.7.1997 / 16:43:50 / cg" |
|
741 |
! ! |
|
742 |
||
743 |
!FileStream methodsFor:'private'! |
|
744 |
||
745 |
createForReadWrite |
|
746 |
"create/truncate the file for read/write. |
|
747 |
If the file existed, its truncated; otherwise its created." |
|
748 |
||
749 |
mode := #readwrite. |
|
750 |
^ self openWithMode:CreateReadWriteMode |
|
751 |
! |
|
752 |
||
753 |
createForWriting |
|
754 |
"create/truncate the file for writeonly. |
|
755 |
If the file existed, its truncated; otherwise its created." |
|
756 |
||
757 |
mode := #writeonly. |
|
758 |
didWrite := true. |
|
759 |
^ self openWithMode:WriteMode |
|
760 |
! |
|
761 |
||
762 |
open |
|
763 |
"open the file" |
|
764 |
||
765 |
pathName isNil ifTrue:[^nil]. |
|
766 |
(mode == #readonly) ifTrue: [ |
|
767 |
didWrite := false. |
|
768 |
^ self openWithMode:ReadMode |
|
769 |
]. |
|
770 |
(mode == #writeonly) ifTrue: [ |
|
771 |
didWrite := true. |
|
772 |
^ self openWithMode:WriteMode |
|
773 |
]. |
|
774 |
^ self openWithMode:ReadWriteMode |
|
775 |
! |
|
776 |
||
777 |
openForAppending |
|
778 |
"open the file for writeonly appending to the end. |
|
779 |
If the file does not exist its an error, return nil; |
|
780 |
otherwise return the receiver." |
|
781 |
||
782 |
mode := #writeonly. |
|
783 |
didWrite := true. |
|
784 |
^ self openWithMode:AppendMode |
|
785 |
! |
|
786 |
||
787 |
openForReadWrite |
|
788 |
"open the file for read/write. |
|
789 |
If the file does not exist its an error, return nil; |
|
790 |
otherwise return the receiver." |
|
791 |
||
792 |
mode := #readwrite. |
|
793 |
^ self openWithMode:ReadWriteMode |
|
794 |
! |
|
795 |
||
796 |
openForReading |
|
797 |
"open the file for readonly. |
|
798 |
If the file does not exist its an error, return nil; |
|
799 |
otherwise return the receiver." |
|
800 |
||
801 |
mode := #readonly. |
|
802 |
didWrite := false. |
|
803 |
^ self openWithMode:ReadMode |
|
804 |
! |
|
805 |
||
806 |
openForWriting |
|
807 |
"open the file writeonly. |
|
808 |
If the file does not exist its an error, return nil; |
|
809 |
otherwise return the receiver." |
|
810 |
||
811 |
mode := #writeonly. |
|
812 |
didWrite := true. |
|
813 |
^ self openWithMode:ReadWriteMode "unix-io does not allow this; open for update here" |
|
814 |
! |
|
815 |
||
816 |
openWithMode:openmode |
|
817 |
"open the file; |
|
818 |
openmode is the string defining the way to open as defined by the stdio library |
|
819 |
(i.e. the 2nd fopen argument). |
|
820 |
||
821 |
This is a private entry, but maybe useful to open a file in a special mode, |
|
822 |
which is proprietrary to the operatingSystem." |
|
823 |
||
824 |
^ self openWithMode:openmode attributes:nil |
|
825 |
! |
|
826 |
||
827 |
openWithMode:openmode attributes:attributeSpec |
|
828 |
"open the file; |
|
829 |
openmode is the string defining the way to open as defined by the stdio library |
|
830 |
(i.e. the 2nd fopen argument). |
|
831 |
||
832 |
attributeSpec is an additional argument, only used with VMS - it allows a file to |
|
833 |
be created as fixedRecord, variableRecord, streamLF, streamCR, ... |
|
834 |
In VMS, if nonNil, it must consist of an array of strings (max:10), giving additional |
|
835 |
attributes (see fopen description). |
|
836 |
Passing a nil specifies the default format (streamLF) - ST/X always invokes this with nil. |
|
837 |
This argument is ignored in UNIX & MSDOS systems. |
|
838 |
||
839 |
This is a private entry, but maybe useful to open/create a file in a special mode, |
|
840 |
which is proprietrary to the operatingSystem." |
|
841 |
||
842 |
|ok| |
|
843 |
||
844 |
filePointer notNil ifTrue:[^ self errorOpen]. |
|
845 |
ok := false. |
|
846 |
%{ |
|
847 |
HFILE f; |
|
848 |
#ifndef xxNO_STDIO |
|
849 |
HFILE fopen(); |
|
850 |
#endif |
|
851 |
OBJ path, fp; |
|
852 |
int pass = 0; |
|
853 |
||
854 |
retry: |
|
855 |
path = __INST(pathName); |
|
856 |
if (__isNonNilObject(path) && (__qClass(path)==String)) { |
|
857 |
do { |
|
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
858 |
# ifdef NO_STDIO |
3746 | 859 |
/*printf("open %s mode=%s\n",__stringVal(path),__stringVal(openmode)); */ |
3818 | 860 |
# ifdef DO_WRAP_CALLS |
3824 | 861 |
f = __STX_C_CALL2((void*)fopen,(void *)__stringVal(path), (void *)__stringVal(openmode)); |
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
862 |
# else |
3746 | 863 |
f = fopen((char *) __stringVal(path), (char *) __stringVal(openmode)); |
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
864 |
# endif |
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
865 |
# else |
3746 | 866 |
__BEGIN_INTERRUPTABLE__ |
867 |
f = fopen((char *) __stringVal(path), (char *) __stringVal(openmode)); |
|
3807
59b3b3518ad5
do wrapCall for fopen; removed unneeded VMS code;
Claus Gittinger <cg@exept.de>
parents:
3755
diff
changeset
|
868 |
__END_INTERRUPTABLE__ |
3746 | 869 |
# endif |
870 |
/* must refetch - could be GC'd */ |
|
871 |
path = __INST(pathName); |
|
872 |
} while ((f == NULL) && (errno == EINTR)); |
|
873 |
||
874 |
if (f == NULL) { |
|
875 |
/* |
|
876 |
* If no filedescriptors available, try to finalize |
|
877 |
* possibly collected fd's and try again. |
|
878 |
*/ |
|
879 |
if (pass == 0 && (errno == ENFILE || errno == EMFILE)) { |
|
880 |
pass = 1; |
|
881 |
__SSEND0(@global(ObjectMemory), @symbol(scavenge), 0); |
|
882 |
__SSEND0(@global(ObjectMemory), @symbol(finalize), 0); |
|
883 |
goto retry; |
|
884 |
} |
|
885 |
getOutOfHere: ; |
|
886 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
887 |
__INST(position) = nil; |
|
888 |
} else { |
|
889 |
__INST(canPosition) = true; |
|
890 |
||
891 |
__INST(filePointer) = fp = __MKOBJ((INT)f); __STORE(self, fp); |
|
892 |
__INST(position) = __MKSMALLINT(1); |
|
893 |
ok = true; |
|
894 |
} |
|
895 |
} |
|
896 |
%}. |
|
897 |
ok ifFalse:[ |
|
898 |
" |
|
899 |
the open failed for some reason ... |
|
900 |
" |
|
901 |
^ self openError |
|
902 |
]. |
|
903 |
self buffered:true. "default is buffered" |
|
904 |
Lobby register:self. |
|
905 |
! |
|
906 |
||
907 |
pathName:filename |
|
908 |
"set the pathname" |
|
909 |
||
910 |
pathName := filename asString |
|
911 |
||
912 |
"Modified: / 28.10.1997 / 14:29:01 / cg" |
|
913 |
! |
|
914 |
||
915 |
pathName:filename in:aDirectory |
|
916 |
"set the pathname starting at aDirectory, a FileDirectory" |
|
917 |
||
918 |
pathName := aDirectory asFilename constructString:filename |
|
919 |
||
920 |
"Modified: / 28.10.1997 / 14:28:54 / cg" |
|
921 |
! |
|
922 |
||
923 |
reOpen |
|
924 |
"sent after snapin to reopen streams" |
|
925 |
||
926 |
|oldPos| |
|
927 |
||
928 |
filePointer notNil ifTrue:[ |
|
929 |
"it was open, when snapped-out" |
|
930 |
filePointer := nil. |
|
931 |
Lobby unregister:self. |
|
932 |
oldPos := position. |
|
933 |
self open. |
|
934 |
filePointer isNil ifTrue:[ |
|
935 |
"/ this happens, if after a restart, |
|
936 |
"/ the file is no longer present or accessable ..." |
|
937 |
||
938 |
(self class name , ' [warning]: could not reOpen file: ', pathName) errorPrintCR. |
|
939 |
] ifFalse:[ |
|
940 |
self position:oldPos. |
|
941 |
] |
|
942 |
] |
|
943 |
||
944 |
"Modified: 10.1.1997 / 17:50:51 / cg" |
|
945 |
! |
|
946 |
||
947 |
setMode:aModeSymbol |
|
948 |
mode := aModeSymbol |
|
949 |
! ! |
|
950 |
||
951 |
!FileStream methodsFor:'queries'! |
|
952 |
||
953 |
fileSize |
|
954 |
"return the size in bytes of the file" |
|
955 |
|oldPosition sz| |
|
956 |
%{ |
|
957 |
||
958 |
#ifndef xxNO_STDIO |
|
959 |
HFILE f; |
|
960 |
struct stat buf; |
|
961 |
int ret; |
|
962 |
int fd; |
|
963 |
||
964 |
if (__INST(filePointer) != nil) { |
|
965 |
f = __FILEVal(__INST(filePointer)); |
|
966 |
fd = fileno(f); |
|
967 |
do { |
|
968 |
ret = fstat(fd, &buf); |
|
969 |
} while ((ret < 0) && (errno == EINTR)); |
|
970 |
if (ret >= 0) { |
|
971 |
RETURN ( __MKSMALLINT(buf.st_size) ); |
|
972 |
} |
|
973 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
974 |
} |
|
975 |
#endif |
|
976 |
%}. |
|
977 |
||
978 |
"could add a fall-back here: |
|
979 |
||
980 |
oldPosition := self position. |
|
981 |
self setToEnd. |
|
982 |
sz := self position. |
|
983 |
self position:oldPosition. |
|
984 |
^ sz |
|
985 |
" |
|
986 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
987 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
988 |
oldPosition := self position. |
|
989 |
self setToEnd. |
|
990 |
sz := self position. |
|
991 |
self position:oldPosition. |
|
992 |
^ sz |
|
993 |
! |
|
994 |
||
995 |
size |
|
996 |
"return the size of the stream; |
|
997 |
thats the number of bytes of the file." |
|
998 |
||
999 |
"/ no obsoleteMethodWarning - size is ok for streams. |
|
1000 |
"/ self obsoleteMethodWarning:'use #fileSize'. |
|
1001 |
||
1002 |
^ self fileSize. |
|
1003 |
||
1004 |
"Modified: 4.10.1997 / 18:01:09 / cg" |
|
1005 |
! ! |
|
1006 |
||
1007 |
!FileStream methodsFor:'testing'! |
|
1008 |
||
1009 |
isFileStream |
|
1010 |
"return true, if the receiver is some kind of fileStream. |
|
1011 |
redefined from Object" |
|
1012 |
||
1013 |
^ true |
|
1014 |
! ! |
|
1015 |
||
1016 |
!FileStream class methodsFor:'documentation'! |
|
1017 |
||
1018 |
version |
|
3824 | 1019 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/FileStr_win32.st,v 1.5 1998-09-11 11:49:45 cg Exp $' |
3746 | 1020 |
! ! |
1021 |
FileStream initialize! |