author | penk |
Mon, 14 Oct 2002 11:19:45 +0200 | |
changeset 6798 | cc084e7ecc88 |
parent 6586 | 0c9731524c07 |
child 7051 | 984d8271d06b |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
159 | 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 |
" |
|
12 |
||
5439 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
1 | 15 |
ExternalStream subclass:#FileStream |
3754
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
16 |
instanceVariableNames:'pathName canPosition removeOnClose' |
4907 | 17 |
classVariableNames:'OpenErrorSignal UserInitiatedFileSaveQuerySignal' |
1088 | 18 |
poolDictionaries:'' |
19 |
category:'Streams-External' |
|
1 | 20 |
! |
21 |
||
216 | 22 |
!FileStream primitiveDefinitions! |
1 | 23 |
%{ |
2903 | 24 |
|
1 | 25 |
#include <stdio.h> |
437 | 26 |
#define _STDIO_H_INCLUDED_ |
27 |
||
10 | 28 |
#include <errno.h> |
437 | 29 |
#define _ERRNO_H_INCLUDED_ |
1 | 30 |
|
31 |
#ifdef transputer |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
32 |
|
1 | 33 |
# include <iocntrl.h> |
34 |
# ifndef fileno |
|
35 |
/* kludge: inmos forgot fileno */ |
|
36 |
# define fileno(f) ((f)->__file) |
|
37 |
# endif |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
38 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
39 |
#else /* not transputer */ |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
40 |
|
1 | 41 |
# include <sys/types.h> |
42 |
# include <sys/stat.h> |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
43 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
44 |
#endif /* not transputer */ |
10 | 45 |
|
42 | 46 |
#ifdef hpux |
68 | 47 |
# define fileno(f) ((f->__fileH << 8) | (f->__fileL)) |
42 | 48 |
#endif |
49 |
||
10 | 50 |
#ifndef SEEK_SET |
13 | 51 |
# define SEEK_SET 0 |
10 | 52 |
#endif |
53 |
#ifndef SEEK_CUR |
|
13 | 54 |
# define SEEK_CUR 1 |
10 | 55 |
#endif |
56 |
#ifndef SEEK_END |
|
13 | 57 |
# define SEEK_END 2 |
10 | 58 |
#endif |
59 |
||
223 | 60 |
/* |
2921 | 61 |
* not all systems have off_t |
2808 | 62 |
* explicit add of those we know to have ... |
63 |
*/ |
|
64 |
#ifdef __osf__ |
|
65 |
# define OFF_T off_t |
|
66 |
#endif |
|
67 |
||
68 |
#ifndef OFF_T |
|
69 |
# define OFF_T long |
|
70 |
#endif |
|
71 |
||
2921 | 72 |
#ifdef __VMS__ |
73 |
/* |
|
74 |
* get those VMS definitions ... |
|
75 |
*/ |
|
76 |
# include <rms.h> |
|
77 |
#endif |
|
78 |
||
2992 | 79 |
#ifndef WIN32 |
6464 | 80 |
extern long ftell(); |
81 |
# ifndef FREEBSD |
|
82 |
extern long lseek(); |
|
83 |
# endif |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
84 |
# define HFILE FILE * |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
85 |
|
2992 | 86 |
#endif |
87 |
||
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
88 |
#ifdef WIN32 |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
89 |
# define NO_STDIO |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
90 |
# ifdef i386 |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
91 |
# define _X86_ |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
92 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
93 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
94 |
# undef INT |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
95 |
# undef Array |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
96 |
# undef Number |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
97 |
# undef Method |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
98 |
# undef Point |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
99 |
# undef Rectangle |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
100 |
# undef Block |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
101 |
# undef Time |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
102 |
# undef Date |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
103 |
# undef Set |
5910 | 104 |
# undef Signal |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
105 |
# undef Delay |
5910 | 106 |
# undef Context |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
107 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
108 |
# define NOATOM |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
109 |
# define NOGDICAPMASKS |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
110 |
# define NOMETAFILE |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
111 |
# define NOMINMAX |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
112 |
//# define NOOPENFILE |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
113 |
# define NOSOUND |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
114 |
# define NOWH |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
115 |
//# define NOCOMM |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
116 |
# define NOKANJI |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
117 |
# define NOCRYPT |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
118 |
//# define NOMCX |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
119 |
# define WIN32_LEAN_AND_MEAN |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
120 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
121 |
# include <windows.h> |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
122 |
# include <winsock.h> /* */ |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
123 |
# include <io.h> |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
124 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
125 |
# if !defined(__BORLANDC__) |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
126 |
# define stat _stat |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
127 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
128 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
129 |
# ifdef __DEF_Array |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
130 |
# define Array __DEF_Array |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
131 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
132 |
# ifdef __DEF_Number |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
133 |
# define Number __DEF_Number |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
134 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
135 |
# ifdef __DEF_Method |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
136 |
# define Method __DEF_Method |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
137 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
138 |
# ifdef __DEF_Point |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
139 |
# define Point __DEF_Point |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
140 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
141 |
# ifdef __DEF_Block |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
142 |
# define Block __DEF_Block |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
143 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
144 |
# ifdef __DEF_Time |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
145 |
# define Time __DEF_Time |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
146 |
# endif |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
147 |
# ifdef __DEF_Date |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
148 |
# define Date __DEF_Date |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
149 |
# endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
150 |
# ifdef __DEF_Set |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
151 |
# define Set __DEF_Set |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
152 |
# endif |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
153 |
# ifdef __DEF_Signal |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
154 |
# define Signal __DEF_Signal |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
155 |
# endif |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
156 |
# ifdef __DEF_Delay |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
157 |
# define Delay __DEF_Delay |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
158 |
# endif |
5910 | 159 |
# ifdef __DEF_Context |
160 |
# define Context __DEF_Context |
|
161 |
# endif |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
162 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
163 |
# define INT int |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
164 |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
165 |
# ifndef DO_WRAP_CALLS |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
166 |
# 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
|
167 |
# 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
|
168 |
# 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
|
169 |
# 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
|
170 |
# else |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
171 |
# 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
|
172 |
# 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
|
173 |
# 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
|
174 |
# 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
|
175 |
# endif |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
176 |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
177 |
/* # define HFILE HANDLE */ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
178 |
# define HFILE FILE * |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
179 |
/* # define fileno(f) f */ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
180 |
|
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
181 |
// extern long lseek(); |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
182 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
183 |
|
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
184 |
#endif /* WIN32 */ |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
185 |
|
2808 | 186 |
/* |
223 | 187 |
* on some systems errno is a macro ... check for it here |
188 |
*/ |
|
189 |
#ifndef errno |
|
190 |
extern errno; |
|
191 |
#endif |
|
192 |
||
1 | 193 |
%} |
173 | 194 |
! ! |
1 | 195 |
|
613 | 196 |
!FileStream class methodsFor:'documentation'! |
197 |
||
198 |
copyright |
|
199 |
" |
|
200 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
201 |
All Rights Reserved |
|
202 |
||
203 |
This software is furnished under a license and may be used |
|
204 |
only in accordance with the terms of that license and with the |
|
205 |
inclusion of the above copyright notice. This software may not |
|
206 |
be provided or otherwise made available to, or used by, any |
|
207 |
other person. No title to or ownership of the software is |
|
208 |
hereby transferred. |
|
209 |
" |
|
210 |
! |
|
211 |
||
212 |
documentation |
|
213 |
" |
|
214 |
This class provides access to the operating systems underlying file |
|
215 |
system (i.e. its an interface to the stdio library). |
|
216 |
||
217 |
Notice, that on some systems, the standard I/O library has performance |
|
218 |
problems when a file is opened for readwrite. |
|
219 |
For best results, open files either readonly or writeonly. |
|
1295 | 220 |
|
2921 | 221 |
Also notice, that some OperatingSystems do not fully support |
222 |
positioning a file stream. |
|
223 |
For example, poor VMS does not allow positioning onto arbitrary |
|
224 |
byte boundaries if the file is a variable-record-RMS file. |
|
225 |
(stupid enough, this is the default for textfiles as created by |
|
226 |
some tools ...) |
|
227 |
Therefore, the instance variable canPosition is set according to |
|
228 |
this and an error is raised, if a position: is attemted. |
|
229 |
I know, this is ugly, but what else could we do ? |
|
230 |
||
231 |
[instance variables:] |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
232 |
pathName <String> the files path (if known) |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
233 |
canPosition <Boolean> positionable - read above comment |
2921 | 234 |
|
1295 | 235 |
[author:] |
2161 | 236 |
Claus Gittinger |
1295 | 237 |
|
238 |
[see also:] |
|
2161 | 239 |
Filename DirectoryStream PipeStream Socket |
613 | 240 |
" |
2921 | 241 |
! |
242 |
||
243 |
examples |
|
244 |
" |
|
245 |
for VMS users only: |
|
246 |
||
247 |
The #openWithMode:attributes: entry allows additional RMS attributes |
|
248 |
to be passed in the second argument, which must be an array of strings |
|
249 |
as described in the 'creat' RTL Library documentation. |
|
250 |
||
251 |
For example, to create a file with fixed records and recordLength of 100, |
|
252 |
use: |
|
253 |
||
254 |
|newFile| |
|
255 |
||
256 |
newFile := FileStream new pathName:'<nameOfFile>'. |
|
257 |
newFile setMode:#writeonly. |
|
258 |
newFile openWithMode:'w' attributes:#('rfm=fix' 'fsz=100'). |
|
259 |
||
260 |
since all of the above is private protocol, and it is considered bad style to |
|
261 |
access these from user programs, we recommend subclassing FileStream as |
|
262 |
something like VMSFixedRecordFileStream, and redefine the instance creation |
|
263 |
method(s) there as appropriate. |
|
264 |
This will retain VMS specifics in one place and enhance maintanability. |
|
265 |
" |
|
266 |
! ! |
|
267 |
||
268 |
!FileStream class methodsFor:'initialization'! |
|
269 |
||
270 |
initialize |
|
271 |
OpenErrorSignal isNil ifTrue:[ |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
272 |
"/ |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
273 |
"/ this is temporary - for now allow an openError to |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
274 |
"/ be unhandled and proceed by returning a nil from the |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
275 |
"/ stream creation method. |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
276 |
"/ In the future, this will be a hard signal. |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
277 |
"/ |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
278 |
OpenErrorSignal := QuerySignal new. |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
279 |
OpenErrorSignal parent:(super openErrorSignal) mayProceed:true. |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
280 |
OpenErrorSignal nameClass:self message:#openErrorSignal. |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
281 |
OpenErrorSignal notifierString:'open error'. |
4907 | 282 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
283 |
UserInitiatedFileSaveQuerySignal := QuerySignal new defaultAnswer:true. |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
284 |
UserInitiatedFileSaveQuerySignal nameClass:self message:#userInitiatedFileSaveQuerySignal. |
2921 | 285 |
] |
3006
b3530950854a
use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents:
2998
diff
changeset
|
286 |
|
b3530950854a
use new initialization message of signal.
Claus Gittinger <cg@exept.de>
parents:
2998
diff
changeset
|
287 |
"Modified: 8.10.1997 / 11:56:39 / cg" |
2921 | 288 |
! ! |
289 |
||
1 | 290 |
!FileStream class methodsFor:'instance creation'! |
291 |
||
613 | 292 |
appendingOldFileNamed:filename |
293 |
"return a FileStream for existing file named filename, aString. |
|
294 |
The file is opened for writeonly access." |
|
1 | 295 |
|
296 |
|newStream| |
|
2 | 297 |
newStream := self new pathName:filename. |
613 | 298 |
newStream openForAppending isNil ifTrue:[^nil]. |
299 |
" |
|
300 |
this is not a good idea; I might like to read the written stuff ... |
|
301 |
||
302 |
newStream readLimit:(newStream size). |
|
303 |
" |
|
304 |
^ newStream |
|
305 |
! |
|
306 |
||
307 |
appendingOldFileNamed:filename in:aDirectory |
|
308 |
"return a FileStream for existing file named filename, aString |
|
309 |
in aDirectory, a FileDirectory. |
|
310 |
The file is opened for writeonly access." |
|
311 |
||
312 |
|newStream| |
|
313 |
newStream := self new pathName:filename in:aDirectory. |
|
314 |
newStream openForAppending isNil ifTrue:[^nil]. |
|
315 |
" |
|
316 |
this is not a good idea; I might like to read the written stuff ... |
|
317 |
||
318 |
newStream readLimit:(newStream size). |
|
319 |
" |
|
1 | 320 |
^ newStream |
321 |
! |
|
322 |
||
613 | 323 |
fileNamed:filename |
324 |
"return a stream on file filename - if the file does not |
|
325 |
already exist, create it. |
|
92 | 326 |
The file is opened for read/write access." |
1 | 327 |
|
613 | 328 |
|stream| |
329 |
||
330 |
stream := self oldFileNamed:filename. |
|
331 |
stream isNil ifTrue:[ |
|
332 |
stream := self newFileNamed:filename |
|
333 |
]. |
|
334 |
^ stream |
|
335 |
! |
|
336 |
||
337 |
fileNamed:filename in:aDirectory |
|
338 |
"return a stream on file filename - if the file does not |
|
339 |
already exist, create it. |
|
340 |
The file is opened for read/write access." |
|
341 |
||
342 |
|stream| |
|
343 |
||
344 |
stream := self oldFileNamed:filename in:aDirectory. |
|
345 |
stream isNil ifTrue:[ |
|
346 |
stream := self newFileNamed:filename in:aDirectory |
|
347 |
]. |
|
348 |
^ stream |
|
1 | 349 |
! |
350 |
||
92 | 351 |
newFileForWritingNamed: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 writeonly access." |
|
355 |
||
356 |
|newStream| |
|
357 |
newStream := self new pathName:filename. |
|
358 |
newStream createForWriting isNil ifTrue:[^nil]. |
|
359 |
^ newStream |
|
360 |
! |
|
361 |
||
362 |
newFileForWritingNamed:filename in:aDirectory |
|
363 |
"return a FileStream for new file named filename, aString |
|
364 |
in aDirectory, a FileDirectory. |
|
365 |
If the file exists, it is truncated, otherwise created. |
|
366 |
The file is opened for writeonly access." |
|
367 |
||
368 |
|newStream| |
|
369 |
newStream := self new pathName:filename in:aDirectory. |
|
370 |
newStream createForWriting isNil ifTrue:[^nil]. |
|
371 |
^ newStream |
|
372 |
! |
|
373 |
||
613 | 374 |
newFileNamed:filename |
375 |
"return a FileStream for new file named filename, aString. |
|
376 |
If the file exists, it is truncated, otherwise created. |
|
377 |
The file is opened for read/write access." |
|
378 |
||
379 |
|newStream| |
|
380 |
newStream := self new pathName:filename. |
|
381 |
newStream createForReadWrite isNil ifTrue:[^nil]. |
|
382 |
^ newStream |
|
3051
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
383 |
|
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
384 |
"Modified: / 28.10.1997 / 14:28:08 / cg" |
613 | 385 |
! |
386 |
||
387 |
newFileNamed:filename in:aDirectory |
|
388 |
"return a FileStream for new file named filename, aString |
|
389 |
in aDirectory, a FileDirectory. |
|
390 |
If the file exists, it is truncated, otherwise created. |
|
391 |
The file is opened for read/write access." |
|
392 |
||
393 |
|newStream| |
|
394 |
newStream := self new pathName:filename in:aDirectory. |
|
395 |
newStream createForReadWrite isNil ifTrue:[^nil]. |
|
396 |
^ newStream |
|
397 |
! |
|
398 |
||
1 | 399 |
oldFileNamed:filename |
400 |
"return a FileStream for existing file named filename, aString. |
|
401 |
The file is opened for read/write access." |
|
402 |
||
403 |
|newStream| |
|
404 |
||
405 |
(OperatingSystem isReadable:filename) ifFalse:[^nil]. |
|
2 | 406 |
newStream := self new pathName:filename. |
1 | 407 |
newStream readwrite. |
408 |
newStream openForReadWrite isNil ifTrue:[^nil]. |
|
42 | 409 |
" |
410 |
this is not a good idea; someone else might be appending ... |
|
411 |
||
1 | 412 |
newStream readLimit:(newStream size). |
42 | 413 |
" |
1 | 414 |
^ newStream |
415 |
! |
|
416 |
||
417 |
oldFileNamed:filename in:aDirectory |
|
418 |
"return a FileStream for existing file named filename, aString |
|
419 |
in aDirectory, a FileDirectory. |
|
420 |
The file is opened for read/write access." |
|
421 |
||
422 |
|newStream| |
|
2 | 423 |
newStream := self new pathName:filename in:aDirectory. |
1 | 424 |
newStream openForReadWrite isNil ifTrue:[^nil]. |
42 | 425 |
" |
426 |
this is not a good idea; someone else might be appending ... |
|
427 |
||
1 | 428 |
newStream readLimit:(newStream size). |
42 | 429 |
" |
1 | 430 |
^ newStream |
431 |
! |
|
432 |
||
433 |
readonlyFileNamed:filename |
|
434 |
"return a readonly FileStream for existing file named filename, aString" |
|
435 |
||
436 |
|newStream| |
|
437 |
||
438 |
(OperatingSystem isReadable:filename) ifFalse:[^nil]. |
|
439 |
||
2 | 440 |
newStream := self new pathName:filename. |
1 | 441 |
newStream openForReading isNil ifTrue:[^nil]. |
42 | 442 |
" |
443 |
this is not a good idea; someone else might be appending ... |
|
444 |
||
1 | 445 |
newStream readLimit:(newStream size). |
42 | 446 |
" |
1 | 447 |
^ newStream |
448 |
! |
|
449 |
||
450 |
readonlyFileNamed:filename in:aDirectory |
|
451 |
"return a readonly FileStream for existing file named filename, aString |
|
452 |
in aDirectory, a FileDirectory" |
|
453 |
||
454 |
|newStream| |
|
2 | 455 |
newStream := self new pathName:filename in:aDirectory. |
1 | 456 |
newStream openForReading isNil ifTrue:[^nil]. |
42 | 457 |
" |
458 |
this is not a good idea; someone else might be appending ... |
|
459 |
||
1 | 460 |
newStream readLimit:(newStream size). |
42 | 461 |
" |
1 | 462 |
^ newStream |
159 | 463 |
! ! |
464 |
||
6586 | 465 |
!FileStream class methodsFor:'Compatibility - ANSI'! |
466 |
||
467 |
write:filename |
|
468 |
"return a FileStream for new file named filename, aString. |
|
469 |
If the file exists, it is truncated, otherwise created. |
|
470 |
The file is opened for read/write access. |
|
471 |
Same as newFileNamed: for ANSI compatibilily" |
|
472 |
||
473 |
^ self newFileNamed:filename |
|
474 |
! ! |
|
475 |
||
6244 | 476 |
!FileStream class methodsFor:'Compatibility - Dolphin'! |
477 |
||
478 |
read:filename text:text |
|
479 |
"return a readonly FileStream for the existing file named filename, aString. |
|
480 |
If the argument, text is false, the stream is setup to read binary bytes, |
|
481 |
if false, it reads characters." |
|
482 |
||
483 |
|s| |
|
484 |
||
485 |
s := self readOnlyFileNamed:filename. |
|
486 |
text ifTrue:[ |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
487 |
s text |
6244 | 488 |
] ifFalse:[ |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
489 |
s binary |
6244 | 490 |
]. |
491 |
^ s |
|
6474 | 492 |
! |
493 |
||
494 |
write:filename mode:modeSymbol |
|
495 |
"return a writable FileStream for the file named filename, aString. |
|
496 |
The modeSymbol controls how the file is opened; currently supported are: |
|
6488 | 497 |
#append |
6474 | 498 |
" |
499 |
||
500 |
modeSymbol == #append ifTrue:[ |
|
6488 | 501 |
^ self appendingOldFileNamed:filename |
6474 | 502 |
]. |
503 |
self halt:'unsupported mode'. |
|
504 |
^ nil |
|
505 |
! |
|
506 |
||
507 |
write:filename text:textModeBoolean |
|
508 |
"return a writable FileStream for the file named filename, aString. |
|
509 |
If the argument, text is false, the stream is setup to write binary bytes, |
|
510 |
if false, it writes characters." |
|
511 |
||
512 |
|s| |
|
513 |
||
6475 | 514 |
s := self newFileNamed:filename. |
6474 | 515 |
s notNil ifTrue:[ |
6488 | 516 |
textModeBoolean ifTrue:[ |
517 |
s text |
|
518 |
] ifFalse:[ |
|
519 |
s binary |
|
520 |
] |
|
6474 | 521 |
]. |
522 |
^ s |
|
6244 | 523 |
! ! |
524 |
||
5186 | 525 |
!FileStream class methodsFor:'Compatibility - Squeak'! |
526 |
||
527 |
readOnlyFileNamed:filename |
|
6244 | 528 |
"return a readonly FileStream for the existing file named filename, aString." |
529 |
||
5186 | 530 |
^ self readonlyFileNamed:filename |
531 |
! ! |
|
532 |
||
6170
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
533 |
!FileStream class methodsFor:'Compatibility - VW'! |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
534 |
|
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
535 |
badArgumentsSignal |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
536 |
^ Error |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
537 |
! ! |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
538 |
|
3233
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
539 |
!FileStream class methodsFor:'Signal constants'! |
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
540 |
|
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
541 |
openErrorSignal |
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
542 |
"return the FileStream specific openErrorSignal. |
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
543 |
This is different from ExternalStream>>OpenErrorSignal!!" |
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
544 |
|
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
545 |
^ OpenErrorSignal |
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
546 |
|
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
547 |
"Created: / 28.1.1998 / 14:41:18 / stefan" |
4907 | 548 |
! |
549 |
||
550 |
userInitiatedFileSaveQuerySignal |
|
551 |
"return the query signal, which is raised before a user-initiated |
|
552 |
file-save / file-saveAs operation is performed. |
|
553 |
The query will be invoked with the fileName which is about to be |
|
554 |
written to. |
|
555 |
The default signal here returnes true, which will grant the save. |
|
556 |
End-user applications may want to catch this signal, |
|
557 |
and only return true for certain directories." |
|
558 |
||
559 |
^ UserInitiatedFileSaveQuerySignal |
|
560 |
||
3233
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
561 |
! ! |
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
562 |
|
5186 | 563 |
!FileStream methodsFor:'Compatibility - Squeak'! |
3044 | 564 |
|
565 |
fullName |
|
566 |
"Squeak compatibility: return the full pathname" |
|
567 |
||
568 |
^ pathName asFilename pathName |
|
569 |
||
570 |
"Created: 17.10.1997 / 17:04:12 / cg" |
|
571 |
"Modified: 20.10.1997 / 19:22:44 / cg" |
|
572 |
! ! |
|
573 |
||
1 | 574 |
!FileStream methodsFor:'accessing'! |
575 |
||
576 |
directoryName |
|
2903 | 577 |
"return the name of the directory I'm in as a string" |
1 | 578 |
|
2903 | 579 |
^ pathName asFilename directoryName |
1 | 580 |
! |
581 |
||
582 |
name |
|
2903 | 583 |
"return my name without leading direcory-path (i.e. the plain fileName) |
584 |
as a string" |
|
1 | 585 |
|
2903 | 586 |
^ pathName asFilename baseName |
1 | 587 |
! |
588 |
||
589 |
pathName |
|
590 |
"return the pathname" |
|
591 |
||
592 |
^ pathName |
|
613 | 593 |
! |
594 |
||
3754
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
595 |
removeOnClose:aBoolean |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
596 |
"set/clear the removeOnClose flag. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
597 |
If set, the file will be removed when closed. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
598 |
Provided mostly for OS's which do not allow an |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
599 |
open file to be removed (i.e. non unixes), |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
600 |
and a fileStream for a tempFile is used. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
601 |
Especially, the CVS-SourceCodeManager returns |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
602 |
this kind of file-handles occasionally. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
603 |
This is an ST/X special feature which is not portable |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
604 |
to other systems." |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
605 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
606 |
removeOnClose := aBoolean |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
607 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
608 |
"Modified: / 13.8.1998 / 12:10:07 / cg" |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
609 |
! |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
610 |
|
613 | 611 |
store:something |
612 |
"what really should this do" |
|
613 |
||
614 |
self nextPutAll:something storeString |
|
615 |
! ! |
|
616 |
||
617 |
!FileStream methodsFor:'error handling'! |
|
618 |
||
619 |
openError |
|
2963 | 620 |
"{ Pragma: +optSpace }" |
621 |
||
613 | 622 |
"report an error, that file open failed" |
623 |
||
624 |
"/ |
|
2921 | 625 |
"/ for now, error on open only raises a querySignal. |
626 |
"/ If its not handled, a failing open will return nil. |
|
627 |
"/ Currently, all users of fileStream check for this |
|
628 |
"/ nil return value (which is a historic leftover) |
|
629 |
"/ |
|
630 |
"/ This will change in one of the next ST/X releases - for |
|
631 |
"/ now, it is best to provide an exceptionHandler AND check the |
|
632 |
"/ return value. |
|
633 |
"/ Sorry about that. |
|
613 | 634 |
"/ |
635 |
LastErrorNumber := lastErrorNumber. |
|
2921 | 636 |
super openError. |
637 |
^ nil |
|
613 | 638 |
! ! |
639 |
||
3754
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
640 |
!FileStream methodsFor:'instance release'! |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
641 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
642 |
closeFile |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
643 |
"low level close - may be redefined in subclasses" |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
644 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
645 |
super closeFile. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
646 |
removeOnClose == true ifTrue:[ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
647 |
pathName asFilename remove. |
3754
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
648 |
] |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
649 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
650 |
"Created: / 13.8.1998 / 12:11:22 / cg" |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
651 |
! ! |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
652 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
653 |
!FileStream methodsFor:'positioning'! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
654 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
655 |
position |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
656 |
"return the read/write position in the file - |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
657 |
notice, in smalltalk indices start at 1 so begin of file is 1" |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
658 |
|
3971 | 659 |
%{ |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
660 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
661 |
HFILE f; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
662 |
long currentPosition; |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
663 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
664 |
if (__INST(filePointer) != nil) { |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
665 |
do { |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
666 |
f = __FILEVal(__INST(filePointer)); |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
667 |
#ifdef WIN32 |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
668 |
__threadErrno = 0; |
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
669 |
if (__INST(buffered) == true) { |
6333 | 670 |
# if 0 |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
671 |
currentPosition = STX_C_CALL1( "ftell", ftell, f); |
6333 | 672 |
# else |
673 |
currentPosition = ftell(f); |
|
674 |
# endif |
|
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
675 |
} else { |
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
676 |
OBJ rA = __INST(readAhead); |
6333 | 677 |
long offs = 0L; |
678 |
||
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
679 |
if (rA != nil) { |
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
680 |
__INST(readAhead) = nil; |
6333 | 681 |
offs = -1L; |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
682 |
} |
6333 | 683 |
# if 0 |
684 |
currentPosition = STX_C_CALL3( "lseek", lseek, fileno(f), offs, SEEK_CUR); |
|
685 |
# else |
|
686 |
currentPosition = lseek(fileno(f), offs, SEEK_CUR); |
|
687 |
# endif |
|
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
688 |
} |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
689 |
#else |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
690 |
if (__INST(buffered) == true) { |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
691 |
currentPosition = ftell(f); |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
692 |
} else { |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
693 |
currentPosition = lseek(fileno(f), 0L, SEEK_CUR); |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
694 |
} |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
695 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
696 |
} while ((currentPosition < 0) && (__threadErrno == EINTR)); |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
697 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
698 |
if (currentPosition >= 0) { |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
699 |
/* |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
700 |
* notice: Smalltalk index starts at 1 |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
701 |
*/ |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
702 |
RETURN ( __MKSMALLINT(currentPosition + 1) ); |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
703 |
} |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
704 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
705 |
} |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
706 |
%}. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
707 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
708 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
709 |
^ self primitiveFailed |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
710 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
711 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
712 |
position:newPos |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
713 |
"set the read/write position in the file" |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
714 |
|
5493 | 715 |
|rslt| |
3971 | 716 |
%{ |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
717 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
718 |
HFILE f; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
719 |
long ret; |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
720 |
OBJ fp; |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
721 |
long nP; |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
722 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
723 |
if ((__INST(canPosition) != false) |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
724 |
|| (newPos == __MKSMALLINT(1))) { |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
725 |
if ((fp = __INST(filePointer)) != nil) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
726 |
if (__isSmallInteger(newPos)) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
727 |
f = __FILEVal(fp); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
728 |
nP = (long)__intVal(newPos); |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
729 |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
730 |
/* |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
731 |
* notice: Smalltalk index starts at 1 |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
732 |
*/ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
733 |
nP--; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
734 |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
735 |
do { |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
736 |
#ifdef WIN32 |
6333 | 737 |
__threadErrno = 0; |
738 |
if (__INST(buffered) == true) { |
|
739 |
ret = STX_C_CALL3( "fseek", fseek, f, nP, SEEK_SET); |
|
740 |
} else { |
|
741 |
__INST(readAhead) = nil; |
|
742 |
ret = STX_C_CALL3( "lseek", lseek, fileno(f), nP, SEEK_SET); |
|
743 |
} |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
744 |
#else |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
745 |
if (__INST(buffered) == true) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
746 |
ret = fseek(f, nP, SEEK_SET); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
747 |
} else { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
748 |
ret = lseek(fileno(f), nP, SEEK_SET); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
749 |
} |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
750 |
#endif |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
751 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
752 |
if (ret >= 0) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
753 |
__INST(position) = newPos; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
754 |
/* |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
755 |
* just to make certain ... |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
756 |
*/ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
757 |
__INST(hitEOF) = false; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
758 |
RETURN ( self ); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
759 |
} |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
760 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
761 |
} |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
762 |
} |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
763 |
} |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
764 |
%}. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
765 |
canPosition == false ifTrue:[ |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
766 |
"/ position by rewinding & re-reading everything up-to |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
767 |
"/ that point. |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
768 |
^ self slowPosition:newPos |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
769 |
]. |
2963 | 770 |
lastErrorNumber notNil ifTrue:[ |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
771 |
(OperatingSystem errorSymbolForNumber:lastErrorNumber) == #EINVAL ifTrue:[ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
772 |
"/ invalid position |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
773 |
^ self positionError |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
774 |
]. |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
775 |
"/ assume I/O error |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
776 |
^ self ioError |
2963 | 777 |
]. |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
778 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
5493 | 779 |
rslt := self positionFile:filePointer position:newPos. |
780 |
rslt >= 0 ifTrue:[ |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
781 |
position := newPos. |
5493 | 782 |
] ifFalse:[ |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
783 |
hitEOF := true. |
5493 | 784 |
] |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
785 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
786 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
787 |
setToEnd |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
788 |
"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
|
789 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
790 |
%{ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
791 |
HFILE f; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
792 |
long ret; |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
793 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
794 |
if (__INST(filePointer) != nil) { |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
795 |
f = __FILEVal(__INST(filePointer)); |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
796 |
__INST(position) = nil; |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
797 |
do { |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
798 |
#ifdef WIN32 |
6333 | 799 |
__threadErrno = 0; |
800 |
if (__INST(buffered) == true) { |
|
801 |
ret = STX_C_CALL3( "fseek", fseek, f, 0L, SEEK_END); |
|
802 |
} else { |
|
803 |
__INST(readAhead) = nil; |
|
804 |
ret = STX_C_CALL3( "lseek", lseek, fileno(f), 0L, SEEK_END); |
|
805 |
} |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
806 |
#else |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
807 |
if (__INST(buffered) == true) { |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
808 |
ret = fseek(f, 0L, SEEK_END); |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
809 |
} else { |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
810 |
ret = lseek(fileno(f), 0L, SEEK_END); |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
811 |
} |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
812 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
813 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
814 |
if (ret >= 0) { |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
815 |
RETURN ( self ); |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
816 |
} |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
817 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
818 |
} |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
819 |
%}. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
820 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
821 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
822 |
^ self primitiveFailed |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
823 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
824 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
825 |
slowPosition:newPos |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
826 |
"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
|
827 |
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
|
828 |
This is required to reposition nonPositionable streams, such |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
829 |
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
|
830 |
Caveat: |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
831 |
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
|
832 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
833 |
|buffer amount| |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
834 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
835 |
self isReadable ifFalse:[ |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
836 |
"/ sorry |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
837 |
^ self positionError |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
838 |
]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
839 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
840 |
buffer := ByteArray new:8*1024. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
841 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
842 |
(position isNil "/ i.e. unknown |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
843 |
or:[newPos < position]) ifTrue:[ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
844 |
self reset. |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
845 |
]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
846 |
[position < newPos] whileTrue:[ |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
847 |
amount := (buffer size) min:(newPos-position). |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
848 |
(self nextBytes:amount into:buffer startingAt:1) ~~ amount ifTrue:[ |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
849 |
^ self positionError |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
850 |
]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
851 |
]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
852 |
"/ ('FileStream [info]: slow position - please convert ''' , pathName printString , ''' to streamLF format') infoPrintCR. |
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 |
|
613 | 855 |
!FileStream methodsFor:'printing & storing'! |
856 |
||
857 |
printOn:aStream |
|
4392 | 858 |
"append a user printed representation of the receiver to aStream. |
859 |
The format is suitable for a human - not meant to be read back." |
|
2903 | 860 |
|
613 | 861 |
aStream nextPutAll:'(a FileStream for:'. |
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
862 |
aStream nextPutAll:pathName printString. |
613 | 863 |
aStream nextPut:$) |
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
864 |
|
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
865 |
"Modified: 30.7.1997 / 13:51:01 / cg" |
613 | 866 |
! |
867 |
||
868 |
storeOn:aStream |
|
2903 | 869 |
"append a representation of the receiver to aStream, |
870 |
from which a copy can be reconstructed later." |
|
871 |
||
613 | 872 |
aStream nextPutAll:'(FileStream oldFileNamed:'. |
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
873 |
aStream nextPutAll:pathName storeString. |
613 | 874 |
(self position ~~ 1) ifTrue:[ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
875 |
aStream nextPutAll:'; position:'. |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
876 |
self position storeOn:aStream |
613 | 877 |
]. |
878 |
aStream nextPut:$) |
|
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
879 |
|
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
880 |
"Modified: 30.7.1997 / 16:43:50 / cg" |
1 | 881 |
! ! |
882 |
||
883 |
!FileStream methodsFor:'private'! |
|
884 |
||
613 | 885 |
createForReadWrite |
886 |
"create/truncate the file for read/write. |
|
887 |
If the file existed, its truncated; otherwise its created." |
|
1 | 888 |
|
613 | 889 |
mode := #readwrite. |
2921 | 890 |
^ self openWithMode:CreateReadWriteMode |
1 | 891 |
! |
892 |
||
613 | 893 |
createForWriting |
894 |
"create/truncate the file for writeonly. |
|
895 |
If the file existed, its truncated; otherwise its created." |
|
1 | 896 |
|
613 | 897 |
mode := #writeonly. |
898 |
didWrite := true. |
|
6798 | 899 |
^ self openWithMode:WriteMode attributes:nil |
1 | 900 |
! |
901 |
||
902 |
open |
|
903 |
"open the file" |
|
904 |
||
905 |
pathName isNil ifTrue:[^nil]. |
|
906 |
(mode == #readonly) ifTrue: [ |
|
159 | 907 |
didWrite := false. |
2921 | 908 |
^ self openWithMode:ReadMode |
1 | 909 |
]. |
910 |
(mode == #writeonly) ifTrue: [ |
|
159 | 911 |
didWrite := true. |
2921 | 912 |
^ self openWithMode:WriteMode |
1 | 913 |
]. |
2921 | 914 |
^ self openWithMode:ReadWriteMode |
1 | 915 |
! |
916 |
||
5439 | 917 |
openFile:pathName withMode:openmode attributes:attributeSpec |
918 |
"open the file; |
|
919 |
openmode is the string defining the way to open as defined by the stdio library |
|
920 |
(i.e. the 2nd fopen argument). |
|
921 |
||
922 |
attributeSpec is an additional argument, only used with VMS - it allows a file to |
|
923 |
be created as fixedRecord, variableRecord, streamLF, streamCR, ... |
|
924 |
In VMS, if nonNil, it must consist of an array of strings (max:10), giving additional |
|
925 |
attributes (see fopen description). |
|
926 |
Passing a nil specifies the default format (streamLF) - ST/X always invokes this with nil. |
|
927 |
This argument is ignored in UNIX & MSDOS systems. |
|
928 |
||
929 |
This is a private entry, but maybe useful to open/create a file in a special mode, |
|
930 |
which is proprietrary to the operatingSystem." |
|
931 |
||
932 |
|filePointer| |
|
933 |
||
934 |
%{ |
|
935 |
HFILE f; |
|
936 |
HFILE fopen(); |
|
937 |
OBJ fp; |
|
938 |
int pass = 0; |
|
939 |
||
940 |
retry: |
|
941 |
if (__isNonNilObject(pathName) && (__qClass(pathName)==String)) { |
|
942 |
#ifdef __VMS__ |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
943 |
do { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
944 |
/* |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
945 |
* allow passing additional RMS arguments. |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
946 |
* stupid: DEC does not seem to offer an interface for passing a char **. |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
947 |
*/ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
948 |
__threadErrno = 0; |
5439 | 949 |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
950 |
{ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
951 |
if (__isArray(attributeSpec)) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
952 |
OBJ *ap = __ArrayInstPtr(attributeSpec)->a_element; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
953 |
int numAttrib = 0; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
954 |
int i; |
5439 | 955 |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
956 |
numAttrib = __arraySize(attributeSpec); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
957 |
for (i=0; i<numAttrib;i++) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
958 |
if (! __isString(ap[i])) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
959 |
f = NULL; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
960 |
__threadErrno = EINVAL; /* invalid argument */ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
961 |
goto getOutOfHere; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
962 |
} |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
963 |
} |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
964 |
switch (numAttrib) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
965 |
case 0: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
966 |
__BEGIN_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
967 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode)); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
968 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
969 |
break; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
970 |
case 1: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
971 |
__BEGIN_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
972 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
973 |
__stringVal(ap[0])); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
974 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
975 |
break; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
976 |
case 2: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
977 |
__BEGIN_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
978 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
979 |
__stringVal(ap[0]), __stringVal(ap[1])); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
980 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
981 |
break; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
982 |
case 3: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
983 |
__BEGIN_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
984 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
985 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2])); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
986 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
987 |
break; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
988 |
case 4: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
989 |
__BEGIN_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
990 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
991 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
992 |
__stringVal(ap[3])); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
993 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
994 |
break; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
995 |
case 5: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
996 |
__BEGIN_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
997 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
998 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
999 |
__stringVal(ap[3]), __stringVal(ap[4])); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1000 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1001 |
break; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1002 |
case 6: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1003 |
__BEGIN_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1004 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1005 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1006 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5])); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1007 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1008 |
break; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1009 |
case 7: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1010 |
__BEGIN_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1011 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1012 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1013 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1014 |
__stringVal(ap[6])); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1015 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1016 |
break; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1017 |
case 8: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1018 |
__BEGIN_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1019 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1020 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1021 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1022 |
__stringVal(ap[6]), __stringVal(ap[7])); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1023 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1024 |
break; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1025 |
case 9: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1026 |
__BEGIN_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1027 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1028 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1029 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1030 |
__stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8])); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1031 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1032 |
break; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1033 |
case 10: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1034 |
__BEGIN_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1035 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1036 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1037 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1038 |
__stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]), |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1039 |
__stringVal(ap[9])); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1040 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1041 |
break; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1042 |
default: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1043 |
f = NULL; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1044 |
__threadErrno = E2BIG; /* too many args */ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1045 |
goto getOutOfHere; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1046 |
} |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1047 |
} else if (attributeSpec != nil) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1048 |
f = NULL; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1049 |
__threadErrno = EINVAL; /* invalid argument */ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1050 |
goto getOutOfHere; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1051 |
} else { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1052 |
/* |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1053 |
* create file as sequential streamLF by default. |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1054 |
*/ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1055 |
__BEGIN_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1056 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), "rfm=stmlf"); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1057 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1058 |
} |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1059 |
} |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1060 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
5439 | 1061 |
|
1062 |
#else /* not VMS */ |
|
1063 |
||
1064 |
# ifdef WIN32 |
|
1065 |
||
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1066 |
do { |
6339 | 1067 |
__threadErrno = 0; |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
1068 |
f = STX_C_CALL2( "fopen", fopen, (char *)__stringVal(pathName), (char *)__stringVal(openmode)); |
6339 | 1069 |
if (__threadErrno == EINTR) { |
1070 |
f = NULL; |
|
1071 |
} |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1072 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
5439 | 1073 |
|
1074 |
# else /* not WIN32 */ |
|
1075 |
||
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1076 |
do { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1077 |
__BEGIN_INTERRUPTABLE__ |
5439 | 1078 |
# ifdef LINUX |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1079 |
/* |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1080 |
* LINUX may ret a non-NULL f even when interrupted. |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1081 |
* Therefore, check errno and fake a null-ret. |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1082 |
*/ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1083 |
__threadErrno = 0; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1084 |
f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode)); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1085 |
if (__threadErrno == EINTR) |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1086 |
f = NULL; |
5439 | 1087 |
# else /* not LINUX */ |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1088 |
f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode)); |
5439 | 1089 |
# endif /* not LINUX */ |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1090 |
__END_INTERRUPTABLE__ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1091 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
5439 | 1092 |
|
1093 |
# endif /* not WIN32 */ |
|
1094 |
#endif /* not VMS */ |
|
1095 |
||
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1096 |
if (f == NULL) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1097 |
/* |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1098 |
* If no filedescriptors available, try to finalize |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1099 |
* possibly collected fd's and try again. |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1100 |
*/ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1101 |
if (pass == 0 && (__threadErrno == ENFILE || __threadErrno == EMFILE)) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1102 |
pass = 1; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1103 |
__SSEND0(@global(ObjectMemory), @symbol(scavenge), 0); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1104 |
__SSEND0(@global(ObjectMemory), @symbol(finalize), 0); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1105 |
goto retry; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1106 |
} |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1107 |
getOutOfHere: ; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1108 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1109 |
__INST(position) = nil; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1110 |
} else { |
5439 | 1111 |
#ifdef __VMS__ |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1112 |
/* |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1113 |
* check to see if this is positionable ... |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1114 |
*/ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1115 |
__INST(canPosition) = false; |
5439 | 1116 |
# ifndef _POSIX_C_SOURCE |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1117 |
{ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1118 |
struct stat statBuffer; |
5439 | 1119 |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1120 |
if (fstat(fileno(f), &statBuffer) >= 0) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1121 |
switch (statBuffer.st_fab_rfm) { |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1122 |
case FAB$C_UDF: /* undefined (also stream binary) */ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1123 |
case FAB$C_VAR: /* variable length records */ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1124 |
case FAB$C_VFC: /* variable fixed control */ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1125 |
case FAB$C_STM: /* RMS-11 stream (valid only for sequen> */ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1126 |
default: |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1127 |
__INST(canPosition) = false; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1128 |
break; |
5439 | 1129 |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1130 |
case FAB$C_FIX: /* fixed length records */ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1131 |
case FAB$C_STMLF: /* LF stream (valid only for sequential> */ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1132 |
case FAB$C_STMCR: /* CR stream (valid only for sequential> */ |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1133 |
__INST(canPosition) = true; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1134 |
break; |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1135 |
} |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1136 |
} |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1137 |
} |
5439 | 1138 |
# endif |
1139 |
#else /* not VMS */ |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1140 |
__INST(canPosition) = true; |
5439 | 1141 |
#endif /* poor VMS */ |
1142 |
||
6488 | 1143 |
if (@global(FileOpenTrace) == true) { |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1144 |
fprintf(stderr, "fopen %s [FileStream] -> %x\n", __stringVal(pathName), f); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1145 |
} |
5439 | 1146 |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1147 |
filePointer = __MKOBJ((INT)f); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1148 |
__INST(position) = __MKSMALLINT(1); |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1149 |
} |
5439 | 1150 |
} |
1151 |
%}. |
|
1152 |
^ filePointer |
|
1153 |
! |
|
1154 |
||
613 | 1155 |
openForAppending |
1156 |
"open the file for writeonly appending to the end. |
|
1157 |
If the file does not exist its an error, return nil; |
|
1158 |
otherwise return the receiver." |
|
1159 |
||
1160 |
mode := #writeonly. |
|
1161 |
didWrite := true. |
|
2921 | 1162 |
^ self openWithMode:AppendMode |
613 | 1163 |
! |
1164 |
||
1165 |
openForReadWrite |
|
1166 |
"open the file for read/write. |
|
1167 |
If the file does not exist its an error, return nil; |
|
1168 |
otherwise return the receiver." |
|
1169 |
||
1170 |
mode := #readwrite. |
|
2921 | 1171 |
^ self openWithMode:ReadWriteMode |
613 | 1172 |
! |
1173 |
||
1174 |
openForReading |
|
1175 |
"open the file for readonly. |
|
1176 |
If the file does not exist its an error, return nil; |
|
1177 |
otherwise return the receiver." |
|
1178 |
||
1179 |
mode := #readonly. |
|
1180 |
didWrite := false. |
|
2921 | 1181 |
^ self openWithMode:ReadMode |
613 | 1182 |
! |
1183 |
||
1184 |
openForWriting |
|
1185 |
"open the file writeonly. |
|
1186 |
If the file does not exist its an error, return nil; |
|
1187 |
otherwise return the receiver." |
|
1188 |
||
1189 |
mode := #writeonly. |
|
1190 |
didWrite := true. |
|
2921 | 1191 |
^ self openWithMode:ReadWriteMode "unix-io does not allow this; open for update here" |
613 | 1192 |
! |
1193 |
||
1 | 1194 |
openWithMode:openmode |
2921 | 1195 |
"open the file; |
1196 |
openmode is the string defining the way to open as defined by the stdio library |
|
1197 |
(i.e. the 2nd fopen argument). |
|
1198 |
||
1199 |
This is a private entry, but maybe useful to open a file in a special mode, |
|
1200 |
which is proprietrary to the operatingSystem." |
|
1201 |
||
1202 |
^ self openWithMode:openmode attributes:nil |
|
1203 |
! |
|
1204 |
||
1205 |
openWithMode:openmode attributes:attributeSpec |
|
2908 | 1206 |
"open the file; |
2921 | 1207 |
openmode is the string defining the way to open as defined by the stdio library |
1208 |
(i.e. the 2nd fopen argument). |
|
1209 |
||
1210 |
attributeSpec is an additional argument, only used with VMS - it allows a file to |
|
1211 |
be created as fixedRecord, variableRecord, streamLF, streamCR, ... |
|
1212 |
In VMS, if nonNil, it must consist of an array of strings (max:10), giving additional |
|
1213 |
attributes (see fopen description). |
|
1214 |
Passing a nil specifies the default format (streamLF) - ST/X always invokes this with nil. |
|
1215 |
This argument is ignored in UNIX & MSDOS systems. |
|
1216 |
||
1217 |
This is a private entry, but maybe useful to open/create a file in a special mode, |
|
1218 |
which is proprietrary to the operatingSystem." |
|
1 | 1219 |
|
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
1220 |
filePointer notNil ifTrue:[^ self errorAlreadyOpen]. |
2921 | 1221 |
|
5439 | 1222 |
filePointer := self openFile:pathName withMode:openmode attributes:attributeSpec. |
1223 |
filePointer isNil ifTrue:[ |
|
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1224 |
" |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1225 |
the open failed for some reason ... |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1226 |
" |
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
6244
diff
changeset
|
1227 |
^ self openError |
1 | 1228 |
]. |
5439 | 1229 |
position := 1. |
2963 | 1230 |
buffered := true. "default is buffered" |
1231 |
Lobby register:self. |
|
1 | 1232 |
! |
1233 |
||
613 | 1234 |
pathName:filename |
1235 |
"set the pathname" |
|
1 | 1236 |
|
3051
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1237 |
pathName := filename asString |
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1238 |
|
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1239 |
"Modified: / 28.10.1997 / 14:29:01 / cg" |
1 | 1240 |
! |
1241 |
||
613 | 1242 |
pathName:filename in:aDirectory |
1243 |
"set the pathname starting at aDirectory, a FileDirectory" |
|
77 | 1244 |
|
3051
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1245 |
pathName := aDirectory asFilename constructString:filename |
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1246 |
|
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1247 |
"Modified: / 28.10.1997 / 14:28:54 / cg" |
1 | 1248 |
! |
1249 |
||
1250 |
reOpen |
|
1251 |
"sent after snapin to reopen streams" |
|
1252 |
||
173 | 1253 |
|oldPos| |
1254 |
||
1 | 1255 |
filePointer notNil ifTrue:[ |
2161 | 1256 |
"it was open, when snapped-out" |
1257 |
filePointer := nil. |
|
1258 |
Lobby unregister:self. |
|
1259 |
oldPos := position. |
|
1260 |
self open. |
|
1261 |
filePointer isNil ifTrue:[ |
|
2903 | 1262 |
"/ this happens, if after a restart, |
1263 |
"/ the file is no longer present or accessable ..." |
|
13 | 1264 |
|
2161 | 1265 |
(self class name , ' [warning]: could not reOpen file: ', pathName) errorPrintCR. |
1266 |
] ifFalse:[ |
|
3940 | 1267 |
oldPos notNil ifTrue:[ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
1268 |
self position:oldPos. |
3940 | 1269 |
] |
2161 | 1270 |
] |
1 | 1271 |
] |
1088 | 1272 |
|
2134
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2078
diff
changeset
|
1273 |
"Modified: 10.1.1997 / 17:50:51 / cg" |
2921 | 1274 |
! |
1275 |
||
1276 |
setMode:aModeSymbol |
|
1277 |
mode := aModeSymbol |
|
31 | 1278 |
! ! |
1279 |
||
2921 | 1280 |
!FileStream methodsFor:'queries'! |
613 | 1281 |
|
2903 | 1282 |
fileSize |
613 | 1283 |
"return the size in bytes of the file" |
1284 |
||
3971 | 1285 |
%{ |
613 | 1286 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
1287 |
HFILE f; |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
1288 |
|
613 | 1289 |
#ifdef transputer |
1290 |
int size; |
|
1291 |
||
1133 | 1292 |
if (__INST(filePointer) != nil) { |
1293 |
f = __FILEVal(__INST(filePointer)); |
|
613 | 1294 |
if ((size = filesize(fileno(f))) >= 0) { |
1133 | 1295 |
RETURN ( __MKSMALLINT(size) ); |
613 | 1296 |
} |
1297 |
} |
|
1298 |
#else |
|
1299 |
struct stat buf; |
|
1300 |
int ret; |
|
1301 |
int fd; |
|
1302 |
||
1133 | 1303 |
if (__INST(filePointer) != nil) { |
1304 |
f = __FILEVal(__INST(filePointer)); |
|
613 | 1305 |
fd = fileno(f); |
1306 |
do { |
|
1307 |
ret = fstat(fd, &buf); |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
1308 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
613 | 1309 |
if (ret >= 0) { |
6463 | 1310 |
RETURN ( __MKSMALLINT( (int)(buf.st_size) ) ); |
613 | 1311 |
} |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4910
diff
changeset
|
1312 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
613 | 1313 |
} |
1314 |
#endif |
|
1315 |
%}. |
|
1316 |
||
1317 |
"could add a fall-back here: |
|
1318 |
||
1319 |
oldPosition := self position. |
|
1320 |
self setToEnd. |
|
1321 |
sz := self position. |
|
1322 |
self position:oldPosition. |
|
1323 |
^ sz |
|
1324 |
" |
|
1325 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
1326 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
1327 |
^ self primitiveFailed |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1328 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1329 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1330 |
size |
2998
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1331 |
"return the size of the stream; |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1332 |
thats the number of bytes of the file." |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1333 |
|
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1334 |
"/ no obsoleteMethodWarning - size is ok for streams. |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1335 |
"/ self obsoleteMethodWarning:'use #fileSize'. |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1336 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1337 |
^ self fileSize. |
2998
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1338 |
|
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1339 |
"Modified: 4.10.1997 / 18:01:09 / cg" |
1 | 1340 |
! ! |
1341 |
||
5493 | 1342 |
!FileStream methodsFor:'rel5 protocol'! |
1343 |
||
1344 |
positionFile:filePointer position:newPos |
|
1345 |
"for migration to rel5 only" |
|
1346 |
||
1347 |
self primitiveFailed |
|
1348 |
||
1349 |
||
1350 |
! ! |
|
1351 |
||
2 | 1352 |
!FileStream methodsFor:'testing'! |
1353 |
||
1354 |
isFileStream |
|
1355 |
"return true, if the receiver is some kind of fileStream. |
|
1356 |
redefined from Object" |
|
1357 |
||
1358 |
^ true |
|
1359 |
! ! |
|
1360 |
||
1088 | 1361 |
!FileStream class methodsFor:'documentation'! |
1362 |
||
1363 |
version |
|
6798 | 1364 |
^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.88 2002-10-14 09:19:45 penk Exp $' |
1088 | 1365 |
! ! |
6798 | 1366 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1367 |
FileStream initialize! |