author | Claus Gittinger <cg@exept.de> |
Tue, 18 May 2004 12:23:59 +0200 | |
changeset 8362 | e17d9ffb6fa8 |
parent 8063 | 1aeaf6e5e012 |
child 8471 | e061e503bf03 |
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. |
613 | 274 |
newStream openForAppending isNil ifTrue:[^nil]. |
275 |
" |
|
276 |
this is not a good idea; I might like to read the written stuff ... |
|
277 |
||
278 |
newStream readLimit:(newStream size). |
|
279 |
" |
|
280 |
^ newStream |
|
7827 | 281 |
|
282 |
" |
|
283 |
FileStream appendingOldFileNamed:'adasdasasd' |
|
284 |
" |
|
613 | 285 |
! |
286 |
||
287 |
appendingOldFileNamed:filename in:aDirectory |
|
288 |
"return a FileStream for existing file named filename, aString |
|
289 |
in aDirectory, a FileDirectory. |
|
290 |
The file is opened for writeonly access." |
|
291 |
||
292 |
|newStream| |
|
293 |
newStream := self new pathName:filename in:aDirectory. |
|
294 |
newStream openForAppending isNil ifTrue:[^nil]. |
|
295 |
" |
|
296 |
this is not a good idea; I might like to read the written stuff ... |
|
297 |
||
298 |
newStream readLimit:(newStream size). |
|
299 |
" |
|
1 | 300 |
^ newStream |
301 |
! |
|
302 |
||
613 | 303 |
fileNamed:filename |
304 |
"return a stream on file filename - if the file does not |
|
305 |
already exist, create it. |
|
92 | 306 |
The file is opened for read/write access." |
1 | 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. |
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 |
613 | 313 |
! |
314 |
||
315 |
fileNamed:filename in:aDirectory |
|
316 |
"return a stream on file filename - if the file does not |
|
317 |
already exist, create it. |
|
318 |
The file is opened for read/write access." |
|
319 |
||
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
320 |
[ |
7965 | 321 |
^ self oldFileNamed:filename in:aDirectory. |
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
322 |
] on:self openErrorSignal do:[:ex| ]. |
613 | 323 |
|
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
324 |
^ self newFileNamed:filename in:aDirectory |
1 | 325 |
! |
326 |
||
92 | 327 |
newFileForWritingNamed:filename |
328 |
"return a FileStream for new file named filename, aString. |
|
329 |
If the file exists, it is truncated, otherwise created. |
|
330 |
The file is opened for writeonly access." |
|
331 |
||
332 |
|newStream| |
|
333 |
newStream := self new pathName:filename. |
|
334 |
newStream createForWriting isNil ifTrue:[^nil]. |
|
335 |
^ newStream |
|
336 |
! |
|
337 |
||
338 |
newFileForWritingNamed:filename in:aDirectory |
|
339 |
"return a FileStream for new file named filename, aString |
|
340 |
in aDirectory, a FileDirectory. |
|
341 |
If the file exists, it is truncated, otherwise created. |
|
342 |
The file is opened for writeonly access." |
|
343 |
||
344 |
|newStream| |
|
345 |
newStream := self new pathName:filename in:aDirectory. |
|
346 |
newStream createForWriting isNil ifTrue:[^nil]. |
|
347 |
^ newStream |
|
348 |
! |
|
349 |
||
613 | 350 |
newFileNamed:filename |
351 |
"return a FileStream for new file named filename, aString. |
|
352 |
If the file exists, it is truncated, otherwise created. |
|
353 |
The file is opened for read/write access." |
|
354 |
||
355 |
|newStream| |
|
356 |
newStream := self new pathName:filename. |
|
357 |
newStream createForReadWrite isNil ifTrue:[^nil]. |
|
358 |
^ newStream |
|
3051
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
359 |
|
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
360 |
"Modified: / 28.10.1997 / 14:28:08 / cg" |
613 | 361 |
! |
362 |
||
363 |
newFileNamed:filename in:aDirectory |
|
364 |
"return a FileStream for new file named filename, aString |
|
365 |
in aDirectory, a FileDirectory. |
|
366 |
If the file exists, it is truncated, otherwise created. |
|
367 |
The file is opened for read/write access." |
|
368 |
||
369 |
|newStream| |
|
370 |
newStream := self new pathName:filename in:aDirectory. |
|
371 |
newStream createForReadWrite isNil ifTrue:[^nil]. |
|
372 |
^ newStream |
|
373 |
! |
|
374 |
||
1 | 375 |
oldFileNamed:filename |
376 |
"return a FileStream for existing file named filename, aString. |
|
7827 | 377 |
The file is opened for read/write access. |
378 |
Raises an error if the file does not exist." |
|
1 | 379 |
|
380 |
|newStream| |
|
381 |
||
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
382 |
"/ 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
|
383 |
"/ (OperatingSystem isReadable:filename) ifFalse:[^ self new openError]. |
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
384 |
|
2 | 385 |
newStream := self new pathName:filename. |
1 | 386 |
newStream readwrite. |
387 |
newStream openForReadWrite isNil ifTrue:[^nil]. |
|
42 | 388 |
" |
389 |
this is not a good idea; someone else might be appending ... |
|
390 |
||
1 | 391 |
newStream readLimit:(newStream size). |
42 | 392 |
" |
1 | 393 |
^ newStream |
7827 | 394 |
|
395 |
" |
|
396 |
FileStream oldFileNamed:'/dAsGiBtEsNiChT' |
|
397 |
" |
|
1 | 398 |
! |
399 |
||
400 |
oldFileNamed:filename in:aDirectory |
|
401 |
"return a FileStream for existing file named filename, aString |
|
402 |
in aDirectory, a FileDirectory. |
|
7827 | 403 |
The file is opened for read/write access. |
404 |
Raises an error if the file does not exist." |
|
1 | 405 |
|
406 |
|newStream| |
|
2 | 407 |
newStream := self new pathName:filename in:aDirectory. |
1 | 408 |
newStream openForReadWrite isNil ifTrue:[^nil]. |
42 | 409 |
" |
410 |
this is not a good idea; someone else might be appending ... |
|
411 |
||
1 | 412 |
newStream readLimit:(newStream size). |
42 | 413 |
" |
1 | 414 |
^ newStream |
7827 | 415 |
|
416 |
" |
|
417 |
FileStream oldFileNamed:'dAsGiBtEsNiChT' in:'/' |
|
418 |
" |
|
1 | 419 |
! |
420 |
||
421 |
readonlyFileNamed:filename |
|
7827 | 422 |
"return a readonly FileStream for existing file named filename, aString. |
423 |
Raises an error if the file does not exist." |
|
1 | 424 |
|
425 |
|newStream| |
|
426 |
||
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
427 |
"/ 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
|
428 |
"/ (OperatingSystem isReadable:filename) ifFalse:[^ self new openError]. |
1 | 429 |
|
2 | 430 |
newStream := self new pathName:filename. |
1 | 431 |
newStream openForReading isNil ifTrue:[^nil]. |
42 | 432 |
" |
433 |
this is not a good idea; someone else might be appending ... |
|
434 |
||
1 | 435 |
newStream readLimit:(newStream size). |
42 | 436 |
" |
1 | 437 |
^ newStream |
7827 | 438 |
|
439 |
" |
|
440 |
FileStream readonlyFileNamed:'dAsGiBtEsNiChT' |
|
441 |
" |
|
1 | 442 |
! |
443 |
||
444 |
readonlyFileNamed:filename in:aDirectory |
|
445 |
"return a readonly FileStream for existing file named filename, aString |
|
7827 | 446 |
in aDirectory, a fileName or string instance representing a directory. |
447 |
Raises an error if the file does not exist." |
|
1 | 448 |
|
449 |
|newStream| |
|
2 | 450 |
newStream := self new pathName:filename in:aDirectory. |
1 | 451 |
newStream openForReading isNil ifTrue:[^nil]. |
42 | 452 |
" |
453 |
this is not a good idea; someone else might be appending ... |
|
454 |
||
1 | 455 |
newStream readLimit:(newStream size). |
42 | 456 |
" |
1 | 457 |
^ newStream |
7827 | 458 |
|
459 |
" |
|
460 |
FileStream readonlyFileNamed:'dAsGiBtEsNiChT' in:'/' |
|
461 |
FileStream readonlyFileNamed:'dAsGiBtEsNiChT' in:'/' asFilename |
|
462 |
" |
|
159 | 463 |
! ! |
464 |
||
7298 | 465 |
!FileStream class methodsFor:'Compatibility-ANSI'! |
6586 | 466 |
|
467 |
write:filename |
|
468 |
"return a FileStream for new file named filename, aString. |
|
469 |
If the file exists, it is truncated, otherwise created. |
|
470 |
The file is opened for read/write access. |
|
471 |
Same as newFileNamed: for ANSI compatibilily" |
|
472 |
||
473 |
^ self newFileNamed:filename |
|
474 |
! ! |
|
475 |
||
7298 | 476 |
!FileStream class methodsFor:'Compatibility-Dolphin'! |
6244 | 477 |
|
478 |
read:filename text:text |
|
479 |
"return a readonly FileStream for the existing file named filename, aString. |
|
480 |
If the argument, text is false, the stream is setup to read binary bytes, |
|
481 |
if false, it reads characters." |
|
482 |
||
483 |
|s| |
|
484 |
||
485 |
s := self readOnlyFileNamed:filename. |
|
486 |
text ifTrue:[ |
|
7872 | 487 |
s text |
6244 | 488 |
] ifFalse:[ |
7872 | 489 |
s binary |
6244 | 490 |
]. |
491 |
^ s |
|
6474 | 492 |
! |
493 |
||
494 |
write:filename mode:modeSymbol |
|
495 |
"return a writable FileStream for the file named filename, aString. |
|
496 |
The modeSymbol controls how the file is opened; currently supported are: |
|
7965 | 497 |
#append |
6474 | 498 |
" |
499 |
||
500 |
modeSymbol == #append ifTrue:[ |
|
7965 | 501 |
^ self appendingOldFileNamed:filename |
6474 | 502 |
]. |
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
503 |
"/ 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
|
504 |
"/ 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
|
505 |
super openErrorSignal raiseRequestErrorString:' - unsupported mode'. |
6474 | 506 |
^ nil |
507 |
! |
|
508 |
||
509 |
write:filename text:textModeBoolean |
|
510 |
"return a writable FileStream for the file named filename, aString. |
|
511 |
If the argument, text is false, the stream is setup to write binary bytes, |
|
512 |
if false, it writes characters." |
|
513 |
||
514 |
|s| |
|
515 |
||
6475 | 516 |
s := self newFileNamed:filename. |
6474 | 517 |
s notNil ifTrue:[ |
7872 | 518 |
textModeBoolean ifTrue:[ |
519 |
s text |
|
520 |
] ifFalse:[ |
|
521 |
s binary |
|
522 |
] |
|
6474 | 523 |
]. |
524 |
^ s |
|
6244 | 525 |
! ! |
526 |
||
7298 | 527 |
!FileStream class methodsFor:'Compatibility-Squeak'! |
5186 | 528 |
|
529 |
readOnlyFileNamed:filename |
|
6244 | 530 |
"return a readonly FileStream for the existing file named filename, aString." |
531 |
||
5186 | 532 |
^ self readonlyFileNamed:filename |
533 |
! ! |
|
534 |
||
7298 | 535 |
!FileStream class methodsFor:'Compatibility-VW'! |
6170
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
536 |
|
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
537 |
badArgumentsSignal |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
538 |
^ Error |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
539 |
! ! |
c00688d17b16
+ #badArgumentSignal (VW compat.)
Claus Gittinger <cg@exept.de>
parents:
5910
diff
changeset
|
540 |
|
3233
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
541 |
!FileStream class methodsFor:'Signal constants'! |
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
542 |
|
4907 | 543 |
userInitiatedFileSaveQuerySignal |
544 |
"return the query signal, which is raised before a user-initiated |
|
545 |
file-save / file-saveAs operation is performed. |
|
546 |
The query will be invoked with the fileName which is about to be |
|
547 |
written to. |
|
548 |
The default signal here returnes true, which will grant the save. |
|
549 |
End-user applications may want to catch this signal, |
|
550 |
and only return true for certain directories." |
|
551 |
||
552 |
^ UserInitiatedFileSaveQuerySignal |
|
553 |
||
3233
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
554 |
! ! |
1d29ae45b333
Must redefine #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3231
diff
changeset
|
555 |
|
7261 | 556 |
!FileStream methodsFor:'Compatibility-Squeak'! |
3044 | 557 |
|
558 |
fullName |
|
559 |
"Squeak compatibility: return the full pathname" |
|
560 |
||
561 |
^ pathName asFilename pathName |
|
562 |
||
563 |
"Created: 17.10.1997 / 17:04:12 / cg" |
|
564 |
"Modified: 20.10.1997 / 19:22:44 / cg" |
|
565 |
! ! |
|
566 |
||
1 | 567 |
!FileStream methodsFor:'accessing'! |
568 |
||
569 |
directoryName |
|
2903 | 570 |
"return the name of the directory I'm in as a string" |
1 | 571 |
|
2903 | 572 |
^ pathName asFilename directoryName |
1 | 573 |
! |
574 |
||
575 |
name |
|
2903 | 576 |
"return my name without leading direcory-path (i.e. the plain fileName) |
577 |
as a string" |
|
1 | 578 |
|
2903 | 579 |
^ pathName asFilename baseName |
1 | 580 |
! |
581 |
||
582 |
pathName |
|
583 |
"return the pathname" |
|
584 |
||
585 |
^ pathName |
|
613 | 586 |
! |
587 |
||
3754
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
588 |
removeOnClose:aBoolean |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
589 |
"set/clear the removeOnClose flag. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
590 |
If set, the file will be removed when closed. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
591 |
Provided mostly for OS's which do not allow an |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
592 |
open file to be removed (i.e. non unixes), |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
593 |
and a fileStream for a tempFile is used. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
594 |
Especially, the CVS-SourceCodeManager returns |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
595 |
this kind of file-handles occasionally. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
596 |
This is an ST/X special feature which is not portable |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
597 |
to other systems." |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
598 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
599 |
removeOnClose := aBoolean |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
600 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
601 |
"Modified: / 13.8.1998 / 12:10:07 / cg" |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
602 |
! |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
603 |
|
613 | 604 |
store:something |
605 |
"what really should this do" |
|
606 |
||
607 |
self nextPutAll:something storeString |
|
608 |
! ! |
|
609 |
||
610 |
!FileStream methodsFor:'error handling'! |
|
611 |
||
612 |
openError |
|
2963 | 613 |
"{ Pragma: +optSpace }" |
614 |
||
613 | 615 |
"report an error, that file open failed" |
616 |
||
7827 | 617 |
"/ This has changed from previous releases: |
618 |
"/ in earlier versions of ST/X, failed file open operations |
|
619 |
"/ returned nil - now, an error is raised. |
|
620 |
"/ The old behavior is simulated by providing an exception |
|
621 |
"/ handler, which proceeds with nil. |
|
613 | 622 |
"/ |
2921 | 623 |
"/ Sorry about that. |
613 | 624 |
"/ |
625 |
LastErrorNumber := lastErrorNumber. |
|
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
626 |
^ super openError. |
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
627 |
|
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
628 |
" |
7827 | 629 |
'/dasGIBtEsbeStimmtNiChT' asFilename readStream |
7091
b399f3d19084
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7053
diff
changeset
|
630 |
" |
613 | 631 |
! ! |
632 |
||
3754
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
633 |
!FileStream methodsFor:'instance release'! |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
634 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
635 |
closeFile |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
636 |
"low level close - may be redefined in subclasses" |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
637 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
638 |
super closeFile. |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
639 |
removeOnClose == true ifTrue:[ |
7872 | 640 |
pathName asFilename remove. |
3754
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
641 |
] |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
642 |
|
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
643 |
"Created: / 13.8.1998 / 12:11:22 / cg" |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
644 |
! ! |
e281b9479361
added removeOnClose feature.
Claus Gittinger <cg@exept.de>
parents:
3233
diff
changeset
|
645 |
|
8362 | 646 |
!FileStream methodsFor:'misc functions'! |
647 |
||
648 |
copyToEndInto:outStream |
|
649 |
"copy the data into another stream." |
|
650 |
||
651 |
|pos n nWritten| |
|
652 |
||
653 |
"the sendfile() system call currently (2004-05-07) handles only descriptors that |
|
654 |
support mmap-like operations as from-fd. |
|
655 |
Therefore, this method is reimplemented here (from ExternalStream)" |
|
656 |
||
657 |
outStream isExternalStream ifTrue:[ |
|
658 |
pos := self position0Based. |
|
659 |
n := self size - pos. |
|
660 |
nWritten := OperatingSystem |
|
661 |
copyFromFd:(self fileDescriptor) |
|
662 |
toFd:(outStream fileDescriptor) |
|
663 |
startIndex:pos |
|
664 |
count:n. |
|
665 |
nWritten = n ifTrue:[ |
|
666 |
^ self |
|
667 |
]. |
|
668 |
nWritten > 0 ifTrue:[ |
|
669 |
self position0Based:pos+nWritten. |
|
670 |
]. |
|
671 |
]. |
|
672 |
^ super copyToEndInto:outStream. |
|
673 |
||
674 |
" |
|
675 |
|in out| |
|
676 |
||
677 |
in := 'Makefile' asFilename readStream. |
|
678 |
out := Stdout. |
|
679 |
in copyToEndInto:out. |
|
680 |
in close. |
|
681 |
" |
|
682 |
! ! |
|
683 |
||
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
684 |
!FileStream methodsFor:'positioning'! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
685 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
686 |
position0Based |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
687 |
"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
|
688 |
|
3971 | 689 |
%{ |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
690 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
691 |
HFILE f; |
7872 | 692 |
off_t currentPosition; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
693 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
694 |
if (__INST(filePointer) != nil) { |
7965 | 695 |
do { |
696 |
f = __FILEVal(__INST(filePointer)); |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
697 |
#ifdef WIN32 |
7965 | 698 |
__threadErrno = 0; |
699 |
if (__INST(buffered) == true) { |
|
6333 | 700 |
# if 0 |
7965 | 701 |
currentPosition = STX_C_CALL1( "ftell", ftell, f); |
6333 | 702 |
# else |
7965 | 703 |
currentPosition = ftell(f); |
6333 | 704 |
# endif |
7965 | 705 |
} else { |
706 |
OBJ rA = __INST(readAhead); |
|
707 |
off_t offs = 0; |
|
6333 | 708 |
|
7965 | 709 |
if (rA != nil) { |
710 |
__INST(readAhead) = nil; |
|
711 |
offs = -1; |
|
712 |
} |
|
6333 | 713 |
# if 0 |
7965 | 714 |
currentPosition = STX_C_CALL3( "lseek", lseek, fileno(f), offs, SEEK_CUR); |
6333 | 715 |
# else |
7965 | 716 |
currentPosition = lseek(fileno(f), offs, SEEK_CUR); |
6333 | 717 |
# endif |
7965 | 718 |
} |
8039
6ef0379296cc
#position0Based did not work on unbuffered streams (with 64 bit off_t).
Stefan Vogel <sv@exept.de>
parents:
8034
diff
changeset
|
719 |
#else /* !WIN32 */ |
7965 | 720 |
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
|
721 |
#ifdef _LFS_LARGEFILE |
7965 | 722 |
currentPosition = ftello(f); |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
723 |
#else |
7965 | 724 |
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
|
725 |
#endif /* ! _LFS_LARGEFILE */ |
7965 | 726 |
} else { |
727 |
currentPosition = lseek(fileno(f), (off_t)0, SEEK_CUR); |
|
728 |
} |
|
8039
6ef0379296cc
#position0Based did not work on unbuffered streams (with 64 bit off_t).
Stefan Vogel <sv@exept.de>
parents:
8034
diff
changeset
|
729 |
#endif /* !WIN32 */ |
7965 | 730 |
} while ((currentPosition < 0) && (__threadErrno == EINTR)); |
6267
10016cc16511
pass name of API/C wrap function
Claus Gittinger <cg@exept.de>
parents:
6259
diff
changeset
|
731 |
|
7965 | 732 |
if (currentPosition >= 0) { |
733 |
OBJ rslt; |
|
7872 | 734 |
|
7965 | 735 |
if (sizeof(currentPosition) == 8) { |
736 |
rslt = __MKINT64 (¤tPosition); |
|
737 |
} else { |
|
738 |
rslt = __MKINT(currentPosition); |
|
739 |
} |
|
740 |
RETURN ( rslt ); |
|
741 |
} |
|
742 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
743 |
} |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
744 |
%}. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
745 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
746 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
747 |
^ self primitiveFailed |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
748 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
749 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
750 |
position0Based:newPos |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
751 |
"set the read/write position in the file" |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
752 |
|
5493 | 753 |
|rslt| |
3971 | 754 |
%{ |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
755 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
756 |
HFILE f; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
757 |
long ret; |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
758 |
OBJ fp; |
7871
5c357f1ba0c9
preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents:
7870
diff
changeset
|
759 |
|
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
760 |
if ((__INST(canPosition) != false) || (newPos == __MKSMALLINT(0))) { |
7965 | 761 |
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
|
762 |
|
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
763 |
#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
|
764 |
# define FSEEK fseeko |
7965 | 765 |
off_t nP; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
766 |
#else |
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
767 |
#define FSEEK fseek |
7965 | 768 |
long nP; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
769 |
#endif |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
770 |
|
7965 | 771 |
if (__isSmallInteger(newPos)) { |
772 |
nP = __intVal(newPos); |
|
773 |
if (nP < 0) { |
|
774 |
__INST(lastErrorNumber) = __MKSMALLINT(EINVAL); |
|
775 |
goto getOutOfHere; |
|
776 |
} |
|
777 |
} else { |
|
778 |
nP = __signedLongIntVal(newPos); |
|
779 |
if (nP < 0) { |
|
780 |
__INST(lastErrorNumber) = __MKSMALLINT(EINVAL); |
|
781 |
goto getOutOfHere; |
|
782 |
} |
|
783 |
if (nP == 0) { |
|
784 |
if (sizeof(nP) == 8) { |
|
785 |
if (__signedLong64IntVal(newPos, &nP) == 0 || nP < 0) { |
|
786 |
__INST(lastErrorNumber) = __MKSMALLINT(EINVAL); |
|
787 |
goto getOutOfHere; |
|
788 |
} |
|
789 |
} else { |
|
790 |
__INST(lastErrorNumber) = __MKSMALLINT(EINVAL); |
|
791 |
goto getOutOfHere; |
|
792 |
} |
|
793 |
} |
|
794 |
} |
|
7871
5c357f1ba0c9
preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents:
7870
diff
changeset
|
795 |
|
7965 | 796 |
f = __FILEVal(fp); |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
797 |
|
7965 | 798 |
do { |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
799 |
#ifdef WIN32 |
7965 | 800 |
__threadErrno = 0; |
801 |
if (__INST(buffered) == true) { |
|
802 |
ret = STX_C_CALL3( "fseek", fseek, f, nP, SEEK_SET); |
|
803 |
} else { |
|
804 |
__INST(readAhead) = nil; |
|
805 |
ret = STX_C_CALL3( "lseek", lseek, fileno(f), nP, SEEK_SET); |
|
806 |
} |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
807 |
#else |
7965 | 808 |
if (__INST(buffered) == true) { |
809 |
ret = FSEEK(f, nP, SEEK_SET); |
|
810 |
} else { |
|
811 |
ret = lseek(fileno(f), nP, SEEK_SET); |
|
812 |
} |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
813 |
#endif |
7965 | 814 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
815 |
if (ret >= 0) { |
|
816 |
__INST(position) = newPos; __STORE(self, newPos); |
|
817 |
/* |
|
818 |
* just to make certain ... |
|
819 |
*/ |
|
820 |
__INST(hitEOF) = false; |
|
821 |
RETURN ( self ); |
|
822 |
} |
|
823 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
824 |
} |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
825 |
} |
7871
5c357f1ba0c9
preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents:
7870
diff
changeset
|
826 |
getOutOfHere: ; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
827 |
#undef FSEEK |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
828 |
%}. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
829 |
canPosition == false ifTrue:[ |
7965 | 830 |
"/ position by rewinding & re-reading everything up-to |
831 |
"/ that point. |
|
832 |
^ self slowPosition0Based:newPos |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
833 |
]. |
2963 | 834 |
lastErrorNumber notNil ifTrue:[ |
7965 | 835 |
(OperatingSystem errorSymbolForNumber:lastErrorNumber) == #EINVAL ifTrue:[ |
836 |
"/ invalid position |
|
837 |
^ self positionError |
|
838 |
]. |
|
839 |
"/ assume I/O error |
|
840 |
^ self ioError |
|
2963 | 841 |
]. |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
842 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
7871
5c357f1ba0c9
preps for 64bit positions; fixed 32bit position
Claus Gittinger <cg@exept.de>
parents:
7870
diff
changeset
|
843 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
844 |
rslt := self positionFile:filePointer position0Based:newPos. |
5493 | 845 |
rslt >= 0 ifTrue:[ |
7965 | 846 |
position := newPos. |
5493 | 847 |
] ifFalse:[ |
7965 | 848 |
hitEOF := true. |
5493 | 849 |
] |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
850 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
851 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
852 |
setToEnd |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
853 |
"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
|
854 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
855 |
%{ |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
856 |
HFILE f; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
857 |
off_t ret; |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
858 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
859 |
if (__INST(filePointer) != nil) { |
7965 | 860 |
f = __FILEVal(__INST(filePointer)); |
861 |
__INST(position) = nil; /* i.e. unknown */ |
|
862 |
do { |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
863 |
#ifdef WIN32 |
7965 | 864 |
__threadErrno = 0; |
865 |
if (__INST(buffered) == true) { |
|
866 |
ret = STX_C_CALL3( "fseek", fseek, f, 0L, SEEK_END); |
|
867 |
} else { |
|
868 |
__INST(readAhead) = nil; |
|
869 |
ret = STX_C_CALL3( "lseek", lseek, fileno(f), 0L, SEEK_END); |
|
870 |
} |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
871 |
#else |
7965 | 872 |
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
|
873 |
#ifdef _LFS_LARGE_FILE |
7965 | 874 |
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
|
875 |
#else |
7965 | 876 |
ret = fseek(f, 0L, SEEK_END); |
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
877 |
#endif |
7965 | 878 |
} else { |
879 |
ret = lseek(fileno(f), (off_t)0, SEEK_END); |
|
880 |
} |
|
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
881 |
#endif |
7965 | 882 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
883 |
if (ret >= 0) { |
|
884 |
RETURN ( self ); |
|
885 |
} |
|
886 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
887 |
} |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
888 |
%}. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
889 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
890 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
891 |
^ self primitiveFailed |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
892 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
893 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
894 |
slowPosition0Based:newPos |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
895 |
"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
|
896 |
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
|
897 |
This is required to reposition nonPositionable streams, such |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
898 |
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
|
899 |
Caveat: |
7965 | 900 |
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
|
901 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
902 |
|buffer amount pos0Based| |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
903 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
904 |
self isReadable ifFalse:[ |
7965 | 905 |
"/ sorry |
906 |
^ self positionError |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
907 |
]. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
908 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
909 |
buffer := ByteArray new:8*1024. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
910 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
911 |
(position isNil "/ i.e. unknown |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
912 |
or:[newPos < (pos0Based := self position0Based)]) ifTrue:[ |
7965 | 913 |
self reset. |
914 |
pos0Based := self position0Based. |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
915 |
]. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
916 |
[pos0Based < newPos] whileTrue:[ |
7965 | 917 |
amount := (buffer size) min:(newPos-pos0Based). |
918 |
(self nextBytes:amount into:buffer startingAt:1) ~~ amount ifTrue:[ |
|
919 |
^ self positionError |
|
920 |
]. |
|
921 |
pos0Based := self position0Based. |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
922 |
]. |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
923 |
"/ ('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
|
924 |
! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
925 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
926 |
slowPosition:newPos |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
927 |
"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
|
928 |
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
|
929 |
This is required to reposition nonPositionable streams, such |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
930 |
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
|
931 |
Caveat: |
7965 | 932 |
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
|
933 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
934 |
^ self slowPosition0Based:(newPos - ZeroPosition) |
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
935 |
! ! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
936 |
|
613 | 937 |
!FileStream methodsFor:'printing & storing'! |
938 |
||
939 |
printOn:aStream |
|
4392 | 940 |
"append a user printed representation of the receiver to aStream. |
941 |
The format is suitable for a human - not meant to be read back." |
|
2903 | 942 |
|
613 | 943 |
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
|
944 |
aStream nextPutAll:pathName printString. |
613 | 945 |
aStream nextPut:$) |
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
946 |
|
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
947 |
"Modified: 30.7.1997 / 13:51:01 / cg" |
613 | 948 |
! |
949 |
||
950 |
storeOn:aStream |
|
2903 | 951 |
"append a representation of the receiver to aStream, |
952 |
from which a copy can be reconstructed later." |
|
953 |
||
613 | 954 |
aStream nextPutAll:'(FileStream oldFileNamed:'. |
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
955 |
aStream nextPutAll:pathName storeString. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6798
diff
changeset
|
956 |
(self position ~~ ZeroPosition) ifTrue:[ |
7872 | 957 |
aStream nextPutAll:'; position:'. |
958 |
self position storeOn:aStream |
|
613 | 959 |
]. |
960 |
aStream nextPut:$) |
|
2811
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
961 |
|
21136662e8f1
dont crash into debugger when printing with nil pathName
Claus Gittinger <cg@exept.de>
parents:
2808
diff
changeset
|
962 |
"Modified: 30.7.1997 / 16:43:50 / cg" |
1 | 963 |
! ! |
964 |
||
965 |
!FileStream methodsFor:'private'! |
|
966 |
||
613 | 967 |
createForReadWrite |
968 |
"create/truncate the file for read/write. |
|
969 |
If the file existed, its truncated; otherwise its created." |
|
1 | 970 |
|
613 | 971 |
mode := #readwrite. |
2921 | 972 |
^ self openWithMode:CreateReadWriteMode |
1 | 973 |
! |
974 |
||
613 | 975 |
createForWriting |
976 |
"create/truncate the file for writeonly. |
|
977 |
If the file existed, its truncated; otherwise its created." |
|
1 | 978 |
|
613 | 979 |
mode := #writeonly. |
980 |
didWrite := true. |
|
6798 | 981 |
^ self openWithMode:WriteMode attributes:nil |
1 | 982 |
! |
983 |
||
984 |
open |
|
985 |
"open the file" |
|
986 |
||
987 |
pathName isNil ifTrue:[^nil]. |
|
988 |
(mode == #readonly) ifTrue: [ |
|
7872 | 989 |
didWrite := false. |
990 |
^ self openWithMode:ReadMode |
|
1 | 991 |
]. |
992 |
(mode == #writeonly) ifTrue: [ |
|
7872 | 993 |
didWrite := true. |
994 |
^ self openWithMode:WriteMode |
|
1 | 995 |
]. |
2921 | 996 |
^ self openWithMode:ReadWriteMode |
1 | 997 |
! |
998 |
||
5439 | 999 |
openFile:pathName withMode:openmode attributes:attributeSpec |
1000 |
"open the file; |
|
1001 |
openmode is the string defining the way to open as defined by the stdio library |
|
1002 |
(i.e. the 2nd fopen argument). |
|
1003 |
||
1004 |
attributeSpec is an additional argument, only used with VMS - it allows a file to |
|
1005 |
be created as fixedRecord, variableRecord, streamLF, streamCR, ... |
|
1006 |
In VMS, if nonNil, it must consist of an array of strings (max:10), giving additional |
|
1007 |
attributes (see fopen description). |
|
1008 |
Passing a nil specifies the default format (streamLF) - ST/X always invokes this with nil. |
|
1009 |
This argument is ignored in UNIX & MSDOS systems. |
|
1010 |
||
1011 |
This is a private entry, but maybe useful to open/create a file in a special mode, |
|
1012 |
which is proprietrary to the operatingSystem." |
|
1013 |
||
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1014 |
|wasBlocked| |
5439 | 1015 |
|
1016 |
%{ |
|
1017 |
HFILE f; |
|
1018 |
HFILE fopen(); |
|
1019 |
OBJ fp; |
|
1020 |
int pass = 0; |
|
1021 |
||
1022 |
retry: |
|
1023 |
if (__isNonNilObject(pathName) && (__qClass(pathName)==String)) { |
|
1024 |
#ifdef __VMS__ |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1025 |
do { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1026 |
/* |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1027 |
* allow passing additional RMS arguments. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1028 |
* 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
|
1029 |
*/ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1030 |
__threadErrno = 0; |
5439 | 1031 |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1032 |
{ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1033 |
if (__isArray(attributeSpec)) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1034 |
OBJ *ap = __ArrayInstPtr(attributeSpec)->a_element; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1035 |
int numAttrib = 0; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1036 |
int i; |
5439 | 1037 |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1038 |
numAttrib = __arraySize(attributeSpec); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1039 |
for (i=0; i<numAttrib;i++) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1040 |
if (! __isString(ap[i])) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1041 |
f = NULL; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1042 |
__threadErrno = EINVAL; /* invalid argument */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1043 |
goto getOutOfHere; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1044 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1045 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1046 |
switch (numAttrib) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1047 |
case 0: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1048 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1049 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode)); |
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 1: |
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])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1056 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1057 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1058 |
case 2: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1059 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1060 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1061 |
__stringVal(ap[0]), __stringVal(ap[1])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1062 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1063 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1064 |
case 3: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1065 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1066 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1067 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1068 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1069 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1070 |
case 4: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1071 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1072 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1073 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1074 |
__stringVal(ap[3])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1075 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1076 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1077 |
case 5: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1078 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1079 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1080 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1081 |
__stringVal(ap[3]), __stringVal(ap[4])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1082 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1083 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1084 |
case 6: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1085 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1086 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1087 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1088 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1089 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1090 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1091 |
case 7: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1092 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1093 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1094 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1095 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1096 |
__stringVal(ap[6])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1097 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1098 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1099 |
case 8: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1100 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1101 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1102 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1103 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1104 |
__stringVal(ap[6]), __stringVal(ap[7])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1105 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1106 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1107 |
case 9: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1108 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1109 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1110 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1111 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1112 |
__stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1113 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1114 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1115 |
case 10: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1116 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1117 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1118 |
__stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1119 |
__stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1120 |
__stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]), |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1121 |
__stringVal(ap[9])); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1122 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1123 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1124 |
default: |
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 |
__threadErrno = E2BIG; /* too many args */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1127 |
goto getOutOfHere; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1128 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1129 |
} else if (attributeSpec != nil) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1130 |
f = NULL; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1131 |
__threadErrno = EINVAL; /* invalid argument */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1132 |
goto getOutOfHere; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1133 |
} else { |
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 |
* create file as sequential streamLF by default. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1136 |
*/ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1137 |
__BEGIN_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1138 |
f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), "rfm=stmlf"); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1139 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1140 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1141 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1142 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
5439 | 1143 |
|
1144 |
#else /* not VMS */ |
|
1145 |
||
1146 |
# ifdef WIN32 |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1147 |
{ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1148 |
char _aPathName[MAXPATHLEN]; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1149 |
char _openMode[64]; |
5439 | 1150 |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1151 |
strncpy(_aPathName, __stringVal(pathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0'; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1152 |
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
|
1153 |
do { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1154 |
__threadErrno = 0; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1155 |
f = STX_C_CALL2( "fopen", fopen, _aPathName, _openMode); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1156 |
if (__threadErrno == EINTR) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1157 |
f = NULL; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1158 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1159 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1160 |
} |
5439 | 1161 |
# else /* not WIN32 */ |
1162 |
||
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1163 |
do { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1164 |
__BEGIN_INTERRUPTABLE__ |
5439 | 1165 |
# ifdef LINUX |
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1166 |
/* |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1167 |
* LINUX may ret a non-NULL f even when interrupted. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1168 |
* Therefore, check errno and fake a null-ret. |
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 |
__threadErrno = 0; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1171 |
f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode)); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1172 |
if (__threadErrno == EINTR) |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1173 |
f = NULL; |
5439 | 1174 |
# else /* not LINUX */ |
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1175 |
f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode)); |
5439 | 1176 |
# endif /* not LINUX */ |
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1177 |
__END_INTERRUPTABLE__ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1178 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
5439 | 1179 |
|
1180 |
# endif /* not WIN32 */ |
|
1181 |
#endif /* not VMS */ |
|
1182 |
||
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1183 |
if (f == NULL) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1184 |
/* |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1185 |
* If no filedescriptors available, try to finalize |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1186 |
* possibly collected fd's and try again. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1187 |
*/ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1188 |
if (pass == 0 && (__threadErrno == ENFILE || __threadErrno == EMFILE)) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1189 |
pass = 1; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1190 |
__SSEND0(@global(ObjectMemory), @symbol(scavenge), 0); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1191 |
__SSEND0(@global(ObjectMemory), @symbol(finalize), 0); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1192 |
goto retry; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1193 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1194 |
getOutOfHere: ; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1195 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1196 |
__INST(position) = nil; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1197 |
} else { |
5439 | 1198 |
#ifdef __VMS__ |
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1199 |
/* |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1200 |
* check to see if this is positionable ... |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1201 |
*/ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1202 |
__INST(canPosition) = false; |
5439 | 1203 |
# ifndef _POSIX_C_SOURCE |
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 |
struct stat statBuffer; |
5439 | 1206 |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1207 |
if (fstat(fileno(f), &statBuffer) >= 0) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1208 |
switch (statBuffer.st_fab_rfm) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1209 |
case FAB$C_UDF: /* undefined (also stream binary) */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1210 |
case FAB$C_VAR: /* variable length records */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1211 |
case FAB$C_VFC: /* variable fixed control */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1212 |
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
|
1213 |
default: |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1214 |
__INST(canPosition) = false; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1215 |
break; |
5439 | 1216 |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1217 |
case FAB$C_FIX: /* fixed length records */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1218 |
case FAB$C_STMLF: /* LF stream (valid only for sequential> */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1219 |
case FAB$C_STMCR: /* CR stream (valid only for sequential> */ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1220 |
__INST(canPosition) = true; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1221 |
break; |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1222 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1223 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1224 |
} |
5439 | 1225 |
# endif |
1226 |
#else /* not VMS */ |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1227 |
__INST(canPosition) = true; |
5439 | 1228 |
#endif /* poor VMS */ |
1229 |
||
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1230 |
if (@global(FileOpenTrace) == true) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1231 |
fprintf(stderr, "fopen %s [FileStream] -> %x\n", __stringVal(pathName), f); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1232 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1233 |
if (f != NULL) { |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1234 |
wasBlocked = __BLOCKINTERRUPTS(); |
8063 | 1235 |
__INST(filePointer) = fp = __MKOBJ((INT)f); __STORE(self, fp); |
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1236 |
} |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1237 |
__INST(position) = @global(PositionableStream:ZeroPosition); |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1238 |
} |
5439 | 1239 |
} |
1240 |
%}. |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1241 |
filePointer notNil ifTrue:[ |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1242 |
Lobby register:self. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1243 |
wasBlocked == false ifTrue:[OperatingSystem unblockInterrupts]. |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1244 |
]. |
5439 | 1245 |
^ filePointer |
1246 |
! |
|
1247 |
||
613 | 1248 |
openForAppending |
1249 |
"open the file for writeonly appending to the end. |
|
1250 |
If the file does not exist its an error, return nil; |
|
1251 |
otherwise return the receiver." |
|
1252 |
||
1253 |
mode := #writeonly. |
|
1254 |
didWrite := true. |
|
2921 | 1255 |
^ self openWithMode:AppendMode |
613 | 1256 |
! |
1257 |
||
1258 |
openForReadWrite |
|
1259 |
"open the file for read/write. |
|
1260 |
If the file does not exist its an error, return nil; |
|
1261 |
otherwise return the receiver." |
|
1262 |
||
1263 |
mode := #readwrite. |
|
2921 | 1264 |
^ self openWithMode:ReadWriteMode |
613 | 1265 |
! |
1266 |
||
1267 |
openForReading |
|
1268 |
"open the file for readonly. |
|
1269 |
If the file does not exist its an error, return nil; |
|
1270 |
otherwise return the receiver." |
|
1271 |
||
1272 |
mode := #readonly. |
|
1273 |
didWrite := false. |
|
2921 | 1274 |
^ self openWithMode:ReadMode |
613 | 1275 |
! |
1276 |
||
1277 |
openForWriting |
|
1278 |
"open the file writeonly. |
|
1279 |
If the file does not exist its an error, return nil; |
|
1280 |
otherwise return the receiver." |
|
1281 |
||
1282 |
mode := #writeonly. |
|
1283 |
didWrite := true. |
|
2921 | 1284 |
^ self openWithMode:ReadWriteMode "unix-io does not allow this; open for update here" |
613 | 1285 |
! |
1286 |
||
1 | 1287 |
openWithMode:openmode |
2921 | 1288 |
"open the file; |
1289 |
openmode is the string defining the way to open as defined by the stdio library |
|
1290 |
(i.e. the 2nd fopen argument). |
|
1291 |
||
1292 |
This is a private entry, but maybe useful to open a file in a special mode, |
|
1293 |
which is proprietrary to the operatingSystem." |
|
1294 |
||
1295 |
^ self openWithMode:openmode attributes:nil |
|
1296 |
! |
|
1297 |
||
1298 |
openWithMode:openmode attributes:attributeSpec |
|
2908 | 1299 |
"open the file; |
2921 | 1300 |
openmode is the string defining the way to open as defined by the stdio library |
1301 |
(i.e. the 2nd fopen argument). |
|
1302 |
||
1303 |
attributeSpec is an additional argument, only used with VMS - it allows a file to |
|
1304 |
be created as fixedRecord, variableRecord, streamLF, streamCR, ... |
|
1305 |
In VMS, if nonNil, it must consist of an array of strings (max:10), giving additional |
|
1306 |
attributes (see fopen description). |
|
1307 |
Passing a nil specifies the default format (streamLF) - ST/X always invokes this with nil. |
|
1308 |
This argument is ignored in UNIX & MSDOS systems. |
|
1309 |
||
1310 |
This is a private entry, but maybe useful to open/create a file in a special mode, |
|
1311 |
which is proprietrary to the operatingSystem." |
|
1 | 1312 |
|
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4392
diff
changeset
|
1313 |
filePointer notNil ifTrue:[^ self errorAlreadyOpen]. |
2921 | 1314 |
|
5439 | 1315 |
filePointer := self openFile:pathName withMode:openmode attributes:attributeSpec. |
1316 |
filePointer isNil ifTrue:[ |
|
8034
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1317 |
" |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1318 |
the open failed for some reason ... |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1319 |
" |
716b32d832bf
raise condition interrupt: interrupt between creation and lobby
ca
parents:
7970
diff
changeset
|
1320 |
^ self openError |
1 | 1321 |
]. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
6798
diff
changeset
|
1322 |
position := ZeroPosition. |
2963 | 1323 |
buffered := true. "default is buffered" |
1 | 1324 |
! |
1325 |
||
613 | 1326 |
pathName:filename |
1327 |
"set the pathname" |
|
1 | 1328 |
|
3051
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1329 |
pathName := filename asString |
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1330 |
|
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1331 |
"Modified: / 28.10.1997 / 14:29:01 / cg" |
1 | 1332 |
! |
1333 |
||
613 | 1334 |
pathName:filename in:aDirectory |
1335 |
"set the pathname starting at aDirectory, a FileDirectory" |
|
77 | 1336 |
|
3051
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1337 |
pathName := aDirectory asFilename constructString:filename |
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1338 |
|
29d10c26d6a3
allow for fileNames to be passed to #pathName:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1339 |
"Modified: / 28.10.1997 / 14:28:54 / cg" |
1 | 1340 |
! |
1341 |
||
1342 |
reOpen |
|
1343 |
"sent after snapin to reopen streams" |
|
1344 |
||
173 | 1345 |
|oldPos| |
1346 |
||
1 | 1347 |
filePointer notNil ifTrue:[ |
7872 | 1348 |
"it was open, when snapped-out" |
1349 |
filePointer := nil. |
|
1350 |
Lobby unregister:self. |
|
1351 |
oldPos := position. |
|
1352 |
self open. |
|
1353 |
filePointer isNil ifTrue:[ |
|
1354 |
"/ this happens, if after a restart, |
|
1355 |
"/ the file is no longer present or accessable ..." |
|
13 | 1356 |
|
7872 | 1357 |
(self class name , ' [warning]: could not reOpen file: ', pathName) errorPrintCR. |
1358 |
] ifFalse:[ |
|
1359 |
oldPos notNil ifTrue:[ |
|
1360 |
self position:oldPos. |
|
1361 |
] |
|
1362 |
] |
|
1 | 1363 |
] |
1088 | 1364 |
|
2134
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2078
diff
changeset
|
1365 |
"Modified: 10.1.1997 / 17:50:51 / cg" |
2921 | 1366 |
! |
1367 |
||
1368 |
setMode:aModeSymbol |
|
1369 |
mode := aModeSymbol |
|
31 | 1370 |
! ! |
1371 |
||
2921 | 1372 |
!FileStream methodsFor:'queries'! |
613 | 1373 |
|
2903 | 1374 |
fileSize |
613 | 1375 |
"return the size in bytes of the file" |
1376 |
||
3971 | 1377 |
%{ |
613 | 1378 |
|
4910
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
1379 |
HFILE f; |
33b0edbb1920
merged back FileStream_win32 into FileStream
Claus Gittinger <cg@exept.de>
parents:
4907
diff
changeset
|
1380 |
|
613 | 1381 |
#ifdef transputer |
7874
5e0319ca5e60
stats filesize can be up-to 32bit now.
Claus Gittinger <cg@exept.de>
parents:
7872
diff
changeset
|
1382 |
unsigned int size; |
613 | 1383 |
|
1133 | 1384 |
if (__INST(filePointer) != nil) { |
7965 | 1385 |
f = __FILEVal(__INST(filePointer)); |
1386 |
if ((size = filesize(fileno(f))) >= 0) { |
|
1387 |
RETURN ( __MKUINT(size) ); |
|
1388 |
} |
|
613 | 1389 |
} |
1390 |
#else |
|
1391 |
struct stat buf; |
|
1392 |
int ret; |
|
1393 |
int fd; |
|
1394 |
||
1133 | 1395 |
if (__INST(filePointer) != nil) { |
7965 | 1396 |
f = __FILEVal(__INST(filePointer)); |
1397 |
fd = fileno(f); |
|
1398 |
do { |
|
1399 |
ret = fstat(fd, &buf); |
|
1400 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
|
1401 |
if (ret >= 0) { |
|
1402 |
OBJ rslt; |
|
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7874
diff
changeset
|
1403 |
|
7965 | 1404 |
if (sizeof(buf.st_size) == 8) { |
1405 |
rslt = __MKINT64(&buf.st_size); |
|
1406 |
} else { |
|
1407 |
rslt = __MKINT(buf.st_size); |
|
1408 |
} |
|
1409 |
RETURN(rslt); |
|
1410 |
} |
|
1411 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
613 | 1412 |
} |
1413 |
#endif |
|
1414 |
%}. |
|
1415 |
||
1416 |
"could add a fall-back here: |
|
1417 |
||
7965 | 1418 |
oldPosition := self position. |
1419 |
self setToEnd. |
|
1420 |
sz := self position. |
|
1421 |
self position:oldPosition. |
|
1422 |
^ sz |
|
613 | 1423 |
" |
1424 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
1425 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
1426 |
^ self primitiveFailed |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1427 |
! |
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1428 |
|
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1429 |
size |
2998
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1430 |
"return the size of the stream; |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1431 |
thats the number of bytes of the file." |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1432 |
|
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1433 |
"/ no obsoleteMethodWarning - size is ok for streams. |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1434 |
"/ self obsoleteMethodWarning:'use #fileSize'. |
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1435 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1436 |
^ self fileSize. |
2998
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1437 |
|
930360fb3f12
#size is not really obsolete
Claus Gittinger <cg@exept.de>
parents:
2992
diff
changeset
|
1438 |
"Modified: 4.10.1997 / 18:01:09 / cg" |
1 | 1439 |
! ! |
1440 |
||
5493 | 1441 |
!FileStream methodsFor:'rel5 protocol'! |
1442 |
||
1443 |
positionFile:filePointer position:newPos |
|
1444 |
"for migration to rel5 only" |
|
1445 |
||
1446 |
self primitiveFailed |
|
1447 |
! ! |
|
1448 |
||
2 | 1449 |
!FileStream methodsFor:'testing'! |
1450 |
||
1451 |
isFileStream |
|
1452 |
"return true, if the receiver is some kind of fileStream. |
|
1453 |
redefined from Object" |
|
1454 |
||
1455 |
^ true |
|
1456 |
! ! |
|
1457 |
||
1088 | 1458 |
!FileStream class methodsFor:'documentation'! |
1459 |
||
1460 |
version |
|
8362 | 1461 |
^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.108 2004-05-18 10:23:59 cg Exp $' |
1088 | 1462 |
! ! |
6798 | 1463 |
|
2936
5cce0f2166d9
OpenErrorSignal already defined in super (ExternalStream).
Stefan Vogel <sv@exept.de>
parents:
2921
diff
changeset
|
1464 |
FileStream initialize! |