author | ca |
Tue, 02 Mar 2004 15:16:08 +0100 | |
changeset 8034 | 716b32d832bf |
parent 7970 | 2ae69eb663eb |
child 8039 | 6ef0379296cc |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
7872 | 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 |
||
5439 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
1 | 15 |
ExternalStream subclass:#FileStream |
7872 | 16 |
instanceVariableNames:'pathName canPosition removeOnClose' |
17 |
classVariableNames:'UserInitiatedFileSaveQuerySignal' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Streams-External' |
|
1 | 20 |
! |
21 |
||
216 | 22 |
!FileStream primitiveDefinitions! |
1 | 23 |
%{ |
2903 | 24 |
|
1 | 25 |
#include <stdio.h> |
437 | 26 |
#define _STDIO_H_INCLUDED_ |
27 |
||
10 | 28 |
#include <errno.h> |
437 | 29 |
#define _ERRNO_H_INCLUDED_ |
1 | 30 |
|
31 |
#ifdef transputer |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
32 |
|
1 | 33 |
# include <iocntrl.h> |
34 |
# ifndef fileno |
|
35 |
/* kludge: inmos forgot fileno */ |
|
36 |
# define fileno(f) ((f)->__file) |
|
37 |
# endif |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
38 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
39 |
#else /* not transputer */ |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
40 |
|
1 | 41 |
# include <sys/types.h> |
42 |
# include <sys/stat.h> |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
43 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
44 |
#endif /* not transputer */ |
10 | 45 |
|
42 | 46 |
#ifdef hpux |
68 | 47 |
# define fileno(f) ((f->__fileH << 8) | (f->__fileL)) |
42 | 48 |
#endif |
49 |
||
10 | 50 |
#ifndef SEEK_SET |
13 | 51 |
# define SEEK_SET 0 |
10 | 52 |
#endif |
53 |
#ifndef SEEK_CUR |
|
13 | 54 |
# define SEEK_CUR 1 |
10 | 55 |
#endif |
56 |
#ifndef SEEK_END |
|
13 | 57 |
# define SEEK_END 2 |
10 | 58 |
#endif |
59 |
||
223 | 60 |
/* |
2921 | 61 |
* not all systems have off_t |
2808 | 62 |
* explicit add of those we know to have ... |
63 |
*/ |
|
64 |
#ifdef __osf__ |
|
65 |
# define OFF_T off_t |
|
66 |
#endif |
|
67 |
||
68 |
#ifndef OFF_T |
|
69 |
# define OFF_T long |
|
70 |
#endif |
|
71 |
||
2921 | 72 |
#ifdef __VMS__ |
73 |
/* |
|
74 |
* get those VMS definitions ... |
|
75 |
*/ |
|
76 |
# include <rms.h> |
|
77 |
#endif |
|
78 |
||
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
79 |
#ifdef WIN32 |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
80 |
# define NO_STDIO |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
81 |
# ifdef i386 |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
82 |
# define _X86_ |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
83 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
84 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
85 |
# undef INT |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
86 |
# undef Array |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
87 |
# undef Number |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
88 |
# undef Method |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
89 |
# undef Point |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
90 |
# undef Rectangle |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
91 |
# undef Block |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
92 |
# undef Time |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
93 |
# undef Date |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
94 |
# undef Set |
5910 | 95 |
# undef Signal |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
96 |
# undef Delay |
5910 | 97 |
# undef Context |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
98 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
99 |
# define NOATOM |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
100 |
# define NOGDICAPMASKS |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
101 |
# define NOMETAFILE |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
102 |
# define NOMINMAX |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
103 |
//# define NOOPENFILE |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
104 |
# define NOSOUND |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
105 |
# define NOWH |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
106 |
//# define NOCOMM |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
107 |
# define NOKANJI |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
108 |
# define NOCRYPT |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
109 |
//# define NOMCX |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
110 |
# define WIN32_LEAN_AND_MEAN |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
111 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
112 |
# include <windows.h> |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
113 |
# include <winsock.h> /* */ |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
114 |
# include <io.h> |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
115 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
116 |
# if !defined(__BORLANDC__) |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
117 |
# define stat _stat |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
118 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
119 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
120 |
# ifdef __DEF_Array |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
121 |
# define Array __DEF_Array |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
122 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
123 |
# ifdef __DEF_Number |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
124 |
# define Number __DEF_Number |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
125 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
126 |
# ifdef __DEF_Method |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
127 |
# define Method __DEF_Method |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
128 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
129 |
# ifdef __DEF_Point |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
130 |
# define Point __DEF_Point |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
131 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
132 |
# ifdef __DEF_Block |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
133 |
# define Block __DEF_Block |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
134 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
135 |
# ifdef __DEF_Time |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
136 |
# define Time __DEF_Time |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
137 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
138 |
# ifdef __DEF_Date |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
139 |
# define Date __DEF_Date |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
140 |
# endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
141 |
# ifdef __DEF_Set |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
142 |
# define Set __DEF_Set |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
143 |
# endif |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
144 |
# ifdef __DEF_Signal |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
145 |
# define Signal __DEF_Signal |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
146 |
# endif |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
147 |
# ifdef __DEF_Delay |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
148 |
# define Delay __DEF_Delay |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
149 |
# endif |
5910 | 150 |
# ifdef __DEF_Context |
151 |
# define Context __DEF_Context |
|
152 |
# endif |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
153 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
154 |
# define INT int |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
155 |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
156 |
# ifndef DO_WRAP_CALLS |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
157 |
# define STX_C_CALL0(__nm__, __f__) __f__((__a1__)) |
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
158 |
# define STX_C_CALL1(__nm__, __f__, __a1__) __f__((__a1__)) |
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
159 |
# define STX_C_CALL2(__nm__, __f__, __a1__, __a2__) __f__((__a1__), (__a2__)) |
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
160 |
# define STX_C_CALL3(__nm__, __f__, __a1__, __a2__, __a3__) __f__((__a1__), (__a2__), (__a3__)) |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
161 |
# else |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
162 |
# define STX_C_CALL0(__nm__, __f__) __STX_C_CALL0(__nm__, (void*)__f__) |
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
163 |
# define STX_C_CALL1(__nm__, __f__, __a1__) __STX_C_CALL1(__nm__, (void*)__f__, (void*)(__a1__)) |
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
164 |
# define STX_C_CALL2(__nm__, __f__, __a1__, __a2__) __STX_C_CALL2(__nm__, (void*)__f__, (void*)(__a1__), (void*)(__a2__)) |
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
165 |
# define STX_C_CALL3(__nm__, __f__, __a1__, __a2__, __a3__) __STX_C_CALL3(__nm__, (void*)__f__, (void*)(__a1__), (void*)(__a2__), (void*)(__a3__)) |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
166 |
# endif |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
167 |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
168 |
/* # define HFILE HANDLE */ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
169 |
# define HFILE FILE * |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
170 |
/* # define fileno(f) f */ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
171 |
|
7970 | 172 |
# ifndef MAXPATHLEN |
173 |
# define MAXPATHLEN MAXPATH |
|
174 |
# endif |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
175 |
|
7970 | 176 |
#else /* not WIN32 */ |
177 |
extern long ftell(); |
|
178 |
# ifndef FREEBSD |
|
179 |
extern long lseek(); |
|
180 |
# endif |
|
181 |
# define HFILE FILE * |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
182 |
|
7970 | 183 |
#endif /* WIN32 or not WIN32*/ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
184 |
|
7570 | 185 |
#include "stxOSDefs.h" |
186 |
||
2808 | 187 |
/* |
223 | 188 |
* on some systems errno is a macro ... check for it here |
189 |
*/ |
|
190 |
#ifndef errno |
|
191 |
extern errno; |
|
192 |
#endif |
|
193 |
||
1 | 194 |
%} |
173 | 195 |
! ! |
1 | 196 |
|
613 | 197 |
!FileStream class methodsFor:'documentation'! |
198 |
||
199 |
copyright |
|
200 |
" |
|
201 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
7872 | 202 |
All Rights Reserved |
613 | 203 |
|
204 |
This software is furnished under a license and may be used |
|
205 |
only in accordance with the terms of that license and with the |
|
206 |
inclusion of the above copyright notice. This software may not |
|
207 |
be provided or otherwise made available to, or used by, any |
|
208 |
other person. No title to or ownership of the software is |
|
209 |
hereby transferred. |
|
210 |
" |
|
211 |
! |
|
212 |
||
213 |
documentation |
|
214 |
" |
|
215 |
This class provides access to the operating systems underlying file |
|
216 |
system (i.e. its an interface to the stdio library). |
|
217 |
||
218 |
Notice, that on some systems, the standard I/O library has performance |
|
219 |
problems when a file is opened for readwrite. |
|
220 |
For best results, open files either readonly or writeonly. |
|
1295 | 221 |
|
2921 | 222 |
Also notice, that some OperatingSystems do not fully support |
223 |
positioning a file stream. |
|
224 |
For example, poor VMS does not allow positioning onto arbitrary |
|
225 |
byte boundaries if the file is a variable-record-RMS file. |
|
226 |
(stupid enough, this is the default for textfiles as created by |
|
227 |
some tools ...) |
|
228 |
Therefore, the instance variable canPosition is set according to |
|
229 |
this and an error is raised, if a position: is attemted. |
|
230 |
I know, this is ugly, but what else could we do ? |
|
231 |
||
232 |
[instance variables:] |
|
7872 | 233 |
pathName <String> the files path (if known) |
234 |
canPosition <Boolean> positionable - read above comment |
|
2921 | 235 |
|
1295 | 236 |
[author:] |
7872 | 237 |
Claus Gittinger |
1295 | 238 |
|
239 |
[see also:] |
|
7872 | 240 |
Filename DirectoryStream PipeStream Socket |
613 | 241 |
" |
2921 | 242 |
! |
243 |
||
244 |
examples |
|
245 |
" |
|
246 |
for VMS users only: |
|
247 |
||
248 |
The #openWithMode:attributes: entry allows additional RMS attributes |
|
249 |
to be passed in the second argument, which must be an array of strings |
|
250 |
as described in the 'creat' RTL Library documentation. |
|
251 |
||
252 |
For example, to create a file with fixed records and recordLength of 100, |
|
253 |
use: |
|
254 |
||
7872 | 255 |
|newFile| |
2921 | 256 |
|
7872 | 257 |
newFile := FileStream new pathName:'<nameOfFile>'. |
258 |
newFile setMode:#writeonly. |
|
259 |
newFile openWithMode:'w' attributes:#('rfm=fix' 'fsz=100'). |
|
2921 | 260 |
|
261 |
since all of the above is private protocol, and it is considered bad style to |
|
262 |
access these from user programs, we recommend subclassing FileStream as |
|
263 |
something like VMSFixedRecordFileStream, and redefine the instance creation |
|
264 |
method(s) there as appropriate. |
|
265 |
This will retain VMS specifics in one place and enhance maintanability. |
|
266 |
" |
|
267 |
! ! |
|
268 |
||
269 |
!FileStream class methodsFor:'initialization'! |
|
270 |
||
271 |
initialize |
|
7379 | 272 |
UserInitiatedFileSaveQuerySignal isNil ifTrue:[ |
7965 | 273 |
"/ |
274 |
"/ this is temporary - for now allow an openError to |
|
275 |
"/ be unhandled and proceed by returning a nil from the |
|
276 |
"/ stream creation method. |
|
277 |
"/ In the future, this will be a hard signal. |
|
278 |
"/ THE FUTURE IS NOW!!!! |
|
279 |
"/ |
|
7379 | 280 |
"/ OpenErrorSignal := QuerySignal new. |
281 |
"/ OpenErrorSignal parent:(super openErrorSignal) mayProceed:true. |
|
282 |
"/ OpenErrorSignal nameClass:self message:#openErrorSignal. |
|
283 |
"/ OpenErrorSignal notifierString:'open error'. |
|
4907 | 284 |
|
7965 | 285 |
UserInitiatedFileSaveQuerySignal := QuerySignal new defaultAnswer:true. |
286 |
UserInitiatedFileSaveQuerySignal nameClass:self message:#userInitiatedFileSaveQuerySignal. |
|
2921 | 287 |
] |
3006
b3530950854a
use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents:
2998
diff
changeset
|
288 |
|
b3530950854a
use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents:
2998
diff
changeset
|
289 |
"Modified: 8.10.1997 / 11:56:39 / cg" |
2921 | 290 |
! ! |
291 |
||
1 | 292 |
!FileStream class methodsFor:'instance creation'! |
293 |
||
613 | 294 |
appendingOldFileNamed:filename |
295 |
"return a FileStream for existing file named filename, aString. |
|
296 |
The file is opened for writeonly access." |
|
1 | 297 |
|
7827 | 298 |
|
1 | 299 |
|newStream| |
7827 | 300 |
|
2 | 301 |
newStream := self new pathName:filename. |
613 | 302 |
newStream openForAppending isNil ifTrue:[^nil]. |
303 |
" |
|
304 |
this is not a good idea; I might like to read the written stuff ... |
|
305 |
||
306 |
newStream readLimit:(newStream size). |
|
307 |
" |
|
308 |
^ newStream |
|
7827 | 309 |
|
310 |
" |
|
311 |
FileStream appendingOldFileNamed:'adasdasasd' |
|
312 |
" |
|
613 | 313 |
! |
314 |
||
315 |
appendingOldFileNamed:filename in:aDirectory |
|
316 |
"return a FileStream for existing file named filename, aString |
|
317 |
in aDirectory, a FileDirectory. |
|
318 |
The file is opened for writeonly access." |
|
319 |
||
320 |
|newStream| |
|
321 |
newStream := self new pathName:filename in:aDirectory. |
|
322 |
newStream openForAppending isNil ifTrue:[^nil]. |
|
323 |
" |
|
324 |
this is not a good idea; I might like to read the written stuff ... |
|
325 |
||
326 |
newStream readLimit:(newStream size). |
|
327 |
" |
|
1 | 328 |
^ newStream |
329 |
! |
|
330 |
||
613 | 331 |
fileNamed:filename |
332 |
"return a stream on file filename - if the file does not |
|
333 |
already exist, create it. |
|
92 | 334 |
The file is opened for read/write access." |
1 | 335 |
|
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
336 |
[ |
7965 | 337 |
^ self oldFileNamed:filename. |
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
338 |
] on:self openErrorSignal do:[:ex| ]. |
613 | 339 |
|
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
340 |
^ self newFileNamed:filename |
613 | 341 |
! |
342 |
||
343 |
fileNamed:filename in:aDirectory |
|
344 |
"return a stream on file filename - if the file does not |
|
345 |
already exist, create it. |
|
346 |
The file is opened for read/write access." |
|
347 |
||
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
348 |
[ |
7965 | 349 |
^ self oldFileNamed:filename in:aDirectory. |
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
350 |
] on:self openErrorSignal do:[:ex| ]. |
613 | 351 |
|
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
352 |
^ self newFileNamed:filename in:aDirectory |
1 | 353 |
! |
354 |
||
92 | 355 |
newFileForWritingNamed:filename |
356 |
"return a FileStream for new file named filename, aString. |
|
357 |
If the file exists, it is truncated, otherwise created. |
|
358 |
The file is opened for writeonly access." |
|
359 |
||
360 |
|newStream| |
|
361 |
newStream := self new pathName:filename. |
|
362 |
newStream createForWriting isNil ifTrue:[^nil]. |
|
363 |
^ newStream |
|
364 |
! |
|
365 |
||
366 |
newFileForWritingNamed:filename in:aDirectory |
|
367 |
"return a FileStream for new file named filename, aString |
|
368 |
in aDirectory, a FileDirectory. |
|
369 |
If the file exists, it is truncated, otherwise created. |
|
370 |
The file is opened for writeonly access." |
|
371 |
||
372 |
|newStream| |
|
373 |
newStream := self new pathName:filename in:aDirectory. |
|
374 |
newStream createForWriting isNil ifTrue:[^nil]. |
|
375 |
^ newStream |
|
376 |
! |
|
377 |
||
613 | 378 |
newFileNamed:filename |
379 |
"return a FileStream for new file named filename, aString. |
|
380 |
If the file exists, it is truncated, otherwise created. |
|
381 |
The file is opened for read/write access." |
|
382 |
||
383 |
|newStream| |
|
384 |
newStream := self new pathName:filename. |
|
385 |
newStream createForReadWrite isNil ifTrue:[^nil]. |
|
386 |
^ newStream |
|
3051
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
387 |
|
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
388 |
"Modified: / 28.10.1997 / 14:28:08 / cg" |
613 | 389 |
! |
390 |
||
391 |
newFileNamed:filename in:aDirectory |
|
392 |
"return a FileStream for new file named filename, aString |
|
393 |
in aDirectory, a FileDirectory. |
|
394 |
If the file exists, it is truncated, otherwise created. |
|
395 |
The file is opened for read/write access." |
|
396 |
||
397 |
|newStream| |
|
398 |
newStream := self new pathName:filename in:aDirectory. |
|
399 |
newStream createForReadWrite isNil ifTrue:[^nil]. |
|
400 |
^ newStream |
|
401 |
! |
|
402 |
||
1 | 403 |
oldFileNamed:filename |
404 |
"return a FileStream for existing file named filename, aString. |
|
7827 | 405 |
The file is opened for read/write access. |
406 |
Raises an error if the file does not exist." |
|
1 | 407 |
|
408 |
|newStream| |
|
409 |
||
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
410 |
"/ We can do the following, but is is an extra OS-systemcall: |
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
411 |
"/ (OperatingSystem isReadable:filename) ifFalse:[^ self new openError]. |
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
412 |
|
2 | 413 |
newStream := self new pathName:filename. |
1 | 414 |
newStream readwrite. |
415 |
newStream openForReadWrite isNil ifTrue:[^nil]. |
|
42 | 416 |
" |
417 |
this is not a good idea; someone else might be appending ... |
|
418 |
||
1 | 419 |
newStream readLimit:(newStream size). |
42 | 420 |
" |
1 | 421 |
^ newStream |
7827 | 422 |
|
423 |
" |
|
424 |
FileStream oldFileNamed:'/dAsGiBtEsNiChT' |
|
425 |
" |
|
1 | 426 |
! |
427 |
||
428 |
oldFileNamed:filename in:aDirectory |
|
429 |
"return a FileStream for existing file named filename, aString |
|
430 |
in aDirectory, a FileDirectory. |
|
7827 | 431 |
The file is opened for read/write access. |
432 |
Raises an error if the file does not exist." |
|
1 | 433 |
|
434 |
|newStream| |
|
2 | 435 |
newStream := self new pathName:filename in:aDirectory. |
1 | 436 |
newStream openForReadWrite isNil ifTrue:[^nil]. |
42 | 437 |
" |
438 |
this is not a good idea; someone else might be appending ... |
|
439 |
||
1 | 440 |
newStream readLimit:(newStream size). |
42 | 441 |
" |
1 | 442 |
^ newStream |
7827 | 443 |
|
444 |
" |
|
445 |
FileStream oldFileNamed:'dAsGiBtEsNiChT' in:'/' |
|
446 |
" |
|
1 | 447 |
! |
448 |
||
449 |
readonlyFileNamed:filename |
|
7827 | 450 |
"return a readonly FileStream for existing file named filename, aString. |
451 |
Raises an error if the file does not exist." |
|
1 | 452 |
|
453 |
|newStream| |
|
454 |
||
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
455 |
"/ We can do the following, but is is an extra OS-systemcall: |
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
456 |
"/ (OperatingSystem isReadable:filename) ifFalse:[^ self new openError]. |
1 | 457 |
|
2 | 458 |
newStream := self new pathName:filename. |
1 | 459 |
newStream openForReading isNil ifTrue:[^nil]. |
42 | 460 |
" |
461 |
this is not a good idea; someone else might be appending ... |
|
462 |
||
1 | 463 |
newStream readLimit:(newStream size). |
42 | 464 |
" |
1 | 465 |
^ newStream |
7827 | 466 |
|
467 |
" |
|
468 |
FileStream readonlyFileNamed:'dAsGiBtEsNiChT' |
|
469 |
" |
|
1 | 470 |
! |
471 |
||
472 |
readonlyFileNamed:filename in:aDirectory |
|
473 |
"return a readonly FileStream for existing file named filename, aString |
|
7827 | 474 |
in aDirectory, a fileName or string instance representing a directory. |
475 |
Raises an error if the file does not exist." |
|
1 | 476 |
|
477 |
|newStream| |
|
2 | 478 |
newStream := self new pathName:filename in:aDirectory. |
1 | 479 |
newStream openForReading isNil ifTrue:[^nil]. |
42 | 480 |
" |
481 |
this is not a good idea; someone else might be appending ... |
|
482 |
||
1 | 483 |
newStream readLimit:(newStream size). |
42 | 484 |
" |
1 | 485 |
^ newStream |
7827 | 486 |
|
487 |
" |
|
488 |
FileStream readonlyFileNamed:'dAsGiBtEsNiChT' in:'/' |
|
489 |
FileStream readonlyFileNamed:'dAsGiBtEsNiChT' in:'/' asFilename |
|
490 |
" |
|
159 | 491 |
! ! |
492 |
||
7298 | 493 |
!FileStream class methodsFor:'Compatibility-ANSI'! |
6586 | 494 |
|
495 |
write:filename |
|
496 |
"return a FileStream for new file named filename, aString. |
|
497 |
If the file exists, it is truncated, otherwise created. |
|
498 |
The file is opened for read/write access. |
|
499 |
Same as newFileNamed: for ANSI compatibilily" |
|
500 |
||
501 |
^ self newFileNamed:filename |
|
502 |
! ! |
|
503 |
||
7298 | 504 |
!FileStream class methodsFor:'Compatibility-Dolphin'! |
6244 | 505 |
|
506 |
read:filename text:text |
|
507 |
"return a readonly FileStream for the existing file named filename, aString. |
|
508 |
If the argument, text is false, the stream is setup to read binary bytes, |
|
509 |
if false, it reads characters." |
|
510 |
||
511 |
|s| |
|
512 |
||
513 |
s := self readOnlyFileNamed:filename. |
|
514 |
text ifTrue:[ |
|
7872 | 515 |
s text |
6244 | 516 |
] ifFalse:[ |
7872 | 517 |
s binary |
6244 | 518 |
]. |
519 |
^ s |
|
6474 | 520 |
! |
521 |
||
522 |
write:filename mode:modeSymbol |
|
523 |
"return a writable FileStream for the file named filename, aString. |
|
524 |
The modeSymbol controls how the file is opened; currently supported are: |
|
7965 | 525 |
#append |
6474 | 526 |
" |
527 |
||
528 |
modeSymbol == #append ifTrue:[ |
|
7965 | 529 |
^ self appendingOldFileNamed:filename |
6474 | 530 |
]. |
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
531 |
"/ self openErrorSignal is a Notification. This will change.. |
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
532 |
"/ We want to raise a real error here |
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
533 |
super openErrorSignal raiseRequestErrorString:' - unsupported mode'. |
6474 | 534 |
^ nil |
535 |
! |
|
536 |
||
537 |
write:filename text:textModeBoolean |
|
538 |
"return a writable FileStream for the file named filename, aString. |
|
539 |
If the argument, text is false, the stream is setup to write binary bytes, |
|
540 |
if false, it writes characters." |
|
541 |
||
542 |
|s| |
|
543 |
||
6475 | 544 |
s := self newFileNamed:filename. |
6474 | 545 |
s notNil ifTrue:[ |
7872 | 546 |
textModeBoolean ifTrue:[ |
547 |
s text |
|
548 |
] ifFalse:[ |
|
549 |
s binary |
|
550 |
] |
|
6474 | 551 |
]. |
552 |
^ s |
|
6244 | 553 |
! ! |
554 |
||
7298 | 555 |
!FileStream class methodsFor:'Compatibility-Squeak'! |
5186 | 556 |
|
557 |
readOnlyFileNamed:filename |
|
6244 | 558 |
"return a readonly FileStream for the existing file named filename, aString." |
559 |
||
5186 | 560 |
^ self readonlyFileNamed:filename |
561 |
! ! |
|
562 |
||
7298 | 563 |
!FileStream class methodsFor:'Compatibility-VW'! |
6170
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
564 |
|
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
565 |
badArgumentsSignal |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
566 |
^ Error |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
567 |
! ! |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
568 |
|
3233
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
569 |
!FileStream class methodsFor:'Signal constants'! |
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
570 |
|
4907 | 571 |
userInitiatedFileSaveQuerySignal |
572 |
"return the query signal, which is raised before a user-initiated |
|
573 |
file-save / file-saveAs operation is performed. |
|
574 |
The query will be invoked with the fileName which is about to be |
|
575 |
written to. |
|
576 |
The default signal here returnes true, which will grant the save. |
|
577 |
End-user applications may want to catch this signal, |
|
578 |
and only return true for certain directories." |
|
579 |
||
580 |
^ UserInitiatedFileSaveQuerySignal |
|
581 |
||
3233
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
582 |
! ! |
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
583 |
|
7261 | 584 |
!FileStream methodsFor:'Compatibility-Squeak'! |
3044 | 585 |
|
586 |
fullName |
|
587 |
"Squeak compatibility: return the full pathname" |
|
588 |
||
589 |
^ pathName asFilename pathName |
|
590 |
||
591 |
"Created: 17.10.1997 / 17:04:12 / cg" |
|
592 |
"Modified: 20.10.1997 / 19:22:44 / cg" |
|
593 |
! ! |
|
594 |
||
1 | 595 |
!FileStream methodsFor:'accessing'! |
596 |
||
597 |
directoryName |
|
2903 | 598 |
"return the name of the directory I'm in as a string" |
1 | 599 |
|
2903 | 600 |
^ pathName asFilename directoryName |
1 | 601 |
! |
602 |
||
603 |
name |
|
2903 | 604 |
"return my name without leading direcory-path (i.e. the plain fileName) |
605 |
as a string" |
|
1 | 606 |
|
2903 | 607 |
^ pathName asFilename baseName |
1 | 608 |
! |
609 |
||
610 |
pathName |
|
611 |
"return the pathname" |
|
612 |
||
613 |
^ pathName |
|
613 | 614 |
! |
615 |
||
3754
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
616 |
removeOnClose:aBoolean |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
617 |
"set/clear the removeOnClose flag. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
618 |
If set, the file will be removed when closed. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
619 |
Provided mostly for OS's which do not allow an |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
620 |
open file to be removed (i.e. non unixes), |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
621 |
and a fileStream for a tempFile is used. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
622 |
Especially, the CVS-SourceCodeManager returns |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
623 |
this kind of file-handles occasionally. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
624 |
This is an ST/X special feature which is not portable |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
625 |
to other systems." |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
626 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
627 |
removeOnClose := aBoolean |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
628 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
629 |
"Modified: / 13.8.1998 / 12:10:07 / cg" |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
630 |
! |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
631 |
|
613 | 632 |
store:something |
633 |
"what really should this do" |
|
634 |
||
635 |
self nextPutAll:something storeString |
|
636 |
! ! |
|
637 |
||
638 |
!FileStream methodsFor:'error handling'! |
|
639 |
||
640 |
openError |
|
2963 | 641 |
"{ Pragma: +optSpace }" |
642 |
||
613 | 643 |
"report an error, that file open failed" |
644 |
||
7827 | 645 |
"/ This has changed from previous releases: |
646 |
"/ in earlier versions of ST/X, failed file open operations |
|
647 |
"/ returned nil - now, an error is raised. |
|
648 |
"/ The old behavior is simulated by providing an exception |
|
649 |
"/ handler, which proceeds with nil. |
|
613 | 650 |
"/ |
2921 | 651 |
"/ Sorry about that. |
613 | 652 |
"/ |
653 |
LastErrorNumber := lastErrorNumber. |
|
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
654 |
^ super openError. |
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
655 |
|
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
656 |
" |
7827 | 657 |
'/dasGIBtEsbeStimmtNiChT' asFilename readStream |
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
658 |
" |
613 | 659 |
! ! |
660 |
||
3754
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
661 |
!FileStream methodsFor:'instance release'! |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
662 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
663 |
closeFile |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
664 |
"low level close - may be redefined in subclasses" |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
665 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
666 |
super closeFile. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
667 |
removeOnClose == true ifTrue:[ |
7872 | 668 |
pathName asFilename remove. |
3754
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
669 |
] |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
670 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
671 |
"Created: / 13.8.1998 / 12:11:22 / cg" |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
672 |
! ! |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
673 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
674 |
!FileStream methodsFor:'positioning'! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
675 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
676 |
position0Based |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
677 |
"return the read/write position in the file" |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
678 |
|
3971 | 679 |
%{ |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
680 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
681 |
HFILE f; |
7872 | 682 |
off_t currentPosition; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
683 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
684 |
if (__INST(filePointer) != nil) { |
7965 | 685 |
do { |
686 |
f = __FILEVal(__INST(filePointer)); |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
687 |
#ifdef WIN32 |
7965 | 688 |
__threadErrno = 0; |
689 |
if (__INST(buffered) == true) { |
|
6333 | 690 |
# if 0 |
7965 | 691 |
currentPosition = STX_C_CALL1( "ftell", ftell, f); |
6333 | 692 |
# else |
7965 | 693 |
currentPosition = ftell(f); |
6333 | 694 |
# endif |
7965 | 695 |
} else { |
696 |
OBJ rA = __INST(readAhead); |
|
697 |
off_t offs = 0; |
|
6333 | 698 |
|
7965 | 699 |
if (rA != nil) { |
700 |
__INST(readAhead) = nil; |
|
701 |
offs = -1; |
|
702 |
} |
|
6333 | 703 |
# if 0 |
7965 | 704 |
currentPosition = STX_C_CALL3( "lseek", lseek, fileno(f), offs, SEEK_CUR); |
6333 | 705 |
# else |
7965 | 706 |
currentPosition = lseek(fileno(f), offs, SEEK_CUR); |
6333 | 707 |
# endif |
7965 | 708 |
} |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
709 |
#else |
7965 | 710 |
if (__INST(buffered) == true) { |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
711 |
#ifdef _LFS_LARGEFILE |
7965 | 712 |
currentPosition = ftello(f); |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
713 |
#else |
7965 | 714 |
currentPosition = ftell(f); |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
715 |
#endif |
7965 | 716 |
} else { |
717 |
currentPosition = lseek(fileno(f), (off_t)0, SEEK_CUR); |
|
718 |
} |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
719 |
#endif |
7965 | 720 |
} while ((currentPosition < 0) && (__threadErrno == EINTR)); |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
721 |
|
7965 | 722 |
if (currentPosition >= 0) { |
723 |
OBJ rslt; |
|
7872 | 724 |
|
7965 | 725 |
if (sizeof(currentPosition) == 8) { |
726 |
rslt = __MKINT64 (¤tPosition); |
|
727 |
} else { |
|
728 |
rslt = __MKINT(currentPosition); |
|
729 |
} |
|
730 |
RETURN ( rslt ); |
|
731 |
} |
|
732 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
733 |
} |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
734 |
%}. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
735 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
736 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
737 |
^ self primitiveFailed |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
738 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
739 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
740 |
position0Based:newPos |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
741 |
"set the read/write position in the file" |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
742 |
|
5493 | 743 |
|rslt| |
3971 | 744 |
%{ |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
745 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
746 |
HFILE f; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
747 |
long ret; |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
748 |
OBJ fp; |
7871
5c357f1ba0c9
preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents:
7870
diff
changeset
|
749 |
|
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
750 |
if ((__INST(canPosition) != false) || (newPos == __MKSMALLINT(0))) { |
7965 | 751 |
if ((fp = __INST(filePointer)) != nil) { |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
752 |
|
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
753 |
#if defined(_LFS_LARGE_FILE) && !defined(WIN32) |
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
754 |
# define FSEEK fseeko |
7965 | 755 |
off_t nP; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
756 |
#else |
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
757 |
#define FSEEK fseek |
7965 | 758 |
long nP; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
759 |
#endif |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
760 |
|
7965 | 761 |
if (__isSmallInteger(newPos)) { |
762 |
nP = __intVal(newPos); |
|
763 |
if (nP < 0) { |
|
764 |
__INST(lastErrorNumber) = __MKSMALLINT(EINVAL); |
|
765 |
goto getOutOfHere; |
|
766 |
} |
|
767 |
} else { |
|
768 |
nP = __signedLongIntVal(newPos); |
|
769 |
if (nP < 0) { |
|
770 |
__INST(lastErrorNumber) = __MKSMALLINT(EINVAL); |
|
771 |
goto getOutOfHere; |
|
772 |
} |
|
773 |
if (nP == 0) { |
|
774 |
if (sizeof(nP) == 8) { |
|
775 |
if (__signedLong64IntVal(newPos, &nP) == 0 || nP < 0) { |
|
776 |
__INST(lastErrorNumber) = __MKSMALLINT(EINVAL); |
|
777 |
goto getOutOfHere; |
|
778 |
} |
|
779 |
} else { |
|
780 |
__INST(lastErrorNumber) = __MKSMALLINT(EINVAL); |
|
781 |
goto getOutOfHere; |
|
782 |
} |
|
783 |
} |
|
784 |
} |
|
7871
5c357f1ba0c9
preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents:
7870
diff
changeset
|
785 |
|
7965 | 786 |
f = __FILEVal(fp); |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
787 |
|
7965 | 788 |
do { |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
789 |
#ifdef WIN32 |
7965 | 790 |
__threadErrno = 0; |
791 |
if (__INST(buffered) == true) { |
|
792 |
ret = STX_C_CALL3( "fseek", fseek, f, nP, SEEK_SET); |
|
793 |
} else { |
|
794 |
__INST(readAhead) = nil; |
|
795 |
ret = STX_C_CALL3( "lseek", lseek, fileno(f), nP, SEEK_SET); |
|
796 |
} |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
797 |
#else |
7965 | 798 |
if (__INST(buffered) == true) { |
799 |
ret = FSEEK(f, nP, SEEK_SET); |
|
800 |
} else { |
|
801 |
ret = lseek(fileno(f), nP, SEEK_SET); |
|
802 |
} |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
803 |
#endif |
7965 | 804 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
805 |
if (ret >= 0) { |
|
806 |
__INST(position) = newPos; __STORE(self, newPos); |
|
807 |
/* |
|
808 |
* just to make certain ... |
|
809 |
*/ |
|
810 |
__INST(hitEOF) = false; |
|
811 |
RETURN ( self ); |
|
812 |
} |
|
813 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
814 |
} |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
815 |
} |
7871
5c357f1ba0c9
preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents:
7870
diff
changeset
|
816 |
getOutOfHere: ; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
817 |
#undef FSEEK |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
818 |
%}. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
819 |
canPosition == false ifTrue:[ |
7965 | 820 |
"/ position by rewinding & re-reading everything up-to |
821 |
"/ that point. |
|
822 |
^ self slowPosition0Based:newPos |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
823 |
]. |
2963 | 824 |
lastErrorNumber notNil ifTrue:[ |
7965 | 825 |
(OperatingSystem errorSymbolForNumber:lastErrorNumber) == #EINVAL ifTrue:[ |
826 |
"/ invalid position |
|
827 |
^ self positionError |
|
828 |
]. |
|
829 |
"/ assume I/O error |
|
830 |
^ self ioError |
|
2963 | 831 |
]. |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
832 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
7871
5c357f1ba0c9
preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents:
7870
diff
changeset
|
833 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
834 |
rslt := self positionFile:filePointer position0Based:newPos. |
5493 | 835 |
rslt >= 0 ifTrue:[ |
7965 | 836 |
position := newPos. |
5493 | 837 |
] ifFalse:[ |
7965 | 838 |
hitEOF := true. |
5493 | 839 |
] |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
840 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
841 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
842 |
setToEnd |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
843 |
"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
|
844 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
845 |
%{ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
846 |
HFILE f; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
847 |
off_t ret; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
848 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
849 |
if (__INST(filePointer) != nil) { |
7965 | 850 |
f = __FILEVal(__INST(filePointer)); |
851 |
__INST(position) = nil; /* i.e. unknown */ |
|
852 |
do { |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
853 |
#ifdef WIN32 |
7965 | 854 |
__threadErrno = 0; |
855 |
if (__INST(buffered) == true) { |
|
856 |
ret = STX_C_CALL3( "fseek", fseek, f, 0L, SEEK_END); |
|
857 |
} else { |
|
858 |
__INST(readAhead) = nil; |
|
859 |
ret = STX_C_CALL3( "lseek", lseek, fileno(f), 0L, SEEK_END); |
|
860 |
} |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
861 |
#else |
7965 | 862 |
if (__INST(buffered) == true) { |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
863 |
#ifdef _LFS_LARGE_FILE |
7965 | 864 |
ret = fseeko(f, (off_t)0, SEEK_END); |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
865 |
#else |
7965 | 866 |
ret = fseek(f, 0L, SEEK_END); |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
867 |
#endif |
7965 | 868 |
} else { |
869 |
ret = lseek(fileno(f), (off_t)0, SEEK_END); |
|
870 |
} |
|
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
871 |
#endif |
7965 | 872 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
873 |
if (ret >= 0) { |
|
874 |
RETURN ( self ); |
|
875 |
} |
|
876 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
877 |
} |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
878 |
%}. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
879 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
880 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
881 |
^ self primitiveFailed |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
882 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
883 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
884 |
slowPosition0Based:newPos |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
885 |
"position the file by re-reading everything up-to newPos. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
886 |
The effect is the same as that of #position:, but its much slower. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
887 |
This is required to reposition nonPositionable streams, such |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
888 |
as tape-streams or variable-record-RMS files under VMS. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
889 |
Caveat: |
7965 | 890 |
This should really be done transparently by the stdio library." |
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
891 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
892 |
|buffer amount pos0Based| |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
893 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
894 |
self isReadable ifFalse:[ |
7965 | 895 |
"/ sorry |
896 |
^ self positionError |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
897 |
]. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
898 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
899 |
buffer := ByteArray new:8*1024. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
900 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
901 |
(position isNil "/ i.e. unknown |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
902 |
or:[newPos < (pos0Based := self position0Based)]) ifTrue:[ |
7965 | 903 |
self reset. |
904 |
pos0Based := self position0Based. |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
905 |
]. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
906 |
[pos0Based < newPos] whileTrue:[ |
7965 | 907 |
amount := (buffer size) min:(newPos-pos0Based). |
908 |
(self nextBytes:amount into:buffer startingAt:1) ~~ amount ifTrue:[ |
|
909 |
^ self positionError |
|
910 |
]. |
|
911 |
pos0Based := self position0Based. |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
912 |
]. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
913 |
"/ ('FileStream [info]: slow position - please convert ''' , pathName printString , ''' to streamLF format') infoPrintCR. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
914 |
! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
915 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
916 |
slowPosition:newPos |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
917 |
"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
|
918 |
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
|
919 |
This is required to reposition nonPositionable streams, such |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
920 |
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
|
921 |
Caveat: |
7965 | 922 |
This should really be done transparently by the stdio library." |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
923 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
924 |
^ self slowPosition0Based:(newPos - ZeroPosition) |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
925 |
! ! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
926 |
|
613 | 927 |
!FileStream methodsFor:'printing & storing'! |
928 |
||
929 |
printOn:aStream |
|
4392 | 930 |
"append a user printed representation of the receiver to aStream. |
931 |
The format is suitable for a human - not meant to be read back." |
|
2903 | 932 |
|
613 | 933 |
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
|
934 |
aStream nextPutAll:pathName printString. |
613 | 935 |
aStream nextPut:$) |
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
936 |
|
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
937 |
"Modified: 30.7.1997 / 13:51:01 / cg" |
613 | 938 |
! |
939 |
||
940 |
storeOn:aStream |
|
2903 | 941 |
"append a representation of the receiver to aStream, |
942 |
from which a copy can be reconstructed later." |
|
943 |
||
613 | 944 |
aStream nextPutAll:'(FileStream oldFileNamed:'. |
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
945 |
aStream nextPutAll:pathName storeString. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6798
diff
changeset
|
946 |
(self position ~~ ZeroPosition) ifTrue:[ |
7872 | 947 |
aStream nextPutAll:'; position:'. |
948 |
self position storeOn:aStream |
|
613 | 949 |
]. |
950 |
aStream nextPut:$) |
|
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
951 |
|
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
952 |
"Modified: 30.7.1997 / 16:43:50 / cg" |
1 | 953 |
! ! |
954 |
||
955 |
!FileStream methodsFor:'private'! |
|
956 |
||
613 | 957 |
createForReadWrite |
958 |
"create/truncate the file for read/write. |
|
959 |
If the file existed, its truncated; otherwise its created." |
|
1 | 960 |
|
613 | 961 |
mode := #readwrite. |
2921 | 962 |
^ self openWithMode:CreateReadWriteMode |
1 | 963 |
! |
964 |
||
613 | 965 |
createForWriting |
966 |
"create/truncate the file for writeonly. |
|
967 |
If the file existed, its truncated; otherwise its created." |
|
1 | 968 |
|
613 | 969 |
mode := #writeonly. |
970 |
didWrite := true. |
|
6798 | 971 |
^ self openWithMode:WriteMode attributes:nil |
1 | 972 |
! |
973 |
||
974 |
open |
|
975 |
"open the file" |
|
976 |
||
977 |
pathName isNil ifTrue:[^nil]. |
|
978 |
(mode == #readonly) ifTrue: [ |
|
7872 | 979 |
didWrite := false. |
980 |
^ self openWithMode:ReadMode |
|
1 | 981 |
]. |
982 |
(mode == #writeonly) ifTrue: [ |
|
7872 | 983 |
didWrite := true. |
984 |
^ self openWithMode:WriteMode |
|
1 | 985 |
]. |
2921 | 986 |
^ self openWithMode:ReadWriteMode |
1 | 987 |
! |
988 |
||
5439 | 989 |
openFile:pathName withMode:openmode attributes:attributeSpec |
990 |
"open the file; |
|
991 |
openmode is the string defining the way to open as defined by the stdio library |
|
992 |
(i.e. the 2nd fopen argument). |
|
993 |
||
994 |
attributeSpec is an additional argument, only used with VMS - it allows a file to |
|
995 |
be created as fixedRecord, variableRecord, streamLF, streamCR, ... |
|
996 |
In VMS, if nonNil, it must consist of an array of strings (max:10), giving additional |
|
997 |
attributes (see fopen description). |
|
998 |
Passing a nil specifies the default format (streamLF) - ST/X always invokes this with nil. |
|
999 |
This argument is ignored in UNIX & MSDOS systems. |
|
1000 |
||
1001 |
This is a private entry, but maybe useful to open/create a file in a special mode, |
|
1002 |
which is proprietrary to the operatingSystem." |
|
1003 |
||
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1004 |
|wasBlocked| |
5439 | 1005 |
|
1006 |
%{ |
|
1007 |
HFILE f; |
|
1008 |
HFILE fopen(); |
|
1009 |
OBJ fp; |
|
1010 |
int pass = 0; |
|
1011 |
||
1012 |
retry: |
|
1013 |
if (__isNonNilObject(pathName) && (__qClass(pathName)==String)) { |
|
1014 |
#ifdef __VMS__ |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1015 |
do { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1016 |
/* |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1017 |
* allow passing additional RMS arguments. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1018 |
* stupid: DEC does not seem to offer an interface for passing a char **. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1019 |
*/ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1020 |
__threadErrno = 0; |
5439 | 1021 |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1022 |
{ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1023 |
if (__isArray(attributeSpec)) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1024 |
OBJ *ap = __ArrayInstPtr(attributeSpec)->a_element; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1025 |
int numAttrib = 0; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1026 |
int i; |
5439 | 1027 |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1028 |
numAttrib = __arraySize(attributeSpec); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1029 |
for (i=0; i<numAttrib;i++) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1030 |
if (! __isString(ap[i])) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1031 |
f = NULL; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1032 |
__threadErrno = EINVAL; /* invalid argument */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1033 |
goto getOutOfHere; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1034 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1035 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1036 |
switch (numAttrib) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1037 |
case 0: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1038 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1039 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode)); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1040 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1041 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1042 |
case 1: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1043 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1044 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1045 |
__stringVal(ap[0])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1046 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1047 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1048 |
case 2: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1049 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1050 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1051 |
__stringVal(ap[0]), __stringVal(ap[1])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1052 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1053 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1054 |
case 3: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1055 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1056 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1057 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1058 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1059 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1060 |
case 4: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1061 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1062 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1063 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1064 |
__stringVal(ap[3])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1065 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1066 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1067 |
case 5: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1068 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1069 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1070 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1071 |
__stringVal(ap[3]), __stringVal(ap[4])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1072 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1073 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1074 |
case 6: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1075 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1076 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1077 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1078 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1079 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1080 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1081 |
case 7: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1082 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1083 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1084 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1085 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1086 |
__stringVal(ap[6])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1087 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1088 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1089 |
case 8: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1090 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1091 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1092 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1093 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1094 |
__stringVal(ap[6]), __stringVal(ap[7])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1095 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1096 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1097 |
case 9: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1098 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1099 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1100 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1101 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1102 |
__stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1103 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1104 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1105 |
case 10: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1106 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1107 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1108 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1109 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1110 |
__stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1111 |
__stringVal(ap[9])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1112 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1113 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1114 |
default: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1115 |
f = NULL; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1116 |
__threadErrno = E2BIG; /* too many args */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1117 |
goto getOutOfHere; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1118 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1119 |
} else if (attributeSpec != nil) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1120 |
f = NULL; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1121 |
__threadErrno = EINVAL; /* invalid argument */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1122 |
goto getOutOfHere; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1123 |
} else { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1124 |
/* |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1125 |
* create file as sequential streamLF by default. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1126 |
*/ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1127 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1128 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), "rfm=stmlf"); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1129 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1130 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1131 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1132 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
5439 | 1133 |
|
1134 |
#else /* not VMS */ |
|
1135 |
||
1136 |
# ifdef WIN32 |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1137 |
{ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1138 |
char _aPathName[MAXPATHLEN]; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1139 |
char _openMode[64]; |
5439 | 1140 |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1141 |
strncpy(_aPathName, __stringVal(pathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1142 |
strncpy(_openMode, __stringVal(openmode), sizeof(_openMode)-1); _openMode[sizeof(_openMode)-1] = '\0'; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1143 |
do { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1144 |
__threadErrno = 0; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1145 |
f = STX_C_CALL2( "fopen", fopen, _aPathName, _openMode); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1146 |
if (__threadErrno == EINTR) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1147 |
f = NULL; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1148 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1149 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1150 |
} |
5439 | 1151 |
# else /* not WIN32 */ |
1152 |
||
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1153 |
do { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1154 |
__BEGIN_INTERRUPTABLE__ |
5439 | 1155 |
# ifdef LINUX |
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1156 |
/* |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1157 |
* LINUX may ret a non-NULL f even when interrupted. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1158 |
* Therefore, check errno and fake a null-ret. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1159 |
*/ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1160 |
__threadErrno = 0; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1161 |
f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode)); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1162 |
if (__threadErrno == EINTR) |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1163 |
f = NULL; |
5439 | 1164 |
# else /* not LINUX */ |
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1165 |
f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode)); |
5439 | 1166 |
# endif /* not LINUX */ |
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1167 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1168 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
5439 | 1169 |
|
1170 |
# endif /* not WIN32 */ |
|
1171 |
#endif /* not VMS */ |
|
1172 |
||
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1173 |
if (f == NULL) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1174 |
/* |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1175 |
* If no filedescriptors available, try to finalize |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1176 |
* possibly collected fd's and try again. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1177 |
*/ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1178 |
if (pass == 0 && (__threadErrno == ENFILE || __threadErrno == EMFILE)) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1179 |
pass = 1; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1180 |
__SSEND0(@global(ObjectMemory), @symbol(scavenge), 0); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1181 |
__SSEND0(@global(ObjectMemory), @symbol(finalize), 0); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1182 |
goto retry; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1183 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1184 |
getOutOfHere: ; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1185 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1186 |
__INST(position) = nil; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1187 |
} else { |
5439 | 1188 |
#ifdef __VMS__ |
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1189 |
/* |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1190 |
* check to see if this is positionable ... |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1191 |
*/ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1192 |
__INST(canPosition) = false; |
5439 | 1193 |
# ifndef _POSIX_C_SOURCE |
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1194 |
{ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1195 |
struct stat statBuffer; |
5439 | 1196 |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1197 |
if (fstat(fileno(f), &statBuffer) >= 0) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1198 |
switch (statBuffer.st_fab_rfm) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1199 |
case FAB$C_UDF: /* undefined (also stream binary) */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1200 |
case FAB$C_VAR: /* variable length records */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1201 |
case FAB$C_VFC: /* variable fixed control */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1202 |
case FAB$C_STM: /* RMS-11 stream (valid only for sequen> */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1203 |
default: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1204 |
__INST(canPosition) = false; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1205 |
break; |
5439 | 1206 |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1207 |
case FAB$C_FIX: /* fixed length records */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1208 |
case FAB$C_STMLF: /* LF stream (valid only for sequential> */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1209 |
case FAB$C_STMCR: /* CR stream (valid only for sequential> */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1210 |
__INST(canPosition) = true; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1211 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1212 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1213 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1214 |
} |
5439 | 1215 |
# endif |
1216 |
#else /* not VMS */ |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1217 |
__INST(canPosition) = true; |
5439 | 1218 |
#endif /* poor VMS */ |
1219 |
||
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1220 |
if (@global(FileOpenTrace) == true) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1221 |
fprintf(stderr, "fopen %s [FileStream] -> %x\n", __stringVal(pathName), f); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1222 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1223 |
if (f != NULL) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1224 |
wasBlocked = __BLOCKINTERRUPTS(); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1225 |
__INST(filePointer) = __MKOBJ((INT)f); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1226 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1227 |
__INST(position) = @global(PositionableStream:ZeroPosition); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1228 |
} |
5439 | 1229 |
} |
1230 |
%}. |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1231 |
filePointer notNil ifTrue:[ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1232 |
Lobby register:self. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1233 |
wasBlocked == false ifTrue:[OperatingSystem unblockInterrupts]. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1234 |
]. |
5439 | 1235 |
^ filePointer |
1236 |
! |
|
1237 |
||
613 | 1238 |
openForAppending |
1239 |
"open the file for writeonly appending to the end. |
|
1240 |
If the file does not exist its an error, return nil; |
|
1241 |
otherwise return the receiver." |
|
1242 |
||
1243 |
mode := #writeonly. |
|
1244 |
didWrite := true. |
|
2921 | 1245 |
^ self openWithMode:AppendMode |
613 | 1246 |
! |
1247 |
||
1248 |
openForReadWrite |
|
1249 |
"open the file for read/write. |
|
1250 |
If the file does not exist its an error, return nil; |
|
1251 |
otherwise return the receiver." |
|
1252 |
||
1253 |
mode := #readwrite. |
|
2921 | 1254 |
^ self openWithMode:ReadWriteMode |
613 | 1255 |
! |
1256 |
||
1257 |
openForReading |
|
1258 |
"open the file for readonly. |
|
1259 |
If the file does not exist its an error, return nil; |
|
1260 |
otherwise return the receiver." |
|
1261 |
||
1262 |
mode := #readonly. |
|
1263 |
didWrite := false. |
|
2921 | 1264 |
^ self openWithMode:ReadMode |
613 | 1265 |
! |
1266 |
||
1267 |
openForWriting |
|
1268 |
"open the file writeonly. |
|
1269 |
If the file does not exist its an error, return nil; |
|
1270 |
otherwise return the receiver." |
|
1271 |
||
1272 |
mode := #writeonly. |
|
1273 |
didWrite := true. |
|
2921 | 1274 |
^ self openWithMode:ReadWriteMode "unix-io does not allow this; open for update here" |
613 | 1275 |
! |
1276 |
||
1 | 1277 |
openWithMode:openmode |
2921 | 1278 |
"open the file; |
1279 |
openmode is the string defining the way to open as defined by the stdio library |
|
1280 |
(i.e. the 2nd fopen argument). |
|
1281 |
||
1282 |
This is a private entry, but maybe useful to open a file in a special mode, |
|
1283 |
which is proprietrary to the operatingSystem." |
|
1284 |
||
1285 |
^ self openWithMode:openmode attributes:nil |
|
1286 |
! |
|
1287 |
||
1288 |
openWithMode:openmode attributes:attributeSpec |
|
2908 | 1289 |
"open the file; |
2921 | 1290 |
openmode is the string defining the way to open as defined by the stdio library |
1291 |
(i.e. the 2nd fopen argument). |
|
1292 |
||
1293 |
attributeSpec is an additional argument, only used with VMS - it allows a file to |
|
1294 |
be created as fixedRecord, variableRecord, streamLF, streamCR, ... |
|
1295 |
In VMS, if nonNil, it must consist of an array of strings (max:10), giving additional |
|
1296 |
attributes (see fopen description). |
|
1297 |
Passing a nil specifies the default format (streamLF) - ST/X always invokes this with nil. |
|
1298 |
This argument is ignored in UNIX & MSDOS systems. |
|
1299 |
||
1300 |
This is a private entry, but maybe useful to open/create a file in a special mode, |
|
1301 |
which is proprietrary to the operatingSystem." |
|
1 | 1302 |
|
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
1303 |
filePointer notNil ifTrue:[^ self errorAlreadyOpen]. |
2921 | 1304 |
|
5439 | 1305 |
filePointer := self openFile:pathName withMode:openmode attributes:attributeSpec. |
1306 |
filePointer isNil ifTrue:[ |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1307 |
" |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1308 |
the open failed for some reason ... |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1309 |
" |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1310 |
^ self openError |
1 | 1311 |
]. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6798
diff
changeset
|
1312 |
position := ZeroPosition. |
2963 | 1313 |
buffered := true. "default is buffered" |
1 | 1314 |
! |
1315 |
||
613 | 1316 |
pathName:filename |
1317 |
"set the pathname" |
|
1 | 1318 |
|
3051
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1319 |
pathName := filename asString |
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1320 |
|
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1321 |
"Modified: / 28.10.1997 / 14:29:01 / cg" |
1 | 1322 |
! |
1323 |
||
613 | 1324 |
pathName:filename in:aDirectory |
1325 |
"set the pathname starting at aDirectory, a FileDirectory" |
|
77 | 1326 |
|
3051
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1327 |
pathName := aDirectory asFilename constructString:filename |
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1328 |
|
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1329 |
"Modified: / 28.10.1997 / 14:28:54 / cg" |
1 | 1330 |
! |
1331 |
||
1332 |
reOpen |
|
1333 |
"sent after snapin to reopen streams" |
|
1334 |
||
173 | 1335 |
|oldPos| |
1336 |
||
1 | 1337 |
filePointer notNil ifTrue:[ |
7872 | 1338 |
"it was open, when snapped-out" |
1339 |
filePointer := nil. |
|
1340 |
Lobby unregister:self. |
|
1341 |
oldPos := position. |
|
1342 |
self open. |
|
1343 |
filePointer isNil ifTrue:[ |
|
1344 |
"/ this happens, if after a restart, |
|
1345 |
"/ the file is no longer present or accessable ..." |
|
13 | 1346 |
|
7872 | 1347 |
(self class name , ' [warning]: could not reOpen file: ', pathName) errorPrintCR. |
1348 |
] ifFalse:[ |
|
1349 |
oldPos notNil ifTrue:[ |
|
1350 |
self position:oldPos. |
|
1351 |
] |
|
1352 |
] |
|
1 | 1353 |
] |
1088 | 1354 |
|
2134
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2078
diff
changeset
|
1355 |
"Modified: 10.1.1997 / 17:50:51 / cg" |
2921 | 1356 |
! |
1357 |
||
1358 |
setMode:aModeSymbol |
|
1359 |
mode := aModeSymbol |
|
31 | 1360 |
! ! |
1361 |
||
2921 | 1362 |
!FileStream methodsFor:'queries'! |
613 | 1363 |
|
2903 | 1364 |
fileSize |
613 | 1365 |
"return the size in bytes of the file" |
1366 |
||
3971 | 1367 |
%{ |
613 | 1368 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
1369 |
HFILE f; |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
1370 |
|
613 | 1371 |
#ifdef transputer |
7874
5e0319ca5e60
stats filesize can be up-to 32bit now.
Claus Gittinger <cg@exept.de>
parents:
7872
diff
changeset
|
1372 |
unsigned int size; |
613 | 1373 |
|
1133 | 1374 |
if (__INST(filePointer) != nil) { |
7965 | 1375 |
f = __FILEVal(__INST(filePointer)); |
1376 |
if ((size = filesize(fileno(f))) >= 0) { |
|
1377 |
RETURN ( __MKUINT(size) ); |
|
1378 |
} |
|
613 | 1379 |
} |
1380 |
#else |
|
1381 |
struct stat buf; |
|
1382 |
int ret; |
|
1383 |
int fd; |
|
1384 |
||
1133 | 1385 |
if (__INST(filePointer) != nil) { |
7965 | 1386 |
f = __FILEVal(__INST(filePointer)); |
1387 |
fd = fileno(f); |
|
1388 |
do { |
|
1389 |
ret = fstat(fd, &buf); |
|
1390 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
|
1391 |
if (ret >= 0) { |
|
1392 |
OBJ rslt; |
|
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
1393 |
|
7965 | 1394 |
if (sizeof(buf.st_size) == 8) { |
1395 |
rslt = __MKINT64(&buf.st_size); |
|
1396 |
} else { |
|
1397 |
rslt = __MKINT(buf.st_size); |
|
1398 |
} |
|
1399 |
RETURN(rslt); |
|
1400 |
} |
|
1401 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
613 | 1402 |
} |
1403 |
#endif |
|
1404 |
%}. |
|
1405 |
||
1406 |
"could add a fall-back here: |
|
1407 |
||
7965 | 1408 |
oldPosition := self position. |
1409 |
self setToEnd. |
|
1410 |
sz := self position. |
|
1411 |
self position:oldPosition. |
|
1412 |
^ sz |
|
613 | 1413 |
" |
1414 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
1415 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
1416 |
^ self primitiveFailed |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1417 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1418 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1419 |
size |
2998
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1420 |
"return the size of the stream; |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1421 |
thats the number of bytes of the file." |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1422 |
|
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1423 |
"/ no obsoleteMethodWarning - size is ok for streams. |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1424 |
"/ self obsoleteMethodWarning:'use #fileSize'. |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1425 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1426 |
^ self fileSize. |
2998
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1427 |
|
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1428 |
"Modified: 4.10.1997 / 18:01:09 / cg" |
1 | 1429 |
! ! |
1430 |
||
5493 | 1431 |
!FileStream methodsFor:'rel5 protocol'! |
1432 |
||
1433 |
positionFile:filePointer position:newPos |
|
1434 |
"for migration to rel5 only" |
|
1435 |
||
1436 |
self primitiveFailed |
|
1437 |
! ! |
|
1438 |
||
2 | 1439 |
!FileStream methodsFor:'testing'! |
1440 |
||
1441 |
isFileStream |
|
1442 |
"return true, if the receiver is some kind of fileStream. |
|
1443 |
redefined from Object" |
|
1444 |
||
1445 |
^ true |
|
1446 |
! ! |
|
1447 |
||
1088 | 1448 |
!FileStream class methodsFor:'documentation'! |
1449 |
||
1450 |
version |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1451 |
^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.105 2004-03-02 14:16:08 ca Exp $' |
1088 | 1452 |
! ! |
6798 | 1453 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1454 |
FileStream initialize! |