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