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