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