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