author | Claus Gittinger <cg@exept.de> |
Mon, 03 Jun 2013 20:41:26 +0200 | |
changeset 15360 | 7bf49766c324 |
parent 14853 | 63ffca691137 |
child 15462 | daed379229a2 |
child 18066 | 89d51443ba6f |
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 |
" |
|
5439 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
1 | 14 |
ExternalStream subclass:#FileStream |
7872 | 15 |
instanceVariableNames:'pathName canPosition removeOnClose' |
16 |
classVariableNames:'UserInitiatedFileSaveQuerySignal' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Streams-External' |
|
1 | 19 |
! |
20 |
||
216 | 21 |
!FileStream primitiveDefinitions! |
1 | 22 |
%{ |
2903 | 23 |
|
14632 | 24 |
#undef String |
25 |
#undef Character |
|
26 |
||
1 | 27 |
#include <stdio.h> |
437 | 28 |
#define _STDIO_H_INCLUDED_ |
29 |
||
10 | 30 |
#include <errno.h> |
437 | 31 |
#define _ERRNO_H_INCLUDED_ |
1 | 32 |
|
33 |
#ifdef transputer |
|
34 |
# include <iocntrl.h> |
|
35 |
# ifndef fileno |
|
36 |
/* kludge: inmos forgot fileno */ |
|
37 |
# define fileno(f) ((f)->__file) |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
38 |
# endif |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
39 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
40 |
#else /* not transputer */ |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
41 |
|
1 | 42 |
# include <sys/types.h> |
43 |
# include <sys/stat.h> |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
44 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
45 |
#endif /* not transputer */ |
10 | 46 |
|
42 | 47 |
#ifdef hpux |
68 | 48 |
# define fileno(f) ((f->__fileH << 8) | (f->__fileL)) |
42 | 49 |
#endif |
50 |
||
2921 | 51 |
#ifdef __VMS__ |
52 |
# include <rms.h> |
|
53 |
#endif |
|
54 |
||
14635
aa0d74813208
Add __ before STX_String, STX_Character
Stefan Vogel <sv@exept.de>
parents:
14633
diff
changeset
|
55 |
#define String __STX_String |
aa0d74813208
Add __ before STX_String, STX_Character
Stefan Vogel <sv@exept.de>
parents:
14633
diff
changeset
|
56 |
#define Character __STX_Character |
14632 | 57 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
58 |
#ifdef WIN32 |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
59 |
# define NO_STDIO |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
60 |
# ifdef __i386__ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
61 |
# define _X86_ |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
62 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
63 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
64 |
# undef INT |
10345 | 65 |
# undef UINT |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
66 |
# undef Array |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
67 |
# undef Number |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
68 |
# undef Method |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
69 |
# undef Point |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
70 |
# undef Rectangle |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
71 |
# undef Block |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
72 |
# undef Time |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
73 |
# undef Date |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
74 |
# undef Set |
5910 | 75 |
# undef Signal |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
76 |
# undef Delay |
5910 | 77 |
# undef Context |
9025 | 78 |
# undef Message |
79 |
# undef Process |
|
10342 | 80 |
# undef Processor |
14632 | 81 |
# undef String |
82 |
# undef Character |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
83 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
84 |
# define NOATOM |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
85 |
# define NOGDICAPMASKS |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
86 |
# define NOMETAFILE |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
87 |
# define NOMINMAX |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
88 |
//# define NOOPENFILE |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
89 |
# define NOSOUND |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
90 |
# define NOWH |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
91 |
//# define NOCOMM |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
92 |
# define NOKANJI |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
93 |
# define NOCRYPT |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
94 |
//# define NOMCX |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
95 |
# define WIN32_LEAN_AND_MEAN |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
96 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
97 |
# include <windows.h> |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
98 |
|
14633 | 99 |
# if 1 // defined(__MINGW64__) |
14632 | 100 |
# include <fcntl.h> |
101 |
# endif |
|
102 |
||
10450
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
103 |
# if defined(__BORLANDC__) |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
104 |
# include <io.h> |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
105 |
# else |
10342 | 106 |
# define lseek _lseek |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
107 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
108 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
109 |
# ifdef __DEF_Array |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
110 |
# define Array __DEF_Array |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
111 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
112 |
# ifdef __DEF_Number |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
113 |
# define Number __DEF_Number |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
114 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
115 |
# ifdef __DEF_Method |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
116 |
# define Method __DEF_Method |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
117 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
118 |
# ifdef __DEF_Point |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
119 |
# define Point __DEF_Point |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
120 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
121 |
# ifdef __DEF_Block |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
122 |
# define Block __DEF_Block |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
123 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
124 |
# ifdef __DEF_Time |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
125 |
# define Time __DEF_Time |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
126 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
127 |
# ifdef __DEF_Date |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
128 |
# define Date __DEF_Date |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
129 |
# endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
130 |
# ifdef __DEF_Set |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
131 |
# define Set __DEF_Set |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
132 |
# endif |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
133 |
# ifdef __DEF_Signal |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
134 |
# define Signal __DEF_Signal |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
135 |
# endif |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
136 |
# ifdef __DEF_Delay |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
137 |
# define Delay __DEF_Delay |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
138 |
# endif |
5910 | 139 |
# ifdef __DEF_Context |
140 |
# define Context __DEF_Context |
|
141 |
# endif |
|
9025 | 142 |
# ifdef __DEF_Message |
143 |
# define Message __DEF_Message |
|
144 |
# endif |
|
145 |
# ifdef __DEF_Process |
|
146 |
# define Process __DEF_Process |
|
147 |
# endif |
|
10342 | 148 |
# ifdef __DEF_Processor |
149 |
# define Processor __DEF_Processor |
|
150 |
# endif |
|
14632 | 151 |
# ifdef __DEF_String |
152 |
# define String __DEF_String |
|
153 |
# endif |
|
154 |
# ifdef __DEF_Character |
|
155 |
# define Character __DEF_Character |
|
156 |
# endif |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
157 |
|
14644 | 158 |
# define INT STX_INT |
159 |
# define UINT STX_UINT |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
160 |
|
14632 | 161 |
# if 0 |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
162 |
# ifndef DO_WRAP_CALLS |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
163 |
# 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
|
164 |
# 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
|
165 |
# 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
|
166 |
# 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
|
167 |
# else |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
168 |
# 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
|
169 |
# 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
|
170 |
# 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
|
171 |
# 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
|
172 |
# endif |
14632 | 173 |
# endif |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
174 |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
175 |
/* # define HFILE HANDLE */ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
176 |
# define HFILE FILE * |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
177 |
/* # define fileno(f) f */ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
178 |
|
7970 | 179 |
#else /* not WIN32 */ |
180 |
# define HFILE FILE * |
|
8039
6ef0379296cc
#position0Based did not work on unbuffered streams (with 64 bit off_t).
Stefan Vogel <sv@exept.de>
parents:
8034
diff
changeset
|
181 |
#endif /* ! WIN32 */ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
182 |
|
14853
63ffca691137
fseek does not need a WRAP_CALL (I hope)
Claus Gittinger <cg@exept.de>
parents:
14848
diff
changeset
|
183 |
#define xxDO_WRAP_CALL_FSEEK |
63ffca691137
fseek does not need a WRAP_CALL (I hope)
Claus Gittinger <cg@exept.de>
parents:
14848
diff
changeset
|
184 |
|
7570 | 185 |
#include "stxOSDefs.h" |
186 |
||
10342 | 187 |
#ifndef SEEK_SET |
188 |
# define SEEK_SET 0 |
|
189 |
#endif |
|
190 |
#ifndef SEEK_CUR |
|
191 |
# define SEEK_CUR 1 |
|
192 |
#endif |
|
193 |
#ifndef SEEK_END |
|
194 |
# define SEEK_END 2 |
|
195 |
#endif |
|
196 |
||
1 | 197 |
%} |
173 | 198 |
! ! |
1 | 199 |
|
613 | 200 |
!FileStream class methodsFor:'documentation'! |
201 |
||
202 |
copyright |
|
203 |
" |
|
204 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
7872 | 205 |
All Rights Reserved |
613 | 206 |
|
207 |
This software is furnished under a license and may be used |
|
208 |
only in accordance with the terms of that license and with the |
|
209 |
inclusion of the above copyright notice. This software may not |
|
210 |
be provided or otherwise made available to, or used by, any |
|
211 |
other person. No title to or ownership of the software is |
|
212 |
hereby transferred. |
|
213 |
" |
|
214 |
! |
|
215 |
||
216 |
documentation |
|
217 |
" |
|
218 |
This class provides access to the operating systems underlying file |
|
219 |
system (i.e. its an interface to the stdio library). |
|
220 |
||
221 |
Notice, that on some systems, the standard I/O library has performance |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
222 |
problems when a file is opened for readwrite. |
613 | 223 |
For best results, open files either readonly or writeonly. |
1295 | 224 |
|
2921 | 225 |
Also notice, that some OperatingSystems do not fully support |
226 |
positioning a file stream. |
|
227 |
For example, poor VMS does not allow positioning onto arbitrary |
|
228 |
byte boundaries if the file is a variable-record-RMS file. |
|
229 |
(stupid enough, this is the default for textfiles as created by |
|
230 |
some tools ...) |
|
231 |
Therefore, the instance variable canPosition is set according to |
|
232 |
this and an error is raised, if a position: is attemted. |
|
233 |
I know, this is ugly, but what else could we do ? |
|
234 |
||
235 |
[instance variables:] |
|
7872 | 236 |
pathName <String> the files path (if known) |
237 |
canPosition <Boolean> positionable - read above comment |
|
2921 | 238 |
|
1295 | 239 |
[author:] |
7872 | 240 |
Claus Gittinger |
1295 | 241 |
|
242 |
[see also:] |
|
7872 | 243 |
Filename DirectoryStream PipeStream Socket |
613 | 244 |
" |
2921 | 245 |
! |
246 |
||
247 |
examples |
|
248 |
" |
|
249 |
for VMS users only: |
|
250 |
||
251 |
The #openWithMode:attributes: entry allows additional RMS attributes |
|
252 |
to be passed in the second argument, which must be an array of strings |
|
253 |
as described in the 'creat' RTL Library documentation. |
|
254 |
||
255 |
For example, to create a file with fixed records and recordLength of 100, |
|
256 |
use: |
|
257 |
||
7872 | 258 |
|newFile| |
2921 | 259 |
|
7872 | 260 |
newFile := FileStream new pathName:'<nameOfFile>'. |
261 |
newFile setMode:#writeonly. |
|
262 |
newFile openWithMode:'w' attributes:#('rfm=fix' 'fsz=100'). |
|
2921 | 263 |
|
264 |
since all of the above is private protocol, and it is considered bad style to |
|
265 |
access these from user programs, we recommend subclassing FileStream as |
|
266 |
something like VMSFixedRecordFileStream, and redefine the instance creation |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
267 |
method(s) there as appropriate. |
2921 | 268 |
This will retain VMS specifics in one place and enhance maintanability. |
269 |
" |
|
270 |
! ! |
|
271 |
||
272 |
!FileStream class methodsFor:'initialization'! |
|
273 |
||
274 |
initialize |
|
7379 | 275 |
UserInitiatedFileSaveQuerySignal isNil ifTrue:[ |
7965 | 276 |
"/ |
277 |
"/ this is temporary - for now allow an openError to |
|
278 |
"/ be unhandled and proceed by returning a nil from the |
|
279 |
"/ stream creation method. |
|
280 |
"/ In the future, this will be a hard signal. |
|
281 |
"/ THE FUTURE IS NOW!!!! |
|
282 |
"/ |
|
7379 | 283 |
"/ OpenErrorSignal := QuerySignal new. |
284 |
"/ OpenErrorSignal parent:(super openErrorSignal) mayProceed:true. |
|
285 |
"/ OpenErrorSignal nameClass:self message:#openErrorSignal. |
|
286 |
"/ OpenErrorSignal notifierString:'open error'. |
|
4907 | 287 |
|
7965 | 288 |
UserInitiatedFileSaveQuerySignal := QuerySignal new defaultAnswer:true. |
289 |
UserInitiatedFileSaveQuerySignal nameClass:self message:#userInitiatedFileSaveQuerySignal. |
|
2921 | 290 |
] |
3006
b3530950854a
use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents:
2998
diff
changeset
|
291 |
|
b3530950854a
use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents:
2998
diff
changeset
|
292 |
"Modified: 8.10.1997 / 11:56:39 / cg" |
2921 | 293 |
! ! |
294 |
||
1 | 295 |
!FileStream class methodsFor:'instance creation'! |
296 |
||
613 | 297 |
appendingOldFileNamed:filename |
298 |
"return a FileStream for existing file named filename, aString. |
|
299 |
The file is opened for writeonly access." |
|
1 | 300 |
|
7827 | 301 |
|
1 | 302 |
|newStream| |
7827 | 303 |
|
2 | 304 |
newStream := self new pathName:filename. |
8508
68cd95545196
Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
305 |
^ newStream openForAppending. |
7827 | 306 |
|
307 |
" |
|
308 |
FileStream appendingOldFileNamed:'adasdasasd' |
|
309 |
" |
|
613 | 310 |
! |
311 |
||
312 |
appendingOldFileNamed:filename in:aDirectory |
|
313 |
"return a FileStream for existing file named filename, aString |
|
314 |
in aDirectory, a FileDirectory. |
|
315 |
The file is opened for writeonly access." |
|
316 |
||
317 |
|newStream| |
|
318 |
newStream := self new pathName:filename in:aDirectory. |
|
8508
68cd95545196
Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
319 |
^ newStream openForAppending. |
1 | 320 |
! |
321 |
||
613 | 322 |
fileNamed:filename |
323 |
"return a stream on file filename - if the file does not |
|
324 |
already exist, create it. |
|
92 | 325 |
The file is opened for read/write access." |
1 | 326 |
|
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
327 |
[ |
7965 | 328 |
^ self oldFileNamed:filename. |
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
329 |
] on:self openErrorSignal do:[:ex| ]. |
613 | 330 |
|
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
331 |
^ self newFileNamed:filename |
613 | 332 |
! |
333 |
||
334 |
fileNamed:filename in:aDirectory |
|
335 |
"return a stream on file filename - if the file does not |
|
336 |
already exist, create it. |
|
337 |
The file is opened for read/write access." |
|
338 |
||
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
339 |
[ |
7965 | 340 |
^ self oldFileNamed:filename in:aDirectory. |
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
341 |
] on:self openErrorSignal do:[:ex| ]. |
613 | 342 |
|
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
343 |
^ self newFileNamed:filename in:aDirectory |
1 | 344 |
! |
345 |
||
92 | 346 |
newFileForWritingNamed:filename |
347 |
"return a FileStream for new file named filename, aString. |
|
348 |
If the file exists, it is truncated, otherwise created. |
|
349 |
The file is opened for writeonly access." |
|
350 |
||
351 |
|newStream| |
|
352 |
newStream := self new pathName:filename. |
|
8508
68cd95545196
Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
353 |
^ newStream createForWriting. |
92 | 354 |
! |
355 |
||
356 |
newFileForWritingNamed:filename in:aDirectory |
|
357 |
"return a FileStream for new file named filename, aString |
|
358 |
in aDirectory, a FileDirectory. |
|
359 |
If the file exists, it is truncated, otherwise created. |
|
360 |
The file is opened for writeonly access." |
|
361 |
||
362 |
|newStream| |
|
363 |
newStream := self new pathName:filename in:aDirectory. |
|
8508
68cd95545196
Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
364 |
^ newStream createForWriting. |
92 | 365 |
! |
366 |
||
613 | 367 |
newFileNamed:filename |
368 |
"return a FileStream for new file named filename, aString. |
|
369 |
If the file exists, it is truncated, otherwise created. |
|
370 |
The file is opened for read/write access." |
|
371 |
||
372 |
|newStream| |
|
373 |
newStream := self new pathName:filename. |
|
8508
68cd95545196
Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
374 |
^ newStream createForReadWrite. |
3051
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
375 |
|
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
376 |
"Modified: / 28.10.1997 / 14:28:08 / cg" |
613 | 377 |
! |
378 |
||
379 |
newFileNamed:filename in:aDirectory |
|
380 |
"return a FileStream for new file named filename, aString |
|
381 |
in aDirectory, a FileDirectory. |
|
382 |
If the file exists, it is truncated, otherwise created. |
|
383 |
The file is opened for read/write access." |
|
384 |
||
385 |
|newStream| |
|
386 |
newStream := self new pathName:filename in:aDirectory. |
|
8508
68cd95545196
Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
387 |
^ newStream createForReadWrite. |
613 | 388 |
! |
389 |
||
1 | 390 |
oldFileNamed:filename |
391 |
"return a FileStream for existing file named filename, aString. |
|
7827 | 392 |
The file is opened for read/write access. |
393 |
Raises an error if the file does not exist." |
|
1 | 394 |
|
395 |
|newStream| |
|
396 |
||
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
397 |
"/ 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
|
398 |
"/ (OperatingSystem isReadable:filename) ifFalse:[^ self new openError]. |
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
399 |
|
2 | 400 |
newStream := self new pathName:filename. |
1 | 401 |
newStream readwrite. |
8508
68cd95545196
Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
402 |
^ newStream openForReadWrite. |
7827 | 403 |
|
404 |
" |
|
405 |
FileStream oldFileNamed:'/dAsGiBtEsNiChT' |
|
406 |
" |
|
1 | 407 |
! |
408 |
||
409 |
oldFileNamed:filename in:aDirectory |
|
410 |
"return a FileStream for existing file named filename, aString |
|
411 |
in aDirectory, a FileDirectory. |
|
7827 | 412 |
The file is opened for read/write access. |
413 |
Raises an error if the file does not exist." |
|
1 | 414 |
|
415 |
|newStream| |
|
2 | 416 |
newStream := self new pathName:filename in:aDirectory. |
8508
68cd95545196
Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
417 |
^ newStream openForReadWrite. |
7827 | 418 |
|
419 |
" |
|
420 |
FileStream oldFileNamed:'dAsGiBtEsNiChT' in:'/' |
|
421 |
" |
|
1 | 422 |
! |
423 |
||
424 |
readonlyFileNamed:filename |
|
7827 | 425 |
"return a readonly FileStream for existing file named filename, aString. |
426 |
Raises an error if the file does not exist." |
|
1 | 427 |
|
428 |
|newStream| |
|
429 |
||
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
430 |
"/ 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
|
431 |
"/ (OperatingSystem isReadable:filename) ifFalse:[^ self new openError]. |
1 | 432 |
|
2 | 433 |
newStream := self new pathName:filename. |
8508
68cd95545196
Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
434 |
^ newStream openForReading. |
7827 | 435 |
|
436 |
" |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
437 |
FileStream readonlyFileNamed:'dAsGiBtEsNiChT' |
7827 | 438 |
" |
1 | 439 |
! |
440 |
||
441 |
readonlyFileNamed:filename in:aDirectory |
|
442 |
"return a readonly FileStream for existing file named filename, aString |
|
7827 | 443 |
in aDirectory, a fileName or string instance representing a directory. |
444 |
Raises an error if the file does not exist." |
|
1 | 445 |
|
446 |
|newStream| |
|
2 | 447 |
newStream := self new pathName:filename in:aDirectory. |
8508
68cd95545196
Allow to proceed with any stream from an #openError handler
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
448 |
^ newStream openForReading. |
7827 | 449 |
|
450 |
" |
|
451 |
FileStream readonlyFileNamed:'dAsGiBtEsNiChT' in:'/' |
|
452 |
FileStream readonlyFileNamed:'dAsGiBtEsNiChT' in:'/' asFilename |
|
453 |
" |
|
159 | 454 |
! ! |
455 |
||
7298 | 456 |
!FileStream class methodsFor:'Compatibility-ANSI'! |
6586 | 457 |
|
458 |
write:filename |
|
459 |
"return a FileStream for new file named filename, aString. |
|
460 |
If the file exists, it is truncated, otherwise created. |
|
461 |
The file is opened for read/write access. |
|
462 |
Same as newFileNamed: for ANSI compatibilily" |
|
463 |
||
464 |
^ self newFileNamed:filename |
|
465 |
! ! |
|
466 |
||
7298 | 467 |
!FileStream class methodsFor:'Compatibility-Dolphin'! |
6244 | 468 |
|
469 |
read:filename text:text |
|
470 |
"return a readonly FileStream for the existing file named filename, aString. |
|
471 |
If the argument, text is false, the stream is setup to read binary bytes, |
|
472 |
if false, it reads characters." |
|
473 |
||
474 |
|s| |
|
475 |
||
476 |
s := self readOnlyFileNamed:filename. |
|
477 |
text ifTrue:[ |
|
7872 | 478 |
s text |
6244 | 479 |
] ifFalse:[ |
7872 | 480 |
s binary |
6244 | 481 |
]. |
482 |
^ s |
|
6474 | 483 |
! |
484 |
||
485 |
write:filename mode:modeSymbol |
|
486 |
"return a writable FileStream for the file named filename, aString. |
|
487 |
The modeSymbol controls how the file is opened; currently supported are: |
|
7965 | 488 |
#append |
6474 | 489 |
" |
490 |
||
491 |
modeSymbol == #append ifTrue:[ |
|
7965 | 492 |
^ self appendingOldFileNamed:filename |
6474 | 493 |
]. |
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
494 |
"/ 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
|
495 |
"/ 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
|
496 |
super openErrorSignal raiseRequestErrorString:' - unsupported mode'. |
6474 | 497 |
^ nil |
498 |
! |
|
499 |
||
500 |
write:filename text:textModeBoolean |
|
501 |
"return a writable FileStream for the file named filename, aString. |
|
502 |
If the argument, text is false, the stream is setup to write binary bytes, |
|
503 |
if false, it writes characters." |
|
504 |
||
505 |
|s| |
|
506 |
||
6475 | 507 |
s := self newFileNamed:filename. |
6474 | 508 |
s notNil ifTrue:[ |
7872 | 509 |
textModeBoolean ifTrue:[ |
510 |
s text |
|
511 |
] ifFalse:[ |
|
512 |
s binary |
|
513 |
] |
|
6474 | 514 |
]. |
515 |
^ s |
|
6244 | 516 |
! ! |
517 |
||
7298 | 518 |
!FileStream class methodsFor:'Compatibility-Squeak'! |
5186 | 519 |
|
520 |
readOnlyFileNamed:filename |
|
6244 | 521 |
"return a readonly FileStream for the existing file named filename, aString." |
522 |
||
5186 | 523 |
^ self readonlyFileNamed:filename |
524 |
! ! |
|
525 |
||
7298 | 526 |
!FileStream class methodsFor:'Compatibility-VW'! |
6170
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
527 |
|
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
528 |
badArgumentsSignal |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
529 |
^ Error |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
530 |
! ! |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
531 |
|
3233
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
532 |
!FileStream class methodsFor:'Signal constants'! |
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
533 |
|
4907 | 534 |
userInitiatedFileSaveQuerySignal |
535 |
"return the query signal, which is raised before a user-initiated |
|
536 |
file-save / file-saveAs operation is performed. |
|
537 |
The query will be invoked with the fileName which is about to be |
|
538 |
written to. |
|
539 |
The default signal here returnes true, which will grant the save. |
|
540 |
End-user applications may want to catch this signal, |
|
541 |
and only return true for certain directories." |
|
542 |
||
543 |
^ UserInitiatedFileSaveQuerySignal |
|
544 |
||
3233
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
545 |
! ! |
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
546 |
|
7261 | 547 |
!FileStream methodsFor:'Compatibility-Squeak'! |
3044 | 548 |
|
549 |
fullName |
|
550 |
"Squeak compatibility: return the full pathname" |
|
551 |
||
552 |
^ pathName asFilename pathName |
|
553 |
||
554 |
"Created: 17.10.1997 / 17:04:12 / cg" |
|
555 |
"Modified: 20.10.1997 / 19:22:44 / cg" |
|
556 |
! ! |
|
557 |
||
1 | 558 |
!FileStream methodsFor:'accessing'! |
559 |
||
12950
5a6dbcf1a274
added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
12711
diff
changeset
|
560 |
contentsOfEntireFile |
5a6dbcf1a274
added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
12711
diff
changeset
|
561 |
"ST-80 compatibility: return contents as a String (or byteArray, if in binary mode). |
5a6dbcf1a274
added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
12711
diff
changeset
|
562 |
See also #contents, which returns the lines as stringCollection for text files." |
5a6dbcf1a274
added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
12711
diff
changeset
|
563 |
|
5a6dbcf1a274
added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
12711
diff
changeset
|
564 |
position == 0 ifTrue:[ |
13778 | 565 |
^ self next:(self fileSize) |
12950
5a6dbcf1a274
added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
12711
diff
changeset
|
566 |
]. |
5a6dbcf1a274
added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
12711
diff
changeset
|
567 |
|
5a6dbcf1a274
added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
12711
diff
changeset
|
568 |
^ super contentsOfEntireFile |
5a6dbcf1a274
added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
12711
diff
changeset
|
569 |
|
5a6dbcf1a274
added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
12711
diff
changeset
|
570 |
"Created: / 18-07-2010 / 22:17:49 / cg" |
5a6dbcf1a274
added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
12711
diff
changeset
|
571 |
! |
5a6dbcf1a274
added: #contentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
12711
diff
changeset
|
572 |
|
1 | 573 |
directoryName |
2903 | 574 |
"return the name of the directory I'm in as a string" |
1 | 575 |
|
2903 | 576 |
^ pathName asFilename directoryName |
1 | 577 |
! |
578 |
||
11437
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
579 |
fileName |
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
580 |
"return the file name - same as pathName for compatibility with |
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
581 |
other smalltalks" |
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
582 |
|
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
583 |
^ pathName asFilename |
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
584 |
! |
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
585 |
|
1 | 586 |
name |
2903 | 587 |
"return my name without leading direcory-path (i.e. the plain fileName) |
588 |
as a string" |
|
1 | 589 |
|
2903 | 590 |
^ pathName asFilename baseName |
1 | 591 |
! |
592 |
||
593 |
pathName |
|
594 |
"return the pathname" |
|
595 |
||
596 |
^ pathName |
|
613 | 597 |
! |
598 |
||
3754
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
599 |
removeOnClose:aBoolean |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
600 |
"set/clear the removeOnClose flag. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
601 |
If set, the file will be removed when closed. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
602 |
Provided mostly for OS's which do not allow an |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
603 |
open file to be removed (i.e. non unixes), |
12207
cb911af5184f
comment in: #removeOnClose:
Claus Gittinger <cg@exept.de>
parents:
11813
diff
changeset
|
604 |
when a fileStream for a tempFile is used. |
3754
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
605 |
Especially, the CVS-SourceCodeManager returns |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
606 |
this kind of file-handles occasionally. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
607 |
This is an ST/X special feature which is not portable |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
608 |
to other systems." |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
609 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
610 |
removeOnClose := aBoolean |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
611 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
612 |
"Modified: / 13.8.1998 / 12:10:07 / cg" |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
613 |
! |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
614 |
|
613 | 615 |
store:something |
616 |
"what really should this do" |
|
617 |
||
618 |
self nextPutAll:something storeString |
|
619 |
! ! |
|
620 |
||
621 |
!FileStream methodsFor:'error handling'! |
|
622 |
||
12687 | 623 |
openError:errorNumber |
624 |
"report an error, that file open failed" |
|
625 |
||
626 |
"This has changed from previous releases: |
|
627 |
in earlier versions of ST/X, failed file open operations |
|
628 |
returned nil - now, an error is raised. |
|
629 |
The old behavior is simulated by providing an exception |
|
630 |
handler, which proceeds with nil: |
|
631 |
||
13778 | 632 |
OpenError ignoreIn:[ |
633 |
'old code expecting nil return values on errors when doing an open'. |
|
12687 | 634 |
|
13778 | 635 |
('/dasGIBtEsbeStimmtNiChT' asFilename readStream) isNil ifTrue:[ |
636 |
self warn:'open failed'. |
|
637 |
]. |
|
638 |
] |
|
12687 | 639 |
" |
640 |
||
641 |
"{ Pragma: +optSpace }" |
|
642 |
||
643 |
LastErrorNumber := errorNumber. |
|
644 |
^ super openError:errorNumber. |
|
645 |
||
646 |
" |
|
647 |
'/dasGIBtEsbeStimmtNiChT' asFilename readStream |
|
648 |
" |
|
613 | 649 |
! ! |
650 |
||
8362 | 651 |
!FileStream methodsFor:'misc functions'! |
652 |
||
8768 | 653 |
copyToEndInto:outStream bufferSize:bufferSize |
8362 | 654 |
"copy the data into another stream." |
655 |
||
656 |
|pos n nWritten| |
|
657 |
||
658 |
"the sendfile() system call currently (2004-05-07) handles only descriptors that |
|
659 |
support mmap-like operations as from-fd. |
|
660 |
Therefore, this method is reimplemented here (from ExternalStream)" |
|
661 |
||
662 |
outStream isExternalStream ifTrue:[ |
|
8881
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
663 |
pos := self position0Based. |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
664 |
n := self size - pos. |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
665 |
nWritten := OperatingSystem |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
666 |
copyFromFd:(self fileDescriptor) |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
667 |
toFd:(outStream fileDescriptor) |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
668 |
startIndex:pos |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
669 |
count:n. |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
670 |
nWritten = n ifTrue:[ |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
671 |
^ self |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
672 |
]. |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
673 |
nWritten > 0 ifTrue:[ |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
674 |
self position0Based:pos+nWritten. |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8776
diff
changeset
|
675 |
]. |
8362 | 676 |
]. |
8768 | 677 |
^ super copyToEndInto:outStream bufferSize:bufferSize. |
8362 | 678 |
|
679 |
" |
|
680 |
|in out| |
|
681 |
||
682 |
in := 'Makefile' asFilename readStream. |
|
683 |
out := Stdout. |
|
684 |
in copyToEndInto:out. |
|
685 |
in close. |
|
686 |
" |
|
687 |
! ! |
|
688 |
||
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
689 |
!FileStream methodsFor:'positioning'! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
690 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
691 |
position0Based |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
692 |
"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
|
693 |
|
3971 | 694 |
%{ |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
695 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
696 |
HFILE f; |
7872 | 697 |
off_t currentPosition; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
698 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
699 |
if (__INST(handle) != nil) { |
7965 | 700 |
do { |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
701 |
f = __FILEVal(__INST(handle)); |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
702 |
#ifdef WIN32 |
7965 | 703 |
__threadErrno = 0; |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
704 |
if (__INST(buffered) == true) { |
6333 | 705 |
# if 0 |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
706 |
currentPosition = STX_C_CALL1( "ftell", ftell, f); |
6333 | 707 |
# else |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
708 |
currentPosition = ftell(f); |
6333 | 709 |
# endif |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
710 |
} else { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
711 |
OBJ rA = __INST(readAhead); |
7965 | 712 |
off_t offs = 0; |
6333 | 713 |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
714 |
if (rA != nil) { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
715 |
__INST(readAhead) = nil; |
7965 | 716 |
offs = -1; |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
717 |
} |
6333 | 718 |
# if 0 |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
719 |
currentPosition = STX_C_CALL3( "lseek", lseek, fileno(f), offs, SEEK_CUR); |
6333 | 720 |
# else |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
721 |
currentPosition = lseek(fileno(f), offs, SEEK_CUR); |
6333 | 722 |
# endif |
7965 | 723 |
} |
8039
6ef0379296cc
#position0Based did not work on unbuffered streams (with 64 bit off_t).
Stefan Vogel <sv@exept.de>
parents:
8034
diff
changeset
|
724 |
#else /* !WIN32 */ |
7965 | 725 |
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
|
726 |
#ifdef _LFS_LARGEFILE |
7965 | 727 |
currentPosition = ftello(f); |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
728 |
#else |
7965 | 729 |
currentPosition = ftell(f); |
8039
6ef0379296cc
#position0Based did not work on unbuffered streams (with 64 bit off_t).
Stefan Vogel <sv@exept.de>
parents:
8034
diff
changeset
|
730 |
#endif /* ! _LFS_LARGEFILE */ |
7965 | 731 |
} else { |
732 |
currentPosition = lseek(fileno(f), (off_t)0, SEEK_CUR); |
|
733 |
} |
|
8039
6ef0379296cc
#position0Based did not work on unbuffered streams (with 64 bit off_t).
Stefan Vogel <sv@exept.de>
parents:
8034
diff
changeset
|
734 |
#endif /* !WIN32 */ |
7965 | 735 |
} while ((currentPosition < 0) && (__threadErrno == EINTR)); |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
736 |
|
7965 | 737 |
if (currentPosition >= 0) { |
738 |
OBJ rslt; |
|
7872 | 739 |
|
7965 | 740 |
if (sizeof(currentPosition) == 8) { |
741 |
rslt = __MKINT64 (¤tPosition); |
|
742 |
} else { |
|
743 |
rslt = __MKINT(currentPosition); |
|
744 |
} |
|
745 |
RETURN ( rslt ); |
|
746 |
} |
|
8913 | 747 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
748 |
} |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
749 |
%}. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
750 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
751 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
752 |
^ self primitiveFailed |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
753 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
754 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
755 |
position0Based:newPos |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
756 |
"set the read/write position in the file" |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
757 |
|
5493 | 758 |
|rslt| |
3971 | 759 |
%{ |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
760 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
761 |
HFILE f; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
762 |
long ret; |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
763 |
OBJ fp; |
7871
5c357f1ba0c9
preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents:
7870
diff
changeset
|
764 |
|
8913 | 765 |
if ((__INST(canPosition) != false) || (newPos == __mkSmallInteger(0))) { |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
766 |
if ((fp = __INST(handle)) != nil) { |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
767 |
|
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
768 |
#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
|
769 |
# define FSEEK fseeko |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
770 |
off_t nP; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
771 |
#else |
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
772 |
#define FSEEK fseek |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
773 |
long nP; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
774 |
#endif |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
775 |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
776 |
if (__isSmallInteger(newPos)) { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
777 |
nP = __intVal(newPos); |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
778 |
if (nP < 0) { |
8913 | 779 |
__INST(lastErrorNumber) = __mkSmallInteger(EINVAL); |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
780 |
goto getOutOfHere; |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
781 |
} |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
782 |
} else { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
783 |
nP = __signedLongIntVal(newPos); |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
784 |
if (nP < 0) { |
8913 | 785 |
__INST(lastErrorNumber) = __mkSmallInteger(EINVAL); |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
786 |
goto getOutOfHere; |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
787 |
} |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
788 |
if (nP == 0) { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
789 |
if (sizeof(nP) == 8) { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
790 |
if (__signedLong64IntVal(newPos, &nP) == 0 || nP < 0) { |
8913 | 791 |
__INST(lastErrorNumber) = __mkSmallInteger(EINVAL); |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
792 |
goto getOutOfHere; |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
793 |
} |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
794 |
} else { |
8913 | 795 |
__INST(lastErrorNumber) = __mkSmallInteger(EINVAL); |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
796 |
goto getOutOfHere; |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
797 |
} |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
798 |
} |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
799 |
} |
7871
5c357f1ba0c9
preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents:
7870
diff
changeset
|
800 |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
801 |
f = __FILEVal(fp); |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
802 |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
803 |
do { |
14853
63ffca691137
fseek does not need a WRAP_CALL (I hope)
Claus Gittinger <cg@exept.de>
parents:
14848
diff
changeset
|
804 |
#if defined(DO_WRAP_CALL_FSEEK) |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
805 |
__threadErrno = 0; |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
806 |
if (__INST(buffered) == true) { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
807 |
ret = STX_C_CALL3( "fseek", fseek, f, nP, SEEK_SET); |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
808 |
} else { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
809 |
__INST(readAhead) = nil; |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
810 |
ret = STX_C_CALL3( "lseek", lseek, fileno(f), nP, SEEK_SET); |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
811 |
} |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
812 |
#else |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
813 |
if (__INST(buffered) == true) { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
814 |
ret = FSEEK(f, nP, SEEK_SET); |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
815 |
} else { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
816 |
ret = lseek(fileno(f), nP, SEEK_SET); |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
817 |
} |
14853
63ffca691137
fseek does not need a WRAP_CALL (I hope)
Claus Gittinger <cg@exept.de>
parents:
14848
diff
changeset
|
818 |
__threadErrno = errno; |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
819 |
#endif |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
820 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
821 |
if (ret >= 0) { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
822 |
__INST(position) = newPos; __STORE(self, newPos); |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
823 |
/* |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
824 |
* just to make certain ... |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
825 |
*/ |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
826 |
__INST(hitEOF) = false; |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
827 |
RETURN ( self ); |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
828 |
} |
8913 | 829 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
830 |
} |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
831 |
} |
7871
5c357f1ba0c9
preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents:
7870
diff
changeset
|
832 |
getOutOfHere: ; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
833 |
#undef FSEEK |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
834 |
%}. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
835 |
canPosition == false ifTrue:[ |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
836 |
"/ position by rewinding & re-reading everything up-to |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
837 |
"/ that point. |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
838 |
^ self slowPosition0Based:newPos |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
839 |
]. |
2963 | 840 |
lastErrorNumber notNil ifTrue:[ |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
841 |
(OperatingSystem errorSymbolForNumber:lastErrorNumber) == #EINVAL ifTrue:[ |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
842 |
"/ invalid position |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
843 |
^ self positionError |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
844 |
]. |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
845 |
"/ assume I/O error |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
846 |
^ self ioError |
2963 | 847 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
848 |
handle isNil ifTrue:[^ self errorNotOpen]. |
7871
5c357f1ba0c9
preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents:
7870
diff
changeset
|
849 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
850 |
rslt := self positionFile:handle position:newPos. |
5493 | 851 |
rslt >= 0 ifTrue:[ |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
852 |
position := newPos. |
5493 | 853 |
] ifFalse:[ |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
854 |
hitEOF := true. |
5493 | 855 |
] |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
856 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
857 |
|
11437
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
858 |
reset |
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
859 |
"additionaly to setting the position to the beginning of the file, |
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
860 |
re-open a previously closed file. This behavior is compatible |
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
861 |
with other Smalltalk dialects" |
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
862 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
863 |
handle isNil ifTrue:[ |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
864 |
"reopen the file" |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
865 |
mode == #readonly ifTrue: [ |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
866 |
self openForReading |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
867 |
] ifFalse:[mode == #writeonly ifTrue: [ |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
868 |
self openForWriting. |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
869 |
] ifFalse:[ |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
870 |
self openForReadWrite. |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
871 |
]]. |
11437
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
872 |
] ifFalse:[ |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
873 |
super reset. |
11437
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
874 |
]. |
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
875 |
! |
7869fd22df88
#reset reopens a closed file (compatibility with other smalltalks)
Stefan Vogel <sv@exept.de>
parents:
11290
diff
changeset
|
876 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
877 |
setToEnd |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
878 |
"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
|
879 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
880 |
%{ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
881 |
HFILE f; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
882 |
off_t ret; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
883 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
884 |
if (__INST(handle) != nil) { |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
885 |
f = __FILEVal(__INST(handle)); |
7965 | 886 |
__INST(position) = nil; /* i.e. unknown */ |
887 |
do { |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
888 |
#ifdef WIN32 |
7965 | 889 |
__threadErrno = 0; |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
890 |
if (__INST(buffered) == true) { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
891 |
ret = STX_C_CALL3( "fseek", fseek, f, 0L, SEEK_END); |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
892 |
} else { |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
893 |
__INST(readAhead) = nil; |
7965 | 894 |
ret = STX_C_CALL3( "lseek", lseek, fileno(f), 0L, SEEK_END); |
895 |
} |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
896 |
#else |
7965 | 897 |
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
|
898 |
#ifdef _LFS_LARGE_FILE |
7965 | 899 |
ret = fseeko(f, (off_t)0, SEEK_END); |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
900 |
#else |
7965 | 901 |
ret = fseek(f, 0L, SEEK_END); |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
902 |
#endif |
7965 | 903 |
} else { |
904 |
ret = lseek(fileno(f), (off_t)0, SEEK_END); |
|
905 |
} |
|
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
906 |
#endif |
7965 | 907 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
908 |
if (ret >= 0) { |
|
909 |
RETURN ( self ); |
|
910 |
} |
|
8913 | 911 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
912 |
} |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
913 |
%}. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
914 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
915 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
916 |
^ self primitiveFailed |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
917 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
918 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
919 |
slowPosition0Based:newPos |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
920 |
"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
|
921 |
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
|
922 |
This is required to reposition nonPositionable streams, such |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
923 |
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
|
924 |
Caveat: |
7965 | 925 |
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
|
926 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
927 |
|buffer amount pos0Based| |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
928 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
929 |
self isReadable ifFalse:[ |
7965 | 930 |
"/ sorry |
931 |
^ self positionError |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
932 |
]. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
933 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
934 |
buffer := ByteArray new:8*1024. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
935 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
936 |
(position isNil "/ i.e. unknown |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
937 |
or:[newPos < (pos0Based := self position0Based)]) ifTrue:[ |
7965 | 938 |
self reset. |
939 |
pos0Based := self position0Based. |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
940 |
]. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
941 |
[pos0Based < newPos] whileTrue:[ |
7965 | 942 |
amount := (buffer size) min:(newPos-pos0Based). |
943 |
(self nextBytes:amount into:buffer startingAt:1) ~~ amount ifTrue:[ |
|
944 |
^ self positionError |
|
945 |
]. |
|
946 |
pos0Based := self position0Based. |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
947 |
]. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
948 |
"/ ('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
|
949 |
! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
950 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
951 |
slowPosition:newPos |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
952 |
"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
|
953 |
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
|
954 |
This is required to reposition nonPositionable streams, such |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
955 |
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
|
956 |
Caveat: |
15360 | 957 |
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
|
958 |
|
15360 | 959 |
^ self slowPosition0Based:newPos |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
960 |
! ! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
961 |
|
613 | 962 |
!FileStream methodsFor:'printing & storing'! |
963 |
||
964 |
printOn:aStream |
|
4392 | 965 |
"append a user printed representation of the receiver to aStream. |
966 |
The format is suitable for a human - not meant to be read back." |
|
2903 | 967 |
|
10354 | 968 |
aStream nextPutAll:self className,'(for: '. |
969 |
pathName printOn:aStream. |
|
970 |
aStream nextPut:$). |
|
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
971 |
|
10354 | 972 |
" |
10450
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
973 |
'/' asFilename readStream printString |
10354 | 974 |
" |
613 | 975 |
! |
976 |
||
977 |
storeOn:aStream |
|
2903 | 978 |
"append a representation of the receiver to aStream, |
979 |
from which a copy can be reconstructed later." |
|
980 |
||
613 | 981 |
aStream nextPutAll:'(FileStream oldFileNamed:'. |
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
982 |
aStream nextPutAll:pathName storeString. |
15360 | 983 |
(self position ~~ 0) ifTrue:[ |
984 |
aStream nextPutAll:'; position:'. |
|
985 |
self position storeOn:aStream |
|
613 | 986 |
]. |
987 |
aStream nextPut:$) |
|
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
988 |
|
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
989 |
"Modified: 30.7.1997 / 16:43:50 / cg" |
1 | 990 |
! ! |
991 |
||
8518
7dc3f9909640
Interchanged the meaning of method privacy -
Stefan Vogel <sv@exept.de>
parents:
8512
diff
changeset
|
992 |
!FileStream protectedMethodsFor:'private'! |
1 | 993 |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
994 |
closeFile |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
995 |
"low level close - may be redefined in subclasses. |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
996 |
Don't send this message, send #close instead" |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
997 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
998 |
super closeFile. |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
999 |
removeOnClose == true ifTrue:[ |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1000 |
pathName asFilename remove. |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
1001 |
] |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
1002 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
1003 |
"Created: / 13.8.1998 / 12:11:22 / cg" |
8472 | 1004 |
! ! |
1005 |
||
1006 |
!FileStream methodsFor:'private'! |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
1007 |
|
613 | 1008 |
createForReadWrite |
1009 |
"create/truncate the file for read/write. |
|
1010 |
If the file existed, its truncated; otherwise its created." |
|
1 | 1011 |
|
613 | 1012 |
mode := #readwrite. |
2921 | 1013 |
^ self openWithMode:CreateReadWriteMode |
1 | 1014 |
! |
1015 |
||
613 | 1016 |
createForWriting |
1017 |
"create/truncate the file for writeonly. |
|
1018 |
If the file existed, its truncated; otherwise its created." |
|
1 | 1019 |
|
613 | 1020 |
mode := #writeonly. |
1021 |
didWrite := true. |
|
8604 | 1022 |
^ self openWithMode:WriteMode |
1 | 1023 |
! |
1024 |
||
5439 | 1025 |
openFile:pathName withMode:openmode attributes:attributeSpec |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1026 |
"open the file; |
5439 | 1027 |
openmode is the string defining the way to open as defined by the stdio library |
1028 |
(i.e. the 2nd fopen argument). |
|
1029 |
||
1030 |
attributeSpec is an additional argument, only used with VMS - it allows a file to |
|
1031 |
be created as fixedRecord, variableRecord, streamLF, streamCR, ... |
|
1032 |
In VMS, if nonNil, it must consist of an array of strings (max:10), giving additional |
|
1033 |
attributes (see fopen description). |
|
1034 |
Passing a nil specifies the default format (streamLF) - ST/X always invokes this with nil. |
|
1035 |
This argument is ignored in UNIX & MSDOS systems. |
|
1036 |
||
1037 |
This is a private entry, but maybe useful to open/create a file in a special mode, |
|
1038 |
which is proprietrary to the operatingSystem." |
|
1039 |
||
14578 | 1040 |
|wasBlocked encodedPathName| |
1041 |
||
1042 |
encodedPathName := OperatingSystem encodePath:pathName. |
|
5439 | 1043 |
|
1044 |
%{ |
|
1045 |
HFILE f; |
|
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1046 |
|
5439 | 1047 |
int pass = 0; |
1048 |
||
1049 |
retry: |
|
14578 | 1050 |
if (__isNonNilObject(encodedPathName) && (__isStringLike(openmode) || __isArrayLike(openmode))) |
5439 | 1051 |
#ifdef __VMS__ |
14578 | 1052 |
if (__isStringLike(pathName)) { |
15360 | 1053 |
do { |
1054 |
/* |
|
1055 |
* allow passing additional RMS arguments. |
|
1056 |
* stupid: DEC does not seem to offer an interface for passing a char **. |
|
1057 |
*/ |
|
1058 |
__threadErrno = 0; |
|
5439 | 1059 |
|
15360 | 1060 |
{ |
1061 |
if (__isArray(attributeSpec)) { |
|
1062 |
OBJ *ap = __ArrayInstPtr(attributeSpec)->a_element; |
|
1063 |
int numAttrib = 0; |
|
1064 |
int i; |
|
5439 | 1065 |
|
15360 | 1066 |
numAttrib = __arraySize(attributeSpec); |
1067 |
for (i=0; i<numAttrib;i++) { |
|
1068 |
if (! __isStringLike(ap[i])) { |
|
1069 |
f = NULL; |
|
1070 |
__threadErrno = EINVAL; /* invalid argument */ |
|
1071 |
goto getOutOfHere; |
|
1072 |
} |
|
1073 |
} |
|
1074 |
switch (numAttrib) { |
|
1075 |
case 0: |
|
1076 |
__BEGIN_INTERRUPTABLE__ |
|
1077 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode)); |
|
1078 |
__END_INTERRUPTABLE__ |
|
1079 |
break; |
|
1080 |
case 1: |
|
1081 |
__BEGIN_INTERRUPTABLE__ |
|
1082 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
|
1083 |
__stringVal(ap[0])); |
|
1084 |
__END_INTERRUPTABLE__ |
|
1085 |
break; |
|
1086 |
case 2: |
|
1087 |
__BEGIN_INTERRUPTABLE__ |
|
1088 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
|
1089 |
__stringVal(ap[0]), __stringVal(ap[1])); |
|
1090 |
__END_INTERRUPTABLE__ |
|
1091 |
break; |
|
1092 |
case 3: |
|
1093 |
__BEGIN_INTERRUPTABLE__ |
|
1094 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
|
1095 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2])); |
|
1096 |
__END_INTERRUPTABLE__ |
|
1097 |
break; |
|
1098 |
case 4: |
|
1099 |
__BEGIN_INTERRUPTABLE__ |
|
1100 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
|
1101 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
|
1102 |
__stringVal(ap[3])); |
|
1103 |
__END_INTERRUPTABLE__ |
|
1104 |
break; |
|
1105 |
case 5: |
|
1106 |
__BEGIN_INTERRUPTABLE__ |
|
1107 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
|
1108 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
|
1109 |
__stringVal(ap[3]), __stringVal(ap[4])); |
|
1110 |
__END_INTERRUPTABLE__ |
|
1111 |
break; |
|
1112 |
case 6: |
|
1113 |
__BEGIN_INTERRUPTABLE__ |
|
1114 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
|
1115 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
|
1116 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5])); |
|
1117 |
__END_INTERRUPTABLE__ |
|
1118 |
break; |
|
1119 |
case 7: |
|
1120 |
__BEGIN_INTERRUPTABLE__ |
|
1121 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
|
1122 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
|
1123 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
|
1124 |
__stringVal(ap[6])); |
|
1125 |
__END_INTERRUPTABLE__ |
|
1126 |
break; |
|
1127 |
case 8: |
|
1128 |
__BEGIN_INTERRUPTABLE__ |
|
1129 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
|
1130 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
|
1131 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
|
1132 |
__stringVal(ap[6]), __stringVal(ap[7])); |
|
1133 |
__END_INTERRUPTABLE__ |
|
1134 |
break; |
|
1135 |
case 9: |
|
1136 |
__BEGIN_INTERRUPTABLE__ |
|
1137 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
|
1138 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
|
1139 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
|
1140 |
__stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8])); |
|
1141 |
__END_INTERRUPTABLE__ |
|
1142 |
break; |
|
1143 |
case 10: |
|
1144 |
__BEGIN_INTERRUPTABLE__ |
|
1145 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
|
1146 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
|
1147 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
|
1148 |
__stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]), |
|
1149 |
__stringVal(ap[9])); |
|
1150 |
__END_INTERRUPTABLE__ |
|
1151 |
break; |
|
1152 |
default: |
|
1153 |
f = NULL; |
|
1154 |
__threadErrno = E2BIG; /* too many args */ |
|
1155 |
goto getOutOfHere; |
|
1156 |
} |
|
1157 |
} else if (attributeSpec != nil) { |
|
1158 |
f = NULL; |
|
1159 |
__threadErrno = EINVAL; /* invalid argument */ |
|
1160 |
goto getOutOfHere; |
|
1161 |
} else { |
|
1162 |
/* |
|
1163 |
* create file as sequential streamLF by default. |
|
1164 |
*/ |
|
1165 |
__BEGIN_INTERRUPTABLE__ |
|
1166 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), "rfm=stmlf"); |
|
1167 |
__END_INTERRUPTABLE__ |
|
1168 |
} |
|
1169 |
} |
|
1170 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
|
11290 | 1171 |
} |
5439 | 1172 |
#else /* not VMS */ |
1173 |
||
1174 |
# ifdef WIN32 |
|
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1175 |
{ |
15360 | 1176 |
DWORD share = 0, access = 0, create = 0, attr = 0; |
1177 |
int numAttrib, i; |
|
1178 |
OBJ *ap; |
|
1179 |
char * __openmode; |
|
1180 |
HANDLE handle; |
|
1181 |
SECURITY_ATTRIBUTES sa; |
|
11290 | 1182 |
|
15360 | 1183 |
if (__isStringLike(openmode)) { |
1184 |
share = FILE_SHARE_READ|FILE_SHARE_WRITE; |
|
1185 |
__openmode = __stringVal(openmode); |
|
1186 |
if (strcmp(__openmode, "rb") == 0) { |
|
1187 |
access = GENERIC_READ; |
|
1188 |
create = OPEN_EXISTING; |
|
1189 |
} else if (strcmp(__openmode, "rb+") == 0) { |
|
1190 |
access = GENERIC_READ | GENERIC_WRITE; |
|
1191 |
create = OPEN_ALWAYS; |
|
1192 |
} else if (strcmp(__openmode, "wb") == 0) { |
|
1193 |
access = GENERIC_WRITE; |
|
1194 |
create = CREATE_ALWAYS; |
|
1195 |
} else if (strcmp(__openmode, "wb+") == 0) { |
|
1196 |
access = GENERIC_READ | GENERIC_WRITE; |
|
1197 |
create = CREATE_ALWAYS; |
|
1198 |
} else if (strcmp(__openmode, "ab") == 0) { |
|
1199 |
access = FILE_APPEND_DATA|FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA| |
|
1200 |
STANDARD_RIGHTS_WRITE|SYNCHRONIZE; |
|
1201 |
create = OPEN_ALWAYS; |
|
1202 |
} else if (strcmp(__openmode, "ab+") == 0) { |
|
1203 |
access = GENERIC_READ |FILE_APPEND_DATA|FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA| |
|
1204 |
STANDARD_RIGHTS_WRITE|SYNCHRONIZE; |
|
1205 |
create = OPEN_ALWAYS; |
|
1206 |
} else { |
|
1207 |
console_fprintf(stderr, "Win32OS [warning]: unsupported open mode\n"); |
|
1208 |
} |
|
1209 |
} else if (__isArrayLike(openmode)) { |
|
1210 |
ap = __ArrayInstPtr(attributeSpec)->a_element; |
|
1211 |
numAttrib = __arraySize(attributeSpec); |
|
1212 |
__openmode = "rb+"; |
|
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1213 |
|
15360 | 1214 |
for (i=0; i<numAttrib; i++) { |
1215 |
OBJ attrSym = ap[i]; |
|
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1216 |
|
15360 | 1217 |
if (attrSym == @symbol(FILE_SHARE_READ)) { |
1218 |
share |= FILE_SHARE_READ; |
|
1219 |
} else if (attrSym == @symbol(FILE_SHARE_WRITE)) { |
|
1220 |
share |= FILE_SHARE_WRITE; |
|
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1221 |
|
15360 | 1222 |
} else if (attrSym == @symbol(GENERIC_READ)) { |
1223 |
access |= GENERIC_READ; |
|
1224 |
} else if (attrSym == @symbol(GENERIC_WRITE)) { |
|
1225 |
access |= GENERIC_WRITE; |
|
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1226 |
|
15360 | 1227 |
} else if (attrSym == @symbol(CREATE_NEW)) { |
1228 |
create |= CREATE_NEW; |
|
1229 |
} else if (attrSym == @symbol(CREATE_ALWAYS)) { |
|
1230 |
create |= CREATE_ALWAYS; |
|
1231 |
} else if (attrSym == @symbol(OPEN_EXISTING)) { |
|
1232 |
create |= OPEN_EXISTING; |
|
1233 |
} else if (attrSym == @symbol(OPEN_ALWAYS)) { |
|
1234 |
create |= OPEN_ALWAYS; |
|
1235 |
} else if (attrSym == @symbol(TRUNCATE_EXISTING)) { |
|
1236 |
create |= TRUNCATE_EXISTING; |
|
5439 | 1237 |
|
15360 | 1238 |
} else if (attrSym == @symbol(FILE_ATTRIBUTE_HIDDEN)) { |
1239 |
attr |= FILE_ATTRIBUTE_HIDDEN; |
|
1240 |
} else if (attrSym == @symbol(FILE_ATTRIBUTE_READONLY)) { |
|
1241 |
attr |= FILE_ATTRIBUTE_READONLY; |
|
1242 |
} else if (attrSym == @symbol(FILE_FLAG_WRITE_THROUGH)) { |
|
1243 |
attr |= FILE_FLAG_WRITE_THROUGH; |
|
1244 |
} else if (attrSym == @symbol(FILE_FLAG_SEQUENTIAL_SCAN)) { |
|
1245 |
attr |= FILE_FLAG_SEQUENTIAL_SCAN; |
|
1246 |
} else if (attrSym == @symbol(FILE_FLAG_DELETE_ON_CLOSE)) { |
|
1247 |
attr |= FILE_FLAG_DELETE_ON_CLOSE; |
|
1248 |
} else { |
|
1249 |
console_fprintf(stderr, "Win32OS [warning]: unsupported open mode\n"); |
|
1250 |
} |
|
1251 |
} |
|
1252 |
} else { |
|
1253 |
f = NULL; |
|
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1254 |
// argumentError = @symbol(badAttributeSpec); |
15360 | 1255 |
goto badArgument; |
1256 |
} |
|
1257 |
if (create == 0) { |
|
1258 |
f = NULL; |
|
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1259 |
// argumentError = @symbol(missingCreateMode); |
15360 | 1260 |
goto badArgument; |
1261 |
} |
|
1262 |
if (attr == 0) { |
|
1263 |
attr = FILE_ATTRIBUTE_NORMAL; |
|
1264 |
} |
|
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1265 |
|
15360 | 1266 |
/* |
1267 |
* create security attributes - make handle inheritable by subprocesses |
|
1268 |
*/ |
|
1269 |
memset(&sa, 0, sizeof (sa)); |
|
1270 |
sa.nLength = sizeof( sa ); |
|
1271 |
sa.bInheritHandle = TRUE; |
|
12630
c6151f8f6854
changed: #openFile:withMode:attributes:
Stefan Vogel <sv@exept.de>
parents:
12467
diff
changeset
|
1272 |
|
15360 | 1273 |
if (__isStringLike(pathName)) { |
1274 |
char _aPathName[MAXPATHLEN]; |
|
11290 | 1275 |
|
15360 | 1276 |
strncpy(_aPathName, __stringVal(pathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
1277 |
do { |
|
1278 |
__threadErrno = 0; |
|
1279 |
handle = STX_API_NOINT_CALL7( "CreateFileA", CreateFileA, _aPathName, access, share, &sa, create, attr, 0 /* hTempl */); |
|
1280 |
if (__threadErrno == EINTR) { |
|
1281 |
handle = INVALID_HANDLE_VALUE; |
|
1282 |
} |
|
1283 |
} while ((handle == INVALID_HANDLE_VALUE) && (__threadErrno == EINTR)); |
|
1284 |
} else if (__isUnicode16String(pathName)) { |
|
1285 |
wchar_t _aPathName[MAXPATHLEN+1]; |
|
1286 |
int i, l; |
|
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1287 |
|
15360 | 1288 |
l = __unicode16StringSize(pathName); |
1289 |
if (l > MAXPATHLEN) l = MAXPATHLEN; |
|
1290 |
for (i=0; i<l; i++) { |
|
1291 |
_aPathName[i] = __unicode16StringVal(pathName)[i]; |
|
1292 |
} |
|
1293 |
_aPathName[i] = 0; |
|
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1294 |
|
15360 | 1295 |
do { |
1296 |
__threadErrno = 0; |
|
1297 |
handle = STX_API_NOINT_CALL7( "CreateFileW", CreateFileW, _aPathName, access, share, &sa, create, attr, 0 /* hTempl */); |
|
1298 |
if (__threadErrno == EINTR) { |
|
1299 |
handle = INVALID_HANDLE_VALUE; |
|
1300 |
} |
|
1301 |
} while ((handle == INVALID_HANDLE_VALUE) && (__threadErrno == EINTR)); |
|
1302 |
} |
|
1303 |
if (handle != INVALID_HANDLE_VALUE) { |
|
1304 |
int fd; |
|
1305 |
extern void __stxWrapApiEnterCritical(), __stxWrapApiLeaveCritical(); |
|
12692
6150a8d7c87e
changed: #openFile:withMode:attributes:
Stefan Vogel <sv@exept.de>
parents:
12687
diff
changeset
|
1306 |
|
15360 | 1307 |
__stxWrapApiEnterCritical(); |
1308 |
fd = _open_osfhandle((long)handle, O_BINARY); |
|
1309 |
if (fd < 0) { |
|
1310 |
if (__threadErrno == 0) { |
|
1311 |
// no more file descriptors |
|
1312 |
__threadErrno = EMFILE; |
|
1313 |
} |
|
1314 |
CloseHandle(handle); |
|
1315 |
f = NULL; |
|
1316 |
} else { |
|
1317 |
f = fdopen(fd, __openmode); |
|
1318 |
} |
|
1319 |
__stxWrapApiLeaveCritical(); |
|
1320 |
} else { |
|
1321 |
f = NULL; |
|
1322 |
} |
|
11290 | 1323 |
} |
5439 | 1324 |
# else /* not WIN32 */ |
1325 |
||
14578 | 1326 |
if (__isStringLike(encodedPathName)) { |
15360 | 1327 |
do { |
1328 |
__BEGIN_INTERRUPTABLE__ |
|
5439 | 1329 |
# ifdef LINUX |
15360 | 1330 |
/* |
1331 |
* LINUX may ret a non-NULL f even when interrupted. |
|
1332 |
* Therefore, check errno and fake a null-ret. |
|
1333 |
*/ |
|
1334 |
__threadErrno = 0; |
|
1335 |
f = fopen((char *) __stringVal(encodedPathName), (char *) __stringVal(openmode)); |
|
1336 |
if (__threadErrno == EINTR) |
|
1337 |
f = NULL; |
|
5439 | 1338 |
# else /* not LINUX */ |
15360 | 1339 |
f = fopen((char *) __stringVal(encodedPathName), (char *) __stringVal(openmode)); |
5439 | 1340 |
# endif /* not LINUX */ |
15360 | 1341 |
__END_INTERRUPTABLE__ |
1342 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
|
11290 | 1343 |
} |
5439 | 1344 |
# endif /* not WIN32 */ |
1345 |
#endif /* not VMS */ |
|
1346 |
||
11290 | 1347 |
if (f == NULL) { |
15360 | 1348 |
/* |
1349 |
* If no filedescriptors available, try to finalize |
|
1350 |
* possibly collected fd's and try again. |
|
1351 |
*/ |
|
1352 |
if (pass == 0 && (__threadErrno == ENFILE || __threadErrno == EMFILE)) { |
|
1353 |
pass = 1; |
|
1354 |
__SSEND0(@global(ObjectMemory), @symbol(scavenge), 0); |
|
1355 |
__SSEND0(@global(ObjectMemory), @symbol(finalize), 0); |
|
1356 |
goto retry; |
|
1357 |
} |
|
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1358 |
badArgument: |
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1359 |
getOutOfHere: |
15360 | 1360 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
1361 |
__INST(position) = nil; |
|
11290 | 1362 |
} else { |
5439 | 1363 |
#ifdef __VMS__ |
15360 | 1364 |
/* |
1365 |
* check to see if this is positionable ... |
|
1366 |
*/ |
|
1367 |
__INST(canPosition) = false; |
|
5439 | 1368 |
# ifndef _POSIX_C_SOURCE |
15360 | 1369 |
{ |
1370 |
struct stat statBuffer; |
|
5439 | 1371 |
|
15360 | 1372 |
if (fstat(fileno(f), &statBuffer) >= 0) { |
1373 |
switch (statBuffer.st_fab_rfm) { |
|
1374 |
case FAB$C_UDF: /* undefined (also stream binary) */ |
|
1375 |
case FAB$C_VAR: /* variable length records */ |
|
1376 |
case FAB$C_VFC: /* variable fixed control */ |
|
1377 |
case FAB$C_STM: /* RMS-11 stream (valid only for sequen) */ |
|
1378 |
default: |
|
1379 |
__INST(canPosition) = false; |
|
1380 |
break; |
|
5439 | 1381 |
|
15360 | 1382 |
case FAB$C_FIX: /* fixed length records */ |
1383 |
case FAB$C_STMLF: /* LF stream (valid only for sequential) */ |
|
1384 |
case FAB$C_STMCR: /* CR stream (valid only for sequential) */ |
|
1385 |
__INST(canPosition) = true; |
|
1386 |
break; |
|
1387 |
} |
|
1388 |
} |
|
1389 |
} |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1390 |
# endif |
5439 | 1391 |
#else /* not VMS */ |
15360 | 1392 |
__INST(canPosition) = true; |
11812
fae9f7c22dbd
Windows: user CreateFile() instead of fopen() to avoid wrong data to be read
Stefan Vogel <sv@exept.de>
parents:
11454
diff
changeset
|
1393 |
#endif /* not VMS */ |
5439 | 1394 |
|
15360 | 1395 |
if (@global(FileOpenTrace) == true) { |
1396 |
console_fprintf(stderr, "fopen %s [FileStream] -> %x\n", __stringVal(pathName), f); |
|
1397 |
} |
|
1398 |
if (f != NULL) { |
|
1399 |
OBJ fp; |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1400 |
|
15360 | 1401 |
wasBlocked = __BLOCKINTERRUPTS(); |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1402 |
#if 0 |
15360 | 1403 |
// The original code was: |
1404 |
__INST(handle) = fp = __MKEXTERNALADDRESS(f); __STORE(self, fp); |
|
1405 |
// but for that, gcc generates wrong code, which loads self (volatile) into |
|
1406 |
// a register (bp), then calls __MKEXTERNALADDRESS, then stores indirect bp. |
|
1407 |
// That is wrong if a scavenge occurs in __MKEXTERNALADDRESS, as bp is now still pointing to the old |
|
1408 |
// object. |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1409 |
#else |
15360 | 1410 |
fp = __MKEXTERNALADDRESS(f); |
1411 |
__INST(handle) = fp; |
|
1412 |
__STORE(self, fp); |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1413 |
#endif |
15360 | 1414 |
} |
5439 | 1415 |
} |
11290 | 1416 |
|
5439 | 1417 |
%}. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1418 |
handle notNil ifTrue:[ |
15360 | 1419 |
position := 0. |
1420 |
handleType := #filePointer. |
|
1421 |
Lobby register:self. |
|
1422 |
wasBlocked == false ifTrue:[OperatingSystem unblockInterrupts]. |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1423 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1424 |
^ handle |
5439 | 1425 |
! |
1426 |
||
613 | 1427 |
openForAppending |
1428 |
"open the file for writeonly appending to the end. |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1429 |
If the file does not exist its an error, raise OpenError; |
613 | 1430 |
otherwise return the receiver." |
1431 |
||
1432 |
mode := #writeonly. |
|
1433 |
didWrite := true. |
|
2921 | 1434 |
^ self openWithMode:AppendMode |
613 | 1435 |
! |
1436 |
||
1437 |
openForReadWrite |
|
1438 |
"open the file for read/write. |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1439 |
If the file does not exist its an error, raise OpenError; |
613 | 1440 |
otherwise return the receiver." |
1441 |
||
1442 |
mode := #readwrite. |
|
2921 | 1443 |
^ self openWithMode:ReadWriteMode |
613 | 1444 |
! |
1445 |
||
1446 |
openForReading |
|
1447 |
"open the file for readonly. |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1448 |
If the file does not exist its an error, raise OpenError; |
613 | 1449 |
otherwise return the receiver." |
1450 |
||
1451 |
mode := #readonly. |
|
1452 |
didWrite := false. |
|
2921 | 1453 |
^ self openWithMode:ReadMode |
613 | 1454 |
! |
1455 |
||
1456 |
openForWriting |
|
8604 | 1457 |
"open the file writeonly. The contents of the file is preserved. |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1458 |
If the file does not exist its an error, raise OpenError; |
613 | 1459 |
otherwise return the receiver." |
1460 |
||
1461 |
mode := #writeonly. |
|
1462 |
didWrite := true. |
|
8604 | 1463 |
"we must not truncate the file!! So do not use WriteMode" |
1464 |
^ self openWithMode:ReadWriteMode |
|
613 | 1465 |
! |
1466 |
||
1 | 1467 |
openWithMode:openmode |
2921 | 1468 |
"open the file; |
1469 |
openmode is the string defining the way to open as defined by the stdio library |
|
1470 |
(i.e. the 2nd fopen argument). |
|
1471 |
||
1472 |
This is a private entry, but maybe useful to open a file in a special mode, |
|
1473 |
which is proprietrary to the operatingSystem." |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1474 |
|
2921 | 1475 |
^ self openWithMode:openmode attributes:nil |
1476 |
! |
|
1477 |
||
1478 |
openWithMode:openmode attributes:attributeSpec |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1479 |
"open the file; |
2921 | 1480 |
openmode is the string defining the way to open as defined by the stdio library |
1481 |
(i.e. the 2nd fopen argument). |
|
1482 |
||
1483 |
attributeSpec is an additional argument, only used with VMS - it allows a file to |
|
1484 |
be created as fixedRecord, variableRecord, streamLF, streamCR, ... |
|
1485 |
In VMS, if nonNil, it must consist of an array of strings (max:10), giving additional |
|
1486 |
attributes (see fopen description). |
|
1487 |
Passing a nil specifies the default format (streamLF) - ST/X always invokes this with nil. |
|
1488 |
This argument is ignored in UNIX & MSDOS systems. |
|
1489 |
||
1490 |
This is a private entry, but maybe useful to open/create a file in a special mode, |
|
1491 |
which is proprietrary to the operatingSystem." |
|
1 | 1492 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1493 |
handle notNil ifTrue:[^ self errorAlreadyOpen]. |
2921 | 1494 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1495 |
handle := self openFile:pathName withMode:openmode attributes:attributeSpec. |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1496 |
handle isNil ifTrue:[ |
15360 | 1497 |
" |
1498 |
the open failed for some reason ... |
|
1499 |
" |
|
1500 |
^ self openError:lastErrorNumber. |
|
1 | 1501 |
]. |
15360 | 1502 |
position := 0. |
8604 | 1503 |
buffered isNil ifTrue:[ |
15360 | 1504 |
buffered := true. "default is buffered" |
8604 | 1505 |
]. |
1 | 1506 |
! |
1507 |
||
613 | 1508 |
pathName:filename |
1509 |
"set the pathname" |
|
1 | 1510 |
|
3051
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1511 |
pathName := filename asString |
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1512 |
|
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1513 |
"Modified: / 28.10.1997 / 14:29:01 / cg" |
1 | 1514 |
! |
1515 |
||
613 | 1516 |
pathName:filename in:aDirectory |
1517 |
"set the pathname starting at aDirectory, a FileDirectory" |
|
77 | 1518 |
|
3051
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1519 |
pathName := aDirectory asFilename constructString:filename |
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1520 |
|
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1521 |
"Modified: / 28.10.1997 / 14:28:54 / cg" |
1 | 1522 |
! |
1523 |
||
1524 |
reOpen |
|
8604 | 1525 |
"USERS WILL NEVER INVOKE THIS METHOD |
1526 |
sent after snapin to reopen streams." |
|
1 | 1527 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1528 |
handle notNil ifTrue:[ |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1529 |
"it was open, when snapped-out" |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1530 |
handle := nil. |
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1531 |
Lobby unregister:self. |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1532 |
pathName isNil ifTrue:[ |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1533 |
^ self. |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1534 |
]. |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1535 |
[ |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1536 |
|oldPos| |
173 | 1537 |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1538 |
"should take care of appending files and open them for |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1539 |
append / position them to the end" |
8604 | 1540 |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1541 |
oldPos := position. |
8604 | 1542 |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1543 |
mode == #readonly ifTrue: [ |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1544 |
self openForReading |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1545 |
] ifFalse:[mode == #writeonly ifTrue: [ |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1546 |
self openForWriting. |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1547 |
] ifFalse:[ |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1548 |
self openForReadWrite. |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1549 |
]]. |
8604 | 1550 |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1551 |
oldPos notNil ifTrue:[ |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1552 |
self position:oldPos. |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1553 |
] |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1554 |
] on:OpenError do:[:ex| |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1555 |
"this happens, if after a restart, |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1556 |
the file is no longer present or accessable ..." |
13 | 1557 |
|
8627
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1558 |
(self class name , ' [warning]: could not reopen file: ', pathName) errorPrintCR. |
5a86b95bebbb
gcc3.3.1 insn-scheduling bug workaround
Claus Gittinger <cg@exept.de>
parents:
8604
diff
changeset
|
1559 |
]. |
1 | 1560 |
] |
1088 | 1561 |
|
2134
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2078
diff
changeset
|
1562 |
"Modified: 10.1.1997 / 17:50:51 / cg" |
2921 | 1563 |
! |
1564 |
||
1565 |
setMode:aModeSymbol |
|
1566 |
mode := aModeSymbol |
|
31 | 1567 |
! ! |
1568 |
||
10395
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1569 |
!FileStream methodsFor:'private fileIn'! |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1570 |
|
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1571 |
fileInNotifying:notifiedLoader passChunk:passChunk |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1572 |
"central method to file in from the receiver, i.e. read chunks and evaluate them - |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1573 |
return the value of the last chunk. |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1574 |
Someone (which is usually some codeView) is notified of errors." |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1575 |
|
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1576 |
^ self fileInNotifying:notifiedLoader passChunk:passChunk inDirectory:(self pathName asFilename directory). |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1577 |
! |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1578 |
|
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1579 |
fileInNotifying:notifiedLoader passChunk:passChunk inDirectory:aDirectory |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1580 |
"central method to file in from the receiver, i.e. read chunks and evaluate them - |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1581 |
return the value of the last chunk. |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1582 |
Someone (which is usually some codeView) is notified of errors. |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1583 |
Add aDirectory to the search path for classes, while performing the fileIn." |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1584 |
|
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1585 |
|oldPath val thisDirectory thisDirectoryPathName| |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1586 |
|
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1587 |
thisDirectory := aDirectory asFilename. |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1588 |
thisDirectoryPathName := thisDirectory pathName. |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1589 |
oldPath := Smalltalk systemPath. |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1590 |
|
10450
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1591 |
[ |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1592 |
Smalltalk systemPath:(oldPath copy addFirst:thisDirectoryPathName; yourself). |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1593 |
self class currentFileInDirectoryQuerySignal answer:thisDirectory do:[ |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1594 |
self class currentSourceContainerQuery answer:self do:[ |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1595 |
val := self basicFileInNotifying:notifiedLoader passChunk:passChunk. |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1596 |
]. |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1597 |
] |
10395
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1598 |
] ensure:[ |
10450
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1599 |
"take care, someone could have changed SystemPath during fileIn!!" |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1600 |
(Smalltalk systemPath copyFrom:2) = oldPath ifTrue:[ |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1601 |
Smalltalk systemPath:oldPath. |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1602 |
] ifFalse:[ |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1603 |
(oldPath includes:thisDirectoryPathName) ifFalse:[ |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1604 |
Smalltalk systemPath remove:thisDirectoryPathName ifAbsent:[]. |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1605 |
Smalltalk flushPathCaches. |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1606 |
]. |
bb40b56ed6b6
Remove unused stat() redefinition
Stefan Vogel <sv@exept.de>
parents:
10407
diff
changeset
|
1607 |
]. |
10395
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1608 |
]. |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1609 |
^ val |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1610 |
|
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1611 |
"Modified: / 23-10-2006 / 16:35:10 / cg" |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1612 |
! ! |
62fd9eba5c4b
Move fileIn methods refering to filenames from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
10354
diff
changeset
|
1613 |
|
2921 | 1614 |
!FileStream methodsFor:'queries'! |
613 | 1615 |
|
2903 | 1616 |
fileSize |
613 | 1617 |
"return the size in bytes of the file" |
1618 |
||
3971 | 1619 |
%{ |
613 | 1620 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
1621 |
HFILE f; |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
1622 |
|
613 | 1623 |
#ifdef transputer |
7874
5e0319ca5e60
stats filesize can be up-to 32bit now.
Claus Gittinger <cg@exept.de>
parents:
7872
diff
changeset
|
1624 |
unsigned int size; |
613 | 1625 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1626 |
if (__INST(handle) != nil) { |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1627 |
f = __FILEVal(__INST(handle)); |
7965 | 1628 |
if ((size = filesize(fileno(f))) >= 0) { |
1629 |
RETURN ( __MKUINT(size) ); |
|
1630 |
} |
|
613 | 1631 |
} |
1632 |
#else |
|
1633 |
struct stat buf; |
|
1634 |
int ret; |
|
1635 |
int fd; |
|
1636 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1637 |
if (__INST(handle) != nil) { |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1638 |
f = __FILEVal(__INST(handle)); |
7965 | 1639 |
fd = fileno(f); |
1640 |
do { |
|
1641 |
ret = fstat(fd, &buf); |
|
1642 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
|
1643 |
if (ret >= 0) { |
|
1644 |
OBJ rslt; |
|
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
1645 |
|
7965 | 1646 |
if (sizeof(buf.st_size) == 8) { |
1647 |
rslt = __MKINT64(&buf.st_size); |
|
1648 |
} else { |
|
1649 |
rslt = __MKINT(buf.st_size); |
|
1650 |
} |
|
1651 |
RETURN(rslt); |
|
1652 |
} |
|
8913 | 1653 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
613 | 1654 |
} |
1655 |
#endif |
|
1656 |
%}. |
|
1657 |
||
1658 |
"could add a fall-back here: |
|
1659 |
||
7965 | 1660 |
oldPosition := self position. |
1661 |
self setToEnd. |
|
1662 |
sz := self position. |
|
1663 |
self position:oldPosition. |
|
1664 |
^ sz |
|
613 | 1665 |
" |
1666 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1667 |
handle isNil ifTrue:[^ self errorNotOpen]. |
613 | 1668 |
^ self primitiveFailed |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1669 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1670 |
|
13051 | 1671 |
isDirectory |
1672 |
^ OperatingSystem isDirectory:pathName |
|
1673 |
! |
|
1674 |
||
14093 | 1675 |
isEmpty |
1676 |
"common stream protocol: are there no bytes in the file?" |
|
1677 |
||
1678 |
^ self fileSize == 0. |
|
1679 |
! |
|
1680 |
||
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1681 |
size |
11454 | 1682 |
"common stream protocol: return the size of the stream; |
2998
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1683 |
thats the number of bytes of the file." |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1684 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1685 |
^ self fileSize. |
2998
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1686 |
|
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1687 |
"Modified: 4.10.1997 / 18:01:09 / cg" |
1 | 1688 |
! ! |
1689 |
||
5493 | 1690 |
!FileStream methodsFor:'rel5 protocol'! |
1691 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
12207
diff
changeset
|
1692 |
positionFile:handle position:newPos |
5493 | 1693 |
"for migration to rel5 only" |
1694 |
||
1695 |
self primitiveFailed |
|
1696 |
! ! |
|
1697 |
||
2 | 1698 |
!FileStream methodsFor:'testing'! |
1699 |
||
1700 |
isFileStream |
|
1701 |
"return true, if the receiver is some kind of fileStream. |
|
1702 |
redefined from Object" |
|
1703 |
||
1704 |
^ true |
|
1705 |
! ! |
|
1706 |
||
1088 | 1707 |
!FileStream class methodsFor:'documentation'! |
1708 |
||
1709 |
version |
|
15360 | 1710 |
^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.156 2013-06-03 18:41:26 cg Exp $' |
12207
cb911af5184f
comment in: #removeOnClose:
Claus Gittinger <cg@exept.de>
parents:
11813
diff
changeset
|
1711 |
! |
cb911af5184f
comment in: #removeOnClose:
Claus Gittinger <cg@exept.de>
parents:
11813
diff
changeset
|
1712 |
|
cb911af5184f
comment in: #removeOnClose:
Claus Gittinger <cg@exept.de>
parents:
11813
diff
changeset
|
1713 |
version_CVS |
15360 | 1714 |
^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.156 2013-06-03 18:41:26 cg Exp $' |
1088 | 1715 |
! ! |
6798 | 1716 |
|
15360 | 1717 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1718 |
FileStream initialize! |