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