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