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