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