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