author | Claus Gittinger <cg@exept.de> |
Mon, 26 Aug 2019 10:06:33 +0200 | |
changeset 24628 | 35b5c06ad5f0 |
parent 24507 | 446e2dcc1a3b |
child 24640 | 76d48838aca5 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
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 |
" |
|
5414 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
17418 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1 | 16 |
ReadWriteStream subclass:#ExternalStream |
22848 | 17 |
instanceVariableNames:'handleType handle mode buffered binary eolMode hitEOF didWrite |
23744 | 18 |
lastErrorNumber readAhead dependents' |
22848 | 19 |
classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal |
20 |
InvalidModeSignal OpenErrorSignal StreamNotOpenSignal |
|
21 |
InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode |
|
22 |
WriteMode AppendMode CreateReadWriteMode StreamIOErrorSignal |
|
23 |
FileOpenTrace MaxNonTenurableExecutors DefaultCopyBufferSize' |
|
24 |
poolDictionaries:'' |
|
25 |
category:'Streams-External' |
|
1 | 26 |
! |
27 |
||
216 | 28 |
!ExternalStream primitiveDefinitions! |
1 | 29 |
%{ |
10328
ad731a7584a3
ensure that win32_fwrite is used for stdout and stderr
Claus Gittinger <cg@exept.de>
parents:
9053
diff
changeset
|
30 |
#undef fwrite |
ad731a7584a3
ensure that win32_fwrite is used for stdout and stderr
Claus Gittinger <cg@exept.de>
parents:
9053
diff
changeset
|
31 |
|
17078 | 32 |
#include "stxOSDefs.h" |
33 |
||
1 | 34 |
#include <stdio.h> |
437 | 35 |
#define _STDIO_H_INCLUDED_ |
36 |
||
2903 | 37 |
#ifndef NO_FCNTL_H |
38 |
# include <fcntl.h> |
|
39 |
# define _FCNTL_H_INCLUDED_ |
|
40 |
#endif |
|
437 | 41 |
|
10 | 42 |
#include <errno.h> |
437 | 43 |
#define _ERRNO_H_INCLUDED_ |
42 | 44 |
|
1141 | 45 |
#ifdef LINUX |
46 |
/* use inline string macros */ |
|
47 |
# define __STRINGDEFS__ |
|
48 |
# include <linuxIntern.h> |
|
49 |
#endif |
|
50 |
||
16508 | 51 |
#if !defined(MSDOS_LIKE) && !defined(__openVMS__) |
52 |
# include <termios.h> |
|
53 |
#endif |
|
54 |
||
42 | 55 |
#ifdef hpux |
56 |
# define fileno(f) ((f->__fileH << 8) | (f->__fileL)) |
|
57 |
#endif |
|
216 | 58 |
|
933
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
59 |
#ifndef SEEK_SET |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
60 |
# define SEEK_SET 0 |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
61 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
62 |
#ifndef SEEK_CUR |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
63 |
# define SEEK_CUR 1 |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
64 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
65 |
#ifndef SEEK_END |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
66 |
# define SEEK_END 2 |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
67 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
68 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
69 |
#if defined(__VMS__) || defined(__sparc__) || defined(__win32__) |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
5101
diff
changeset
|
70 |
# define CLEAR_ERRNO __threadErrno = 0; |
2961 | 71 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
72 |
# define CLEAR_ERRNO /* nothing */ |
2961 | 73 |
#endif |
74 |
||
3420 | 75 |
#ifdef LATER |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
76 |
# define __isFilePointer(x) (__Class(x) == ExternalStream__FilePointer) |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
77 |
# define __CHANGECLASS(o, x) (__qClass(o) = (x), o) |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
78 |
# define __MKFILEPOINTER(f) __CHANGECLASS(__MKEXTERNALADDRESS(f), ExternalStream__FilePointer) |
3420 | 79 |
#else |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
80 |
# define __MKFILEPOINTER(f) __MKEXTERNALADDRESS(f) |
3420 | 81 |
#endif |
82 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
83 |
#ifdef __win32__ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
84 |
# define NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
85 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
86 |
# undef __HANDLE_INTERRUPTS__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
87 |
# define __HANDLE_INTERRUPTS__ /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
88 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
89 |
# undef __BEGIN_INTERRUPTABLE__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
90 |
# define __BEGIN_INTERRUPTABLE__ /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
91 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
92 |
# undef __END_INTERRUPTABLE__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
93 |
# define __END_INTERRUPTABLE__ /* nothing */ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
94 |
#endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
95 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
96 |
# ifdef __i386__ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
97 |
# define _X86_ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
98 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
99 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
100 |
#ifdef __win32__ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
101 |
# undef INT |
14644 | 102 |
# undef UINT |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
103 |
# undef Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
104 |
# undef Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
105 |
# undef Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
106 |
# undef Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
107 |
# undef Rectangle |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
108 |
# undef Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
109 |
# undef Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
110 |
# undef Date |
7832 | 111 |
# undef Delay |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
112 |
# undef Set |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
113 |
# undef Signal |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
114 |
# undef Context |
9023 | 115 |
# undef Message |
9024 | 116 |
# undef Process |
10339 | 117 |
# undef Processor |
14632 | 118 |
# undef String |
119 |
# undef Character |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
120 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
121 |
# define NOATOM |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
122 |
# define NOGDICAPMASKS |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
123 |
# define NOMETAFILE |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
124 |
# define NOMINMAX |
14068 | 125 |
//# define NOOPENFILE |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
126 |
# define NOSOUND |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
127 |
# define NOWH |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
128 |
//# define NOCOMM |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
129 |
# define NOKANJI |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
130 |
# define NOCRYPT |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
131 |
//# define NOMCX |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
132 |
# define WIN32_LEAN_AND_MEAN |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
133 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
134 |
# include <windows.h> |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
135 |
# include <winsock2.h> |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
136 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
137 |
# ifdef __DEF_Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
138 |
# define Array __DEF_Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
139 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
140 |
# ifdef __DEF_Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
141 |
# define Number __DEF_Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
142 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
143 |
# ifdef __DEF_Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
144 |
# define Method __DEF_Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
145 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
146 |
# ifdef __DEF_Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
147 |
# define Point __DEF_Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
148 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
149 |
# ifdef __DEF_Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
150 |
# define Block __DEF_Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
151 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
152 |
# ifdef __DEF_Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
153 |
# define Time __DEF_Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
154 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
155 |
# ifdef __DEF_Date |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
156 |
# define Date __DEF_Date |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
157 |
# endif |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
158 |
# ifdef __DEF_Set |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
159 |
# define Set __DEF_Set |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
160 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
161 |
# ifdef __DEF_Signal |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
162 |
# define Signal __DEF_Signal |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
163 |
# endif |
7832 | 164 |
# ifdef __DEF_Delay |
165 |
# define Delay __DEF_Delay |
|
166 |
# endif |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
167 |
# ifdef __DEF_Context |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
168 |
# define Context __DEF_Context |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
169 |
# endif |
9023 | 170 |
# ifdef __DEF_Message |
171 |
# define Message __DEF_Message |
|
172 |
# endif |
|
9024 | 173 |
# ifdef __DEF_Process |
174 |
# define Process __DEF_Process |
|
175 |
# endif |
|
10339 | 176 |
# ifdef __DEF_Processor |
177 |
# define Processor __DEF_Processor |
|
178 |
# endif |
|
14632 | 179 |
# ifdef __DEF_String |
180 |
# define String __DEF_String |
|
181 |
# endif |
|
182 |
# ifdef __DEF_Character |
|
183 |
# define Character __DEF_Character |
|
184 |
# endif |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
185 |
|
14644 | 186 |
# define INT STX_INT |
187 |
# define UINT STX_UINT |
|
188 |
# ifndef off_t |
|
189 |
# define off_t long |
|
190 |
# endif |
|
23110 | 191 |
|
23111 | 192 |
size_t __win32_fwrite(char *, size_t , size_t , FILE *); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
193 |
#endif /* __win32__ */ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
194 |
|
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
195 |
#ifndef NO_STDIO /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
196 |
# define STDIO_NEEDS_FSEEK |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
197 |
# define FILEPOINTER FILE * |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
198 |
# define READ(f, cp, n) read(f, cp, n) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
199 |
# define WRITE(f, cp, n) write(f, cp, n) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
200 |
# define FFLUSH(fp) fflush(fp) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
201 |
# define FILENO(f) fileno(f) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
202 |
#endif /* use STDIO */ |
3681 | 203 |
|
3682 | 204 |
#ifdef DEBUGGING |
4092 | 205 |
extern char *__survStartPtr, *__survEndPtr; |
3682 | 206 |
# define DEBUGBUFFER(buf) \ |
3681 | 207 |
if (((char *)(buf) >= __survStartPtr) \ |
208 |
&& ((char *)(buf) < __survEndPtr)) { \ |
|
23743 | 209 |
__fatal0("read into survivor\n"); \ |
3681 | 210 |
} |
211 |
||
3682 | 212 |
#else |
213 |
# define DEBUGBUFFER(buf) /* nothing */ |
|
214 |
#endif |
|
215 |
||
216 | 216 |
/* |
217 |
* stdio library requires an fseek before reading whenever a file |
|
218 |
* is open for read/write and the last operation was a write. |
|
219 |
* (also vice-versa). |
|
220 |
* All code should use the following macro before doing reads: |
|
221 |
*/ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
222 |
#ifdef STDIO_NEEDS_FSEEK |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
223 |
# define OPT_FSEEK(f, pos, whence) fseek(f, pos, whence) |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
224 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
225 |
# define OPT_FSEEK(f, pos, whence) /* nothing */ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
226 |
#endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
227 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
228 |
#ifdef __win32__ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
229 |
# define READ(ret, f, cp, n, handleType) { \ |
23743 | 230 |
if (handleType == @symbol(socketHandle)) { \ |
231 |
(ret) = __STX_WSA_NOINT_CALL4("recv", recv, (f), (cp), (n), 0); \ |
|
232 |
} else { \ |
|
233 |
HANDLE h = _get_osfhandle(fileno(f)); \ |
|
234 |
if (handleType == @symbol(socketFilePointer)) { \ |
|
235 |
(ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\ |
|
236 |
} else { \ |
|
237 |
int __res; \ |
|
238 |
(ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\ |
|
239 |
(ret) = (ret) > 0 ? __res : (__threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1); \ |
|
240 |
} \ |
|
241 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
242 |
} |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
243 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
244 |
# define WRITE(ret, f, cp, n, handleType) { \ |
23743 | 245 |
if (handleType == @symbol(socketHandle)) { \ |
246 |
(ret) = __STX_WSA_NOINT_CALL4("send", send, (f), (cp), (n), 0); \ |
|
247 |
} else {\ |
|
248 |
HANDLE h = _get_osfhandle(fileno(f)); \ |
|
249 |
if (handleType == @symbol(socketFilePointer)) { \ |
|
250 |
(ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\ |
|
251 |
} else {\ |
|
252 |
int __res; \ |
|
253 |
(ret) = __STX_API_NOINT_CALL5("WriteFile", WriteFile, h, (cp), (n), &__res, 0);\ |
|
254 |
(ret) = (ret) ? __res : -1; \ |
|
255 |
} \ |
|
256 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
257 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
258 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
259 |
# define FFLUSH(fp) fflush(fp) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
260 |
# undef STDIO_NEEDS_FSEEK |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
261 |
# define FILEPOINTER FILE * |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
262 |
# define FILENO(f) fileno(f) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
263 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
264 |
# define __READING__(f) \ |
1133 | 265 |
if ((__INST(didWrite) != false) \ |
266 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
23743 | 267 |
__INST(didWrite) = false; \ |
268 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
216 | 269 |
} |
270 |
||
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
271 |
# define __WRITING__(f) \ |
1133 | 272 |
if ((__INST(didWrite) != true) \ |
273 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
23743 | 274 |
__INST(didWrite) = true; \ |
275 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
216 | 276 |
} |
277 |
||
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
278 |
# define __UNGETC__(c, f, isBuffered) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
279 |
if (isBuffered) { \ |
23743 | 280 |
ungetc((c), (f)); \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
281 |
} else { \ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
282 |
__INST(readAhead) = __mkSmallInteger((c)); \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
283 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
284 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
285 |
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
286 |
if (isBuffered) { \ |
23743 | 287 |
for (;;) { \ |
288 |
CLEAR_ERRNO; \ |
|
289 |
(ret) = getc(f); \ |
|
290 |
if ((ret) >= 0) { \ |
|
291 |
*(buf) = (ret); \ |
|
292 |
(ret) = 1; \ |
|
293 |
} else if (ferror(f)) { \ |
|
294 |
if (__threadErrno == EINTR) { \ |
|
295 |
clearerr(f); \ |
|
296 |
continue; \ |
|
297 |
} \ |
|
298 |
} else { \ |
|
299 |
(ret) = 0; \ |
|
300 |
} \ |
|
301 |
break; \ |
|
302 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
303 |
} else { \ |
23743 | 304 |
OBJ rA = __INST(readAhead); \ |
305 |
if (rA != nil) { \ |
|
306 |
*(buf) = (char)__intVal(rA); \ |
|
307 |
__INST(readAhead) = nil; \ |
|
308 |
(ret) = 1; \ |
|
309 |
} else { \ |
|
310 |
for (;;) { \ |
|
311 |
CLEAR_ERRNO; \ |
|
312 |
READ((ret), f, buf, 1, handleType); \ |
|
313 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
314 |
break; \ |
|
315 |
} \ |
|
316 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
317 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
318 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
319 |
/* |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
320 |
* read_bytes into a c-buffer |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
321 |
* (which may NOT move) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
322 |
*/ |
12548 | 323 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
324 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
325 |
if (isBuffered) { \ |
23743 | 326 |
int __offs = 0; \ |
327 |
while (__offs < (cnt)) { \ |
|
328 |
CLEAR_ERRNO; \ |
|
329 |
(ret) = getc(f); \ |
|
330 |
if ((ret) < 0) { \ |
|
331 |
if (ferror(f)) { \ |
|
332 |
if (__threadErrno == EINTR) { \ |
|
333 |
clearerr(f); \ |
|
334 |
continue; \ |
|
335 |
} \ |
|
336 |
} else { \ |
|
337 |
(ret) = 0; \ |
|
338 |
} \ |
|
339 |
break; \ |
|
340 |
} \ |
|
341 |
(buf)[__offs++] = (ret); \ |
|
342 |
} \ |
|
343 |
if (__offs > 0) \ |
|
344 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
345 |
} else { \ |
23743 | 346 |
int __offs = 0; \ |
347 |
\ |
|
348 |
while (__offs < (cnt)) { \ |
|
349 |
OBJ rA = __INST(readAhead); \ |
|
350 |
if (rA != nil) { \ |
|
351 |
(buf)[__offs] = __intVal(rA); \ |
|
352 |
__INST(readAhead) = nil; \ |
|
353 |
(ret) = 1; \ |
|
354 |
} else { \ |
|
355 |
CLEAR_ERRNO; \ |
|
356 |
READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
357 |
if ((ret) <= 0) { \ |
|
358 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
359 |
continue; \ |
|
360 |
} \ |
|
361 |
break; \ |
|
362 |
} \ |
|
363 |
} \ |
|
364 |
__offs += (ret); \ |
|
365 |
} \ |
|
366 |
if (__offs > 0) \ |
|
367 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
368 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
369 |
|
12548 | 370 |
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
371 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
372 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
373 |
int oldFlags; \ |
23743 | 374 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
375 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
376 |
if (isBuffered) { \ |
23743 | 377 |
while (__offs < (cnt)) { \ |
378 |
CLEAR_ERRNO; \ |
|
379 |
(ret) = getc(f); \ |
|
380 |
if ((ret) < 0) { \ |
|
381 |
if (ferror(f)) { \ |
|
382 |
if (__threadErrno == EINTR) { \ |
|
383 |
clearerr(f); \ |
|
384 |
continue; \ |
|
385 |
} \ |
|
386 |
} else { \ |
|
387 |
(ret) = 0; \ |
|
388 |
} \ |
|
389 |
break; \ |
|
390 |
} \ |
|
391 |
(buf)[__offs++] = (ret); \ |
|
392 |
} \ |
|
393 |
if (__offs > 0) \ |
|
394 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
395 |
} else { \ |
23743 | 396 |
while (__offs < (cnt)) { \ |
397 |
OBJ rA = __INST(readAhead); \ |
|
398 |
if (rA != nil) { \ |
|
399 |
(buf)[__offs] = __intVal(rA); \ |
|
400 |
__INST(readAhead) = nil; \ |
|
401 |
(ret) = 1; \ |
|
402 |
__offs ++; \ |
|
403 |
continue; \ |
|
404 |
} \ |
|
405 |
CLEAR_ERRNO; \ |
|
406 |
{ \ |
|
407 |
int res = -1, ok = 0; \ |
|
408 |
SOCKET sock = 0; \ |
|
409 |
if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \ |
|
410 |
|| (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \ |
|
411 |
|| (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \ |
|
412 |
if (!ok) { \ |
|
413 |
__threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \ |
|
414 |
(ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \ |
|
415 |
break; \ |
|
416 |
} \ |
|
417 |
if (res > 0) { \ |
|
418 |
if (res > ((cnt)-__offs)) \ |
|
419 |
res = (cnt)-__offs; \ |
|
420 |
READ((ret), f, (buf)+__offs, res, handleType); \ |
|
421 |
} else { \ |
|
422 |
if (sock && send(sock, NULL, 0, 0) == SOCKET_ERROR) { \ |
|
423 |
(ret) = -1; __threadErrno = WSAGetLastError(); \ |
|
424 |
} else { \ |
|
425 |
(ret) = 0; \ |
|
426 |
} \ |
|
427 |
break; \ |
|
428 |
} \ |
|
429 |
} else { \ |
|
430 |
READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
431 |
} \ |
|
432 |
} \ |
|
433 |
if ((ret) <= 0) { \ |
|
434 |
if ((ret) < 0 && __threadErrno == EINTR)\ |
|
435 |
continue; \ |
|
436 |
break; \ |
|
437 |
} \ |
|
438 |
__offs += (ret); \ |
|
439 |
} \ |
|
440 |
if (__offs > 0) \ |
|
441 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
442 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
443 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
444 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
445 |
# define IO_BUFFER_SIZE (8*1024) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
446 |
|
12548 | 447 |
# define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
448 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
449 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
450 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
451 |
char *buf = (char *)(obj); \ |
23743 | 452 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
453 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
454 |
if (isBuffered) { \ |
23743 | 455 |
while (__offs < (cnt)) { \ |
456 |
CLEAR_ERRNO; \ |
|
457 |
(ret) = getc(f); \ |
|
458 |
if ((ret) < 0) { \ |
|
459 |
if (ferror(f)) { \ |
|
460 |
if (__threadErrno == EINTR) { \ |
|
461 |
clearerr(f); \ |
|
462 |
/* refetch */ \ |
|
463 |
buf = (char *)(obj); \ |
|
464 |
continue; \ |
|
465 |
} \ |
|
466 |
} else { \ |
|
467 |
(ret) = 0; \ |
|
468 |
} \ |
|
469 |
break; \ |
|
470 |
} \ |
|
471 |
(buf)[__ooffs+__offs] = (ret); \ |
|
472 |
__offs++; \ |
|
473 |
} \ |
|
474 |
if (__offs > 0) \ |
|
475 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
476 |
} else { \ |
23743 | 477 |
while (__offs < (cnt)) { \ |
478 |
char __buf[IO_BUFFER_SIZE]; \ |
|
479 |
OBJ rA = __INST(readAhead); \ |
|
480 |
if (rA != nil) { \ |
|
481 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
482 |
__INST(readAhead) = nil; \ |
|
483 |
(ret) = 1; \ |
|
484 |
} else { \ |
|
485 |
int l; \ |
|
486 |
CLEAR_ERRNO; \ |
|
487 |
l = (cnt)-__offs; \ |
|
488 |
if ( l > IO_BUFFER_SIZE) \ |
|
489 |
l = IO_BUFFER_SIZE; \ |
|
490 |
READ((ret),f, __buf, l, handleType); \ |
|
491 |
if ((ret) <= 0) { \ |
|
492 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
493 |
continue; \ |
|
494 |
} \ |
|
495 |
break; \ |
|
496 |
} \ |
|
497 |
} \ |
|
498 |
if ((ret) > 0 ) { \ |
|
499 |
/* refetch */ \ |
|
500 |
buf = (char *)(obj); \ |
|
501 |
memcpy((buf)+__ooffs+__offs,__buf,(ret)); \ |
|
502 |
__offs += (ret); \ |
|
503 |
} else { \ |
|
504 |
(ret) = 0; \ |
|
505 |
} \ |
|
506 |
} \ |
|
507 |
if (__offs > 0) \ |
|
508 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
509 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
510 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
511 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
512 |
# define __READAVAILBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
513 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
514 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
515 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
516 |
char *buf = (char *)(obj); \ |
23743 | 517 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
518 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
519 |
if (isBuffered) { \ |
23743 | 520 |
while (__offs < (cnt)) { \ |
521 |
CLEAR_ERRNO; \ |
|
522 |
(ret) = getc(f); \ |
|
523 |
if ((ret) < 0) { \ |
|
524 |
if (ferror(f)) { \ |
|
525 |
if (__threadErrno == EINTR) { \ |
|
526 |
clearerr(f); \ |
|
527 |
/* refetch */ \ |
|
528 |
buf = (char *)(obj); \ |
|
529 |
continue; \ |
|
530 |
} \ |
|
531 |
} else { \ |
|
532 |
(ret) = 0; \ |
|
533 |
} \ |
|
534 |
break; \ |
|
535 |
} \ |
|
536 |
(buf)[__ooffs+__offs] = (ret); \ |
|
537 |
__offs++; \ |
|
538 |
} \ |
|
539 |
if (__offs > 0) \ |
|
540 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
541 |
} else { \ |
23743 | 542 |
while (__offs < (cnt)) { \ |
543 |
char __buf[IO_BUFFER_SIZE]; \ |
|
544 |
OBJ rA = __INST(readAhead); \ |
|
545 |
if (rA != nil) { \ |
|
546 |
(buf)[__ooffs+__offs] = __intVal(rA);\ |
|
547 |
__INST(readAhead) = nil; \ |
|
548 |
(ret) = 1; \ |
|
549 |
__offs++; \ |
|
550 |
continue; \ |
|
551 |
} \ |
|
552 |
{ \ |
|
553 |
int res = -1, ok = 0; \ |
|
554 |
SOCKET sock = 0; \ |
|
555 |
int l = (cnt)-__offs; \ |
|
556 |
CLEAR_ERRNO; \ |
|
557 |
if (l > IO_BUFFER_SIZE) l = IO_BUFFER_SIZE; \ |
|
558 |
if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \ |
|
559 |
|| (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \ |
|
560 |
|| (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \ |
|
561 |
if (!ok) { \ |
|
562 |
__threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \ |
|
563 |
(ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \ |
|
564 |
break; \ |
|
565 |
} \ |
|
566 |
if (res > 0) { \ |
|
567 |
if (res > l) res = l; \ |
|
568 |
READ((ret), f, __buf, res, handleType); \ |
|
569 |
} else { \ |
|
570 |
if (sock && send(sock, NULL, 0, 0) == SOCKET_ERROR) { \ |
|
571 |
(ret) = -1; __threadErrno = WSAGetLastError(); \ |
|
572 |
} else { \ |
|
573 |
(ret) = 0; \ |
|
574 |
} \ |
|
575 |
break; \ |
|
576 |
} \ |
|
577 |
} else { \ |
|
578 |
READ((ret), f, __buf, l, handleType); \ |
|
579 |
} \ |
|
580 |
if ((ret) <= 0) { \ |
|
581 |
if ((ret) < 0 && __threadErrno == EINTR) \ |
|
582 |
continue; \ |
|
583 |
break; \ |
|
584 |
} \ |
|
585 |
} \ |
|
586 |
if ((ret) > 0) { \ |
|
587 |
buf = (char *)(obj); \ |
|
588 |
memcpy((buf)+__ooffs+__offs, __buf, (ret)); \ |
|
589 |
__offs += (ret); \ |
|
590 |
} else { \ |
|
591 |
(ret) = 0; \ |
|
592 |
} \ |
|
593 |
} \ |
|
594 |
if (__offs > 0) \ |
|
595 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
596 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
597 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
598 |
|
12548 | 599 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
600 |
if (isBuffered) { \ |
23743 | 601 |
for (;;) { \ |
602 |
CLEAR_ERRNO; \ |
|
603 |
ret = putc(*(buf), f); \ |
|
604 |
if ((ret) >= 0) { \ |
|
605 |
(ret) = 1; \ |
|
606 |
} else if (ferror(f)) { \ |
|
607 |
if (__threadErrno == EINTR) { \ |
|
608 |
clearerr(f); \ |
|
609 |
continue; \ |
|
610 |
} \ |
|
611 |
} else \ |
|
612 |
(ret) = 0; \ |
|
613 |
break; \ |
|
614 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
615 |
} else { \ |
23743 | 616 |
for (;;) { \ |
617 |
CLEAR_ERRNO; \ |
|
618 |
WRITE(ret,f, buf, 1, handleType); \ |
|
619 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
620 |
break; \ |
|
621 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
622 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
623 |
|
12548 | 624 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
625 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
626 |
if (isBuffered) { \ |
23743 | 627 |
int __offs = 0; \ |
628 |
while (__offs < (cnt)) { \ |
|
629 |
CLEAR_ERRNO; \ |
|
630 |
(ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
|
631 |
if ((ret) <= 0) { \ |
|
632 |
if (ferror(f)) { \ |
|
633 |
if (__threadErrno == EINTR) { \ |
|
634 |
clearerr(f); \ |
|
635 |
continue; \ |
|
636 |
} \ |
|
637 |
break; \ |
|
638 |
} else { \ |
|
639 |
(ret) = 0; \ |
|
640 |
} \ |
|
641 |
} \ |
|
642 |
__offs += (ret); \ |
|
643 |
} \ |
|
644 |
if (__offs > 0) \ |
|
645 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
646 |
} else { \ |
23743 | 647 |
int __offs = 0; \ |
648 |
while (__offs < (cnt)) { \ |
|
649 |
CLEAR_ERRNO; \ |
|
650 |
WRITE((ret),f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
651 |
if ((ret) <= 0) { \ |
|
652 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
653 |
continue; \ |
|
654 |
} \ |
|
655 |
break; \ |
|
656 |
} \ |
|
657 |
__offs += (ret); \ |
|
658 |
} \ |
|
659 |
if (__offs > 0) \ |
|
660 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
661 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
662 |
|
12548 | 663 |
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
664 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
665 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
666 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
667 |
char *buf = (char *)(obj); \ |
23743 | 668 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
669 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
670 |
if (isBuffered) { \ |
23743 | 671 |
while (__offs < (cnt)) { \ |
672 |
CLEAR_ERRNO; \ |
|
673 |
ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
|
674 |
if ((ret) <= 0) { \ |
|
675 |
if (ferror(f)) { \ |
|
676 |
if (__threadErrno == EINTR) { \ |
|
677 |
/* refetch */ \ |
|
678 |
buf = (char *)(obj); \ |
|
679 |
clearerr(f); \ |
|
680 |
continue; \ |
|
681 |
} \ |
|
682 |
break; \ |
|
683 |
} else { \ |
|
684 |
(ret) = 0; \ |
|
685 |
} \ |
|
686 |
} \ |
|
687 |
__offs += (ret); \ |
|
688 |
} \ |
|
689 |
if (__offs > 0) \ |
|
690 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
691 |
} else { \ |
23743 | 692 |
while (__offs < (cnt)) { \ |
693 |
char __buf[IO_BUFFER_SIZE]; \ |
|
694 |
int l; \ |
|
695 |
CLEAR_ERRNO; \ |
|
696 |
l = (cnt)-__offs; \ |
|
697 |
if ( l > IO_BUFFER_SIZE) \ |
|
698 |
l = IO_BUFFER_SIZE; \ |
|
699 |
/* refetch */ \ |
|
700 |
buf = (char *)(obj); \ |
|
701 |
memcpy(__buf,(buf)+__ooffs+__offs,l); \ |
|
702 |
WRITE(ret,f, __buf, l, handleType); \ |
|
703 |
if ((ret) <= 0) { \ |
|
704 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
705 |
continue; \ |
|
706 |
} \ |
|
707 |
break; \ |
|
708 |
} \ |
|
709 |
__offs += (ret); \ |
|
710 |
} \ |
|
711 |
if (__offs > 0) \ |
|
712 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
713 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
714 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
715 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
716 |
#else /* ! __win32__ */ |
16296 | 717 |
/* ======================== UNIX / LINUX ====================================================== */ |
16373
9b9827530bf4
Adapt previous change for linux
Stefan Vogel <sv@exept.de>
parents:
16368
diff
changeset
|
718 |
typedef int SOCKET; |
9b9827530bf4
Adapt previous change for linux
Stefan Vogel <sv@exept.de>
parents:
16368
diff
changeset
|
719 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
720 |
# define __READING__(f) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
721 |
if ((__INST(didWrite) != false) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
722 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
23743 | 723 |
__INST(didWrite) = false; \ |
724 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
725 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
726 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
727 |
# define __WRITING__(f) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
728 |
if ((__INST(didWrite) != true) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
729 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
23743 | 730 |
__INST(didWrite) = true; \ |
731 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
732 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
733 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
734 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
735 |
# ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
736 |
# define __UNGETC__(c, f, isBuffered) \ |
8913 | 737 |
__INST(readAhead) = __mkSmallInteger((c)); |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
738 |
# else /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
739 |
# define __UNGETC__(c, f, isBuffered) \ |
2264 | 740 |
if (isBuffered) { \ |
23743 | 741 |
ungetc((c), (f)); \ |
2264 | 742 |
} else { \ |
23743 | 743 |
__INST(readAhead) = __mkSmallInteger((c)); \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
744 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
745 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
746 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
747 |
# ifdef NO_STDIO |
12548 | 748 |
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
749 |
{ \ |
23743 | 750 |
OBJ rA = __INST(readAhead); \ |
751 |
if (rA != nil) { \ |
|
752 |
*(buf) = __intVal(rA); \ |
|
753 |
DEBUGBUFFER(buf); \ |
|
754 |
__INST(readAhead) = nil; \ |
|
755 |
(ret) = 1; \ |
|
756 |
} else { \ |
|
757 |
for (;;) { \ |
|
758 |
CLEAR_ERRNO; \ |
|
759 |
(ret) = READ(f, buf, 1, handleType); \ |
|
760 |
DEBUGBUFFER(buf); \ |
|
761 |
if ((ret) >= 0) break; \ |
|
762 |
if (errno != EINTR) { \ |
|
763 |
break; \ |
|
764 |
} \ |
|
765 |
__HANDLE_INTERRUPTS__; \ |
|
766 |
} \ |
|
767 |
} \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
768 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
769 |
# else /* use STDIO */ |
12548 | 770 |
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \ |
2264 | 771 |
if (isBuffered) { \ |
23743 | 772 |
for (;;) { \ |
773 |
CLEAR_ERRNO; \ |
|
774 |
(ret) = getc(f); \ |
|
775 |
if ((ret) >= 0) { \ |
|
776 |
DEBUGBUFFER(buf); \ |
|
777 |
*(buf) = (ret); \ |
|
778 |
(ret) = 1; \ |
|
779 |
} else if (ferror(f)) { \ |
|
780 |
if (errno == EINTR) { \ |
|
781 |
__HANDLE_INTERRUPTS__; \ |
|
782 |
clearerr(f); \ |
|
783 |
continue; \ |
|
784 |
} \ |
|
785 |
} else \ |
|
786 |
(ret) = 0; \ |
|
787 |
break; \ |
|
788 |
} \ |
|
2264 | 789 |
} else { \ |
23743 | 790 |
OBJ rA = __INST(readAhead); \ |
791 |
if (rA != nil) { \ |
|
792 |
*(buf) = __intVal(rA); \ |
|
793 |
DEBUGBUFFER(buf); \ |
|
794 |
__INST(readAhead) = nil; \ |
|
795 |
(ret) = 1; \ |
|
796 |
} else { \ |
|
797 |
for (;;) { \ |
|
798 |
CLEAR_ERRNO; \ |
|
799 |
(ret) = read(fileno(f), buf, 1); \ |
|
800 |
DEBUGBUFFER(buf); \ |
|
801 |
if ((ret) >= 0) break; \ |
|
802 |
if (errno != EINTR) { \ |
|
803 |
break; \ |
|
804 |
} \ |
|
805 |
__HANDLE_INTERRUPTS__; \ |
|
806 |
} \ |
|
807 |
} \ |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
808 |
} |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
809 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
810 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
811 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
812 |
* read_bytes into a c-buffer |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
813 |
* (which may NOT move) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
814 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
815 |
# ifdef NO_STDIO |
12548 | 816 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
817 |
{ \ |
23743 | 818 |
int __offs = 0, __cnt; \ |
819 |
\ |
|
820 |
while (__offs < (cnt)) { \ |
|
821 |
OBJ rA = __INST(readAhead); \ |
|
822 |
if (rA != nil) { \ |
|
823 |
(buf)[__offs] = __intVal(rA); \ |
|
824 |
DEBUGBUFFER(buf); \ |
|
825 |
__INST(readAhead) = nil; \ |
|
826 |
__offs++; \ |
|
827 |
} else { \ |
|
828 |
CLEAR_ERRNO; \ |
|
829 |
__cnt = READ(f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
830 |
DEBUGBUFFER(buf); \ |
|
831 |
if (__cnt <= 0) { \ |
|
832 |
if (__cnt < 0 && errno == EINTR) { \ |
|
833 |
__HANDLE_INTERRUPTS__; \ |
|
834 |
continue; \ |
|
835 |
} \ |
|
836 |
break; \ |
|
837 |
} \ |
|
838 |
__offs += __cnt; \ |
|
839 |
} \ |
|
840 |
} \ |
|
841 |
if (__offs > 0) \ |
|
842 |
(ret) = __offs; \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
843 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
844 |
# else /* use STDIO */ |
12548 | 845 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
846 |
(ret) = 0; \ |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
847 |
if (isBuffered) { \ |
23743 | 848 |
int __offs = 0; \ |
849 |
while (__offs < (cnt)) { \ |
|
850 |
CLEAR_ERRNO; \ |
|
851 |
(ret) = getc(f); \ |
|
852 |
if ((ret) < 0) { \ |
|
853 |
if (ferror(f)) { \ |
|
854 |
if (errno == EINTR) { \ |
|
855 |
__HANDLE_INTERRUPTS__; \ |
|
856 |
clearerr(f); \ |
|
857 |
continue; \ |
|
858 |
} \ |
|
859 |
} else { \ |
|
860 |
(ret) = 0; \ |
|
861 |
} \ |
|
862 |
break; \ |
|
863 |
} \ |
|
864 |
DEBUGBUFFER(buf); \ |
|
865 |
(buf)[__offs++] = (ret); \ |
|
866 |
} \ |
|
867 |
if (__offs > 0) \ |
|
868 |
(ret) = __offs; \ |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
869 |
} else { \ |
23743 | 870 |
int __offs = 0, __cnt; \ |
871 |
int fd = fileno(f); \ |
|
872 |
\ |
|
873 |
while (__offs < (cnt)) { \ |
|
874 |
OBJ rA = __INST(readAhead); \ |
|
875 |
if (rA != nil) { \ |
|
876 |
DEBUGBUFFER(buf); \ |
|
877 |
(buf)[__offs] = __intVal(rA); \ |
|
878 |
__INST(readAhead) = nil; \ |
|
879 |
__offs++; \ |
|
880 |
} else { \ |
|
881 |
CLEAR_ERRNO; \ |
|
882 |
__cnt = read(fd, (buf)+__offs, (cnt)-__offs); \ |
|
883 |
DEBUGBUFFER(buf); \ |
|
884 |
if (__cnt <= 0) { \ |
|
885 |
if (__cnt < 0 && errno == EINTR) { \ |
|
886 |
__HANDLE_INTERRUPTS__; \ |
|
887 |
continue; \ |
|
888 |
} \ |
|
889 |
break; \ |
|
890 |
} \ |
|
891 |
__offs += __cnt; \ |
|
892 |
} \ |
|
893 |
} \ |
|
894 |
if (__offs > 0) \ |
|
895 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
896 |
} |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
897 |
|
6563
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
898 |
|
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
899 |
/* |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
900 |
* FNDELAY and O_NDELAY is deprecated, O_NONBLOCK is used in POSIX, XPG, etc... |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
901 |
*/ |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
902 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
903 |
# if defined(F_GETFL) && defined(F_SETFL) && (defined(O_NONBLOCK) || defined(O_NDELAY) || defined(FNDELAY)) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
904 |
# define SETFLAGS(fd, flags) \ |
23743 | 905 |
fcntl(fd, F_SETFL, flags) |
6563
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
906 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
907 |
# if defined(O_NONBLOCK) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
908 |
# define __STX_NONBLOCK_FLAG O_NONBLOCK |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
909 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
910 |
# if defined(O_NDELAY) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
911 |
# define __STX_NONBLOCK_FLAG O_NDELAY |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
912 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
913 |
# define __STX_NONBLOCK_FLAG FNDELAY |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
914 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
915 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
916 |
|
15342 | 917 |
# define SETNONBLOCKING(fd, oldFlags) \ |
23743 | 918 |
{ \ |
919 |
int flags = fcntl(fd, F_GETFL, 0); \ |
|
920 |
if (flags >= 0) { \ |
|
921 |
fcntl(fd, F_SETFL, flags | __STX_NONBLOCK_FLAG); \ |
|
922 |
} \ |
|
923 |
oldFlags = flags; \ |
|
924 |
} |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
925 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
926 |
# define SETFLAGS(fd, flags) /* nothing */ |
15342 | 927 |
# define SETNONBLOCKING(fd, oldFlags) /* nothing */ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
928 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
929 |
|
12548 | 930 |
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
931 |
{ \ |
15342 | 932 |
int __offs = 0, __cnt; \ |
3681 | 933 |
int oldFlags; \ |
23743 | 934 |
\ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
935 |
(ret) = 0; \ |
15342 | 936 |
SETNONBLOCKING(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
937 |
if (isBuffered) { \ |
23743 | 938 |
while (__offs < (cnt)) { \ |
939 |
CLEAR_ERRNO; \ |
|
940 |
(ret) = getc(f); \ |
|
941 |
if ((ret) < 0) { \ |
|
942 |
if (ferror(f)) { \ |
|
943 |
if (errno == EINTR) { \ |
|
944 |
(ret) = 0; \ |
|
945 |
clearerr(f); \ |
|
946 |
break; \ |
|
947 |
} \ |
|
948 |
} else { \ |
|
949 |
(ret) = 0; \ |
|
950 |
} \ |
|
951 |
break; \ |
|
952 |
} \ |
|
953 |
(buf)[__offs++] = (ret); \ |
|
954 |
DEBUGBUFFER(buf); \ |
|
955 |
} \ |
|
956 |
if (__offs > 0) \ |
|
957 |
(ret) = __offs; \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
958 |
} else { \ |
23743 | 959 |
int fd = fileno(f); \ |
960 |
\ |
|
961 |
while (__offs < (cnt)) { \ |
|
962 |
OBJ rA = __INST(readAhead); \ |
|
963 |
if (rA != nil) { \ |
|
964 |
(buf)[__offs] = __intVal(rA); \ |
|
965 |
DEBUGBUFFER(buf); \ |
|
966 |
__INST(readAhead) = nil; \ |
|
967 |
__offs++; \ |
|
968 |
continue; \ |
|
969 |
} \ |
|
970 |
CLEAR_ERRNO; \ |
|
971 |
__cnt = read(fd, (buf)+__offs, (cnt)-__offs); \ |
|
972 |
DEBUGBUFFER(buf); \ |
|
973 |
if (__cnt > 0) { \ |
|
974 |
__offs += __cnt; \ |
|
975 |
} \ |
|
976 |
break; \ |
|
977 |
} \ |
|
978 |
if (__offs > 0) \ |
|
979 |
(ret) = __offs; \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
980 |
} \ |
3681 | 981 |
SETFLAGS(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
982 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
983 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
984 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
985 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
986 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
987 |
* read_bytes into an object |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
988 |
* (which may be moved by GC) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
989 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
990 |
# ifdef NO_STDIO |
12548 | 991 |
# define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
992 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
993 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
994 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
995 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
996 |
char *buf = (char *)(obj); \ |
23743 | 997 |
\ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
998 |
(ret) = 0; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
999 |
{ \ |
23743 | 1000 |
while (__offs < (cnt)) { \ |
1001 |
OBJ rA = __INST(readAhead); \ |
|
1002 |
if (rA != nil) { \ |
|
1003 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1004 |
DEBUGBUFFER(buf); \ |
|
1005 |
__INST(readAhead) = nil; \ |
|
1006 |
__offs++; \ |
|
1007 |
} else { \ |
|
1008 |
CLEAR_ERRNO; \ |
|
1009 |
__cnt = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \ |
|
1010 |
DEBUGBUFFER(buf); \ |
|
1011 |
if (__cnt <= 0) { \ |
|
1012 |
if (__cnt < 0 && errno == EINTR) { \ |
|
1013 |
__HANDLE_INTERRUPTS__; \ |
|
1014 |
/* refetch */ \ |
|
1015 |
buf = (char *)(obj); \ |
|
1016 |
continue; \ |
|
1017 |
} \ |
|
1018 |
break; \ |
|
1019 |
} \ |
|
1020 |
__offs += __cnt; \ |
|
1021 |
} \ |
|
1022 |
} \ |
|
1023 |
if (__offs > 0) \ |
|
1024 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1025 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1026 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
1027 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1028 |
# else /* use STDIO */ |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
1029 |
|
12548 | 1030 |
# define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1031 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1032 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1033 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1034 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1035 |
char *buf = (char *)(obj); \ |
23743 | 1036 |
\ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1037 |
(ret) = 0; \ |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1038 |
if (isBuffered) { \ |
23743 | 1039 |
while (__offs < (cnt)) { \ |
1040 |
CLEAR_ERRNO; \ |
|
1041 |
(ret) = getc(f); \ |
|
1042 |
if ((ret) < 0) { \ |
|
1043 |
if (ferror(f)) { \ |
|
1044 |
if (errno == EINTR) { \ |
|
1045 |
__HANDLE_INTERRUPTS__; \ |
|
1046 |
clearerr(f); \ |
|
1047 |
/* refetch */ \ |
|
1048 |
buf = (char *)(obj); \ |
|
1049 |
DEBUGBUFFER(buf); \ |
|
1050 |
continue; \ |
|
1051 |
} \ |
|
1052 |
} else { \ |
|
1053 |
(ret) = 0; \ |
|
1054 |
} \ |
|
1055 |
break; \ |
|
1056 |
} \ |
|
1057 |
(buf)[__ooffs+__offs] = (ret); \ |
|
1058 |
DEBUGBUFFER(buf); \ |
|
1059 |
__offs++; \ |
|
1060 |
} \ |
|
1061 |
if (__offs > 0) \ |
|
1062 |
(ret) = __offs; \ |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1063 |
} else { \ |
23743 | 1064 |
int fd = fileno(f); \ |
1065 |
\ |
|
1066 |
while (__offs < (cnt)) { \ |
|
1067 |
OBJ rA = __INST(readAhead); \ |
|
1068 |
if (rA != nil) { \ |
|
1069 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1070 |
DEBUGBUFFER(buf); \ |
|
1071 |
__INST(readAhead) = nil; \ |
|
1072 |
__offs++; \ |
|
1073 |
} else { \ |
|
1074 |
CLEAR_ERRNO; \ |
|
1075 |
__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1076 |
DEBUGBUFFER(buf); \ |
|
1077 |
if (__cnt <= 0) { \ |
|
1078 |
if (__cnt < 0 && errno == EINTR) { \ |
|
1079 |
__HANDLE_INTERRUPTS__; \ |
|
1080 |
/* refetch */ \ |
|
1081 |
buf = (char *)(obj); \ |
|
1082 |
continue; \ |
|
1083 |
} \ |
|
1084 |
break; \ |
|
1085 |
} \ |
|
1086 |
__offs += __cnt; \ |
|
1087 |
} \ |
|
1088 |
} \ |
|
1089 |
if (__offs > 0) \ |
|
1090 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1091 |
} \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1092 |
} |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1093 |
|
12548 | 1094 |
# define __READAVAILBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1095 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1096 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1097 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1098 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1099 |
char *buf = (char *)(obj); \ |
15342 | 1100 |
int oldFlags; \ |
23743 | 1101 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1102 |
(ret) = 0; \ |
15342 | 1103 |
SETNONBLOCKING(fileno(f), oldFlags); \ |
23743 | 1104 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1105 |
if (isBuffered) { \ |
23743 | 1106 |
while (__offs < (cnt)) { \ |
1107 |
CLEAR_ERRNO; \ |
|
1108 |
(ret) = getc(f); \ |
|
1109 |
if ((ret) < 0) { \ |
|
1110 |
if (ferror(f)) { \ |
|
1111 |
if (errno == EINTR) { \ |
|
1112 |
clearerr(f); \ |
|
1113 |
/* refetch */ \ |
|
1114 |
buf = (char *)(obj); \ |
|
1115 |
(ret) = 0; \ |
|
1116 |
break; \ |
|
1117 |
} \ |
|
1118 |
} else { \ |
|
1119 |
(ret) = 0; \ |
|
1120 |
} \ |
|
1121 |
break; \ |
|
1122 |
} \ |
|
1123 |
(buf)[__ooffs+__offs] = (ret); \ |
|
1124 |
DEBUGBUFFER(buf); \ |
|
1125 |
__offs++; \ |
|
1126 |
} \ |
|
1127 |
if (__offs > 0) \ |
|
1128 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1129 |
} else { \ |
23743 | 1130 |
int fd = fileno(f); \ |
1131 |
\ |
|
1132 |
while (__offs < (cnt)) { \ |
|
1133 |
OBJ rA = __INST(readAhead); \ |
|
1134 |
if (rA != nil) { \ |
|
1135 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1136 |
DEBUGBUFFER(buf); \ |
|
1137 |
__INST(readAhead) = nil; \ |
|
1138 |
__offs++; \ |
|
1139 |
continue; \ |
|
1140 |
} \ |
|
1141 |
CLEAR_ERRNO; \ |
|
1142 |
__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1143 |
DEBUGBUFFER(buf); \ |
|
1144 |
if (__cnt > 0) { \ |
|
1145 |
__offs += __cnt; \ |
|
1146 |
} \ |
|
1147 |
break; \ |
|
1148 |
} \ |
|
1149 |
if (__offs > 0) \ |
|
1150 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1151 |
} \ |
15342 | 1152 |
SETFLAGS(fileno(f), oldFlags); \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1153 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1154 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1155 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1156 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1157 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1158 |
# ifdef NO_STDIO |
12548 | 1159 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
23743 | 1160 |
for (;;) { \ |
1161 |
CLEAR_ERRNO; \ |
|
1162 |
(ret) = WRITE(f, buf, 1, handleType); \ |
|
1163 |
if ((ret) >= 0) break; \ |
|
1164 |
if (errno != EINTR) { \ |
|
1165 |
break; \ |
|
1166 |
} \ |
|
1167 |
__HANDLE_INTERRUPTS__; \ |
|
1168 |
} |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1169 |
# else /* use STDIO */ |
12548 | 1170 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1171 |
if (isBuffered) { \ |
23743 | 1172 |
for (;;) { \ |
1173 |
CLEAR_ERRNO; \ |
|
1174 |
ret = putc(*(buf), f); \ |
|
1175 |
if ((ret) >= 0) { \ |
|
1176 |
(ret) = 1; \ |
|
1177 |
} else if (ferror(f)) { \ |
|
1178 |
/* SOLARIS/SPARC (2.6) generates spurious errors with errno = 0 */ \ |
|
1179 |
if (errno == EINTR || errno == 0) { \ |
|
1180 |
__HANDLE_INTERRUPTS__; \ |
|
1181 |
clearerr(f); \ |
|
1182 |
continue; \ |
|
1183 |
} \ |
|
1184 |
} else \ |
|
1185 |
(ret) = 0; \ |
|
1186 |
break; \ |
|
1187 |
} \ |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1188 |
} else { \ |
23743 | 1189 |
for (;;) { \ |
1190 |
CLEAR_ERRNO; \ |
|
1191 |
(ret) = write(fileno(f), buf, 1); \ |
|
1192 |
if ((ret) >= 0) break; \ |
|
1193 |
if (errno != EINTR) { \ |
|
1194 |
break; \ |
|
1195 |
} \ |
|
1196 |
__HANDLE_INTERRUPTS__; \ |
|
1197 |
} \ |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1198 |
} |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1199 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1200 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1201 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1202 |
* write_bytes from a c-buffer |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1203 |
* (which may NOT move) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1204 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1205 |
# ifdef NO_STDIO |
12548 | 1206 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2961 | 1207 |
(ret) = 0; \ |
1208 |
{ \ |
|
23743 | 1209 |
int __offs = 0; \ |
1210 |
while (__offs < (cnt)) { \ |
|
1211 |
CLEAR_ERRNO; \ |
|
1212 |
ret = WRITE(f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
1213 |
if (ret <= 0) { \ |
|
1214 |
if (ret < 0 && errno == EINTR) { \ |
|
1215 |
__HANDLE_INTERRUPTS__; \ |
|
1216 |
continue; \ |
|
1217 |
} \ |
|
1218 |
break; \ |
|
1219 |
} \ |
|
1220 |
__offs += (ret); \ |
|
1221 |
} \ |
|
1222 |
if (__offs > 0) \ |
|
1223 |
(ret) = __offs; \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1224 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1225 |
# else /* use STDIO */ |
12548 | 1226 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2961 | 1227 |
(ret) = 0; \ |
1228 |
if (isBuffered) { \ |
|
23743 | 1229 |
int __offs = 0; \ |
1230 |
while (__offs < (cnt)) { \ |
|
1231 |
CLEAR_ERRNO; \ |
|
1232 |
(ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
|
1233 |
if ((ret) <= 0) { \ |
|
1234 |
if (ferror(f)) { \ |
|
1235 |
if (errno == EINTR) { \ |
|
1236 |
__HANDLE_INTERRUPTS__; \ |
|
1237 |
clearerr(f); \ |
|
1238 |
continue; \ |
|
1239 |
} \ |
|
1240 |
} else { \ |
|
1241 |
(ret) = 0; \ |
|
1242 |
} \ |
|
1243 |
break; \ |
|
1244 |
} \ |
|
1245 |
__offs += (ret); \ |
|
1246 |
} \ |
|
1247 |
if (__offs > 0) \ |
|
1248 |
(ret) = __offs; \ |
|
2961 | 1249 |
} else { \ |
23743 | 1250 |
int __offs = 0; \ |
1251 |
while (__offs < (cnt)) { \ |
|
1252 |
CLEAR_ERRNO; \ |
|
1253 |
(ret) = write(fileno(f), (buf)+__offs, (cnt)-__offs);\ |
|
1254 |
if ((ret) <= 0) { \ |
|
1255 |
if ((ret) < 0) { \ |
|
1256 |
if (errno == EINTR) { \ |
|
1257 |
__HANDLE_INTERRUPTS__; \ |
|
1258 |
continue; \ |
|
1259 |
} \ |
|
1260 |
} \ |
|
1261 |
break; \ |
|
1262 |
} \ |
|
1263 |
__offs += (ret); \ |
|
1264 |
} \ |
|
1265 |
if (__offs > 0) \ |
|
1266 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1267 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1268 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1269 |
|
223 | 1270 |
/* |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1271 |
* write_bytes from an object |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1272 |
* (which may be moved around by GC) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1273 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1274 |
# ifdef NO_STDIO |
12548 | 1275 |
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1276 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1277 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1278 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1279 |
char *buf = (char *)(obj); \ |
23743 | 1280 |
\ |
2961 | 1281 |
(ret) = 0; \ |
1282 |
{ \ |
|
23743 | 1283 |
while (__offs < (cnt)) { \ |
1284 |
CLEAR_ERRNO; \ |
|
1285 |
ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \ |
|
1286 |
if (ret <= 0) { \ |
|
1287 |
if (ret < 0 && errno == EINTR) { \ |
|
1288 |
__HANDLE_INTERRUPTS__; \ |
|
1289 |
/* refetch */ \ |
|
1290 |
buf = (char *)(obj); \ |
|
1291 |
continue; \ |
|
1292 |
} \ |
|
1293 |
break; \ |
|
1294 |
} \ |
|
1295 |
__offs += (ret); \ |
|
1296 |
} \ |
|
1297 |
if (__offs > 0) \ |
|
1298 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1299 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1300 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1301 |
# else /* use STDIO */ |
12548 | 1302 |
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1303 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1304 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1305 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1306 |
char *buf = (char *)(obj); \ |
23743 | 1307 |
\ |
2961 | 1308 |
(ret) = 0; \ |
1309 |
if (isBuffered) { \ |
|
23743 | 1310 |
while (__offs < (cnt)) { \ |
1311 |
CLEAR_ERRNO; \ |
|
1312 |
(ret) = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
|
1313 |
if ((ret) <= 0) { \ |
|
1314 |
if (ferror(f)) { \ |
|
1315 |
if (errno == EINTR) { \ |
|
1316 |
__HANDLE_INTERRUPTS__; \ |
|
1317 |
/* refetch */ \ |
|
1318 |
buf = (char *)(obj); \ |
|
1319 |
clearerr(f); \ |
|
1320 |
continue; \ |
|
1321 |
} \ |
|
1322 |
break; \ |
|
1323 |
} else { \ |
|
1324 |
(ret) = 0; \ |
|
1325 |
} \ |
|
1326 |
} \ |
|
1327 |
__offs += (ret); \ |
|
1328 |
} \ |
|
2961 | 1329 |
} else { \ |
23743 | 1330 |
while (__offs < (cnt)) { \ |
1331 |
CLEAR_ERRNO; \ |
|
1332 |
(ret) = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1333 |
if ((ret) <= 0) { \ |
|
1334 |
if ((ret) < 0) { \ |
|
1335 |
if (errno == EINTR){ \ |
|
1336 |
__HANDLE_INTERRUPTS__; \ |
|
1337 |
/* refetch */ \ |
|
1338 |
buf = (char *)(obj); \ |
|
1339 |
continue; \ |
|
1340 |
} \ |
|
1341 |
} \ |
|
1342 |
break; \ |
|
1343 |
} \ |
|
1344 |
__offs += (ret); \ |
|
1345 |
} \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1346 |
} \ |
15845 | 1347 |
if (__offs > 0) \ |
23743 | 1348 |
(ret) = __offs; \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1349 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1350 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1351 |
#endif /* unix */ |
1 | 1352 |
%} |
188 | 1353 |
! ! |
1 | 1354 |
|
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1355 |
!ExternalStream class methodsFor:'documentation'! |
22 | 1356 |
|
88 | 1357 |
copyright |
1358 |
" |
|
1359 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1360 |
All Rights Reserved |
88 | 1361 |
|
1362 |
This software is furnished under a license and may be used |
|
1363 |
only in accordance with the terms of that license and with the |
|
1364 |
inclusion of the above copyright notice. This software may not |
|
1365 |
be provided or otherwise made available to, or used by, any |
|
1366 |
other person. No title to or ownership of the software is |
|
1367 |
hereby transferred. |
|
1368 |
" |
|
1369 |
! |
|
1370 |
||
22 | 1371 |
documentation |
1372 |
" |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1373 |
ExternalStream defines protocol common to Streams which have a file-descriptor and |
68 | 1374 |
represent some file or communicationChannel of the underlying OperatingSystem. |
1375 |
ExternalStream is abstract; concrete classes are FileStream, PipeStream etc. |
|
77 | 1376 |
|
159 | 1377 |
ExternalStreams can be in two modes: text- (the default) and binary-mode. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1378 |
In text-mode, the elements read/written are characters; |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1379 |
while in binary-mode the basic elements are bytes which read/write as SmallIntegers |
68 | 1380 |
in the range 0..255. |
22 | 1381 |
|
68 | 1382 |
Also, the stream can be either in buffered or unbuffered mode. In buffered mode, |
1383 |
data is not written until either a cr is written (in text mode) or a synchronizeOutput |
|
1384 |
is sent (in both modes). |
|
22 | 1385 |
|
77 | 1386 |
The underlying OperatingSystem streams may either be closed explicitely (sending a close) |
68 | 1387 |
or just forgotten - in this case, the garbage collector will eventually collect the |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1388 |
object AND a close will be performed automatically (but you will NOT know when this |
77 | 1389 |
happens - so it is recommended, that you close your files when no longer needed). |
159 | 1390 |
Closing is also suggested, since if smalltalk is finished (be it by purpose, or due to |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1391 |
some crash) the data will not be in the file, if unclosed. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1392 |
All streams understand the close message, so it never hurts to use it (it is defined as |
77 | 1393 |
a noop in one of the superclasses). |
22 | 1394 |
|
68 | 1395 |
Most of the methods found here redefine inherited methods for better performance, |
1396 |
since I/O from/to files should be fast. |
|
22 | 1397 |
|
68 | 1398 |
Recovering a snapshot: |
1295 | 1399 |
not all streams can be restored to the state they had before - see the implementation of |
1400 |
reOpen in subclasses for more information. |
|
1401 |
For streams sitting on some communication channel (i.e. Pipes and Sockets) you should |
|
1402 |
reestablish the stream upon image restart (make someone dependent on ObjectMemory). |
|
1403 |
FileStreams are reopened and positioned to their offset they had at snapshot time. |
|
1404 |
This may fail, if the file was removed or renamed - or lead to confusion |
|
1405 |
if the contents changed in the meantime. |
|
1406 |
Therefore, it is a good idea to reopen files and check for these things at restart time. |
|
1407 |
||
1408 |
[Instance variables:] |
|
1409 |
||
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1410 |
handleType <Symbol> desribes what handle is: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1411 |
win32: #fileHandle, #socketHandle, |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1412 |
#filePointer, #socketFilePointer, #pipeFilePointer |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1413 |
unix: #filePointer, #socketFilePointer, #pipeFilePointer |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1414 |
needed for win32, which uses different APIs for the different handles (sigh) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1415 |
handle <Integer> used to be always a filePointer somehow mapped to an integer (FILE* - not the fd); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1416 |
now, either a filePointer or a handle (win32) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1417 |
mode <Symbol> #readwrite, #readonly or #writeonly |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1418 |
buffered <Boolean> true, if buffered (i.e. collects characters - does |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1419 |
not output immediately) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1420 |
binary <Boolean> true if in binary mode (reads bytes instead of chars) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1421 |
eolMode <Symbol> one of nil, #nl, #cr or #crlf. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1422 |
determines how lines should be terminated. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1423 |
nil -> newLine (as in Unix); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1424 |
#crlf -> with cr-lf (as in MSDOS) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1425 |
#cr -> with cr (as in VMS) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1426 |
hitEOF <Boolean> true, if EOF was reached |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1427 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1428 |
lastErrorNumber <Integer> the value of errno (only valid right after the error - |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1429 |
updated with next i/o operation) |
1295 | 1430 |
|
1431 |
[Class variables:] |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1432 |
Lobby <Registry> keeps track of used ext-streams (to free up FILE*'s) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1433 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1434 |
StreamErrorSignal <Signal> parent of all stream errors (see Stream class) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1435 |
InvalidReadSignal <Signal> raised on read from writeonly stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1436 |
InvalidWriteSignal <Signal> raised on write to readonly stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1437 |
InvalidModeSignal <Signal> raised on text I/O with binary-stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1438 |
or binary I/O with text-stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1439 |
OpenErrorSignal <Signal> raised if open fails |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1440 |
StreamNotOpenSignal <Signal> raised on I/O with non-open stream |
159 | 1441 |
|
1442 |
Additional notes: |
|
1443 |
This class is implemented using the underlying stdio-c library package, which |
|
1444 |
has both advantages and disadvantages: since it is portable (posix defined), porting |
|
1445 |
ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library |
|
1446 |
has big problems handling unbounded Streams, since the EOF handling in stdio is |
|
1447 |
not prepared for data to arrive after EOF has been reached - time will show, if we need |
|
1448 |
a complete rewrite for UnboundedStream ... |
|
325 | 1449 |
|
188 | 1450 |
Also, depending on the system, the stdio library behaves infriendly when signals |
1451 |
occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal |
|
1452 |
is handled transparently - on SYS5.3 (i.e. non unixes :-) the read operation returns |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1453 |
an error and errno is set to EINTR. |
20411 | 1454 |
That's what the ugly code around all getc-calls is for ... |
1295 | 1455 |
Since things get more and more ugly - we will rewrite ExternalStream |
1456 |
completely, to NOT use any stdio stuff (and do its buffering itself). |
|
325 | 1457 |
|
1458 |
Notice that typical stdio's use a single errno global variable to return an error code, |
|
16508 | 1459 |
this was bad design in the stdio lib (right from the very beginning), since it's much |
325 | 1460 |
harder to deal with this in the presence of lightweight processes, where errno gets |
1461 |
overwritten by an I/O operation done in another thread. (stdio should have been written |
|
1462 |
to return errno as a negative number ...). |
|
1463 |
To deal with this, the scheduler treats errno like a per-thread private variable, |
|
1464 |
and saves/restores the errno setting when switching to another thread. |
|
1465 |
(Notice that some thread packages do this also, but ST/X's thread implementation |
|
1466 |
does not depend on those, but instead uses a portable private package). |
|
1467 |
||
216 | 1468 |
Finally, if an stdio-stream is open for both reading and writing, we have to call |
1469 |
fseek whenever we are about to read after write and vice versa. |
|
1470 |
Two macros (__READING__ and __WRITING__) have been defined to be used before every |
|
1471 |
fread/fgetc and fwrite/putc respectively. |
|
1295 | 1472 |
|
1473 |
[author:] |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1474 |
Claus Gittinger |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1475 |
Stefan Vogel (many, many fixes ...) |
1295 | 1476 |
|
1477 |
[see also:] |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1478 |
FileStream Socket PipeStream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1479 |
Filename OperatingSystem |
22 | 1480 |
" |
3255 | 1481 |
! |
1482 |
||
1483 |
examples |
|
1484 |
" |
|
1485 |
open a file, read the contents and display it in a textView: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1486 |
[exBegin] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1487 |
|topView scrollPane textView fileStream text| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1488 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1489 |
topView := StandardSystemView new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1490 |
topView label:'contents of Makefile'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1491 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1492 |
scrollPane := HVScrollableView in:topView. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1493 |
scrollPane origin:0.0@0.0 corner:1.0@1.0. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1494 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1495 |
textView := EditTextView new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1496 |
scrollPane scrolledView:textView. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1497 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1498 |
fileStream := 'Makefile' asFilename readStream. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1499 |
text := fileStream upToEnd. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1500 |
fileStream close. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1501 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1502 |
textView contents:text. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1503 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1504 |
topView open. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1505 |
[exEnd] |
3255 | 1506 |
|
1507 |
||
1508 |
Notice, all of the above can also be done (simply) as: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1509 |
[exBegin] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1510 |
EditTextView openOn:'Makefile' |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1511 |
[exEnd] |
3255 | 1512 |
" |
22 | 1513 |
! ! |
1514 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1515 |
!ExternalStream class methodsFor:'initialization'! |
1 | 1516 |
|
18636 | 1517 |
closeFiles |
1518 |
"close all files. |
|
1519 |
To be called on exit of Smalltalk." |
|
1520 |
||
1521 |
Lobby do:[:eachFileStream | |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1522 |
(eachFileStream ~~ Stdin |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1523 |
and:[eachFileStream ~~ Stdout |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1524 |
and:[eachFileStream ~~ Stderr]]) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1525 |
eachFileStream close |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1526 |
]. |
18636 | 1527 |
]. |
22709 | 1528 |
|
1529 |
"Modified: / 25-04-2018 / 15:23:41 / stefan" |
|
18636 | 1530 |
! |
1531 |
||
2920 | 1532 |
initDefaultEOLMode |
1533 |
OperatingSystem isUNIXlike ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1534 |
"/ unix EOL conventions |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1535 |
DefaultEOLMode := #nl |
2920 | 1536 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1537 |
OperatingSystem isVMSlike ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1538 |
"/ vms EOL conventions |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1539 |
DefaultEOLMode := #cr |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1540 |
] ifFalse:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1541 |
"/ msdos EOL conventions |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1542 |
"/ msdos uses #crlf. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1543 |
"/ the following breaks all programs, which do not explicitly |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1544 |
"/ change th eolMode when writing/reading binary files (zip reader) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1545 |
"/ MUST change all classes before doing the following. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1546 |
"/ Anyway: for backward compatibility (swisscom), it is left in this |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1547 |
"/ mode (for a while, I hope). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1548 |
DefaultEOLMode := #crlf. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1549 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1550 |
"/ DefaultEOLMode := #nl |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1551 |
] |
2920 | 1552 |
] |
1553 |
! |
|
1554 |
||
1555 |
initModeStrings |
|
1556 |
"initialize modeStrings which are passed down to the underlying |
|
1557 |
fopen/fdopen functions." |
|
1558 |
||
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1559 |
OperatingSystem isMSDOSlike ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1560 |
ReadMode := 'rb'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1561 |
ReadWriteMode := 'rb+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1562 |
WriteMode := 'wb'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1563 |
AppendMode := 'ab+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1564 |
CreateReadWriteMode := 'wb+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1565 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1566 |
ReadMode := 'r'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1567 |
ReadWriteMode := 'r+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1568 |
WriteMode := 'w'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1569 |
AppendMode := 'a+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1570 |
CreateReadWriteMode := 'w+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1571 |
] |
2920 | 1572 |
! |
1573 |
||
1 | 1574 |
initialize |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
1575 |
OpenErrorSignal isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1576 |
OpenErrorSignal := OpenError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1577 |
OpenErrorSignal notifierString:'open error'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1578 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1579 |
InvalidReadSignal := InvalidReadError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1580 |
InvalidReadSignal notifierString:'stream does not support reading'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1581 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1582 |
InvalidWriteSignal := InvalidWriteError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1583 |
InvalidWriteSignal notifierString:'stream does not support writing'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1584 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1585 |
InvalidModeSignal := InvalidModeError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1586 |
InvalidModeSignal notifierString:'binary/text mode mismatch'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1587 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1588 |
InvalidOperationSignal := InvalidOperationError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1589 |
InvalidOperationSignal notifierString:'unsupported file operation'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1590 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1591 |
StreamNotOpenSignal := StreamNotOpenError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1592 |
StreamNotOpenSignal notifierString:'stream is not open'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1593 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1594 |
StreamIOErrorSignal := StreamIOError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1595 |
StreamIOErrorSignal notifierString:'I/O error'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1596 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1597 |
"/ self patchByteOrderOptimizedMethods |
159 | 1598 |
]. |
1599 |
||
31 | 1600 |
Lobby isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1601 |
Lobby := Registry new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1602 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1603 |
"want to get informed when returning from snapshot" |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1604 |
ObjectMemory addDependent:self |
2920 | 1605 |
]. |
5442 | 1606 |
DefaultEOLMode isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1607 |
self initDefaultEOLMode. |
5442 | 1608 |
]. |
1609 |
ReadMode isNil ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1610 |
self initModeStrings. |
5442 | 1611 |
]. |
18790 | 1612 |
|
1613 |
"limit the amount of newspace to be used for non-tenurable executors to 5%" |
|
18929 | 1614 |
"/ MaxNonTenurableExecutors := ObjectMemory newSpaceSize // (Socket sizeOfInst:0) // 20. |
1615 |
"/ cg: changed because Socket is not in libbasic. Thus, standalone (libbasic only) |
|
1616 |
"/ programs would fail to start. |
|
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
1617 |
MaxNonTenurableExecutors := (ObjectMemory newSpaceSize // 20 min:2000). |
18790 | 1618 |
|
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1619 |
"Modified: / 21.5.1998 / 16:33:53 / cg" |
1 | 1620 |
! |
1621 |
||
19615 | 1622 |
patchByteOrderOptimizedMethods |
1623 |
"EXPERIMENTAL (not yet done by default): |
|
1624 |
change the underlying implementation of |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1625 |
nextPutInt16MSB / nextPutInt16LSB |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1626 |
nextPutInt32MSB / nextPutInt32LSB |
19615 | 1627 |
to the corresponding NATIVE methods." |
1628 |
||
1629 |
|native16 native32| |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
1630 |
|
19615 | 1631 |
native16 := self compiledMethodAt:#nextPutInt16NATIVE:. |
1632 |
native32 := self compiledMethodAt:#nextPutInt32NATIVE:. |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
1633 |
|
19615 | 1634 |
UninterpretedBytes isBigEndian ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1635 |
(self compiledMethodAt:#nextPutInt16MSB:) code:(native16 code). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1636 |
(self compiledMethodAt:#nextPutInt32MSB:) code:(native32 code). |
19615 | 1637 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1638 |
(self compiledMethodAt:#nextPutInt16LSB:) code:(native16 code). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1639 |
(self compiledMethodAt:#nextPutInt32LSB:) code:(native32 code). |
19615 | 1640 |
]. |
1641 |
! |
|
1642 |
||
1 | 1643 |
reOpenFiles |
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1644 |
"reopen all files (if possible) after a snapShot load. |
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1645 |
This is invoked via the #earlyRestart change notification." |
1 | 1646 |
|
18636 | 1647 |
Lobby do:[:eachFileStream | |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1648 |
eachFileStream reOpen |
2920 | 1649 |
]. |
1 | 1650 |
! |
1651 |
||
1469 | 1652 |
update:something with:aParameter from:changedObject |
1 | 1653 |
"have to reopen files when returning from snapshot" |
1654 |
||
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1655 |
something == #earlyRestart ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1656 |
self reOpenFiles. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1657 |
self initDefaultEOLMode |
1 | 1658 |
] |
1469 | 1659 |
|
1660 |
"Created: 15.6.1996 / 15:19:59 / cg" |
|
1 | 1661 |
! ! |
1662 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1663 |
!ExternalStream class methodsFor:'instance creation'! |
612 | 1664 |
|
12706 | 1665 |
forFileDescriptor:aFileDescriptor mode:modeSymbol |
2920 | 1666 |
"given a fileDescriptor, create an ExternalStream object |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1667 |
to operate on this fd. |
12706 | 1668 |
The modeSymbol-argument is #readonly, #readwrite, .... |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1669 |
This may be used to wrap fd's as returned by user |
2920 | 1670 |
primitive code, or to wrap pipe-fds into externalStreams." |
1671 |
||
12706 | 1672 |
^ self forFileDescriptor:aFileDescriptor mode:modeSymbol buffered:true handleType:nil |
7002 | 1673 |
|
1674 |
" |
|
1675 |
the example below will probably fail (15 is a random FD): |
|
1676 |
||
1677 |
|s| |
|
1678 |
||
1679 |
s := ExternalStream forFileDescriptor:15 mode:'r'. |
|
1680 |
s next. |
|
1681 |
" |
|
1682 |
||
1683 |
"Created: 29.2.1996 / 18:05:00 / cg" |
|
1684 |
"Modified: 29.2.1996 / 18:17:07 / cg" |
|
1685 |
! |
|
1686 |
||
12706 | 1687 |
forFileDescriptor:aFileDescriptor mode:modeSymbol buffered:buffered handleType:handleTypeSymbol |
7002 | 1688 |
"given a fileDescriptor, create an ExternalStream object |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1689 |
to operate on this fd. |
12706 | 1690 |
The modeSymbol-argument is #readonly, #readwrite, .... |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1691 |
This may be used to wrap fd's as returned by user |
7002 | 1692 |
primitive code, or to wrap pipe-fds into externalStreams." |
1693 |
||
21224 | 1694 |
^ self new |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1695 |
buffered:buffered; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1696 |
connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol. |
2920 | 1697 |
|
1698 |
" |
|
1699 |
the example below will probably fail (15 is a random FD): |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1700 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1701 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1702 |
|
21224 | 1703 |
s := ExternalStream forFileDescriptor:15 mode:#readonly buffered:false handleType:#filePointer. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1704 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1705 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1706 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1707 |
"Created: 29.2.1996 / 18:05:00 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1708 |
"Modified: 29.2.1996 / 18:17:07 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1709 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1710 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1711 |
forReadWriteToFileDescriptor:aFileDescriptor |
2920 | 1712 |
"given a fileDescriptor, create an ExternalStream object |
1713 |
to read/write from/to this fd. This may be used to wrap fd's |
|
1714 |
as returned by user primitive code, or to wrap pipe- |
|
1715 |
filedescriptors into externalStreams." |
|
1716 |
||
12706 | 1717 |
^ self forFileDescriptor:aFileDescriptor mode:#readWrite |
2920 | 1718 |
|
1719 |
" |
|
1720 |
the example below will probably fail (15 is a random FD): |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1721 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1722 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1723 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1724 |
s := ExternalStream forReadWriteToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1725 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1726 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1727 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1728 |
"Created: 29.2.1996 / 18:15:08 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1729 |
"Modified: 29.2.1996 / 18:16:25 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1730 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1731 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1732 |
forReadingFromFileDescriptor:aFileDescriptor |
2920 | 1733 |
"given a fileDescriptor, create an ExternalStream object |
1734 |
to read from this fd. This may be used to wrap fd's |
|
1735 |
as returned by user primitive code, or to wrap pipe- |
|
1736 |
filedescriptors into externalStreams." |
|
1737 |
||
12706 | 1738 |
^ self forFileDescriptor:aFileDescriptor mode:#readonly |
2920 | 1739 |
|
1740 |
" |
|
1741 |
the example below will probably fail (15 is a random FD): |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1742 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1743 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1744 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1745 |
s := ExternalStream forReadingFromFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1746 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1747 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1748 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1749 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1750 |
|pipe readFd writeFd rs ws| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1751 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1752 |
'create OS pipe ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1753 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1754 |
pipe := OperatingSystem makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1755 |
readFd := pipe at:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1756 |
writeFd := pipe at:2. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1757 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1758 |
'connect Smalltalk streams ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1759 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1760 |
rs := ExternalStream forReadingFromFileDescriptor:readFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1761 |
ws := ExternalStream forWritingToFileDescriptor:writeFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1762 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1763 |
'read ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1764 |
[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1765 |
1 to:10 do:[:i | |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1766 |
Transcript showCR:rs nextLine |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1767 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1768 |
rs close. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1769 |
] forkAt:7. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1770 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1771 |
'write ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1772 |
[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1773 |
1 to:10 do:[:i | |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1774 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1775 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1776 |
ws close. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1777 |
] fork. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1778 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1779 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1780 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1781 |
"Created: 29.2.1996 / 18:14:24 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1782 |
"Modified: 29.2.1996 / 18:25:02 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1783 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1784 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1785 |
forWritingToFileDescriptor:aFileDescriptor |
2920 | 1786 |
"given a fileDescriptor, create an ExternalStream object |
1787 |
to write to this fd. This may be used to wrap fd's |
|
1788 |
as returned by user primitive code, or to wrap pipe- |
|
1789 |
filedescriptors into externalStreams." |
|
1790 |
||
12706 | 1791 |
^ self forFileDescriptor:aFileDescriptor mode:#writeonly |
2920 | 1792 |
|
1793 |
" |
|
1794 |
the example below will probably fail (15 is a random FD): |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1795 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1796 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1797 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1798 |
s := ExternalStream forWritingToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1799 |
s binary. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1800 |
s nextPut:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1801 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1802 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1803 |
"Created: 29.2.1996 / 18:14:43 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1804 |
"Modified: 29.2.1996 / 18:15:54 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1805 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1806 |
|
612 | 1807 |
new |
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
1808 |
"re-enable new - disabled in Stream superclass" |
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
1809 |
|
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
1810 |
^ self basicNew initialize. |
612 | 1811 |
! ! |
1812 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1813 |
!ExternalStream class methodsFor:'Signal constants'! |
159 | 1814 |
|
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1815 |
inaccessibleSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1816 |
"ST-80 compatibility: return openErrorSignal" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1817 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1818 |
^ self openErrorSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1819 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1820 |
"Created: 2.7.1996 / 12:27:16 / stefan" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1821 |
! |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1822 |
|
612 | 1823 |
invalidModeSignal |
1824 |
"return the signal raised when doing text-I/O with a binary stream |
|
1825 |
or binary-I/O with a text stream" |
|
1826 |
||
8074 | 1827 |
^ InvalidModeError |
159 | 1828 |
! |
1829 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1830 |
invalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1831 |
"return the signal raised when an unsupported or invalid |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1832 |
I/O operation is attempted" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1833 |
|
8074 | 1834 |
^ InvalidOperationError |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1835 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1836 |
|
159 | 1837 |
invalidReadSignal |
1838 |
"return the signal raised when reading from writeonly streams" |
|
1839 |
||
8074 | 1840 |
^ InvalidReadError |
159 | 1841 |
! |
1842 |
||
1843 |
invalidWriteSignal |
|
1844 |
"return the signal raised when writing to readonly streams" |
|
1845 |
||
8074 | 1846 |
^ InvalidWriteError |
159 | 1847 |
! |
1848 |
||
612 | 1849 |
openErrorSignal |
1850 |
"return the signal raised when a file open failed" |
|
1851 |
||
1852 |
^ OpenErrorSignal |
|
1853 |
! |
|
1854 |
||
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1855 |
streamIOErrorSignal |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1856 |
"return the signal raised when an I/O error occurs. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1857 |
(for example, a device-IO-error, or reading an NFS-dir, |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1858 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1859 |
|
8074 | 1860 |
^ StreamIOError |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1861 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1862 |
"Created: / 21.5.1998 / 16:32:55 / cg" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1863 |
! |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1864 |
|
159 | 1865 |
streamNotOpenSignal |
1866 |
"return the signal raised on I/O with closed streams" |
|
1867 |
||
8074 | 1868 |
^ StreamNotOpenError |
2 | 1869 |
! ! |
1870 |
||
22697 | 1871 |
!ExternalStream class methodsFor:'accessing'! |
1872 |
||
1873 |
openStreams |
|
1874 |
"answer a collection of open Streams having this class" |
|
1875 |
||
1876 |
|openStreams| |
|
1877 |
||
1878 |
openStreams := OrderedCollection new. |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1879 |
Lobby keysDo:[:eachStream| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1880 |
(eachStream isKindOf:self) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1881 |
openStreams add:eachStream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1882 |
] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1883 |
]. |
22697 | 1884 |
|
1885 |
^ openStreams |
|
1886 |
||
1887 |
" |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1888 |
self openStreams |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1889 |
Socket openStreams |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1890 |
NonPositionableExternalStream openStreams |
22697 | 1891 |
" |
1892 |
||
1893 |
"Created: / 24-04-2018 / 09:23:33 / stefan" |
|
1894 |
! ! |
|
1895 |
||
21337 | 1896 |
!ExternalStream class methodsFor:'defaults'! |
1897 |
||
1898 |
defaultCopyBufferSize:anInteger |
|
1899 |
"allows changing the size of buffer used when copying big |
|
1900 |
files/buld data from one stream to another. |
|
1901 |
Due to a bug on older Windows systems, the default used in copyToEndInto: |
|
1902 |
is chosen very conservatively, as the copy used to fail with big buffers. |
|
1903 |
However, modern Windows systems seem to not suffer from that bug, |
|
22578 | 1904 |
and bigger buffer sizes will dramatically increase the performance of |
21337 | 1905 |
copies to/from network drives. |
1906 |
This method allows for fine tuning, in case you run into performance problems, |
|
1907 |
or network buffer failures. |
|
1908 |
When nil, a somewhat conservative compromise is used." |
|
22578 | 1909 |
|
21337 | 1910 |
^ DefaultCopyBufferSize |
1911 |
! ! |
|
1912 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1913 |
!ExternalStream class methodsFor:'error handling'! |
92 | 1914 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1915 |
errorReporter |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1916 |
"I know about error codes" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1917 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1918 |
^ self |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1919 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1920 |
|
92 | 1921 |
lastErrorNumber |
159 | 1922 |
"return the errno of the last error" |
92 | 1923 |
|
1924 |
^ LastErrorNumber |
|
159 | 1925 |
|
1926 |
" |
|
1927 |
ExternalStream lastErrorNumber |
|
1928 |
" |
|
92 | 1929 |
! |
1930 |
||
1931 |
lastErrorString |
|
1932 |
"return a message string describing the last error" |
|
1933 |
||
1934 |
^ OperatingSystem errorTextForNumber:LastErrorNumber |
|
1935 |
||
1936 |
" |
|
1937 |
ExternalStream lastErrorString |
|
1938 |
" |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1939 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1940 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1941 |
reportOn:anErrorSymbolOrNumber |
20259 | 1942 |
"an error occurred. |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1943 |
Report it via an Exception" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1944 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1945 |
anErrorSymbolOrNumber isInteger ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1946 |
StreamError |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1947 |
raiseRequestWith:anErrorSymbolOrNumber |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1948 |
errorString:(' - os error:' , (OperatingSystem errorTextForNumber:anErrorSymbolOrNumber)) |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1949 |
]. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1950 |
(self respondsTo:anErrorSymbolOrNumber) ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1951 |
self perform:anErrorSymbolOrNumber |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1952 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1953 |
StreamError |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1954 |
raiseRequestWith:anErrorSymbolOrNumber |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1955 |
errorString:(' - ' , anErrorSymbolOrNumber printString) |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1956 |
]. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1957 |
^ false |
92 | 1958 |
! ! |
1959 |
||
20987 | 1960 |
!ExternalStream class methodsFor:'finalization'! |
1961 |
||
1962 |
finalizationLobby |
|
1963 |
"answer the registry used for finalization. |
|
1964 |
ExternalStreams have their own Registry" |
|
1965 |
||
1966 |
^ Lobby |
|
1967 |
! ! |
|
1968 |
||
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1969 |
!ExternalStream class methodsFor:'obsolete'! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1970 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1971 |
makePTYPair |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1972 |
"obsolete since 12-07-2003" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1973 |
<resource:#obsolete> |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1974 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1975 |
self obsoleteMethodWarning:'use NonPositionableExternalStream makePTYPair'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1976 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1977 |
^ NonPositionableExternalStream makePTYPair. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1978 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1979 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1980 |
makePipe |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1981 |
"obsolete since 12-07-2003" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1982 |
<resource:#obsolete> |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1983 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1984 |
self obsoleteMethodWarning:'use NonPositionableExternalStream makePipe'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1985 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1986 |
^ NonPositionableExternalStream makePipe. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1987 |
! ! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1988 |
|
21037 | 1989 |
!ExternalStream class methodsFor:'testing'! |
1990 |
||
1991 |
isAbstract |
|
1992 |
^ self == ExternalStream |
|
1993 |
! ! |
|
1994 |
||
7261 | 1995 |
!ExternalStream methodsFor:'Compatibility-Dolphin'! |
6474 | 1996 |
|
1997 |
beText |
|
1998 |
self text |
|
1999 |
! ! |
|
2000 |
||
7261 | 2001 |
!ExternalStream methodsFor:'Compatibility-Squeak'! |
3044 | 2002 |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2003 |
nextInto:aByteArrayOrString |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2004 |
"read elements into the argument, whose size determines the amount |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2005 |
of bytes to read. If not enough elements could be read, return |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2006 |
a copy of the argument; otherwise, return the filled argument." |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2007 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2008 |
|n nWanted| |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2009 |
|
4368 | 2010 |
nWanted := aByteArrayOrString byteSize. |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2011 |
n := self nextAvailableBytes:nWanted into:aByteArrayOrString startingAt:1. |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2012 |
n == nWanted ifTrue:[^ aByteArrayOrString]. |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2013 |
^ aByteArrayOrString copyTo:n |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2014 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2015 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2016 |
|
4368 | 2017 |
readInto:aContainer startingAt:index count:nElements |
2018 |
"same as #nextBytes:into:startingAt: for ByteArrays; |
|
2019 |
for LongArrays, nelements longs are read. |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2020 |
Squeak compatibility." |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2021 |
|
4368 | 2022 |
|elementSize n| |
2023 |
||
2024 |
elementSize := aContainer class elementByteSize. |
|
13940
12eb1c056d5e
fixed: #readInto:startingAt:count:; offset was wrong for non-byte elements
Claus Gittinger <cg@exept.de>
parents:
13927
diff
changeset
|
2025 |
n := self nextBytes:nElements*elementSize into:aContainer startingAt:(index-1)*elementSize+1. |
4368 | 2026 |
^ n // elementSize |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2027 |
|
13940
12eb1c056d5e
fixed: #readInto:startingAt:count:; offset was wrong for non-byte elements
Claus Gittinger <cg@exept.de>
parents:
13927
diff
changeset
|
2028 |
"Modified: / 14-01-2012 / 19:00:35 / cg" |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2029 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2030 |
|
3044 | 2031 |
readOnly |
2032 |
"Squeak compatibility: make the stream readOnly" |
|
2033 |
||
2034 |
mode := #readonly |
|
2035 |
||
2036 |
"Modified: 20.10.1997 / 19:23:04 / cg" |
|
2037 |
"Created: 20.10.1997 / 19:23:19 / cg" |
|
2038 |
! ! |
|
2039 |
||
5187 | 2040 |
!ExternalStream methodsFor:'Signal constants'! |
2041 |
||
2042 |
invalidReadSignal |
|
2043 |
^ self class invalidReadSignal |
|
2044 |
||
2045 |
"Created: / 3.12.1998 / 15:12:06 / cg" |
|
2046 |
! |
|
2047 |
||
2048 |
invalidWriteSignal |
|
2049 |
^ self class invalidWriteSignal |
|
2050 |
||
2051 |
"Created: / 3.12.1998 / 15:12:10 / cg" |
|
2052 |
! ! |
|
2053 |
||
1 | 2054 |
!ExternalStream methodsFor:'accessing'! |
2055 |
||
612 | 2056 |
binary |
2057 |
"switch to binary mode - default is text" |
|
2058 |
||
2059 |
binary := true |
|
1 | 2060 |
! |
2061 |
||
23900 | 2062 |
binary:beBinaryBool |
2063 |
"switch to binary mode - default is text" |
|
2064 |
||
2065 |
|wasBinary| |
|
2066 |
||
2067 |
wasBinary := binary. |
|
2068 |
binary := beBinaryBool. |
|
2069 |
^ wasBinary |
|
2070 |
||
2071 |
"Created: / 13-03-2019 / 19:18:53 / Stefan Vogel" |
|
2072 |
! |
|
2073 |
||
1 | 2074 |
buffered:aBoolean |
23900 | 2075 |
"turn buffering on or off - default is on. |
2076 |
Answer the previous bufferd state." |
|
2077 |
||
2078 |
|wasBuffered| |
|
2079 |
||
2080 |
wasBuffered := buffered. |
|
2081 |
buffered := aBoolean. |
|
2082 |
^ wasBuffered. |
|
2083 |
||
2084 |
"Modified (comment): / 13-03-2019 / 19:33:16 / Stefan Vogel" |
|
1 | 2085 |
! |
2086 |
||
2087 |
contents |
|
2 | 2088 |
"return the contents of the file from the current position up-to |
2089 |
the end. If the stream is in binary mode, a ByteArray containing |
|
2090 |
the byte values is returned. |
|
2091 |
In text-mode, a collection of strings, each representing one line, |
|
2092 |
is returned." |
|
2093 |
||
20092 | 2094 |
|text| |
2 | 2095 |
|
2096 |
binary ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2097 |
^ self upToEnd. |
2 | 2098 |
]. |
1 | 2099 |
|
20092 | 2100 |
"/ text mode |
244 | 2101 |
text := StringCollection new. |
1 | 2102 |
[self atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2103 |
|line| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2104 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2105 |
line := self nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2106 |
line isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2107 |
^ text |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2108 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2109 |
text add:line |
1 | 2110 |
]. |
2111 |
^ text |
|
2112 |
! |
|
2113 |
||
11751
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2114 |
contentsAsString |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2115 |
"to compensate for the bad naming, use this to make things explicit. |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2116 |
See also #contents, which returns the lines as stringCollection for textFiles." |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2117 |
|
22848 | 2118 |
binary ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2119 |
^ [ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2120 |
binary := false. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2121 |
self contentsOfEntireFile. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2122 |
] ensure:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2123 |
binary := true. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2124 |
]. |
22848 | 2125 |
]. |
2126 |
||
2127 |
^ self contentsOfEntireFile. |
|
2128 |
||
2129 |
"Modified: / 09-05-2018 / 19:37:36 / stefan" |
|
11751
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2130 |
! |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2131 |
|
612 | 2132 |
contentsOfEntireFile |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
2133 |
"ST-80 compatibility: return contents as a String (or byteArray, if in binary mode). |
3876 | 2134 |
See also #contents, which returns the lines as stringCollection for text files." |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
2135 |
|
6305 | 2136 |
^ self upToEnd |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
2137 |
|
3876 | 2138 |
"Modified: / 3.7.1996 / 13:22:16 / stefan" |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
2139 |
"Modified: / 27.11.1998 / 16:29:43 / cg" |
2 | 2140 |
! |
2141 |
||
612 | 2142 |
contentsSpecies |
2143 |
"return the kind of object to be returned by sub-collection builders |
|
2144 |
(such as upTo)" |
|
159 | 2145 |
|
21139 | 2146 |
binary ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2147 |
^ ByteArray |
159 | 2148 |
]. |
612 | 2149 |
^ String |
2 | 2150 |
! |
2151 |
||
23745 | 2152 |
dependents |
23751 | 2153 |
^ dependents ? #() |
23745 | 2154 |
|
2155 |
"Created: / 19-02-2019 / 16:08:09 / Claus Gittinger" |
|
23751 | 2156 |
"Modified: / 19-02-2019 / 23:42:56 / Claus Gittinger" |
23745 | 2157 |
! |
2158 |
||
2159 |
dependents:aDependentsCollection |
|
2160 |
dependents := aDependentsCollection |
|
2161 |
||
2162 |
"Created: / 19-02-2019 / 16:08:23 / Claus Gittinger" |
|
2163 |
! |
|
2164 |
||
16776 | 2165 |
eolMode |
2166 |
"return how end-of-line (EOL) is to be marked. |
|
2167 |
Returns one one of: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2168 |
#crlf -> add a CR-NL, as in MSDOS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2169 |
#cr -> add a CR, as in VMS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2170 |
#nl -> add a NL, as in Unix |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2171 |
#eot -> add an EOT (= 0x04, as used in some modems/protocols) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2172 |
#etx -> add an ETX (= 0x03, as used in some modems/protocols) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2173 |
#nl -> add a NL, as in Unix |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2174 |
nil -> transparent |
16776 | 2175 |
" |
2176 |
||
17115
2ef08a902c34
did report error in close always as writeError - although it could also happen on a readonly stream
Claus Gittinger <cg@exept.de>
parents:
17078
diff
changeset
|
2177 |
^ eolMode |
21097 | 2178 |
|
2179 |
"Modified (comment): / 06-12-2016 / 14:26:24 / cg" |
|
16776 | 2180 |
! |
2181 |
||
2920 | 2182 |
eolMode:aSymbolOrNil |
2183 |
"specify how end-of-line (EOL) is to be marked. |
|
2184 |
The argument may be one of: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2185 |
#crlf -> add a CR-NL, as in MSDOS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2186 |
#cr -> add a CR, as in VMS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2187 |
#nl -> add a NL, as in Unix |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2188 |
#eot -> add an EOT (= 0x04, as used in some modems/protocols) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2189 |
#etx -> add an ETX (= 0x03, as used in some modems/protocols) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2190 |
anyOther -> like #nl |
2920 | 2191 |
" |
2192 |
||
17462 | 2193 |
aSymbolOrNil == #crnl ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2194 |
eolMode := #crlf |
17462 | 2195 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2196 |
aSymbolOrNil == #lf ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2197 |
eolMode := #nl |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2198 |
] ifFalse:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2199 |
eolMode := aSymbolOrNil |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2200 |
] |
17462 | 2201 |
]. |
21097 | 2202 |
|
2203 |
"Modified (comment): / 06-12-2016 / 14:26:37 / cg" |
|
2920 | 2204 |
! |
2205 |
||
612 | 2206 |
fileDescriptor |
2207 |
"return the fileDescriptor of the receiver - |
|
2208 |
notice: this one returns the underlying OSs fileDescriptor - |
|
2209 |
this may not be available on all platforms (i.e. non unix systems)." |
|
1 | 2210 |
|
21742 | 2211 |
|fileClosed| |
22578 | 2212 |
|
3971 | 2213 |
%{ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2214 |
OBJ _handle = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2215 |
|
21742 | 2216 |
fileClosed = false; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2217 |
if (_handle != nil) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2218 |
if ((__INST(handleType) == @symbol(fileHandle)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2219 |
|| (__INST(handleType) == @symbol(socketHandle))) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2220 |
RETURN (_handle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2221 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2222 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2223 |
if ((__INST(handleType) == nil) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2224 |
|| (__INST(handleType) == @symbol(filePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2225 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2226 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2227 |
FILE *file = __FILEVal(_handle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2228 |
if (file != NULL) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2229 |
int fileNo = fileno(file); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2230 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2231 |
if (fileNo >= 0) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2232 |
RETURN ( __MKINT(fileNo)); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2233 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2234 |
fileClosed = true; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2235 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2236 |
} |
1 | 2237 |
} |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2238 |
%}. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2239 |
handle isNil ifTrue:[^ self errorNotOpen]. |
21742 | 2240 |
fileClosed ifTrue:[handle := nil. ^ self errorNotOpen]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2241 |
^ self fileDescriptorOfFile:handle |
21689 | 2242 |
|
21742 | 2243 |
"Modified: / 05-05-2017 / 16:27:34 / cg" |
2244 |
! |
|
2245 |
||
2246 |
fileDescriptorOfFile:aHandle |
|
5852 | 2247 |
"for migration to rel5 only: |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2248 |
return the fileDescriptor of the argument handle - |
5852 | 2249 |
notice: this one returns the underlying OSs fileDescriptor - |
2250 |
this may not be available on all platforms (i.e. non unix systems)." |
|
2251 |
||
18312 | 2252 |
%{ |
2253 |
#ifdef __SCHTEAM__ |
|
21742 | 2254 |
return context._RETURN(aHandle); |
18312 | 2255 |
#endif |
2256 |
%}. |
|
21742 | 2257 |
^ nil |
2258 |
||
2259 |
"Modified: / 05-05-2017 / 16:20:20 / cg" |
|
612 | 2260 |
! |
2261 |
||
10455 | 2262 |
fileHandle |
2263 |
"return the fileHandle of the receiver. |
|
2264 |
Under unix, this is the fileDescriptor; under windows, this is the Handle." |
|
2265 |
||
2266 |
%{ |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2267 |
OBJ _handle = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2268 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2269 |
if (_handle != nil) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2270 |
if ((__INST(handleType) == @symbol(fileHandle)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2271 |
|| (__INST(handleType) == @symbol(socketHandle))) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2272 |
RETURN (_handle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2273 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2274 |
if (__INST(handleType) == @symbol(pipeFilePointer)) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2275 |
RETURN (__MKINT(fileno(__FILEVal(_handle)))); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2276 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2277 |
if ((__INST(handleType) == nil) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2278 |
|| (__INST(handleType) == @symbol(filePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2279 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2280 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
2281 |
#ifdef __win32__ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2282 |
RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileno(__FILEVal(_handle))))); |
10455 | 2283 |
#else |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2284 |
FILE *file = __FILEVal(_handle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2285 |
if (file != NULL) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2286 |
int fileNo = fileno(file); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2287 |
if (fileNo >= 0) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2288 |
RETURN (__MKINT(fileNo)); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2289 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2290 |
} |
10455 | 2291 |
#endif |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2292 |
} |
10455 | 2293 |
} |
2294 |
%}. |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2295 |
^ handle |
21688 | 2296 |
|
2297 |
"Modified: / 07-04-2017 / 16:34:40 / cg" |
|
10455 | 2298 |
! |
2299 |
||
612 | 2300 |
filePointer |
2301 |
"return the filePointer of the receiver - |
|
2302 |
notice: for portability stdio is used; this means you will get |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2303 |
a FILE * - not a fileDescriptor. |
612 | 2304 |
(what you really get is a corresponding integer). |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2305 |
You cannot do much with the returned value |
612 | 2306 |
- except passing it to a primitive, for example." |
2307 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2308 |
(handleType isNil or:[handleType == #filePointer]) ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2309 |
^ handle |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2310 |
]. |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2311 |
^ self error:'not a FILE*' |
612 | 2312 |
! |
2313 |
||
21229 | 2314 |
handle |
2315 |
^ handle |
|
2316 |
! |
|
2317 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2318 |
handleType |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2319 |
^ handleType |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2320 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2321 |
|
5323 | 2322 |
lineEndCRLF |
2323 |
eolMode := #crlf |
|
2324 |
! |
|
2325 |
||
17672 | 2326 |
lineEndLF |
2327 |
eolMode := #nl |
|
2328 |
! |
|
2329 |
||
3016 | 2330 |
lineEndTransparent |
17426
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
2331 |
eolMode := #nl |
3016 | 2332 |
! |
2333 |
||
8069
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2334 |
pathName |
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2335 |
"answer the pathName of the stream. |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2336 |
Only FileStreams know the pathName, so we return an empty string here" |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2337 |
|
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2338 |
^ '' |
8069
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2339 |
! |
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2340 |
|
612 | 2341 |
readonly |
2342 |
"set access mode to readonly" |
|
2343 |
||
2344 |
mode := #readonly |
|
2345 |
! |
|
2346 |
||
2347 |
readwrite |
|
2348 |
"set access mode to readwrite" |
|
2349 |
||
2350 |
mode := #readwrite |
|
2351 |
! |
|
2352 |
||
2353 |
text |
|
2354 |
"switch to text mode - default is text" |
|
2355 |
||
2356 |
binary := false |
|
2357 |
! |
|
2358 |
||
2359 |
useCRLF:aBoolean |
|
20147 | 2360 |
<resource: #obsolete> |
2920 | 2361 |
"turn on or off CRLF sending (instead of LF only) - default is off. |
2362 |
This method is provided for backward compatibility - see #eolMode: |
|
2363 |
which offers another choice." |
|
2364 |
||
2365 |
aBoolean ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2366 |
eolMode := #crlf |
2920 | 2367 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2368 |
eolMode := #nl |
2920 | 2369 |
]. |
1 | 2370 |
! |
2371 |
||
612 | 2372 |
writeonly |
2373 |
"set access mode to writeonly" |
|
2374 |
||
2375 |
mode := #writeonly |
|
2376 |
! ! |
|
2377 |
||
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2378 |
!ExternalStream methodsFor:'closing'! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2379 |
|
20679 | 2380 |
abortAndClose |
2381 |
"close the stream - added for protocol compatibility with Socket and PipeStream. |
|
2382 |
see comment there" |
|
2383 |
||
2384 |
self close. |
|
2385 |
||
2386 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
|
2387 |
! |
|
2388 |
||
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2389 |
close |
20106 | 2390 |
"Close the stream. |
2391 |
No error if the stream is not open." |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2392 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2393 |
self isOpen ifTrue:[ |
23879 | 2394 |
self unregisterForFinalization. |
2395 |
self isOpen ifTrue:[ |
|
2396 |
self closeFile. |
|
2397 |
dependents notNil ifTrue:[ |
|
2398 |
self changed:#close. |
|
2399 |
]. |
|
2400 |
]. |
|
16300 | 2401 |
]. |
23745 | 2402 |
|
2403 |
"Modified: / 19-02-2019 / 16:08:51 / Claus Gittinger" |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2404 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2405 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2406 |
shutDown |
20679 | 2407 |
"close the stream - added for protocol compatibility with Socket. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2408 |
see comment there" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2409 |
|
19072 | 2410 |
self close. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2411 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2412 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2413 |
! ! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2414 |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2415 |
!ExternalStream methodsFor:'copying'! |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2416 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2417 |
copy |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2418 |
"answer a copy of myself. |
22713 | 2419 |
Have to dup the filedescriptor and position the copy" |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2420 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2421 |
|copy| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2422 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2423 |
copy := super copy. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2424 |
copy dupFd. |
22713 | 2425 |
self isPositionable ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2426 |
copy position:position. |
22713 | 2427 |
]. |
18779 | 2428 |
copy registerForFinalization. |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2429 |
^ copy |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2430 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2431 |
" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2432 |
|stream1 stream2| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2433 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2434 |
stream1 := Filename newTemporary writeStream. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2435 |
stream2 := stream1 copy. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2436 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2437 |
stream1 inspect. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2438 |
stream2 inspect. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2439 |
" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2440 |
! ! |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2441 |
|
23913 | 2442 |
!ExternalStream methodsFor:'defaults'! |
2443 |
||
2444 |
bufferSizeForBulkCopy |
|
2445 |
"return the size of buffer used when copying big files/bulk data |
|
2446 |
from one stream to another. |
|
2447 |
Due to a bug on older Windows systems, the default used |
|
2448 |
is chosen very conservatively, as the copy used to fail with big buffers. |
|
2449 |
However, modern Windows systems seem to not suffer from that bug, |
|
2450 |
and bigger buffer sizes will dramatically increase the performance of |
|
2451 |
copies to/from network drives. |
|
2452 |
Setting DefaultCopyBufferSize allows for fine tuning, |
|
2453 |
in case you run into performance problems, or network buffer failures. |
|
2454 |
When nil, a somewhat conservative compromise is used." |
|
2455 |
||
2456 |
DefaultCopyBufferSize notNil ifTrue:[^ DefaultCopyBufferSize]. |
|
2457 |
||
2458 |
(OperatingSystem isMSWINDOWSlike and:[OperatingSystem isWin7Like not]) ifTrue:[ |
|
2459 |
"/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ? |
|
2460 |
^ 1 * 1024. |
|
2461 |
]. |
|
2462 |
^ 64 * 1024. |
|
2463 |
||
2464 |
"Created: / 13-03-2019 / 16:49:17 / Stefan Vogel" |
|
2465 |
"Modified: / 13-03-2019 / 23:19:43 / Stefan Vogel" |
|
2466 |
! ! |
|
2467 |
||
612 | 2468 |
!ExternalStream methodsFor:'error handling'! |
2469 |
||
2470 |
argumentMustBeCharacter |
|
14440 | 2471 |
"report an error, that the argument must be a character in 0..FF" |
2472 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2473 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2474 |
|
14440 | 2475 |
ArgumentError raiseErrorString:' - argument must be a single byte character' |
612 | 2476 |
! |
2477 |
||
2478 |
argumentMustBeInteger |
|
14440 | 2479 |
"report an error, that the argument must be an integer" |
2480 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2481 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2482 |
|
14440 | 2483 |
ArgumentError raiseErrorString:' - argument must be an integer' |
77 | 2484 |
! |
2485 |
||
612 | 2486 |
argumentMustBeString |
14440 | 2487 |
"report an error, that the argument must be a string" |
2488 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2489 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2490 |
|
14440 | 2491 |
ArgumentError raiseErrorString:' - argument must be a string' |
612 | 2492 |
! |
2493 |
||
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2494 |
errorAlreadyOpen |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2495 |
"{ Pragma: +optSpace }" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2496 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2497 |
"report an error, that the stream is already opened" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2498 |
|
8074 | 2499 |
^ OpenError |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2500 |
raiseRequestWith:self |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2501 |
errorString:' - stream is already open' |
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2502 |
|
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2503 |
" |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2504 |
self new errorAlreadyOpen |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2505 |
" |
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2506 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2507 |
"Modified: / 8.5.1999 / 20:12:30 / cg" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2508 |
! |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2509 |
|
612 | 2510 |
errorBinary |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2511 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2512 |
|
612 | 2513 |
"report an error, that the stream is in binary mode" |
2514 |
||
8074 | 2515 |
^ InvalidModeError |
24383 | 2516 |
raiseRequestWith:self |
2517 |
errorString:(self className , ' is in binary mode') |
|
2518 |
"/ in:thisContext sender |
|
2519 |
||
2520 |
"Modified: / 08-05-1999 / 20:12:43 / cg" |
|
2521 |
"Modified: / 28-06-2019 / 08:43:06 / Claus Gittinger" |
|
612 | 2522 |
! |
2523 |
||
2524 |
errorNotBinary |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2525 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2526 |
|
612 | 2527 |
"report an error, that the stream is not in binary mode" |
2528 |
||
8074 | 2529 |
^ InvalidModeError |
24383 | 2530 |
raiseRequestWith:self |
2531 |
errorString:(self className , ' is not in binary mode') |
|
2532 |
"/ in:thisContext sender |
|
2533 |
||
2534 |
"Modified: / 08-05-1999 / 20:12:40 / cg" |
|
2535 |
"Modified: / 28-06-2019 / 08:43:11 / Claus Gittinger" |
|
1 | 2536 |
! |
2537 |
||
612 | 2538 |
errorNotBuffered |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2539 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2540 |
|
612 | 2541 |
"report an error, that the stream is not in buffered mode" |
2542 |
||
8074 | 2543 |
^ StreamError |
24383 | 2544 |
raiseRequestWith:self |
2545 |
errorString:(self className , ' is unbuffered - operation not allowed') |
|
2546 |
"/ in:thisContext sender |
|
2547 |
||
2548 |
"Modified: / 08-05-1999 / 20:12:36 / cg" |
|
2549 |
"Modified: / 28-06-2019 / 08:43:14 / Claus Gittinger" |
|
612 | 2550 |
! |
2551 |
||
2552 |
errorReadOnly |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2553 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2554 |
|
612 | 2555 |
"report an error, that the stream is a readOnly stream" |
2556 |
||
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2557 |
^ InvalidWriteSignal raiseRequestWith:self "/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2558 |
|
4468 | 2559 |
"Modified: / 30.7.1999 / 17:08:19 / cg" |
612 | 2560 |
! |
2561 |
||
6255
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2562 |
errorReporter |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2563 |
"ST-80 mimicry." |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2564 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
2565 |
^ self class |
6255
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2566 |
! |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2567 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2568 |
errorUnsupportedOperation |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2569 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2570 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2571 |
"report an error, that some unsupported operation was attempted" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2572 |
|
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2573 |
^ InvalidOperationError raiseRequestWith:self "/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2574 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2575 |
"Modified: / 8.5.1999 / 20:12:24 / cg" |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2576 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2577 |
|
612 | 2578 |
errorWriteOnly |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2579 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2580 |
|
612 | 2581 |
"report an error, that the stream is a writeOnly stream" |
2582 |
||
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2583 |
^ InvalidReadError raiseRequestWith:self "/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2584 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2585 |
"Modified: / 8.5.1999 / 20:12:20 / cg" |
2 | 2586 |
! |
2587 |
||
612 | 2588 |
ioError |
20259 | 2589 |
"report an error, that some I/O error occurred. |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2590 |
(for example, a device-IO-error, or reading an NFS-dir, |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2591 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2592 |
|
16296 | 2593 |
"{ Pragma: +optSpace }" |
2594 |
||
2595 |
self ioError:lastErrorNumber |
|
2596 |
||
2597 |
"Modified: / 8.5.1999 / 20:12:16 / cg" |
|
2598 |
! |
|
2599 |
||
2600 |
ioError:errorNumber |
|
20259 | 2601 |
"report an error, that some I/O error occurred. |
16296 | 2602 |
(for example, a device-IO-error, or reading an NFS-dir, |
2603 |
which is no longer available and has been mounted soft)" |
|
2604 |
||
2605 |
"{ Pragma: +optSpace }" |
|
2606 |
||
2607 |
^ StreamIOError newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2608 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2609 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2610 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2611 |
raiseRequest |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2612 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2613 |
"Modified: / 8.5.1999 / 20:12:16 / cg" |
612 | 2614 |
! |
2615 |
||
2616 |
lastErrorNumber |
|
2617 |
"return the last error" |
|
2618 |
||
2619 |
^ lastErrorNumber |
|
2620 |
! |
|
2621 |
||
2622 |
lastErrorString |
|
2623 |
"return a message string describing the last error" |
|
2624 |
||
2625 |
(lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2626 |
^ 'I/O error' |
612 | 2627 |
]. |
2628 |
^ OperatingSystem errorTextForNumber:lastErrorNumber |
|
2 | 2629 |
! |
2630 |
||
10932 | 2631 |
lastErrorSymbol |
2632 |
"return an error symbol describing the last error" |
|
2633 |
||
2634 |
^ OperatingSystem errorSymbolForNumber:lastErrorNumber |
|
2635 |
! |
|
2636 |
||
612 | 2637 |
openError |
12688 | 2638 |
"report an error, that the open failed" |
2639 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2640 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2641 |
|
14438 | 2642 |
^ self openError:lastErrorNumber. |
612 | 2643 |
! |
2644 |
||
12688 | 2645 |
openError:errorNumber |
2646 |
"report an error, that the open failed" |
|
2647 |
||
2648 |
"{ Pragma: +optSpace }" |
|
2649 |
||
15496 | 2650 |
|exClass errorHolder| |
2651 |
||
2652 |
errorHolder := OperatingSystem errorHolderForNumber:errorNumber. |
|
2653 |
||
2654 |
exClass := (errorHolder errorCategory == #nonexistentSignal) |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2655 |
ifTrue:[ FileDoesNotExistException ] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2656 |
ifFalse:[ OpenError ]. |
13673 | 2657 |
|
2658 |
^ exClass newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2659 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2660 |
osErrorHolder:errorHolder; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2661 |
"/ cg: initialized lazily - see OpenError>>#description |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2662 |
"/ errorString:(' : ' , errorHolder errorString); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2663 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2664 |
raiseRequest |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2665 |
"/ in:thisContext sender |
13673 | 2666 |
|
2667 |
"Modified: / 09-09-2011 / 07:22:49 / cg" |
|
12688 | 2668 |
! |
2669 |
||
612 | 2670 |
readError |
20259 | 2671 |
"report an error, that some read error occurred" |
15845 | 2672 |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2673 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2674 |
|
15845 | 2675 |
^ self readError:lastErrorNumber |
2676 |
! |
|
2677 |
||
2678 |
readError:errorNumber |
|
20259 | 2679 |
"report an error, that some read error occurred" |
612 | 2680 |
|
15845 | 2681 |
"{ Pragma: +optSpace }" |
2682 |
||
2683 |
^ ReadError newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2684 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2685 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2686 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2687 |
raiseRequest |
612 | 2688 |
! |
2689 |
||
2690 |
writeError |
|
20259 | 2691 |
"report an error, that some write error occurred" |
15845 | 2692 |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2693 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2694 |
|
15845 | 2695 |
^ self writeError:lastErrorNumber |
2696 |
! |
|
2697 |
||
2698 |
writeError:errorNumber |
|
20259 | 2699 |
"report an error, that some write error occurred" |
612 | 2700 |
|
15845 | 2701 |
"{ Pragma: +optSpace }" |
2702 |
||
2703 |
^ WriteError newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2704 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2705 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2706 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2707 |
raiseRequest |
612 | 2708 |
! ! |
2709 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2710 |
!ExternalStream methodsFor:'finalization'! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2711 |
|
22694 | 2712 |
beExecutor |
2713 |
"mark myself as being an executor for finalization. |
|
2714 |
We mis-use the mode symbol for this." |
|
2715 |
||
2716 |
mode := #executor. |
|
2717 |
||
2718 |
"Created: / 23-04-2018 / 18:17:01 / stefan" |
|
2719 |
! |
|
2720 |
||
15468 | 2721 |
executor |
2722 |
"return a copy for finalization-registration; |
|
2723 |
since all we need at finalization time is the fileDescriptor, |
|
2724 |
a cheaper copy is possible." |
|
2725 |
||
22694 | 2726 |
^ self class basicNew |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2727 |
beExecutor; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2728 |
setAccessor:handleType to:handle; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2729 |
yourself. |
22694 | 2730 |
|
2731 |
"Modified: / 23-04-2018 / 18:34:38 / stefan" |
|
15468 | 2732 |
! |
2733 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2734 |
finalize |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2735 |
"some Stream has been collected - close the file if not already done" |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2736 |
|
20679 | 2737 |
self closeFile |
18779 | 2738 |
! |
2739 |
||
2740 |
reRegisterForFinalization |
|
2741 |
Lobby registerChange:self. |
|
2742 |
! |
|
2743 |
||
2744 |
registerForFinalization |
|
2745 |
||
2746 |
"keep myself in newSpace, so it will be finalized early" |
|
18790 | 2747 |
Lobby size < MaxNonTenurableExecutors ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2748 |
ObjectMemory preventTenureOf:self. |
18790 | 2749 |
]. |
18779 | 2750 |
Lobby register:self. |
2751 |
! |
|
2752 |
||
2753 |
unregisterForFinalization |
|
2754 |
Lobby unregister:self. |
|
2755 |
"probably the object will be collected soon..." |
|
18793 | 2756 |
ObjectMemory allowTenureOf:self |
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2757 |
! ! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2758 |
|
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2759 |
!ExternalStream methodsFor:'initialization'! |
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2760 |
|
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2761 |
initialize |
15921 | 2762 |
position := 0. |
2763 |
binary := false. |
|
2764 |
buffered := true. |
|
19687 | 2765 |
self initializeEOLMode. |
2766 |
hitEOF := false. |
|
2767 |
! |
|
2768 |
||
2769 |
initializeEOLMode |
|
15921 | 2770 |
eolMode := DefaultEOLMode. |
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2771 |
! ! |
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2772 |
|
2 | 2773 |
!ExternalStream methodsFor:'line reading/writing'! |
1 | 2774 |
|
2775 |
nextLine |
|
2776 |
"read the next line (characters up to newline). |
|
2777 |
Return a string containing those characters excluding the newline. |
|
2778 |
If the previous-to-last character is a cr, this is also removed, |
|
16508 | 2779 |
so it's possible to read alien (i.e. ms-dos) text as well. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2780 |
The line must be shorter than 32K characters - otherwise an error is signalled." |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2781 |
|
16296 | 2782 |
|line error| |
971
eb70f5674303
max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents:
933
diff
changeset
|
2783 |
|
12873 | 2784 |
%{ /* STACK:100000 */ |
1 | 2785 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2786 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2787 |
int len, ret; |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
2788 |
char buffer[32*1024]; |
521
70533ec40482
use new MKSTRING_L if length is known (avoids a useless strlen)
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
2789 |
char *rslt, *nextPtr, *limit; |
22 | 2790 |
int fd, ch; |
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
2791 |
int _buffered; |
216 | 2792 |
OBJ fp; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2793 |
int lineTooLong = 0; |
2920 | 2794 |
int cutOff = 0; |
1 | 2795 |
|
1133 | 2796 |
__INST(lastErrorNumber) = nil; |
12548 | 2797 |
if ((__INST(handleType) == nil) |
2798 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2799 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2800 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 2801 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 2802 |
if (((fp = __INST(handle)) != nil) |
2803 |
&& (__INST(mode) != @symbol(writeonly)) |
|
2804 |
&& (__INST(binary) != true) |
|
2805 |
) { |
|
2806 |
f = __FILEVal(fp); |
|
2807 |
buffer[0] = '\0'; |
|
2808 |
||
2809 |
_buffered = (__INST(buffered) == true); |
|
2810 |
if (_buffered) { |
|
2811 |
__READING__(f); |
|
2812 |
} |
|
2813 |
||
2814 |
rslt = nextPtr = buffer; |
|
2815 |
limit = buffer + sizeof(buffer) - 2; |
|
2816 |
||
2817 |
for (;;) { |
|
2818 |
__READBYTE__(ret, f, nextPtr, _buffered, __INST(handleType)); |
|
2819 |
if (ret <= 0) { |
|
2820 |
if (nextPtr == buffer) |
|
2821 |
rslt = NULL; |
|
2822 |
if (ret == 0) { |
|
2823 |
__INST(hitEOF) = true; |
|
2824 |
break; |
|
2825 |
} else { |
|
23538 | 2826 |
# ifdef __win32__ |
23743 | 2827 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 2828 |
# endif |
23743 | 2829 |
error = __mkSmallInteger(__threadErrno); |
2830 |
goto err; |
|
2831 |
} |
|
2832 |
} |
|
2833 |
||
2834 |
if (*nextPtr == '\n') { |
|
2835 |
cutOff = 1; |
|
2836 |
*nextPtr = '\0'; |
|
2837 |
break; |
|
2838 |
} |
|
2839 |
if (*nextPtr == '\r') { |
|
2840 |
char peekChar; |
|
2841 |
||
2842 |
/* |
|
2843 |
* peek ahead for a newLine ... |
|
2844 |
*/ |
|
2845 |
__READBYTE__(ret, f, &peekChar, _buffered, __INST(handleType)); |
|
2846 |
if (ret <= 0) { |
|
2847 |
cutOff = 1; |
|
2848 |
*nextPtr = '\0'; |
|
2849 |
if (ret == 0) { |
|
2850 |
__INST(hitEOF) = true; |
|
2851 |
break; |
|
2852 |
} |
|
23538 | 2853 |
# ifdef __win32__ |
23743 | 2854 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 2855 |
# endif |
23743 | 2856 |
error = __mkSmallInteger(__threadErrno); |
2857 |
goto err; |
|
2858 |
} |
|
2859 |
||
2860 |
if (peekChar == '\n') { |
|
2861 |
cutOff = 2; |
|
2862 |
*nextPtr = '\0'; |
|
2863 |
break; |
|
2864 |
} |
|
2865 |
||
2866 |
__UNGETC__(peekChar, f, _buffered); |
|
2867 |
||
2868 |
cutOff = 1; |
|
2869 |
*nextPtr = '\0'; |
|
2870 |
break; |
|
2871 |
} |
|
2872 |
||
2873 |
nextPtr++; |
|
2874 |
if (nextPtr >= limit) { |
|
2875 |
*nextPtr = '\0'; |
|
2876 |
lineTooLong = 1; |
|
2877 |
break; |
|
2878 |
} |
|
2879 |
} |
|
2880 |
||
2881 |
if (rslt != NULL) { |
|
2882 |
len = nextPtr-buffer; |
|
2883 |
||
2884 |
if (__isSmallInteger(__INST(position))) { |
|
2885 |
INT np = __intVal(__INST(position)) + len + cutOff; |
|
2886 |
OBJ t; |
|
2887 |
||
2888 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
2889 |
} else { |
|
2890 |
__INST(position) = nil; /* i.e. do not know */ |
|
2891 |
} |
|
2892 |
/* remove any EOL character */ |
|
2893 |
if (len != 0) { |
|
2894 |
if (buffer[len-1] == '\n') { |
|
2895 |
buffer[--len] = '\0'; |
|
2896 |
} |
|
2897 |
if ((len != 0) && (buffer[len-1] == '\r')) { |
|
2898 |
buffer[--len] = '\0'; |
|
2899 |
} |
|
2900 |
} |
|
2901 |
line = __MKSTRING_L(buffer, len); |
|
2902 |
if (! lineTooLong) { |
|
2903 |
RETURN ( line ); |
|
2904 |
} |
|
2905 |
} |
|
2906 |
} |
|
1 | 2907 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
2908 |
err: ; |
159 | 2909 |
%}. |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2910 |
line notNil ifTrue:[ |
23743 | 2911 |
"/ the line as read is longer than 32k characters (boy - what a line) |
2912 |
"/ The exception raised below can be handled to ask the user |
|
2913 |
"/ and to read more and return the concatenation from the exception handler |
|
2914 |
"/ (the receiver and the partial line are passed as parameter) |
|
2915 |
"/ If unhandled, we do exactly that: read the rest and return the concatenation |
|
2916 |
"/ i.e. the full line - whatever its size is. |
|
2917 |
||
2918 |
LineTooLongErrorSignal isHandled ifTrue:[ |
|
2919 |
^ LineTooLongErrorSignal |
|
2920 |
raiseRequestWith:(Array with:self with:line) |
|
2921 |
errorString:('line too long read error') |
|
2922 |
]. |
|
2923 |
'ExternalStream [info]: very long line in nextLine' infoPrintCR. |
|
2924 |
^ line , super nextLine "use super to avoid recursion" |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2925 |
]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2926 |
|
21139 | 2927 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 2928 |
error notNil ifTrue:[ |
23743 | 2929 |
lastErrorNumber := error. |
2930 |
^ self readError:error |
|
16296 | 2931 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2932 |
handle isNil ifTrue:[^ self errorNotOpen]. |
1 | 2933 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
21139 | 2934 |
binary ifTrue:[^ self errorBinary]. |
5431 | 2935 |
^ super nextLine |
23538 | 2936 |
|
2937 |
"Modified: / 22-11-2018 / 14:46:40 / Stefan Vogel" |
|
1 | 2938 |
! |
2939 |
||
2940 |
nextPutLine:aString |
|
2920 | 2941 |
"write the characters in aString and append an end-of-Line marker |
2942 |
(LF, CR or CRLF - depending in the setting of eolMode)" |
|
1 | 2943 |
|
16296 | 2944 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2945 |
%{ |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
2946 |
OBJ fp; |
1 | 2947 |
|
1133 | 2948 |
__INST(lastErrorNumber) = nil; |
12548 | 2949 |
if ((__INST(handleType) == nil) |
2950 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2951 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2952 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 2953 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 2954 |
if (((fp = __INST(handle)) != nil) |
2955 |
&& (__INST(mode) != @symbol(readonly)) |
|
2956 |
&& (__INST(binary) != true) |
|
2957 |
&& __isStringLike(aString) |
|
2958 |
) { |
|
2959 |
int _buffered = (__INST(buffered) == true); |
|
2960 |
int len = __stringSize(aString); |
|
2961 |
int cnt, len1; |
|
2962 |
FILEPOINTER f = __FILEVal(fp); |
|
2963 |
char *cp; |
|
2964 |
int o_offs; |
|
2965 |
||
2966 |
if (_buffered) { |
|
2967 |
__WRITING__(f) |
|
2968 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
2969 |
#ifdef __win32__ |
23743 | 2970 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
2971 |
cnt = __win32_fwrite(__stringVal(aString), 1, len, f); |
|
2972 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2973 |
#endif |
23743 | 2974 |
{ |
2975 |
o_offs = (char *)__stringVal(aString)-(char *)aString; |
|
2976 |
__WRITEBYTES_OBJ__(cnt, f, aString, o_offs, len, _buffered, __INST(handleType)); |
|
2977 |
} |
|
2978 |
if (cnt == len) { |
|
2979 |
OBJ mode = __INST(eolMode); |
|
2980 |
||
2981 |
len1 = len; |
|
2982 |
||
2983 |
if (mode == @symbol(cr)) { |
|
2984 |
cp = "\r"; len = 1; |
|
2985 |
} else if (mode == @symbol(crlf)) { |
|
2986 |
cp = "\r\n"; len = 2; |
|
2987 |
} else if (mode == @symbol(eot)) { |
|
2988 |
cp = "\004"; len = 1; |
|
2989 |
} else if (mode == @symbol(etx)) { |
|
2990 |
cp = "\003"; len = 1; |
|
2991 |
} else { |
|
2992 |
cp = "\n"; len = 1; |
|
2993 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
2994 |
#ifdef __win32__ |
23743 | 2995 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
2996 |
cnt = __win32_fwrite(cp, 1, len, f); |
|
2997 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2998 |
#endif |
23743 | 2999 |
{ |
3000 |
__WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType)); |
|
3001 |
} |
|
3002 |
if (cnt > 0) { |
|
3003 |
if (__isSmallInteger(__INST(position))) { |
|
3004 |
INT np = __intVal(__INST(position)) + len1 + cnt; |
|
3005 |
OBJ t; |
|
3006 |
||
3007 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3008 |
} else { |
|
3009 |
__INST(position) = nil; /* i.e. do not know */ |
|
3010 |
} |
|
3011 |
RETURN ( self ); |
|
3012 |
} |
|
3013 |
} |
|
23538 | 3014 |
# ifdef __win32__ |
23743 | 3015 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3016 |
# endif |
23743 | 3017 |
error = __mkSmallInteger(__threadErrno); |
3018 |
} |
|
1 | 3019 |
} |
159 | 3020 |
%}. |
16296 | 3021 |
error notNil ifTrue:[ |
23743 | 3022 |
lastErrorNumber := error. |
3023 |
self writeError:error. |
|
3024 |
^ self |
|
16296 | 3025 |
]. |
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
3026 |
super nextPutLine:aString. |
23538 | 3027 |
|
3028 |
"Modified: / 22-11-2018 / 14:48:48 / Stefan Vogel" |
|
1 | 3029 |
! |
3030 |
||
3031 |
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil |
|
68 | 3032 |
"read from aStream up to and including a line starting with aStringOrNil |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3033 |
and append all lines to self. |
159 | 3034 |
Can be used to copy/create large files or copy from a pipe/socket. |
68 | 3035 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3036 |
If aStringOrNil is nil or not matched, copy proceeds to the end." |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3037 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3038 |
|line| |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3039 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3040 |
[aStream atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3041 |
line := aStream nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3042 |
line isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3043 |
^ self. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3044 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3045 |
self nextPutLine:line. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3046 |
(aStringOrNil notNil and:[line startsWith:aStringOrNil]) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3047 |
^ self |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3048 |
] |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3049 |
]. |
1 | 3050 |
! |
3051 |
||
3052 |
peekForLineStartingWith:aString |
|
3053 |
"read ahead for next line starting with aString; |
|
159 | 3054 |
return the line-string if found, or nil if EOF is encountered. |
7118 | 3055 |
If matched, do not advance position beyond that line |
159 | 3056 |
i.e. nextLine will read the matched line. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
3057 |
If not matched, reposition to original position for further reading." |
1 | 3058 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3059 |
|firstPos lastPos line| |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3060 |
|
1 | 3061 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3062 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2 | 3063 |
binary ifTrue:[^ self errorBinary]. |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3064 |
buffered ifFalse:[^ self errorNotBuffered]. |
12 | 3065 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3066 |
firstPos := self position. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3067 |
[self atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3068 |
lastPos := self position. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3069 |
line := self nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3070 |
line isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3071 |
self position:firstPos. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3072 |
^ nil |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3073 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3074 |
(line startsWith:aString) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3075 |
self position:lastPos. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3076 |
^ line |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3077 |
] |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3078 |
]. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3079 |
self position:firstPos. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3080 |
^ nil |
1 | 3081 |
! |
3082 |
||
3083 |
peekForLineStartingWithAny:aCollectionOfStrings |
|
3084 |
"read ahead for next line starting with any of aCollectionOfStrings; |
|
3085 |
return the index in aCollection if found, nil otherwise.. |
|
3086 |
If no match, do not change position; otherwise advance right before the |
|
3087 |
matched line so that nextLine will return this line." |
|
3088 |
||
3089 |
|line startPos linePos index| |
|
3090 |
||
3091 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3092 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2 | 3093 |
binary ifTrue:[^ self errorBinary]. |
3094 |
||
1 | 3095 |
startPos := self position. |
3096 |
[self atEnd] whileFalse:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3097 |
linePos := self position. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3098 |
line := self nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3099 |
line notNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3100 |
index := 1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3101 |
aCollectionOfStrings do:[:prefix | |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3102 |
(line startsWith:prefix) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3103 |
self position:linePos. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3104 |
^ index |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3105 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3106 |
index := index + 1 |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3107 |
] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3108 |
] |
1 | 3109 |
]. |
3110 |
self position:startPos. |
|
3111 |
^ nil |
|
3112 |
! ! |
|
3113 |
||
612 | 3114 |
!ExternalStream methodsFor:'misc functions'! |
3115 |
||
3116 |
async:aBoolean |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3117 |
"set/clear the async attribute - if set, the availability of data on |
612 | 3118 |
the receiver will trigger an ioInterrupt. |
779 | 3119 |
If cleared (which is the default) no special notification is made. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3120 |
Notice: |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3121 |
not every OS supports this |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3122 |
- check with OS>>supportsIOInterrupts before using" |
92 | 3123 |
|
3124 |
|fd| |
|
3125 |
||
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3126 |
OperatingSystem supportsIOInterrupts ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3127 |
^ self errorUnsupportedOperation |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3128 |
]. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3129 |
|
92 | 3130 |
fd := self fileDescriptor. |
22195 | 3131 |
"self fileDescriptor may set handle to nil" |
3132 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3133 |
||
612 | 3134 |
aBoolean ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3135 |
^ OperatingSystem enableIOInterruptsOn:fd |
612 | 3136 |
]. |
3137 |
^ OperatingSystem disableIOInterruptsOn:fd |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3138 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3139 |
"Modified: 11.1.1997 / 17:50:21 / cg" |
92 | 3140 |
! |
3141 |
||
612 | 3142 |
blocking:aBoolean |
3143 |
"set/clear the blocking attribute - if set (which is the default) |
|
3144 |
a read (using next) on the receiver will block until data is available. |
|
3145 |
If cleared, a read operation will immediately return with a value of |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3146 |
nil. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3147 |
Turning off blocking is useful when reading from PipeStreams |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3148 |
or Sockets, and the amount of data to be read is not known |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3149 |
in advance. However, the data must then be read using #nextBytes: |
8616 | 3150 |
methods, in order to avoid other (pastEndRead) exceptions." |
92 | 3151 |
|
22195 | 3152 |
|fd| |
3153 |
||
3154 |
fd := self fileDescriptor. |
|
3155 |
"self fileDescriptor may set handle to nil" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3156 |
handle isNil ifTrue:[^ self errorNotOpen]. |
22195 | 3157 |
^ OperatingSystem setBlocking:aBoolean on:fd. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3158 |
|
3174 | 3159 |
"Modified: / 11.1.1997 / 17:48:01 / cg" |
3160 |
"Modified: / 15.1.1998 / 11:49:48 / stefan" |
|
612 | 3161 |
! |
3162 |
||
3163 |
ioctl:ioctlNumber |
|
3164 |
"to provide a simple ioctl facility - an ioctl is performed |
|
3165 |
on the underlying file; no arguments are passed." |
|
3166 |
||
2920 | 3167 |
^ self ioctl:ioctlNumber with:nil |
3168 |
! |
|
3169 |
||
3170 |
ioctl:ioctlNumber with:arg |
|
3171 |
"to provide a simple ioctl facility - an ioctl is performed |
|
3172 |
on the underlying file; the argument is passed as argument. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3173 |
This is not used by ST/X, but provided for special situations |
2920 | 3174 |
- for example, to control proprietrary I/O devices. |
3175 |
||
3176 |
Since the type of the argument depends on the ioctl being |
|
3177 |
performed, different arg types are allowed here. |
|
3178 |
If the argument is nil, an ioctl without argument is performed. |
|
16508 | 3179 |
If the argument is an integral number, it's directly passed; |
3180 |
if it's a kind of ByteArray (ByteArray, String or Structure), |
|
2920 | 3181 |
or external data (ExternalBytes or ExternalAddress), |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3182 |
a pointer to the data is passed. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3183 |
This allows performing most ioctls |
2920 | 3184 |
- however, it might be tricky to setup the buffer. |
3185 |
Be careful in what you pass - ST/X cannot validate its correctness." |
|
3186 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3187 |
|error| |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3188 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3189 |
%{ |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3190 |
#if !defined(MSDOS_LIKE) && !defined(__openVMS__) |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3191 |
int fd; |
10552
d52aa8e066e5
#ioctl:with: accept 32-bit integers as arguments
Stefan Vogel <sv@exept.de>
parents:
10469
diff
changeset
|
3192 |
int ret; |
d52aa8e066e5
#ioctl:with: accept 32-bit integers as arguments
Stefan Vogel <sv@exept.de>
parents:
10469
diff
changeset
|
3193 |
unsigned int ioNum; |
2920 | 3194 |
INT ioArg; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3195 |
OBJ fp = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3196 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3197 |
if (fp == nil) |
23743 | 3198 |
goto out; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3199 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3200 |
if (!__isInteger(ioctlNumber) |
23743 | 3201 |
|| (!__isInteger(arg) |
3202 |
&& (arg != nil) |
|
3203 |
&& !__isBytes(arg) |
|
3204 |
&& !__isExternalBytesLike(arg) |
|
3205 |
&& !__isExternalAddress(arg))) { |
|
3206 |
error = @symbol(badArgument); |
|
3207 |
goto out; |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3208 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3209 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3210 |
if (__INST(handleType) == @symbol(socketHandle)) { |
23743 | 3211 |
fd = (int)((SOCKET)(__FILEVal(fp))); |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3212 |
} else |
23743 | 3213 |
if ((__INST(handleType) == nil) |
3214 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3215 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3216 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3217 |
fd = fileno(__FILEVal(fp)); |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3218 |
} else { |
23743 | 3219 |
error = @symbol(badHandleType); |
3220 |
goto out; |
|
612 | 3221 |
} |
16508 | 3222 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3223 |
ioNum = __unsignedLongIntVal(ioctlNumber); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3224 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3225 |
__BEGIN_INTERRUPTABLE__ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3226 |
do { |
23743 | 3227 |
__threadErrno = 0; |
3228 |
if (arg == nil) { |
|
3229 |
ioArg = 0; |
|
3230 |
} else if (__isSmallInteger(arg)) { |
|
3231 |
ioArg = __intVal(arg); |
|
3232 |
} else if (__isInteger(arg)) { |
|
3233 |
ioArg = __unsignedLongIntVal(arg); |
|
3234 |
} else if (__isExternalBytesLike(arg)) { |
|
3235 |
ioArg = (INT)(__externalBytesAddress(arg)); |
|
3236 |
} else if (__isExternalAddress(arg)) { |
|
3237 |
ioArg = (INT)(__externalAddressVal(arg)); |
|
3238 |
} else { |
|
3239 |
ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element); |
|
3240 |
} |
|
3241 |
ret = ioctl(fd, ioNum, ioArg); |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3242 |
} while (ret < 0 && __threadErrno == EINTR); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3243 |
__END_INTERRUPTABLE__ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3244 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3245 |
if (ret >= 0) { |
23743 | 3246 |
RETURN ( __mkSmallInteger(ret) ); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3247 |
} |
23538 | 3248 |
# ifdef __win32__ |
23743 | 3249 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3250 |
# endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3251 |
error = __mkSmallInteger(__threadErrno); |
791 | 3252 |
#endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3253 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3254 |
out:; |
612 | 3255 |
%}. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3256 |
error notNil ifTrue:[ |
23743 | 3257 |
lastErrorNumber := error. |
3258 |
^ self ioError:error. |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3259 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3260 |
handle isNil ifTrue:[^ self errorNotOpen]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3261 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3262 |
"/ the system does not support ioctl (MSDOS or VMS) |
2920 | 3263 |
^ self errorUnsupportedOperation |
23538 | 3264 |
|
3265 |
"Modified: / 22-11-2018 / 14:42:04 / Stefan Vogel" |
|
612 | 3266 |
! |
3267 |
||
16551 | 3268 |
reset |
3269 |
"set the read position to the beginning of the collection" |
|
3270 |
||
3271 |
self position:0 |
|
3272 |
! |
|
3273 |
||
3274 |
setToEnd |
|
3275 |
"redefined since it must be implemented differently" |
|
3276 |
||
3277 |
^ self subclassResponsibility |
|
3278 |
! |
|
3279 |
||
3280 |
sync |
|
3281 |
"make sure, that the OS writes cached data to the disk" |
|
3282 |
||
3283 |
|error| |
|
3284 |
||
3285 |
self flush. |
|
3286 |
||
3287 |
%{ |
|
3288 |
#if !defined(__openVMS__) |
|
3289 |
int fd; |
|
3290 |
int ret; |
|
3291 |
OBJ fp = __INST(handle); |
|
3292 |
||
3293 |
if (fp == nil) |
|
23743 | 3294 |
goto out; |
16551 | 3295 |
|
3296 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
23743 | 3297 |
// syncing a socket to disk ? |
3298 |
error = @symbol(badHandleType); |
|
3299 |
goto out; |
|
3300 |
// fd = __FILEVal(fp); |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3301 |
} else |
23743 | 3302 |
if ((__INST(handleType) == nil) |
3303 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3304 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3305 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3306 |
fd = fileno(__FILEVal(fp)); |
|
16551 | 3307 |
} else { |
23743 | 3308 |
error = @symbol(badHandleType); |
3309 |
goto out; |
|
16551 | 3310 |
} |
3311 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3312 |
#ifdef __win32__ |
16551 | 3313 |
__threadErrno = 0; |
3314 |
ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd)); |
|
3315 |
if (ret) { |
|
23743 | 3316 |
RETURN (self); |
16551 | 3317 |
} |
23538 | 3318 |
__threadErrno = __WIN32_ERR(GetLastError()); |
16551 | 3319 |
#else |
3320 |
__BEGIN_INTERRUPTABLE__ |
|
3321 |
do { |
|
23743 | 3322 |
ret = fsync(fd); |
16551 | 3323 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
3324 |
__END_INTERRUPTABLE__ |
|
3325 |
||
3326 |
if (ret >= 0) { |
|
23743 | 3327 |
RETURN (self); |
16551 | 3328 |
} |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3329 |
#endif /* ! __win32__ */ |
16551 | 3330 |
error = __mkSmallInteger(__threadErrno); |
3331 |
#endif /* ! __openVMS__ */ |
|
3332 |
out:; |
|
3333 |
%}. |
|
3334 |
error notNil ifTrue:[ |
|
23743 | 3335 |
lastErrorNumber := error. |
3336 |
self ioError:error. |
|
3337 |
^ self. |
|
16551 | 3338 |
]. |
3339 |
handle isNil ifTrue:[self errorNotOpen]. |
|
3340 |
||
3341 |
" |
|
23743 | 3342 |
|f| |
3343 |
f := 'x' asFilename writeStream. |
|
3344 |
f nextPutAll:'hallo'; sync; syncData; close |
|
16551 | 3345 |
" |
23538 | 3346 |
|
3347 |
"Modified: / 22-11-2018 / 14:51:43 / Stefan Vogel" |
|
16551 | 3348 |
! |
3349 |
||
3350 |
syncData |
|
3351 |
"make sure, that the OS writes cached data to the disk. |
|
3352 |
In this case, metadata is only written, if it is |
|
3353 |
required to read the file's data (so metadata will not be written, |
|
3354 |
if only access/modification time has changed)." |
|
3355 |
|error| |
|
3356 |
||
3357 |
self flush. |
|
3358 |
||
3359 |
%{ |
|
3360 |
#if !defined(__openVMS__) |
|
3361 |
int fd; |
|
3362 |
int ret; |
|
3363 |
OBJ fp = __INST(handle); |
|
3364 |
||
3365 |
if (fp == nil) |
|
23743 | 3366 |
goto out; |
16551 | 3367 |
|
3368 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
23743 | 3369 |
// syncing a socket to disk ? |
3370 |
error = @symbol(badHandleType); |
|
3371 |
goto out; |
|
3372 |
// fd = __FILEVal(fp); |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3373 |
} else |
23743 | 3374 |
if ((__INST(handleType) == nil) |
3375 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3376 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3377 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3378 |
fd = fileno(__FILEVal(fp)); |
|
16551 | 3379 |
} else { |
23743 | 3380 |
error = @symbol(badHandleType); |
3381 |
goto out; |
|
16551 | 3382 |
} |
3383 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3384 |
#ifdef __win32__ |
16551 | 3385 |
__threadErrno = 0; |
3386 |
ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd)); |
|
3387 |
if (ret) { |
|
23743 | 3388 |
RETURN (self); |
16551 | 3389 |
} |
23538 | 3390 |
__threadErrno = __WIN32_ERR(GetLastError()); |
16551 | 3391 |
#else |
3392 |
__BEGIN_INTERRUPTABLE__ |
|
3393 |
do { |
|
23743 | 3394 |
ret = fdatasync(fd); |
16551 | 3395 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
3396 |
__END_INTERRUPTABLE__ |
|
3397 |
||
3398 |
if (ret >= 0) { |
|
23743 | 3399 |
RETURN (self); |
16551 | 3400 |
} |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3401 |
#endif /* ! __win32__ */ |
16551 | 3402 |
error = __mkSmallInteger(__threadErrno); |
3403 |
#endif /* ! __openVMS__ */ |
|
3404 |
out:; |
|
3405 |
%}. |
|
3406 |
||
3407 |
error notNil ifTrue:[ |
|
23743 | 3408 |
lastErrorNumber := error. |
3409 |
self ioError:error. |
|
3410 |
^ self. |
|
16551 | 3411 |
]. |
3412 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3413 |
||
3414 |
"if notdef HAS_DATASYNC, fall back" |
|
3415 |
self sync. |
|
3416 |
||
3417 |
" |
|
23743 | 3418 |
|f| |
3419 |
f := 'x' asFilename writeStream. |
|
3420 |
f nextPutAll:'hallo'; sync; syncData; close |
|
16551 | 3421 |
" |
23538 | 3422 |
|
3423 |
"Modified: / 22-11-2018 / 14:51:31 / Stefan Vogel" |
|
16551 | 3424 |
! |
3425 |
||
16508 | 3426 |
tcgetattr |
3427 |
"unix only: |
|
3428 |
provide the information of a tcgetattr call as a dictionary. |
|
3429 |
This provides terminal setting values of a tty or pty. |
|
3430 |
Used by terminal emulators. |
|
3431 |
On non-unix systems, an unsupported operation error is raised" |
|
3432 |
||
3433 |
|error ret |
|
3434 |
iflags "/ input flags |
|
3435 |
ignbrk brkint ignpar parmrk inpck istrip inlcr igncr |
|
16509
2cf139885242
Fixed ExternalStream>>tcgetattr
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16508
diff
changeset
|
3436 |
icrnl iuclc ixon ixoff ixany imaxbel iutf8 |
16508 | 3437 |
oflags "/ output flags |
3438 |
opost onlcr ocrnl olcuc onocr onlret oxtabs onoteot |
|
3439 |
cflags "/ control flags |
|
3440 |
csize cstopb cread parenb parodd hupcl clocal |
|
3441 |
lflags "/ local flags |
|
3442 |
echoke echoe echok echo echonl echoprt echoctl |
|
3443 |
isig icanon altwerase iexten extproc tostop |
|
3444 |
| |
|
3445 |
||
3446 |
%{ |
|
3447 |
#if !defined(MSDOS_LIKE) && !defined(__openVMS__) |
|
3448 |
int fd; |
|
3449 |
int _ret; |
|
3450 |
OBJ fp = __INST(handle); |
|
3451 |
struct termios t; |
|
3452 |
int sz; |
|
3453 |
||
3454 |
if (fp == nil) |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3455 |
goto out; |
16508 | 3456 |
|
3457 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3458 |
// cg: termina attributes of a socket? |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3459 |
error = @symbol(badHandleType); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3460 |
goto out; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3461 |
// fd = __FILEVal(fp); |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3462 |
} else |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3463 |
if ((__INST(handleType) == nil) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3464 |
|| (__INST(handleType) == @symbol(filePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3465 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3466 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3467 |
fd = fileno(__FILEVal(fp)); |
16508 | 3468 |
} else { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3469 |
error = @symbol(badHandleType); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3470 |
goto out; |
16508 | 3471 |
} |
3472 |
||
3473 |
__BEGIN_INTERRUPTABLE__ |
|
3474 |
do { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3475 |
__threadErrno = 0; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3476 |
_ret = tcgetattr(fd, &t); |
16508 | 3477 |
} while (_ret < 0 && __threadErrno == EINTR); |
3478 |
__END_INTERRUPTABLE__ |
|
3479 |
||
3480 |
if (_ret < 0) { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3481 |
error = __mkSmallInteger(__threadErrno); |
16508 | 3482 |
} |
3483 |
ignbrk = t.c_iflag & IGNBRK ? true : false; |
|
3484 |
brkint = t.c_iflag & BRKINT ? true : false; |
|
3485 |
ignpar = t.c_iflag & IGNPAR ? true : false; |
|
3486 |
parmrk = t.c_iflag & PARMRK ? true : false; |
|
3487 |
inpck = t.c_iflag & INPCK ? true : false; |
|
3488 |
istrip = t.c_iflag & ISTRIP ? true : false; |
|
3489 |
inlcr = t.c_iflag & INLCR ? true : false; |
|
3490 |
ixon = t.c_iflag & IXON ? true : false; |
|
3491 |
ixoff = t.c_iflag & IXOFF ? true : false; |
|
3492 |
ixany = t.c_iflag & IXANY ? true : false; |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3493 |
# ifdef IMAXBEL |
16508 | 3494 |
imaxbel = t.c_iflag & IMAXBEL ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3495 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3496 |
# ifdef IUCLC |
16508 | 3497 |
iuclc = t.c_iflag & IUCLC ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3498 |
# endif |
16508 | 3499 |
|
3500 |
opost = t.c_oflag & OPOST ? true : false; |
|
3501 |
onlcr = t.c_oflag & ONLCR ? true : false; |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3502 |
# ifdef OXTABS |
16508 | 3503 |
oxtabs = t.c_oflag & OXTABS ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3504 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3505 |
# ifdef ONOTEOT |
16508 | 3506 |
onoteot = t.c_oflag & ONOTEOT ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3507 |
# endif |
16508 | 3508 |
ocrnl = t.c_oflag & OCRNL ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3509 |
# ifdef OLCUC |
16508 | 3510 |
olcuc = t.c_oflag & OLCUC ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3511 |
# endif |
16508 | 3512 |
onocr = t.c_oflag & ONOCR ? true : false; |
3513 |
onlret = t.c_oflag & ONLRET ? true : false; |
|
3514 |
||
3515 |
sz = t.c_cflag & CSIZE; |
|
3516 |
switch (sz) { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3517 |
case CS5: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3518 |
csize = @symbol(cs5); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3519 |
break; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3520 |
case CS6: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3521 |
csize = @symbol(cs6); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3522 |
break; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3523 |
case CS7: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3524 |
csize = @symbol(cs7); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3525 |
break; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3526 |
case CS8: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3527 |
csize = @symbol(cs8); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3528 |
break; |
16508 | 3529 |
} |
3530 |
cstopb = t.c_cflag & CSTOPB ? true : false; |
|
3531 |
cread = t.c_cflag & CREAD ? true : false; |
|
3532 |
parenb = t.c_cflag & PARENB ? true : false; |
|
3533 |
parodd = t.c_cflag & PARODD ? true : false; |
|
3534 |
hupcl = t.c_cflag & HUPCL ? true : false; |
|
3535 |
clocal = t.c_cflag & CLOCAL ? true : false; |
|
3536 |
||
3537 |
echoke = t.c_lflag & ECHOKE ? true : false; |
|
3538 |
echoe = t.c_lflag & ECHOE ? true : false; |
|
3539 |
echo = t.c_lflag & ECHO ? true : false; |
|
3540 |
echonl = t.c_lflag & ECHONL ? true : false; |
|
3541 |
echoctl = t.c_lflag & ECHOCTL ? true : false; |
|
3542 |
isig = t.c_lflag & ISIG ? true : false; |
|
3543 |
icanon = t.c_lflag & ICANON ? true : false; |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3544 |
# ifdef ALTWERASE |
16508 | 3545 |
altwerase = t.c_lflag & ALTWERASE ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3546 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3547 |
# ifdef IEXTEN |
16508 | 3548 |
iexten = t.c_lflag & IEXTEN ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3549 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3550 |
# ifdef EXTPROC |
16508 | 3551 |
extproc = t.c_lflag & EXTPROC ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3552 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3553 |
# ifdef TOSTOP |
16508 | 3554 |
tostop = t.c_lflag & TOSTOP ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3555 |
# endif |
16508 | 3556 |
|
3557 |
#else |
|
3558 |
error = @symbol(unsupportedOperation); |
|
3559 |
#endif |
|
3560 |
||
3561 |
out:; |
|
3562 |
%}. |
|
3563 |
error notNil ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3564 |
error == #unsupportedOperation ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3565 |
"/ the system does not support tcgetattr |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3566 |
^ self errorUnsupportedOperation |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3567 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3568 |
lastErrorNumber := error. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3569 |
^ self ioError:error. |
16508 | 3570 |
]. |
3571 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3572 |
||
3573 |
"/ construct a dictionary... |
|
3574 |
ret := Dictionary new. |
|
3575 |
ret at:#iflags put:(iflags := Dictionary new). |
|
3576 |
ret at:#oflags put:(oflags := Dictionary new). |
|
3577 |
ret at:#cflags put:(cflags := Dictionary new). |
|
3578 |
ret at:#lflags put:(lflags := Dictionary new). |
|
3579 |
iflags at:#ignbrk put:ignbrk. |
|
3580 |
iflags at:#brkint put:brkint. |
|
3581 |
iflags at:#ignpar put:ignpar. |
|
3582 |
iflags at:#parmrk put:parmrk. |
|
3583 |
iflags at:#inpck put:inpck. |
|
3584 |
iflags at:#istrip put:istrip. |
|
3585 |
iflags at:#inlcr put:inlcr. |
|
3586 |
iflags at:#igncr put:igncr. |
|
3587 |
iflags at:#icrnl put:icrnl. |
|
16509
2cf139885242
Fixed ExternalStream>>tcgetattr
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16508
diff
changeset
|
3588 |
iflags at:#uiclc put:iuclc. |
16508 | 3589 |
iflags at:#ixon put:ixon. |
3590 |
iflags at:#ixoff put:ixoff. |
|
3591 |
iflags at:#ixany put:ixany. |
|
3592 |
iflags at:#imaxbel put:imaxbel. |
|
3593 |
iflags at:#iutf8 put:iutf8. |
|
3594 |
||
3595 |
oflags at:#opost put:opost. |
|
3596 |
oflags at:#onlcr put:onlcr. |
|
3597 |
oflags at:#oxtabs put:oxtabs. |
|
3598 |
oflags at:#onoteot put:onoteot. |
|
3599 |
||
3600 |
cflags at:#csize put:csize. |
|
3601 |
cflags at:#cstopb put:cstopb. |
|
3602 |
cflags at:#cread put:cread. |
|
3603 |
cflags at:#parenb put:parenb. |
|
3604 |
cflags at:#parodd put:parodd. |
|
3605 |
cflags at:#hupcl put:hupcl. |
|
3606 |
cflags at:#clocal put:clocal. |
|
3607 |
||
3608 |
lflags at:#echoke put:echoke. |
|
3609 |
lflags at:#echoe put:echoe. |
|
3610 |
lflags at:#echok put:echok. |
|
3611 |
lflags at:#echo put:echo. |
|
3612 |
lflags at:#echonl put:echonl. |
|
3613 |
lflags at:#echoprt put:echoprt. |
|
3614 |
lflags at:#echoctl put:echoctl. |
|
3615 |
lflags at:#isig put:isig. |
|
3616 |
lflags at:#icanon put:icanon. |
|
3617 |
lflags at:#altwerase put:altwerase. |
|
3618 |
lflags at:#iexten put:iexten. |
|
3619 |
lflags at:#extproc put:extproc. |
|
3620 |
lflags at:#tostop put:tostop. |
|
3621 |
^ ret |
|
612 | 3622 |
! ! |
3623 |
||
3624 |
!ExternalStream methodsFor:'non homogenous reading'! |
|
3625 |
||
17609 | 3626 |
next:count into:aCollection startingAt:start |
20092 | 3627 |
"return the next count bytes or characters from the stream." |
3628 |
||
17609 | 3629 |
|readCount| |
3630 |
||
3631 |
readCount := self nextBytes:count into:aCollection startingAt:start. |
|
3632 |
readCount = count ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3633 |
^ aCollection. |
17609 | 3634 |
]. |
3635 |
^ aCollection copyFrom:1 to:start+readCount-1. |
|
15254 | 3636 |
! |
3637 |
||
3674 | 3638 |
nextAvailable:count |
3639 |
"return the next count elements of the stream as aCollection. |
|
3640 |
If the stream reaches the end before count elements have been read, |
|
3641 |
return what is available. (i.e. a shorter collection). |
|
3642 |
The type of collection is specified in #contentsSpecies." |
|
3643 |
||
3956
51f1a9a4d63f
changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents:
3949
diff
changeset
|
3644 |
|buffer n| |
3674 | 3645 |
|
20092 | 3646 |
buffer := self contentsSpecies uninitializedNew:count. |
3674 | 3647 |
n := self nextAvailableBytes:count into:buffer startingAt:1. |
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3648 |
n == 0 ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3649 |
binary ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3650 |
^ #[] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3651 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3652 |
^ '' |
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3653 |
]. |
3674 | 3654 |
|
3655 |
n ~~ count ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3656 |
^ buffer copyTo:n |
3674 | 3657 |
]. |
3658 |
^ buffer. |
|
3659 |
||
3660 |
" |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3661 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:3 |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3662 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
3674 | 3663 |
(ReadStream on:'hello') nextAvailable:3 |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3664 |
(ReadStream on:'hello') nextAvailable:10 |
3674 | 3665 |
" |
3666 |
||
3667 |
"Modified: / 16.6.1998 / 15:52:41 / cg" |
|
3668 |
! |
|
3669 |
||
17608 | 3670 |
nextAvailable:count into:aCollection startingAt:pos |
3671 |
"return the next count elements of the stream into aCollection at position pos." |
|
3672 |
||
3673 |
^ self nextAvailableBytes:count into:aCollection startingAt:pos. |
|
3674 |
! |
|
3675 |
||
24507 | 3676 |
nextAvailableBytes:count |
3677 |
"return the next count bytes of the stream as a byteArray. |
|
3678 |
If the stream reaches the end before count bytes have been read, |
|
3679 |
return what is available. (i.e. a shorter byteArray)." |
|
3680 |
||
3681 |
|buffer n| |
|
3682 |
||
3683 |
buffer := ByteArray uninitializedNew:count. |
|
3684 |
n := self nextAvailableBytes:count into:buffer startingAt:1. |
|
3685 |
n == 0 ifTrue:[ |
|
3686 |
^ #[] |
|
3687 |
]. |
|
3688 |
||
3689 |
n ~~ count ifTrue:[ |
|
3690 |
^ buffer copyTo:n |
|
3691 |
]. |
|
3692 |
^ buffer. |
|
3693 |
||
3694 |
" |
|
3695 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:3 |
|
3696 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
|
3697 |
(ReadStream on:'hello') nextAvailable:3 |
|
3698 |
(ReadStream on:'hello') nextAvailable:10 |
|
3699 |
" |
|
3700 |
||
3701 |
"Modified: / 16.6.1998 / 15:52:41 / cg" |
|
3702 |
! |
|
3703 |
||
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3704 |
nextAvailableBytes:count into:anObject startingAt:start |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3705 |
"read the next count bytes into an object and return the number of |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3706 |
bytes read or the number of bytes read, if EOF is encountered before, |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3707 |
or no more bytes are available for reading (from the pipe/socket). |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3708 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3709 |
If the receiver is some socket/pipe-like stream, an exception |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3710 |
is raised if the connection is broken. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3711 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3712 |
Notice, that in contrast to other methods, |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3713 |
this does NOT return nil on EOF, but the actual count. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3714 |
Thus allowing read of partial blocks. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3715 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3716 |
The object must have non-pointer indexed instvars |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3717 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray). |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3718 |
If anObject is a string or byteArray and reused, this provides the |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3719 |
fastest possible physical I/O (since no new objects are allocated). |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3720 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3721 |
Use with care - non object oriented I/O. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3722 |
Warning: in general, you cannot use this method to pass data from other |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3723 |
architectures since it does not care for byte order or float representation." |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3724 |
|
16296 | 3725 |
|error| |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3726 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3727 |
%{ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3728 |
FILEPOINTER f; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3729 |
int cnt, offs, ret, _buffered; |
15987 | 3730 |
int objSize, nInstBytes; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3731 |
char *cp; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3732 |
char *extPtr; |
7195
755c46f9b774
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7118
diff
changeset
|
3733 |
OBJ fp; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3734 |
int o_offs; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3735 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3736 |
__INST(lastErrorNumber) = nil; |
12548 | 3737 |
if ((__INST(handleType) == nil) |
3738 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3739 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3740 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3741 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23897 | 3742 |
if (((fp = __INST(handle)) != nil) |
3743 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3744 |
&& __bothSmallInteger(count, start) |
|
3745 |
) { |
|
3746 |
f = __FILEVal(fp); |
|
3747 |
||
3748 |
cnt = __intVal(count); |
|
3749 |
offs = __intVal(start) - 1; |
|
3750 |
||
3751 |
if (__isExternalBytesLike(anObject)) { |
|
3752 |
OBJ sz; |
|
3753 |
||
3754 |
nInstBytes = 0; |
|
3755 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
|
3756 |
if (extPtr == NULL) goto bad; |
|
3757 |
sz = __externalBytesSize(anObject); |
|
3758 |
if (__isSmallInteger(sz)) { |
|
3759 |
objSize = __intVal(sz); |
|
3760 |
} else { |
|
3761 |
objSize = 0; /* unknown */ |
|
3762 |
} |
|
3763 |
} else { |
|
3764 |
OBJ oClass = __Class(anObject); |
|
3765 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3766 |
||
3767 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3768 |
||
3769 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3770 |
case BYTEARRAY: |
|
3771 |
case WORDARRAY: |
|
3772 |
case LONGARRAY: |
|
3773 |
case SWORDARRAY: |
|
3774 |
case SLONGARRAY: |
|
3775 |
case FLOATARRAY: |
|
3776 |
break; |
|
3777 |
case DOUBLEARRAY: |
|
15987 | 3778 |
#ifdef __NEED_DOUBLE_ALIGN |
23897 | 3779 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
15987 | 3780 |
#endif |
23897 | 3781 |
break; |
3782 |
case LONGLONGARRAY: |
|
3783 |
case SLONGLONGARRAY: |
|
16296 | 3784 |
#ifdef __NEED_LONGLONG_ALIGN |
23897 | 3785 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3786 |
#endif |
23897 | 3787 |
break; |
3788 |
default: |
|
3789 |
goto bad; |
|
3790 |
} |
|
3791 |
extPtr = (char *)0; |
|
3792 |
objSize = __Size(anObject) - nInstBytes; |
|
3793 |
} |
|
3794 |
||
3795 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
3796 |
_buffered = (__INST(buffered) == true); |
|
3797 |
if (_buffered) { |
|
3798 |
__READING__(f); |
|
3799 |
} |
|
3800 |
||
3801 |
if (extPtr) { |
|
3802 |
__READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType)); |
|
3803 |
} else { |
|
3804 |
/* |
|
3805 |
* on interrupt, anObject may be moved to another location. |
|
3806 |
* So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__, |
|
3807 |
* to get a new address. |
|
3808 |
*/ |
|
3809 |
offs += nInstBytes; |
|
3810 |
__READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType)); |
|
3811 |
} |
|
3812 |
/* 0 is NOT an EOF condition here ... */ |
|
3813 |
if (ret >= 0) { |
|
3814 |
if (__isSmallInteger(__INST(position))) { |
|
3815 |
INT np = __intVal(__INST(position)) + ret; |
|
3816 |
OBJ t; |
|
3817 |
||
3818 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3819 |
} else { |
|
3820 |
__INST(position) = nil; /* i.e. do not know */ |
|
3821 |
} |
|
3822 |
RETURN (__mkSmallInteger(ret)); |
|
3823 |
} |
|
3824 |
__INST(position) = nil; |
|
23538 | 3825 |
# ifdef __win32__ |
23897 | 3826 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3827 |
# endif |
23897 | 3828 |
error = __mkSmallInteger(__threadErrno); |
3829 |
} |
|
3830 |
} |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3831 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3832 |
bad: ; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3833 |
%}. |
20092 | 3834 |
hitEOF ifTrue:[^ 0]. |
16296 | 3835 |
error notNil ifTrue:[ |
23897 | 3836 |
lastErrorNumber := error. |
3837 |
^ self readError:error |
|
16296 | 3838 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3839 |
handle isNil ifTrue:[^ self errorNotOpen]. |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3840 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3841 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3842 |
count not integer or arg not bit-like (String, ByteArray etc) |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3843 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3844 |
^ self primitiveFailed |
23538 | 3845 |
|
23897 | 3846 |
"Modified: / 13-03-2019 / 17:07:07 / Stefan Vogel" |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3847 |
! |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3848 |
|
612 | 3849 |
nextByte |
3850 |
"read the next byte and return it as an Integer; return nil on error. |
|
3851 |
This is allowed in both text and binary modes, always returning the |
|
3852 |
bytes binary value as an integer in 0..255." |
|
3853 |
||
16296 | 3854 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3855 |
%{ |
18364 | 3856 |
#ifdef __SCHTEAM__ |
3857 |
STObject handle = self.instVarAt(I_handle); |
|
3858 |
||
3859 |
if (handle != STObject.Nil) { |
|
23743 | 3860 |
STObject next; |
3861 |
||
3862 |
next = handle.nextByte(); |
|
3863 |
if (next != STObject.EOF) { |
|
3864 |
self.instVarAt_put(I_position, STObject.Nil); |
|
3865 |
return __c__._RETURN( next ); |
|
3866 |
} |
|
3867 |
self.instVarAt_put(I_hitEOF, STObject.True); |
|
18364 | 3868 |
} |
3869 |
#else |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3870 |
FILEPOINTER f; |
612 | 3871 |
unsigned char byte; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3872 |
int ret, _buffered; |
612 | 3873 |
OBJ fp; |
3874 |
||
1133 | 3875 |
__INST(lastErrorNumber) = nil; |
12548 | 3876 |
if ((__INST(handleType) == nil) |
3877 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3878 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3879 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3880 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 3881 |
if (((fp = __INST(handle)) != nil) |
3882 |
&& (__INST(mode) != @symbol(writeonly))) { |
|
3883 |
f = __FILEVal(fp); |
|
3884 |
||
3885 |
_buffered = (__INST(buffered) == true); |
|
3886 |
if (_buffered) { |
|
3887 |
__READING__(f) |
|
3888 |
} |
|
3889 |
__READBYTE__(ret, f, &byte, _buffered, __INST(handleType)); |
|
3890 |
if (ret > 0) { |
|
3891 |
if (__isSmallInteger(__INST(position))) { |
|
3892 |
INT np = __intVal(__INST(position)) + 1; |
|
3893 |
OBJ t; |
|
3894 |
||
3895 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3896 |
} else { |
|
3897 |
__INST(position) = nil; /* i.e. do not know */ |
|
3898 |
} |
|
3899 |
RETURN (__mkSmallInteger(byte)); |
|
3900 |
} |
|
3901 |
||
3902 |
if (ret == 0) { |
|
3903 |
__INST(hitEOF) = true; |
|
3904 |
} else /* ret < 0 */ { |
|
3905 |
__INST(position) = nil; |
|
23538 | 3906 |
# ifdef __win32__ |
23743 | 3907 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3908 |
# endif |
23743 | 3909 |
error = __mkSmallInteger(__threadErrno); |
3910 |
} |
|
3911 |
} |
|
612 | 3912 |
} |
18364 | 3913 |
#endif /* not SCHTEAM */ |
612 | 3914 |
%}. |
8614 | 3915 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 3916 |
error notNil ifTrue:[ |
23743 | 3917 |
lastErrorNumber := error. |
3918 |
^ self readError:error |
|
16296 | 3919 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3920 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 3921 |
^ self errorWriteOnly |
23538 | 3922 |
|
3923 |
"Modified: / 22-11-2018 / 14:45:15 / Stefan Vogel" |
|
612 | 3924 |
! |
3925 |
||
3926 |
nextBytes:count into:anObject startingAt:start |
|
3927 |
"read the next count bytes into an object and return the number of |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3928 |
bytes read or the number of bytes read, if EOF is encountered before. |
612 | 3929 |
If the receiver is some socket/pipe-like stream, an exception |
3930 |
is raised if the connection is broken. |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3931 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3932 |
Warning: if used with a pipe/socket, this blocks until the requested number |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3933 |
of bytes have been read. See #nextAvailableBytes:into:startingAt: |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3934 |
to only read whats there. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3935 |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3936 |
Notice, that in contrast to other methods, |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3937 |
this does NOT return nil on EOF, but the actual count. |
612 | 3938 |
Thus allowing read of partial blocks. |
3939 |
||
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3940 |
The object must have non-pointer indexed instvars |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3941 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3942 |
or an externalBytes object (with known size). |
612 | 3943 |
If anObject is a string or byteArray and reused, this provides the |
3944 |
fastest possible physical I/O (since no new objects are allocated). |
|
3945 |
||
3946 |
Use with care - non object oriented I/O. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3947 |
Warning: in general, you cannot use this method to pass data from other |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3948 |
architectures (unless you prepared the buffer with care), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3949 |
since it does not care for byte order or float representation." |
612 | 3950 |
|
16296 | 3951 |
|error| |
612 | 3952 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3953 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3954 |
int cnt, offs, ret, _buffered; |
15987 | 3955 |
int objSize, nInstBytes; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3956 |
char *extPtr; |
7195
755c46f9b774
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7118
diff
changeset
|
3957 |
OBJ fp; |
612 | 3958 |
|
1133 | 3959 |
__INST(lastErrorNumber) = nil; |
12548 | 3960 |
if ((__INST(handleType) == nil) |
3961 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3962 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3963 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3964 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 3965 |
if (((fp = __INST(handle)) != nil) |
3966 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3967 |
&& __bothSmallInteger(count, start) |
|
3968 |
) { |
|
3969 |
f = __FILEVal(fp); |
|
3970 |
||
3971 |
cnt = __intVal(count); |
|
3972 |
offs = __intVal(start) - 1; |
|
3973 |
||
3974 |
if (__isExternalBytesLike(anObject)) { |
|
3975 |
OBJ sz; |
|
3976 |
||
3977 |
nInstBytes = 0; |
|
3978 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
|
3979 |
if (extPtr == NULL) goto bad; |
|
3980 |
sz = __externalBytesSize(anObject); |
|
3981 |
if (__isSmallInteger(sz)) { |
|
3982 |
objSize = __intVal(sz); |
|
3983 |
} else { |
|
3984 |
objSize = 0; /* unknown */ |
|
3985 |
} |
|
3986 |
} else { |
|
3987 |
OBJ oClass = __Class(anObject); |
|
3988 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3989 |
||
3990 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3991 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3992 |
case BYTEARRAY: |
|
3993 |
case WORDARRAY: |
|
3994 |
case LONGARRAY: |
|
3995 |
case SWORDARRAY: |
|
3996 |
case SLONGARRAY: |
|
3997 |
case FLOATARRAY: |
|
3998 |
break; |
|
3999 |
case DOUBLEARRAY: |
|
15987 | 4000 |
#ifdef __NEED_DOUBLE_ALIGN |
23743 | 4001 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
15987 | 4002 |
#endif |
23743 | 4003 |
break; |
4004 |
case LONGLONGARRAY: |
|
4005 |
case SLONGLONGARRAY: |
|
16296 | 4006 |
#ifdef __NEED_LONGLONG_ALIGN |
23743 | 4007 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
16296 | 4008 |
#endif |
23743 | 4009 |
break; |
4010 |
default: |
|
4011 |
goto bad; |
|
4012 |
} |
|
4013 |
extPtr = (char *)0; |
|
4014 |
objSize = __Size(anObject) - nInstBytes; |
|
4015 |
} |
|
4016 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
4017 |
_buffered = (__INST(buffered) == true); |
|
4018 |
if (_buffered) { |
|
4019 |
__READING__(f); |
|
4020 |
} |
|
4021 |
||
4022 |
if (extPtr) { |
|
4023 |
__READBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType)); |
|
4024 |
} else { |
|
4025 |
/* |
|
4026 |
* on interrupt, anObject may be moved to another location. |
|
4027 |
* So we pass anObject, and the offset to the __READBYTES_OBJ__ macro. |
|
4028 |
*/ |
|
4029 |
offs += nInstBytes; |
|
4030 |
__READBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType)); |
|
4031 |
} |
|
4032 |
||
4033 |
if (ret > 0) { |
|
4034 |
if (__isSmallInteger(__INST(position))) { |
|
4035 |
INT np = __intVal(__INST(position)) + ret; |
|
4036 |
OBJ t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4037 |
} else { |
|
4038 |
__INST(position) = nil; /* i.e. do not know */ |
|
4039 |
} |
|
4040 |
RETURN (__mkSmallInteger(ret)); |
|
4041 |
} |
|
4042 |
if (ret == 0) { |
|
4043 |
__INST(hitEOF) = true; |
|
4044 |
} else /* ret < 0 */ { |
|
4045 |
__INST(position) = nil; |
|
23538 | 4046 |
# ifdef __win32__ |
23743 | 4047 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4048 |
# endif |
23743 | 4049 |
error = __mkSmallInteger(__threadErrno); |
4050 |
} |
|
4051 |
} |
|
4052 |
} |
|
612 | 4053 |
} |
4054 |
bad: ; |
|
4055 |
%}. |
|
20092 | 4056 |
hitEOF ifTrue:[^ 0]. |
16296 | 4057 |
error notNil ifTrue:[ |
23743 | 4058 |
lastErrorNumber := error. |
4059 |
^ self readError:error |
|
16296 | 4060 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4061 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4062 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
4063 |
" |
|
4064 |
count not integer or arg not bit-like (String, ByteArray etc) |
|
4065 |
" |
|
4066 |
^ self primitiveFailed |
|
23538 | 4067 |
|
4068 |
"Modified: / 22-11-2018 / 14:45:28 / Stefan Vogel" |
|
92 | 4069 |
! |
4070 |
||
19219 | 4071 |
nextInt16MSB:msbFlag |
4072 |
"Read two bytes and return the value as a 16-bit signed Integer. |
|
4073 |
If msbFlag is true, value is read with most-significant byte first, |
|
4074 |
otherwise least-significant byte comes first. |
|
4075 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
4076 |
Works in both binary and text modes." |
|
4077 |
||
4078 |
|error| |
|
4079 |
%{ |
|
4080 |
OBJ fp; |
|
4081 |
||
4082 |
__INST(lastErrorNumber) = nil; |
|
4083 |
if ((__INST(handleType) == nil) |
|
4084 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4085 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4086 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4087 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 4088 |
if (((fp = __INST(handle)) != nil) |
4089 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4090 |
) { |
|
4091 |
FILEPOINTER f; |
|
4092 |
int ret, _buffered; |
|
4093 |
short value; |
|
4094 |
union { |
|
4095 |
unsigned char buffer[2]; |
|
4096 |
short shortVal; |
|
4097 |
} u; |
|
4098 |
||
4099 |
f = __FILEVal(fp); |
|
4100 |
_buffered = (__INST(buffered) == true); |
|
4101 |
if (_buffered) { |
|
4102 |
__READING__(f) |
|
4103 |
} |
|
4104 |
__READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType)); |
|
4105 |
||
4106 |
if (ret == 2) { |
|
4107 |
if (__isSmallInteger(__INST(position))) { |
|
4108 |
INT np = __intVal(__INST(position)) + 2; |
|
4109 |
OBJ t; |
|
4110 |
||
4111 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4112 |
} else { |
|
4113 |
__INST(position) = nil; /* i.e. do not know */ |
|
4114 |
} |
|
4115 |
if (msbFlag == true) { |
|
19219 | 4116 |
#if defined(__MSBFIRST__) |
23743 | 4117 |
value = u.shortVal; |
19219 | 4118 |
#else |
23743 | 4119 |
value = ((u.buffer[0] & 0xFF) << 8) | (u.buffer[1] & 0xFF); |
19219 | 4120 |
#endif |
23743 | 4121 |
} else { |
19219 | 4122 |
#if defined(__LSBFIRST__) |
23743 | 4123 |
value = u.shortVal; |
19219 | 4124 |
#else |
23743 | 4125 |
value = ((u.buffer[1] & 0xFF) << 8) | (u.buffer[0] & 0xFF); |
19219 | 4126 |
#endif |
23743 | 4127 |
} |
4128 |
RETURN (__mkSmallInteger(value)); |
|
4129 |
} |
|
4130 |
||
4131 |
if (ret < 0) { |
|
4132 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4133 |
# ifdef __win32__ |
23743 | 4134 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4135 |
# endif |
23743 | 4136 |
error = __mkSmallInteger(__threadErrno); |
4137 |
} else /* ret == 0 */ { |
|
4138 |
__INST(hitEOF) = true; |
|
4139 |
} |
|
4140 |
} |
|
19219 | 4141 |
} |
4142 |
%}. |
|
4143 |
hitEOF ifTrue:[^ self pastEndRead]. |
|
4144 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
4145 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
4146 |
lastErrorNumber := error. |
|
4147 |
^ self readError:error. |
|
23538 | 4148 |
|
4149 |
"Modified: / 22-11-2018 / 14:45:57 / Stefan Vogel" |
|
612 | 4150 |
! |
4151 |
||
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
4152 |
nextInt32MSB:msbFlag |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
4153 |
"Read four bytes and return the value as a 32-bit signed Integer, |
612 | 4154 |
which may be a LargeInteger. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
4155 |
If msbFlag is true, value is read with most-significant byte first, |
612 | 4156 |
otherwise least-significant byte comes first. |
4157 |
A nil is returned, if EOF is hit before all 4 bytes have been read. |
|
4158 |
Works in both binary and text modes." |
|
4159 |
||
16296 | 4160 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4161 |
%{ |
612 | 4162 |
OBJ fp; |
4163 |
||
1133 | 4164 |
__INST(lastErrorNumber) = nil; |
12548 | 4165 |
if ((__INST(handleType) == nil) |
4166 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4167 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4168 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4169 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4170 |
if (((fp = __INST(handle)) != nil) |
4171 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4172 |
) { |
|
4173 |
FILEPOINTER f; |
|
4174 |
int ret, _buffered; |
|
4175 |
int value; |
|
4176 |
union { |
|
4177 |
unsigned char buffer[4]; |
|
4178 |
int intVal; |
|
4179 |
} u; |
|
4180 |
||
4181 |
f = __FILEVal(fp); |
|
4182 |
_buffered = (__INST(buffered) == true); |
|
4183 |
if (_buffered) { |
|
4184 |
__READING__(f) |
|
4185 |
} |
|
4186 |
__READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType)); |
|
4187 |
||
4188 |
if (ret == 4) { |
|
4189 |
if (__isSmallInteger(__INST(position))) { |
|
4190 |
INT np = __intVal(__INST(position)) + 4; |
|
4191 |
OBJ t; |
|
4192 |
||
4193 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4194 |
} else { |
|
4195 |
__INST(position) = nil; /* i.e. do not know */ |
|
4196 |
} |
|
4197 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4198 |
#if defined(__MSBFIRST__) |
23743 | 4199 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4200 |
#else |
23743 | 4201 |
value = (u.buffer[0] & 0xFF); |
4202 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
|
4203 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
|
4204 |
value = (value << 8) | (u.buffer[3] & 0xFF); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4205 |
#endif |
23743 | 4206 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4207 |
#if defined(__LSBFIRST__) |
23743 | 4208 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4209 |
#else |
23743 | 4210 |
value = (u.buffer[3] & 0xFF); |
4211 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
|
4212 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
|
4213 |
value = (value << 8) | (u.buffer[0] & 0xFF); |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4214 |
#endif |
23743 | 4215 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4216 |
#if __POINTER_SIZE__ == 8 |
23743 | 4217 |
RETURN ( __mkSmallInteger(value)); |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4218 |
#else |
23743 | 4219 |
RETURN ( __MKINT(value) ); |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4220 |
#endif |
23743 | 4221 |
} |
4222 |
||
4223 |
if (ret < 0) { |
|
4224 |
__INST(position) = nil; |
|
23538 | 4225 |
# ifdef __win32__ |
23743 | 4226 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4227 |
# endif |
23743 | 4228 |
error = __mkSmallInteger(__threadErrno); |
4229 |
} else /* ret == 0 */ { |
|
4230 |
__INST(hitEOF) = true; |
|
4231 |
} |
|
4232 |
} |
|
612 | 4233 |
} |
4234 |
%}. |
|
8614 | 4235 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4236 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4237 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4238 |
lastErrorNumber := error. |
4239 |
^ self readError:error. |
|
23538 | 4240 |
|
4241 |
"Modified: / 22-11-2018 / 14:46:05 / Stefan Vogel" |
|
362 | 4242 |
! |
4243 |
||
19219 | 4244 |
nextUnsignedInt16MSB:msbFlag |
4245 |
"Read two bytes and return the value as a 16-bit unsigned Integer. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
4246 |
If msbFlag is true, value is read with most-significant byte first, |
612 | 4247 |
otherwise least-significant byte comes first. |
4248 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
4249 |
Works in both binary and text modes." |
|
4250 |
||
16296 | 4251 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4252 |
%{ |
612 | 4253 |
OBJ fp; |
4254 |
||
1133 | 4255 |
__INST(lastErrorNumber) = nil; |
12548 | 4256 |
if ((__INST(handleType) == nil) |
4257 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4258 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4259 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4260 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4261 |
if (((fp = __INST(handle)) != nil) |
4262 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4263 |
) { |
|
4264 |
FILEPOINTER f; |
|
4265 |
int ret, _buffered; |
|
4266 |
unsigned int value; |
|
4267 |
union { |
|
4268 |
unsigned char buffer[2]; |
|
4269 |
unsigned short shortVal; |
|
4270 |
} u; |
|
4271 |
||
4272 |
f = __FILEVal(fp); |
|
4273 |
_buffered = (__INST(buffered) == true); |
|
4274 |
if (_buffered) { |
|
4275 |
__READING__(f) |
|
4276 |
} |
|
4277 |
__READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType)); |
|
4278 |
||
4279 |
if (ret == 2) { |
|
4280 |
if (__isSmallInteger(__INST(position))) { |
|
4281 |
INT np = __intVal(__INST(position)) + 2; |
|
4282 |
OBJ t; |
|
4283 |
||
4284 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4285 |
} else { |
|
4286 |
__INST(position) = nil; /* i.e. do not know */ |
|
4287 |
} |
|
4288 |
if (msbFlag == true) { |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4289 |
#if defined(__MSBFIRST__) |
23743 | 4290 |
value = u.shortVal; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4291 |
#else |
23743 | 4292 |
value = (u.buffer[0] << 8) | u.buffer[1]; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4293 |
#endif |
23743 | 4294 |
} else { |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4295 |
#if defined(__LSBFIRST__) |
23743 | 4296 |
value = u.shortVal; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4297 |
#else |
23743 | 4298 |
value = (u.buffer[1] << 8) | u.buffer[0]; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4299 |
#endif |
23743 | 4300 |
} |
4301 |
RETURN (__mkSmallInteger(value)); |
|
4302 |
} |
|
4303 |
||
4304 |
if (ret < 0) { |
|
4305 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4306 |
# ifdef __win32__ |
23743 | 4307 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4308 |
# endif |
23743 | 4309 |
error = __mkSmallInteger(__threadErrno); |
4310 |
} else /* ret == 0 */ { |
|
4311 |
__INST(hitEOF) = true; |
|
4312 |
} |
|
4313 |
} |
|
612 | 4314 |
} |
4315 |
%}. |
|
8614 | 4316 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4317 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4318 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4319 |
lastErrorNumber := error. |
4320 |
^ self readError:error. |
|
23538 | 4321 |
|
4322 |
"Modified: / 22-11-2018 / 14:49:05 / Stefan Vogel" |
|
612 | 4323 |
! |
4324 |
||
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
4325 |
nextUnsignedInt32MSB:msbFlag |
612 | 4326 |
"Read four bytes and return the value as a 32-bit unsigned Integer, which may be |
4327 |
a LargeInteger. |
|
4328 |
If msbFlag is true, value is read with most-significant byte first, otherwise |
|
4329 |
least-significant byte comes first. |
|
4330 |
A nil is returned, if endOfFile occurs before all 4 bytes have been read. |
|
4331 |
Works in both binary and text modes." |
|
4332 |
||
16296 | 4333 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4334 |
%{ |
612 | 4335 |
OBJ fp; |
4336 |
||
1133 | 4337 |
__INST(lastErrorNumber) = nil; |
12548 | 4338 |
if ((__INST(handleType) == nil) |
4339 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4340 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4341 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4342 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4343 |
if (((fp = __INST(handle)) != nil) |
4344 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4345 |
) { |
|
4346 |
FILEPOINTER f; |
|
4347 |
int ret, _buffered; |
|
4348 |
unsigned INT value; |
|
4349 |
union { |
|
4350 |
unsigned char buffer[4]; |
|
4351 |
unsigned int intVal; |
|
4352 |
} u; |
|
4353 |
||
4354 |
f = __FILEVal(fp); |
|
4355 |
_buffered = (__INST(buffered) == true); |
|
4356 |
if (_buffered) { |
|
4357 |
__READING__(f) |
|
4358 |
} |
|
4359 |
__READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType)); |
|
4360 |
||
4361 |
if (ret == 4) { |
|
4362 |
if (__isSmallInteger(__INST(position))) { |
|
4363 |
INT np = __intVal(__INST(position)) + 4; |
|
4364 |
OBJ t; |
|
4365 |
||
4366 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4367 |
} else { |
|
4368 |
__INST(position) = nil; /* i.e. do not know */ |
|
4369 |
} |
|
4370 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4371 |
#if defined(__MSBFIRST__) |
23743 | 4372 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4373 |
#else |
23743 | 4374 |
value = u.buffer[0]; |
4375 |
value = (value << 8) | u.buffer[1]; |
|
4376 |
value = (value << 8) | u.buffer[2]; |
|
4377 |
value = (value << 8) | u.buffer[3]; |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4378 |
#endif |
23743 | 4379 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4380 |
#if defined(__LSBFIRST__) |
23743 | 4381 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4382 |
#else |
23743 | 4383 |
value = u.buffer[3]; |
4384 |
value = (value << 8) | u.buffer[2]; |
|
4385 |
value = (value << 8) | u.buffer[1]; |
|
4386 |
value = (value << 8) | u.buffer[0]; |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4387 |
#endif |
23743 | 4388 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4389 |
#if __POINTER_SIZE__ == 8 |
23743 | 4390 |
value &= 0xFFFFFFFF; |
4391 |
RETURN (__mkSmallInteger(value)); |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4392 |
#else |
23743 | 4393 |
if (value <= _MAX_INT) { |
4394 |
RETURN (__mkSmallInteger(value)); |
|
4395 |
} |
|
4396 |
RETURN (__MKULARGEINT(value) ); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4397 |
#endif |
23743 | 4398 |
} |
4399 |
||
4400 |
if (ret < 0) { |
|
4401 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4402 |
# ifdef __win32__ |
23743 | 4403 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4404 |
# endif |
23743 | 4405 |
error = __mkSmallInteger(__threadErrno); |
4406 |
} else /* ret == 0 */ { |
|
4407 |
__INST(hitEOF) = true; |
|
4408 |
} |
|
4409 |
} |
|
612 | 4410 |
} |
4411 |
%}. |
|
8614 | 4412 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4413 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4414 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4415 |
lastErrorNumber := error. |
4416 |
^ self readError:error. |
|
23538 | 4417 |
|
4418 |
"Modified: / 22-11-2018 / 14:49:23 / Stefan Vogel" |
|
612 | 4419 |
! |
4420 |
||
4421 |
nextWord |
|
15452 | 4422 |
<resource: #obsolete> |
612 | 4423 |
"in text-mode: |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4424 |
read the alphaNumeric next word (i.e. up to non letter-or-digit). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4425 |
return a string containing those characters. |
612 | 4426 |
in binary-mode: |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4427 |
read two bytes (msb-first) and return the value as a 16-bit |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4428 |
unsigned Integer (for compatibility with other smalltalks)" |
612 | 4429 |
|
4430 |
binary ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4431 |
self obsoleteMethodWarning:'use #nextUnsignedInt16MSB:true'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4432 |
^ self nextUnsignedInt16MSB:true |
92 | 4433 |
]. |
14518 | 4434 |
self obsoleteMethodWarning:'use #nextAlphaNumericWord'. |
612 | 4435 |
^ self nextAlphaNumericWord |
4436 |
! ! |
|
4437 |
||
4438 |
!ExternalStream methodsFor:'non homogenous writing'! |
|
4439 |
||
4440 |
nextPutByte:aByteValue |
|
4441 |
"write a byte. |
|
4442 |
Works in both binary and text modes." |
|
4443 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4444 |
|error| |
16296 | 4445 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4446 |
%{ |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
4447 |
OBJ fp; |
612 | 4448 |
|
1133 | 4449 |
__INST(lastErrorNumber) = nil; |
12548 | 4450 |
if ((__INST(handleType) == nil) |
4451 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4452 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4453 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4454 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4455 |
if (((fp = __INST(handle)) != nil) |
4456 |
&& (__INST(mode) != @symbol(readonly)) |
|
4457 |
&& __isSmallInteger(aByteValue) |
|
4458 |
||
4459 |
) { |
|
4460 |
int _buffered = (__INST(buffered) == true); |
|
4461 |
FILEPOINTER f = __FILEVal(fp); |
|
4462 |
char c = __intVal(aByteValue); |
|
4463 |
int cnt; |
|
4464 |
||
4465 |
if (_buffered) { |
|
4466 |
__WRITING__(f) |
|
4467 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4468 |
#ifdef __win32__ |
23743 | 4469 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
4470 |
cnt = __win32_fwrite(&c, 1, 1, f); |
|
4471 |
} else |
|
9053
f3f3d48d6f44
fix writing to stdout/stderr for winstx non-console operation
Claus Gittinger <cg@exept.de>
parents:
9024
diff
changeset
|
4472 |
#endif |
23743 | 4473 |
{ |
4474 |
__WRITEBYTE__(cnt, f, &c, _buffered, __INST(handleType)); |
|
4475 |
} |
|
4476 |
if (cnt == 1) { |
|
4477 |
if (__isSmallInteger(__INST(position))) { |
|
4478 |
INT np = __intVal(__INST(position)) + 1; |
|
4479 |
OBJ t; |
|
4480 |
||
4481 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4482 |
} else { |
|
4483 |
__INST(position) = nil; /* i.e. do not know */ |
|
4484 |
} |
|
4485 |
RETURN (self); |
|
4486 |
} |
|
4487 |
if (cnt < 0) { |
|
4488 |
__INST(position) = nil; /* i.e. do not know */ |
|
4489 |
} |
|
23538 | 4490 |
# ifdef __win32__ |
23743 | 4491 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4492 |
# endif |
23743 | 4493 |
error = __mkSmallInteger(__threadErrno); |
4494 |
} |
|
612 | 4495 |
} |
4496 |
%}. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4497 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4498 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
16296 | 4499 |
lastErrorNumber := error. |
4500 |
self writeError:error. |
|
23538 | 4501 |
|
4502 |
"Modified: / 22-11-2018 / 14:47:34 / Stefan Vogel" |
|
612 | 4503 |
! |
4504 |
||
19219 | 4505 |
nextPutInt16:anIntegerOrCharacter MSB:msbFlag |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4506 |
"Write the argument, anIntegerOrCharacter as a short (two bytes). |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4507 |
If msbFlag is true, data is written most-significant byte first; |
19615 | 4508 |
otherwise least first. |
22266 | 4509 |
Notice that integers in the range 16r-8000 to +16rFFFF can be written |
19615 | 4510 |
(i.e. both signed and unsigned int32 values can be written. |
19219 | 4511 |
Works in both binary and text modes." |
4512 |
||
4513 |
|error| |
|
4514 |
%{ |
|
4515 |
int num; |
|
4516 |
union { |
|
23743 | 4517 |
char bytes[2]; |
4518 |
short shortVal; |
|
19219 | 4519 |
} u; |
4520 |
OBJ fp; |
|
4521 |
||
4522 |
__INST(lastErrorNumber) = nil; |
|
4523 |
if ((__INST(handleType) == nil) |
|
4524 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4525 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4526 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4527 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 4528 |
if (((fp = __INST(handle)) != nil) |
4529 |
&& (__INST(mode) != @symbol(readonly)) |
|
4530 |
) { |
|
4531 |
FILEPOINTER f = __FILEVal(fp); |
|
4532 |
int _buffered = (__INST(buffered) == true); |
|
4533 |
int cnt; |
|
4534 |
||
4535 |
if (__isSmallInteger(anIntegerOrCharacter)) { |
|
4536 |
num = __intVal(anIntegerOrCharacter); |
|
4537 |
} else if (__isCharacter(anIntegerOrCharacter)) { |
|
4538 |
num = __smallIntegerVal(__characterVal(anIntegerOrCharacter)); |
|
4539 |
} else |
|
4540 |
goto out; |
|
4541 |
||
4542 |
if (msbFlag == true) { |
|
19219 | 4543 |
#if defined(__MSBFIRST__) |
23743 | 4544 |
u.shortVal = num; |
19219 | 4545 |
#else |
23743 | 4546 |
u.bytes[0] = (num >> 8) & 0xFF; |
4547 |
u.bytes[1] = num & 0xFF; |
|
19219 | 4548 |
#endif |
23743 | 4549 |
} else { |
19219 | 4550 |
#if defined(__LSBFIRST__) |
23743 | 4551 |
u.shortVal = num; |
19219 | 4552 |
#else |
23743 | 4553 |
u.bytes[1] = (num >> 8) & 0xFF; |
4554 |
u.bytes[0] = num & 0xFF; |
|
19219 | 4555 |
#endif |
23743 | 4556 |
} |
4557 |
||
4558 |
if (_buffered) { |
|
4559 |
__WRITING__(f) |
|
4560 |
} |
|
4561 |
__WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType)); |
|
4562 |
||
4563 |
if (cnt == 2) { |
|
4564 |
if (__isSmallInteger(__INST(position))) { |
|
4565 |
INT np = __intVal(__INST(position)) + 2; |
|
4566 |
OBJ t; |
|
4567 |
||
4568 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4569 |
} else { |
|
4570 |
__INST(position) = nil; /* i.e. do not know */ |
|
4571 |
} |
|
4572 |
RETURN ( self ); |
|
4573 |
} |
|
4574 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4575 |
# ifdef __win32__ |
23743 | 4576 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4577 |
# endif |
23743 | 4578 |
error = __mkSmallInteger(__threadErrno); |
4579 |
} |
|
19219 | 4580 |
} |
4581 |
out:; |
|
4582 |
%}. |
|
4583 |
error notNil ifTrue:[ |
|
23743 | 4584 |
lastErrorNumber := error. |
4585 |
self writeError:error. |
|
4586 |
^ self |
|
19219 | 4587 |
]. |
4588 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4589 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
4590 |
self argumentMustBeInteger |
|
22266 | 4591 |
|
4592 |
"Modified: / 19-09-2017 / 16:32:29 / stefan" |
|
23538 | 4593 |
"Modified: / 22-11-2018 / 14:48:14 / Stefan Vogel" |
19219 | 4594 |
! |
4595 |
||
19615 | 4596 |
nextPutInt16LSB:anIntegerOrCharacter |
4597 |
"do not remove. |
|
4598 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4599 |
|
19615 | 4600 |
self nextPutInt16:anIntegerOrCharacter MSB:false |
4601 |
! |
|
4602 |
||
4603 |
nextPutInt16MSB:anIntegerOrCharacter |
|
4604 |
"do not remove. |
|
4605 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4606 |
|
19615 | 4607 |
self nextPutInt16:anIntegerOrCharacter MSB:true |
4608 |
! |
|
4609 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4610 |
nextPutInt16NATIVE:anIntegerOrCharacter |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4611 |
"Write the argument, anIntegerOrCharacter as a short (two bytes) in native byte order. |
23934 | 4612 |
This is the CPU-specific byte order (LSB on x86 and VAX, MSB on sparc, and possibly on ARM). |
22266 | 4613 |
Notice that integers in the range 16r-8000 to +16rFFFF can be written |
19615 | 4614 |
(i.e. both signed and unsigned int32 values can be written. |
4615 |
Works in both binary and text modes." |
|
4616 |
||
4617 |
|error| |
|
4618 |
%{ |
|
4619 |
int num; |
|
4620 |
union { |
|
23934 | 4621 |
char bytes[2]; |
4622 |
short shortVal; |
|
19615 | 4623 |
} u; |
4624 |
OBJ fp; |
|
4625 |
||
4626 |
__INST(lastErrorNumber) = nil; |
|
4627 |
if ((__INST(handleType) == nil) |
|
4628 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4629 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4630 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4631 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23934 | 4632 |
if (((fp = __INST(handle)) != nil) |
4633 |
&& (__INST(mode) != @symbol(readonly)) |
|
4634 |
) { |
|
4635 |
FILEPOINTER f = __FILEVal(fp); |
|
4636 |
int _buffered = (__INST(buffered) == true); |
|
4637 |
int cnt; |
|
4638 |
||
4639 |
if (__isSmallInteger(anIntegerOrCharacter)) { |
|
4640 |
num = __intVal(anIntegerOrCharacter); |
|
4641 |
} else if (__isCharacter(anIntegerOrCharacter)) { |
|
4642 |
num = __smallIntegerVal(__characterVal(anIntegerOrCharacter)); |
|
4643 |
} else |
|
4644 |
goto out; |
|
4645 |
||
4646 |
u.shortVal = num; |
|
4647 |
||
4648 |
if (_buffered) { |
|
4649 |
__WRITING__(f) |
|
4650 |
} |
|
4651 |
__WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType)); |
|
4652 |
||
4653 |
if (cnt == 2) { |
|
4654 |
if (__isSmallInteger(__INST(position))) { |
|
4655 |
INT np = __intVal(__INST(position)) + 2; |
|
4656 |
OBJ t; |
|
4657 |
||
4658 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4659 |
} else { |
|
4660 |
__INST(position) = nil; /* i.e. do not know */ |
|
4661 |
} |
|
4662 |
RETURN ( self ); |
|
4663 |
} |
|
4664 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4665 |
# ifdef __win32__ |
23934 | 4666 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4667 |
# endif |
23934 | 4668 |
error = __mkSmallInteger(__threadErrno); |
4669 |
} |
|
19615 | 4670 |
} |
4671 |
out:; |
|
4672 |
%}. |
|
4673 |
self nextPutInt16:anIntegerOrCharacter MSB:(UninterpretedBytes isBigEndian). |
|
22266 | 4674 |
|
4675 |
"Modified: / 19-09-2017 / 16:32:40 / stefan" |
|
23538 | 4676 |
"Modified: / 22-11-2018 / 14:48:23 / Stefan Vogel" |
23934 | 4677 |
"Modified: / 17-03-2019 / 14:52:06 / Claus Gittinger" |
19615 | 4678 |
! |
4679 |
||
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
4680 |
nextPutInt32:aNumber MSB:msbFlag |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4681 |
"Write the argument, aNumber as a long (four bytes). |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4682 |
If msbFlag is true, data is written most-significant byte first; |
19615 | 4683 |
otherwise least first. |
22266 | 4684 |
Notice that integers in the range 16r-80000000 to +16rFFFFFFFF can be written |
19615 | 4685 |
(i.e. both signed and unsigned int32 values can be written. |
612 | 4686 |
Works in both binary and text modes." |
4687 |
||
16296 | 4688 |
|error| |
4689 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4690 |
%{ |
612 | 4691 |
int num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4692 |
union { |
23743 | 4693 |
char bytes[4]; |
4694 |
int intVal; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4695 |
} u; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4696 |
OBJ fp; |
612 | 4697 |
|
1133 | 4698 |
__INST(lastErrorNumber) = nil; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4699 |
if (__isSmallInteger(aNumber)) { |
23743 | 4700 |
num = __intVal(aNumber); |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4701 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4702 |
#if __POINTER_SIZE__ == 8 |
23743 | 4703 |
// always more than 4-bytes |
4704 |
goto badArg; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4705 |
#else |
23743 | 4706 |
num = __longIntVal(aNumber); |
4707 |
if (num == 0) { |
|
4708 |
num = __signedLongIntVal(aNumber); |
|
4709 |
if (num == 0) { |
|
4710 |
/* bad arg or out-of-range integer |
|
4711 |
* (handled by the fallBack code) |
|
4712 |
*/ |
|
4713 |
goto badArg; |
|
4714 |
} |
|
4715 |
} |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4716 |
#endif |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4717 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4718 |
|
12548 | 4719 |
if ((__INST(handleType) == nil) |
4720 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4721 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4722 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4723 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4724 |
if (((fp = __INST(handle)) != nil) |
4725 |
&& (__INST(mode) != @symbol(readonly)) |
|
4726 |
) { |
|
4727 |
int _buffered = (__INST(buffered) == true); |
|
4728 |
FILEPOINTER f = __FILEVal(fp); |
|
4729 |
int cnt; |
|
4730 |
||
4731 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4732 |
#if defined(__MSBFIRST__) |
23743 | 4733 |
u.intVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4734 |
#else |
23743 | 4735 |
u.bytes[0] = (num >> 24) & 0xFF; |
4736 |
u.bytes[1] = (num >> 16) & 0xFF; |
|
4737 |
u.bytes[2] = (num >> 8) & 0xFF; |
|
4738 |
u.bytes[3] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4739 |
#endif |
23743 | 4740 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4741 |
#if defined(__LSBFIRST__) |
23743 | 4742 |
u.intVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4743 |
#else |
23743 | 4744 |
u.bytes[3] = (num >> 24) & 0xFF; |
4745 |
u.bytes[2] = (num >> 16) & 0xFF; |
|
4746 |
u.bytes[1] = (num >> 8) & 0xFF; |
|
4747 |
u.bytes[0] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4748 |
#endif |
23743 | 4749 |
} |
4750 |
||
4751 |
if (_buffered) { |
|
4752 |
__WRITING__(f) |
|
4753 |
} |
|
4754 |
__WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType)); |
|
4755 |
||
4756 |
if (cnt == 4) { |
|
4757 |
if (__isSmallInteger(__INST(position))) { |
|
4758 |
INT np = __intVal(__INST(position)) + 4; |
|
4759 |
OBJ t; |
|
4760 |
||
4761 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4762 |
} else { |
|
4763 |
__INST(position) = nil; /* i.e. do not know */ |
|
4764 |
} |
|
4765 |
RETURN ( self ); |
|
4766 |
} |
|
4767 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4768 |
# ifdef __win32__ |
23743 | 4769 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4770 |
# endif |
23743 | 4771 |
error = __mkSmallInteger(__threadErrno); |
4772 |
} |
|
612 | 4773 |
} |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4774 |
badArg: ; |
612 | 4775 |
%}. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4776 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4777 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
16296 | 4778 |
error notNil ifTrue:[ |
23743 | 4779 |
lastErrorNumber := error. |
4780 |
self writeError:error. |
|
4781 |
^ self |
|
16296 | 4782 |
]. |
612 | 4783 |
|
4784 |
aNumber isInteger ifTrue:[ |
|
23743 | 4785 |
^ super nextPutInt32:aNumber MSB:msbFlag |
92 | 4786 |
]. |
612 | 4787 |
self argumentMustBeInteger |
22266 | 4788 |
|
4789 |
"Modified: / 19-09-2017 / 16:32:50 / stefan" |
|
23538 | 4790 |
"Modified: / 22-11-2018 / 14:48:29 / Stefan Vogel" |
19615 | 4791 |
! |
4792 |
||
4793 |
nextPutInt32LSB:anIntegerOrCharacter |
|
4794 |
"do not remove. |
|
4795 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4796 |
|
19615 | 4797 |
self nextPutInt32:anIntegerOrCharacter MSB:false |
4798 |
! |
|
4799 |
||
4800 |
nextPutInt32MSB:anIntegerOrCharacter |
|
4801 |
"do not remove. |
|
4802 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4803 |
|
19615 | 4804 |
self nextPutInt32:anIntegerOrCharacter MSB:true |
4805 |
! |
|
4806 |
||
4807 |
nextPutInt32NATIVE:anInteger |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4808 |
"Write the argument, anInteger as a long (four bytes) in native byte order. |
23934 | 4809 |
This is the CPU-specific byte order (LSB on x86 and VAX, MSB on sparc and possibly on ARM). |
22266 | 4810 |
Notice that integers in the range 16r-80000000 to +16rFFFFFFFF can be written |
19615 | 4811 |
(i.e. both signed and unsigned int32 values can be written. |
4812 |
Works in both binary and text modes. |
|
4813 |
Notice: this message should not be sent explicitly by ANY program. |
|
23934 | 4814 |
the following implementation replaces the code of either nextPutInt32MSB or LSB |
4815 |
dynamically (see #initialize on the class side)" |
|
19615 | 4816 |
|
4817 |
|error| |
|
4818 |
||
4819 |
%{ |
|
4820 |
int num; |
|
4821 |
union { |
|
23934 | 4822 |
char bytes[4]; |
4823 |
int intVal; |
|
19615 | 4824 |
} u; |
4825 |
OBJ fp; |
|
4826 |
||
4827 |
__INST(lastErrorNumber) = nil; |
|
4828 |
if (__isSmallInteger(anInteger)) { |
|
23934 | 4829 |
num = __intVal(anInteger); |
19615 | 4830 |
} else { |
4831 |
#if __POINTER_SIZE__ == 8 |
|
23934 | 4832 |
// always more than 4-bytes |
4833 |
goto badArg; |
|
19615 | 4834 |
#else |
23934 | 4835 |
num = __longIntVal(anInteger); |
4836 |
if (num == 0) { |
|
4837 |
num = __signedLongIntVal(anInteger); |
|
4838 |
if (num == 0) { |
|
4839 |
/* bad arg or out-of-range integer |
|
4840 |
* (handled by the fallBack code) |
|
4841 |
*/ |
|
4842 |
goto badArg; |
|
4843 |
} |
|
4844 |
} |
|
19615 | 4845 |
#endif |
4846 |
} |
|
4847 |
||
4848 |
if ((__INST(handleType) == nil) |
|
4849 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4850 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4851 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4852 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23934 | 4853 |
if (((fp = __INST(handle)) != nil) |
4854 |
&& (__INST(mode) != @symbol(readonly)) |
|
4855 |
) { |
|
4856 |
int _buffered = (__INST(buffered) == true); |
|
4857 |
FILEPOINTER f = __FILEVal(fp); |
|
4858 |
int cnt; |
|
4859 |
||
4860 |
u.intVal = num; |
|
4861 |
if (_buffered) { |
|
4862 |
__WRITING__(f) |
|
4863 |
} |
|
4864 |
__WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType)); |
|
4865 |
||
4866 |
if (cnt == 4) { |
|
4867 |
if (__isSmallInteger(__INST(position))) { |
|
4868 |
INT np = __intVal(__INST(position)) + 4; |
|
4869 |
OBJ t; |
|
4870 |
||
4871 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4872 |
} else { |
|
4873 |
__INST(position) = nil; /* i.e. do not know */ |
|
4874 |
} |
|
4875 |
RETURN ( self ); |
|
4876 |
} |
|
4877 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4878 |
# ifdef __win32__ |
23934 | 4879 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4880 |
# endif |
23934 | 4881 |
error = __mkSmallInteger(__threadErrno); |
4882 |
} |
|
19615 | 4883 |
} |
4884 |
badArg: ; |
|
4885 |
%}. |
|
4886 |
self nextPutInt32:anInteger MSB:(UninterpretedBytes isBigEndian) |
|
22266 | 4887 |
|
4888 |
"Modified: / 19-09-2017 / 16:32:59 / stefan" |
|
23538 | 4889 |
"Modified: / 22-11-2018 / 14:48:41 / Stefan Vogel" |
23934 | 4890 |
"Modified: / 17-03-2019 / 14:52:23 / Claus Gittinger" |
20092 | 4891 |
! |
4892 |
||
4893 |
nextPutUtf16:aCharacter |
|
4894 |
"append my UTF-16 MSB representation to the argument, aStream. |
|
4895 |
UTF-16 can encode only characters with code points between 0 to 16r10FFFF." |
|
4896 |
||
4897 |
self nextPutUtf16Bytes:aCharacter MSB:true |
|
4898 |
||
4899 |
" |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4900 |
(FileStream newTemporary |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4901 |
nextPutUtf16:$B; |
24628 | 4902 |
nextPutUtf16:$Ä; |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4903 |
nextPutUtf16:(Character codePoint:16r10CCCC); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4904 |
reset; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4905 |
binary; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4906 |
contents) |
20092 | 4907 |
" |
4908 |
! |
|
4909 |
||
4910 |
nextPutUtf16:aCharacter MSB:msbFlag |
|
4911 |
"append my UTF-16 MSB representation to the argument, aStream. |
|
4912 |
UTF-16 can encode only characters with code points between 0 to 16r10FFFF." |
|
4913 |
||
4914 |
self nextPutUtf16Bytes:aCharacter MSB:msbFlag |
|
10 | 4915 |
! ! |
612 | 4916 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4917 |
!ExternalStream methodsFor:'positioning'! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4918 |
|
15619 | 4919 |
position |
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4920 |
self subclassResponsibility |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4921 |
! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4922 |
|
15619 | 4923 |
position:index0Based |
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4924 |
self subclassResponsibility |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4925 |
! ! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4926 |
|
12631 | 4927 |
!ExternalStream methodsFor:'printing & storing'! |
4928 |
||
4929 |
printOn:aStream |
|
14068 | 4930 |
aStream |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4931 |
nextPutAll:self className; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4932 |
nextPut:$(. |
22245 | 4933 |
handleType printOn:aStream. |
4934 |
aStream nextPutAll:':('. |
|
12631 | 4935 |
handle printOn:aStream. |
4936 |
aStream nextPutAll:'))' |
|
4937 |
! ! |
|
4938 |
||
612 | 4939 |
!ExternalStream methodsFor:'private'! |
4940 |
||
4941 |
clearEOF |
|
4942 |
hitEOF := false |
|
20987 | 4943 |
! |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4944 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4945 |
closeFile |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4946 |
"low level close - may be redefined in subclasses |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4947 |
Don't send this message, send #close instead" |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4948 |
|
12674 | 4949 |
|fp error| |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4950 |
|
20679 | 4951 |
handle isNil ifTrue:[ |
23743 | 4952 |
^ self. |
20679 | 4953 |
]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4954 |
fp := handle. |
19767 | 4955 |
"/ (didWrite==true and:[binary ~~ true and:[eolMode = #crlf]]) ifTrue: [ self breakPoint:#sr ]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4956 |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4957 |
%{ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4958 |
int rslt; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4959 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4960 |
if (__INST(handleType) == @symbol(socketHandle)) { |
23743 | 4961 |
SOCKET sock = (SOCKET)(__FILEVal(fp)); |
4962 |
||
23879 | 4963 |
// whether the close() will be successful or not - the handle is invalid now! |
4964 |
__INST(handle) = nil; |
|
4965 |
||
23743 | 4966 |
if (@global(FileOpenTrace) == true) { |
4967 |
fprintf(stderr, "close socket [ExternalStream] %"_lx_"\n", (INT)sock); |
|
4968 |
} |
|
4969 |
||
4970 |
do { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4971 |
#ifdef __win32__ |
23743 | 4972 |
rslt = __STX_WSA_NOINT_CALL1("closesocket", closesocket, sock); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4973 |
#else |
23743 | 4974 |
__threadErrno = 0; |
4975 |
__BEGIN_INTERRUPTABLE__ |
|
4976 |
rslt = close(sock); |
|
4977 |
__END_INTERRUPTABLE__ |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4978 |
#endif |
23743 | 4979 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4980 |
} else if ((__INST(handleType) == nil) |
23743 | 4981 |
|| (__INST(handleType) == @symbol(filePointer)) |
4982 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4983 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4984 |
{ |
23743 | 4985 |
FILEPOINTER f = __FILEVal(fp); |
4986 |
||
23879 | 4987 |
// whether the close() will be successful or not - the handle is invalid now! |
4988 |
__INST(handle) = nil; |
|
4989 |
||
23743 | 4990 |
if (@global(FileOpenTrace) == true) { |
4991 |
fprintf(stderr, "fclose [ExternalStream] %"_lx_"\n", (INT)f); |
|
4992 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4993 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4994 |
#ifdef __win32__ |
23743 | 4995 |
if (__INST(mode) != @symbol(readonly) && __INST(buffered) != false) { |
4996 |
// do a fflush() first, so that fclose() doesn't block |
|
4997 |
// we suspect, that EINTR causes problems in fclose() |
|
4998 |
do { |
|
4999 |
__threadErrno = 0; |
|
5000 |
rslt = __STX_C_CALL1("fflush", fflush, f); |
|
5001 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
5002 |
if (rslt < 0) |
|
5003 |
goto err; |
|
5004 |
} |
|
5005 |
do { |
|
5006 |
__threadErrno = 0; |
|
5007 |
rslt = __STX_C_NOINT_CALL1("fclose", fclose, f); |
|
5008 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5009 |
#else |
23743 | 5010 |
// cg: not sure why, but on osx, I get blocked occasionally in fclose |
5011 |
// lets try this: |
|
5012 |
if ((__INST(mode) != @symbol(readonly)) && (__INST(buffered) != false)) { |
|
5013 |
// do a fflush() first, so that fclose() doesn't block |
|
5014 |
// we suspect, that EINTR causes problems in fclose() |
|
5015 |
do { |
|
5016 |
clearerr(f); |
|
5017 |
__threadErrno = 0; |
|
5018 |
__BEGIN_INTERRUPTABLE__ |
|
5019 |
rslt = fflush(f); |
|
5020 |
__END_INTERRUPTABLE__ |
|
5021 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
5022 |
if (rslt < 0) |
|
5023 |
goto err; |
|
5024 |
} |
|
5025 |
do { |
|
5026 |
clearerr(f); |
|
5027 |
__threadErrno = 0; |
|
5028 |
__BEGIN_INTERRUPTABLE__ |
|
5029 |
rslt = fclose(f); |
|
5030 |
__END_INTERRUPTABLE__ |
|
5031 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5032 |
#endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5033 |
} else { |
23743 | 5034 |
error = @symbol(badHandleType); |
5035 |
goto out; |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5036 |
} |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5037 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5038 |
if (rslt < 0) { |
23538 | 5039 |
err: |
5040 |
# ifdef __win32__ |
|
23743 | 5041 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5042 |
# endif |
23743 | 5043 |
error = __mkSmallInteger(__threadErrno); |
5044 |
goto out; |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5045 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5046 |
RETURN (self); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5047 |
|
12674 | 5048 |
out:; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5049 |
%}. |
12674 | 5050 |
|
5051 |
error notNil ifTrue:[ |
|
23743 | 5052 |
error isInteger ifTrue:[ |
5053 |
lastErrorNumber := error. |
|
5054 |
mode == #readonly ifTrue:[ |
|
5055 |
self ioError:error. |
|
5056 |
] ifFalse:[ |
|
5057 |
self writeError:error. |
|
5058 |
]. |
|
5059 |
^ self. |
|
5060 |
]. |
|
5061 |
self primitiveFailed:error. |
|
5062 |
^ self. |
|
12674 | 5063 |
]. |
5064 |
||
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5065 |
"/ fallback for rel5 |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5066 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5067 |
fp := handle. |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5068 |
fp notNil ifTrue:[ |
23743 | 5069 |
handle := nil. |
5070 |
self closeFile:fp |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5071 |
] |
22681 | 5072 |
|
5073 |
"Modified: / 19-04-2018 / 10:57:54 / stefan" |
|
23538 | 5074 |
"Modified: / 22-11-2018 / 12:18:22 / Stefan Vogel" |
23737 | 5075 |
"Modified: / 14-02-2019 / 15:42:44 / Claus Gittinger" |
20987 | 5076 |
! |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5077 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5078 |
closeFile:handle |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5079 |
"for rel5 only" |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5080 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5081 |
self primitiveFailed |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5082 |
! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5083 |
|
12706 | 5084 |
connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5085 |
"connect a fileDescriptor; openmode is the string defining the way to open. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5086 |
This can be used to connect an externally provided fileDescriptor (from |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5087 |
primitive code) or a pipeFileDescriptor (as returned by makePipe) to |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5088 |
a Stream object. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5089 |
The openMode ('r', 'w' etc.) must match the mode in which |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5090 |
the fileDescriptor was originally opened (otherwise i/o errors will be reported later)." |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5091 |
|
21224 | 5092 |
|error openmode| |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5093 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5094 |
handle notNil ifTrue:[^ self errorAlreadyOpen]. |
12706 | 5095 |
mode := modeSymbol. |
5096 |
openmode := self fopenMode. |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5097 |
%{ |
12683 | 5098 |
FILEPOINTER f = 0; |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5099 |
OBJ fp; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5100 |
FILE *fdopen(); |
12683 | 5101 |
int fd = -2; |
5102 |
||
5103 |
if (__isStringLike(openmode)) { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5104 |
#ifdef __win32__ |
23743 | 5105 |
__stxWrapApiEnterCritical(); |
12688 | 5106 |
#endif |
23743 | 5107 |
if (__isSmallInteger(aFileDescriptor)) { |
5108 |
fd = __intVal(aFileDescriptor); |
|
5109 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5110 |
#ifdef __win32__ |
23743 | 5111 |
else if (__isExternalAddressLike(aFileDescriptor)) { |
5112 |
fd = _open_osfhandle((long)__externalAddressVal(aFileDescriptor), O_BINARY); |
|
5113 |
if (fd < 0) { |
|
5114 |
if (__threadErrno == 0) { |
|
5115 |
// no more file descriptors |
|
5116 |
__threadErrno = EMFILE; |
|
5117 |
} |
|
5118 |
error = __mkSmallInteger(__WIN32_ERR(GetLastError())); |
|
5119 |
__stxWrapApiLeaveCritical(); |
|
5120 |
goto out; |
|
5121 |
} |
|
5122 |
} |
|
12683 | 5123 |
#endif |
23743 | 5124 |
f = (FILEPOINTER) fdopen(fd, (char *)__stringVal(openmode)); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5125 |
#ifdef __win32__ |
23743 | 5126 |
__stxWrapApiLeaveCritical(); |
12688 | 5127 |
#endif |
23743 | 5128 |
if (f == NULL) { |
23538 | 5129 |
# ifdef __win32__ |
23743 | 5130 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5131 |
# endif |
23743 | 5132 |
error =__mkSmallInteger(__threadErrno); |
5133 |
} else { |
|
5134 |
if (@global(FileOpenTrace) == true) { |
|
5135 |
fprintf(stderr, "fdopen [ExternalStream] %"_ld_" (%"_lx_") -> %"_lx_"\n", (INT)fd, (INT)fd, (INT)f); |
|
5136 |
} |
|
5137 |
||
5138 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
|
5139 |
} |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5140 |
} |
12688 | 5141 |
out:; |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5142 |
%}. |
21224 | 5143 |
error notNil ifTrue:[ |
23743 | 5144 |
" |
5145 |
the open failed for some reason ... |
|
5146 |
" |
|
5147 |
OperatingSystem closeFd:aFileDescriptor. |
|
5148 |
lastErrorNumber := error. |
|
5149 |
position := nil. |
|
5150 |
^ self openError:error |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5151 |
]. |
21224 | 5152 |
|
5153 |
position := 0. |
|
5154 |
buffered isNil ifTrue:[ |
|
23743 | 5155 |
buffered := true. "default is buffered" |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5156 |
]. |
21224 | 5157 |
handleType := handleTypeSymbol. |
5158 |
self registerForFinalization. |
|
23538 | 5159 |
|
5160 |
"Modified: / 22-11-2018 / 14:39:27 / Stefan Vogel" |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5161 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5162 |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5163 |
dupFd |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5164 |
"duplicate my file descriptor" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5165 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5166 |
|fd dupFd| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5167 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5168 |
fd := self fileHandle. |
22578 | 5169 |
fd isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5170 |
^ self errorNotOpen. |
20690 | 5171 |
]. |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5172 |
dupFd := OperatingSystem dup:fd. |
10989 | 5173 |
self setFileHandle:dupFd mode:self fopenMode. |
10995 | 5174 |
! |
10989 | 5175 |
|
5176 |
fopenMode |
|
5177 |
"answer the mode for fopen. |
|
5178 |
Only used internally" |
|
5179 |
||
5180 |
mode == #readonly ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5181 |
^ ReadMode |
10989 | 5182 |
]. |
5183 |
mode == #writeonly ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5184 |
^ WriteMode |
10989 | 5185 |
]. |
5186 |
mode == #readWrite ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5187 |
^ ReadWriteMode |
10989 | 5188 |
]. |
5189 |
mode == #append ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5190 |
^ AppendMode |
10989 | 5191 |
]. |
5192 |
^ ReadWriteMode |
|
10995 | 5193 |
! |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5194 |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5195 |
open:aPath withMode:openModeString |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5196 |
"low level open; opens the file/device and sets the handle instance |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5197 |
variable. Careful: this does not care for any other state." |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5198 |
|
16296 | 5199 |
|ok error| |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5200 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5201 |
ok := false. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5202 |
%{ |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5203 |
FILE *f; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5204 |
OBJ fp; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5205 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5206 |
if (__isStringLike(aPath) && __isStringLike(openModeString)) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5207 |
#ifdef __win32__ |
10339 | 5208 |
# if 1 |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5209 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5210 |
# else |
23743 | 5211 |
__BEGIN_INTERRUPTABLE__ |
5212 |
do { |
|
5213 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
|
5214 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
|
5215 |
__END_INTERRUPTABLE__ |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5216 |
# endif |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5217 |
#else /* UNIX */ |
23743 | 5218 |
__BEGIN_INTERRUPTABLE__ |
5219 |
do { |
|
5220 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
|
5221 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
|
5222 |
__END_INTERRUPTABLE__ |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5223 |
#endif /* UNIX */ |
23743 | 5224 |
if (f == NULL) { |
23538 | 5225 |
# ifdef __win32__ |
23743 | 5226 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5227 |
# endif |
23743 | 5228 |
error = __mkSmallInteger(__threadErrno); |
5229 |
} else { |
|
5230 |
if (@global(FileOpenTrace) == true) { |
|
5231 |
fprintf(stderr, "fopen %s [ExternalStream] -> %"_lx_"\n", __stringVal(aPath), (INT)f); |
|
5232 |
} |
|
5233 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
|
5234 |
__INST(handleType) = @symbol(filePointer); |
|
5235 |
ok = true; |
|
5236 |
} |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5237 |
} |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5238 |
%}. |
16296 | 5239 |
ok ifTrue:[ |
23743 | 5240 |
position := 0. |
5241 |
self registerForFinalization. |
|
5242 |
^ self. |
|
16296 | 5243 |
]. |
5244 |
error notNil ifTrue:[ |
|
23743 | 5245 |
" |
5246 |
the open failed for some reason ... |
|
5247 |
" |
|
5248 |
lastErrorNumber := error. |
|
5249 |
self openError:error. |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5250 |
]. |
16296 | 5251 |
self primitiveFailed. |
23538 | 5252 |
|
5253 |
"Modified: / 22-11-2018 / 14:49:56 / Stefan Vogel" |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5254 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5255 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5256 |
reOpen |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5257 |
"USERS WILL NEVER INVOKE THIS METHOD |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5258 |
sent after snapin to reopen streams. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5259 |
cannot reopen here since I am abstract and have no device knowledge" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5260 |
|
24383 | 5261 |
self className errorPrint. ' [warning]: automatic reOpen not supported - stream closed' errorPrintCR. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5262 |
handle := nil. |
18779 | 5263 |
self unregisterForFinalization. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5264 |
|
24383 | 5265 |
"Modified: / 10-01-1997 / 17:50:44 / cg" |
5266 |
"Modified: / 28-06-2019 / 08:43:21 / Claus Gittinger" |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5267 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5268 |
|
12398 | 5269 |
setAccessor:what to:something |
5270 |
"set the filePointer/fileHandle to the given one; |
|
5271 |
low level private & friend interface; may also be used to connect to some |
|
5272 |
externally provided handle." |
|
5273 |
||
5274 |
handle := something. |
|
5275 |
handleType := what. |
|
5276 |
! |
|
5277 |
||
5278 |
setFileHandle:something |
|
5279 |
"set the fileHandle to the given one; |
|
5280 |
low level private & friend interface; may also be used to connect to some |
|
5281 |
externally provided file handle." |
|
5282 |
||
5283 |
self setAccessor:#fileHandle to:something |
|
5284 |
! |
|
5285 |
||
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5286 |
setFileHandle:anIntegerOrExternalAddress mode:openMode |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5287 |
"set the handle based upon a given fileHandle - |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5288 |
notice: this one is based on the underlying OSs fileDescriptor - |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5289 |
this is a fileDescriptor (Integer) on Unix and Windows, or an Handle (ExternalAddres) on Windows only. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5290 |
It may not be available on all platforms." |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5291 |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5292 |
%{ |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5293 |
FILEPOINTER f; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5294 |
OBJ fp; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5295 |
FILE *fdopen(); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5296 |
int fd; |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5297 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5298 |
if (!__isStringLike(openMode)) |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5299 |
goto err; |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5300 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5301 |
#ifdef __win32__ |
12688 | 5302 |
__stxWrapApiEnterCritical(); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5303 |
if (__isExternalAddressLike(anIntegerOrExternalAddress) ) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5304 |
HANDLE __fileHandle = (HANDLE)__externalAddressVal(anIntegerOrExternalAddress); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5305 |
fd = _open_osfhandle((long)__fileHandle, O_BINARY); /* should we handle readonly, append or text mode? */ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5306 |
if (fd < 0) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5307 |
__stxWrapApiLeaveCritical(); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5308 |
CloseHandle(__fileHandle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5309 |
goto err; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5310 |
} |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5311 |
} else |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5312 |
#endif |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5313 |
if (__isSmallInteger(anIntegerOrExternalAddress)) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5314 |
fd = __smallIntegerVal(anIntegerOrExternalAddress); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5315 |
} else { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5316 |
#ifdef __win32__ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5317 |
__stxWrapApiLeaveCritical(); |
12688 | 5318 |
#endif |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5319 |
goto err; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5320 |
} |
10997 | 5321 |
f = fdopen(fd, __stringVal(openMode)); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5322 |
#ifdef __win32__ |
12688 | 5323 |
__stxWrapApiLeaveCritical(); |
5324 |
#endif |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5325 |
if (f != NULL) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5326 |
if (@global(FileOpenTrace) == true) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5327 |
fprintf(stderr, "fdopen [ExternalStream] %d -> %"_lx_"\n", fd, (INT)f); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5328 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5329 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5330 |
__INST(handleType) = @symbol(filePointer); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5331 |
RETURN (self); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5332 |
} |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5333 |
err:; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5334 |
%}. |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5335 |
^ self primitiveFailed |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5336 |
! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5337 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5338 |
setFilePointer:something |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5339 |
"set the filePointer to the given one; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5340 |
low level private & friend interface; may also be used to connect to some |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5341 |
externally provided file." |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5342 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5343 |
self setAccessor:#filePointer to:something |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5344 |
! |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5345 |
|
12398 | 5346 |
setLastError:aNumber |
5347 |
lastErrorNumber := aNumber |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5348 |
! |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5349 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5350 |
setSocketHandle:something |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5351 |
"set the socketHandle to the given one; |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5352 |
low level private & friend interface; may also be used to connect to some |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5353 |
externally provided socket handle." |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5354 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5355 |
self setAccessor:#socketHandle to:something |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5356 |
! ! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5357 |
|
612 | 5358 |
!ExternalStream methodsFor:'queries'! |
5359 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5360 |
nextError |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5361 |
"return the error by trying to read something. |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5362 |
Should only be used, when we know, that a read operation |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5363 |
will return an error (otherwise a character may be lost). |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5364 |
Return an integer (error number), 0 (EOF) or nil (no error)" |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5365 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5366 |
%{ /*NOCONTEXT*/ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5367 |
FILEPOINTER f; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5368 |
int ret, _buffered; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5369 |
OBJ fp; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5370 |
unsigned char ch; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5371 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5372 |
if ((__INST(handleType) == nil) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5373 |
|| (__INST(handleType) == @symbol(filePointer)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5374 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5375 |
|| (__INST(handleType) == @symbol(socketHandle)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5376 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5377 |
if (((fp = __INST(handle)) != nil) |
5378 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5379 |
) { |
|
5380 |
f = __FILEVal(fp); |
|
5381 |
||
5382 |
_buffered = (__INST(buffered) == true); |
|
5383 |
if (_buffered) { |
|
5384 |
__READING__(f) |
|
5385 |
} |
|
5386 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
5387 |
||
5388 |
if (ret > 0) { |
|
5389 |
RETURN(nil) |
|
5390 |
} |
|
5391 |
if (ret < 0) { |
|
23538 | 5392 |
# ifdef __win32__ |
23743 | 5393 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5394 |
# endif |
23743 | 5395 |
RETURN(__mkSmallInteger(__threadErrno)); |
5396 |
} else /* ret == 0 */ { |
|
5397 |
RETURN(__mkSmallInteger(0)); /* EOF */ |
|
5398 |
} |
|
5399 |
} |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5400 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5401 |
%}. |
23538 | 5402 |
|
5403 |
"Modified: / 22-11-2018 / 15:07:16 / Stefan Vogel" |
|
612 | 5404 |
! |
5405 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5406 |
numAvailable |
21130 | 5407 |
<resource: #obsolete> |
5408 |
^ self numAvailableForRead |
|
612 | 5409 |
! ! |
5410 |
||
5411 |
!ExternalStream methodsFor:'reading'! |
|
5412 |
||
5413 |
next |
|
5414 |
"return the next element; advance read position. |
|
5415 |
In binary mode, an integer is returned, otherwise a character. |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5416 |
If there are no more elements, either an exception is thrown or nil is returned |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5417 |
- see #pastEndRead." |
1 | 5418 |
|
16296 | 5419 |
|c error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5420 |
%{ |
18364 | 5421 |
#ifdef __SCHTEAM__ |
5422 |
STObject handle = self.instVarAt(I_handle); |
|
5423 |
||
5424 |
if (handle != STObject.Nil) { |
|
23743 | 5425 |
STObject next; |
5426 |
||
5427 |
if (self.instVarAt(I_binary) == STObject.True) { |
|
5428 |
next = handle.nextByte(); |
|
5429 |
} else { |
|
5430 |
next = handle.nextChar(); |
|
5431 |
} |
|
5432 |
if (next != STObject.EOF) { |
|
5433 |
self.instVarAt_put(I_position, STObject.Nil); |
|
5434 |
return __c__._RETURN( next ); |
|
5435 |
} |
|
5436 |
self.instVarAt_put(I_hitEOF, STObject.True); |
|
18364 | 5437 |
} |
5438 |
#else |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5439 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5440 |
int ret, _buffered; |
612 | 5441 |
OBJ pos, fp; |
5442 |
unsigned char ch; |
|
5443 |
||
1133 | 5444 |
__INST(lastErrorNumber) = nil; |
12548 | 5445 |
if ((__INST(handleType) == nil) |
5446 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5447 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5448 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5449 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5450 |
if (((fp = __INST(handle)) != nil) |
5451 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5452 |
) { |
|
5453 |
f = __FILEVal(fp); |
|
5454 |
||
5455 |
_buffered = (__INST(buffered) == true); |
|
5456 |
if (_buffered) { |
|
5457 |
__READING__(f) |
|
5458 |
} |
|
5459 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
5460 |
||
5461 |
if (ret > 0) { |
|
5462 |
pos = __INST(position); |
|
5463 |
if (__isSmallInteger(pos)) { |
|
5464 |
OBJ t; |
|
5465 |
||
5466 |
t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t); |
|
5467 |
} else { |
|
5468 |
__INST(position) = nil; /* i.e. do not know */ |
|
5469 |
} |
|
5470 |
if (__INST(binary) == true) { |
|
5471 |
RETURN ( __mkSmallInteger(ch) ); |
|
5472 |
} |
|
5473 |
RETURN ( __MKCHARACTER(ch) ); |
|
5474 |
} |
|
5475 |
||
5476 |
__INST(position) = nil; |
|
5477 |
if (ret < 0) { |
|
23538 | 5478 |
# ifdef __win32__ |
23743 | 5479 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5480 |
# endif |
23743 | 5481 |
error = __mkSmallInteger(__threadErrno); |
5482 |
} else /* ret == 0 */ { |
|
5483 |
__INST(hitEOF) = true; |
|
5484 |
} |
|
5485 |
} |
|
612 | 5486 |
} |
18364 | 5487 |
#endif /* not SCHTEAM */ |
612 | 5488 |
%}. |
21139 | 5489 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 5490 |
error notNil ifTrue:[ |
23743 | 5491 |
lastErrorNumber := error. |
5492 |
^ self readError:error |
|
16296 | 5493 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5494 |
handle isNil ifTrue:[^ self errorNotOpen]. |
5420 | 5495 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
5496 |
||
5497 |
readAhead notNil ifTrue:[ |
|
23743 | 5498 |
c := readAhead. |
5499 |
readAhead := nil. |
|
5500 |
^ c. |
|
5420 | 5501 |
]. |
20679 | 5502 |
|
5503 |
"unknown handleType - future" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5504 |
c := self nextByteFromFile:handle. |
5430 | 5505 |
c isNil ifTrue:[ |
23743 | 5506 |
^ self pastEndRead. |
5430 | 5507 |
]. |
21139 | 5508 |
binary ifTrue:[ |
23743 | 5509 |
^ c |
5420 | 5510 |
]. |
5511 |
^ Character value:c |
|
23538 | 5512 |
|
5513 |
"Modified: / 22-11-2018 / 14:44:30 / Stefan Vogel" |
|
612 | 5514 |
! |
5515 |
||
5516 |
next:count |
|
5517 |
"return the next count elements of the stream as a collection. |
|
5518 |
Redefined to return a String or ByteArray instead of the default: Array." |
|
5519 |
||
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5520 |
|coll nRead| |
612 | 5521 |
|
20092 | 5522 |
coll := self contentsSpecies uninitializedNew:count. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5523 |
nRead := self nextBytes:count into:coll startingAt:1. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5524 |
|
20092 | 5525 |
nRead ~~ count ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5526 |
"/ for readStream protocol compatibility, |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5527 |
"/ we must raise an exception here. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5528 |
^ self pastEndRead |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5529 |
]. |
612 | 5530 |
^ coll |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5531 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5532 |
"Modified: 11.1.1997 / 17:44:17 / cg" |
612 | 5533 |
! |
5534 |
||
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5535 |
nextOrNil |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5536 |
"return the next element; advance read position. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5537 |
In binary mode, an integer is returned, otherwise a character. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5538 |
If there are no more elements, nil is returned. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5539 |
This is #atEnd and #next in a single operation - to speed up some code" |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5540 |
|
16296 | 5541 |
|c error| |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5542 |
%{ |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5543 |
FILEPOINTER f; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5544 |
int ret, _buffered; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5545 |
OBJ pos, fp; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5546 |
unsigned char ch; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5547 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5548 |
__INST(lastErrorNumber) = nil; |
12548 | 5549 |
if ((__INST(handleType) == nil) |
5550 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5551 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5552 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5553 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5554 |
if (((fp = __INST(handle)) != nil) |
5555 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5556 |
) { |
|
5557 |
f = __FILEVal(fp); |
|
5558 |
||
5559 |
_buffered = (__INST(buffered) == true); |
|
5560 |
if (_buffered) { |
|
5561 |
__READING__(f) |
|
5562 |
} |
|
5563 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
5564 |
||
5565 |
if (ret > 0) { |
|
5566 |
pos = __INST(position); |
|
5567 |
if (__isSmallInteger(pos)) { |
|
5568 |
OBJ t; |
|
5569 |
||
5570 |
t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t); |
|
5571 |
} else { |
|
5572 |
__INST(position) = nil; /* i.e. do not know */ |
|
5573 |
} |
|
5574 |
if (__INST(binary) == true) { |
|
5575 |
RETURN ( __mkSmallInteger(ch) ); |
|
5576 |
} |
|
5577 |
RETURN ( __MKCHARACTER(ch) ); |
|
5578 |
} |
|
5579 |
||
5580 |
__INST(position) = nil; |
|
5581 |
if (ret < 0) { |
|
23538 | 5582 |
# ifdef __win32__ |
23743 | 5583 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5584 |
# endif |
23743 | 5585 |
error = __mkSmallInteger(__threadErrno); |
5586 |
} else /* ret == 0 */ { |
|
5587 |
__INST(hitEOF) = true; |
|
5588 |
} |
|
5589 |
} |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5590 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5591 |
%}. |
21139 | 5592 |
hitEOF ifTrue:[^ nil]. |
16296 | 5593 |
error notNil ifTrue:[ |
23743 | 5594 |
lastErrorNumber := error. |
5595 |
^ self readError:error. |
|
16296 | 5596 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5597 |
handle isNil ifTrue:[^ self errorNotOpen]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5598 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5599 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5600 |
readAhead notNil ifTrue:[ |
23743 | 5601 |
c := readAhead. |
5602 |
readAhead := nil. |
|
5603 |
^ c. |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5604 |
]. |
20679 | 5605 |
|
5606 |
"unknown handleType - future" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5607 |
c := self nextByteFromFile:handle. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5608 |
c isNil ifTrue:[ |
23743 | 5609 |
^ nil. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5610 |
]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5611 |
binary == true ifTrue:[ |
23743 | 5612 |
^ c |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5613 |
]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5614 |
^ Character value:c |
23538 | 5615 |
|
5616 |
"Modified: / 22-11-2018 / 14:46:49 / Stefan Vogel" |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5617 |
! |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5618 |
|
612 | 5619 |
peek |
5620 |
"return the element to be read next without advancing read position. |
|
5621 |
In binary mode, an integer is returned, otherwise a character. |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5622 |
If there are no more elements, either an exception is thrown or nil is returned |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5623 |
- see #pastEndRead." |
612 | 5624 |
|
16296 | 5625 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5626 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5627 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5628 |
unsigned char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5629 |
int ret, _buffered; |
216 | 5630 |
OBJ fp; |
3672
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5631 |
OBJ ra; |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5632 |
|
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5633 |
if ((ra = __INST(readAhead)) != nil) { |
23743 | 5634 |
if (__INST(binary) == true) { |
5635 |
RETURN ( ra ); |
|
5636 |
} |
|
5637 |
c = __intVal(ra); |
|
5638 |
RETURN ( __MKCHARACTER(c) ); |
|
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
5639 |
} |
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
5640 |
|
1133 | 5641 |
__INST(lastErrorNumber) = nil; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5642 |
|
12548 | 5643 |
if ((__INST(handleType) == nil) |
5644 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5645 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5646 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5647 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5648 |
if (((fp = __INST(handle)) != nil) |
5649 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5650 |
) { |
|
5651 |
f = __FILEVal(fp); |
|
5652 |
_buffered = (__INST(buffered) == true); |
|
5653 |
if (_buffered) { |
|
5654 |
__READING__(f) |
|
5655 |
} |
|
5656 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
|
5657 |
||
5658 |
if (ret > 0) { |
|
5659 |
__UNGETC__(c, f, _buffered); |
|
5660 |
||
5661 |
if (__INST(binary) == true) { |
|
5662 |
RETURN ( __mkSmallInteger(c) ); |
|
5663 |
} |
|
5664 |
RETURN ( __MKCHARACTER(c) ); |
|
5665 |
} |
|
5666 |
if (ret < 0) { |
|
23538 | 5667 |
# ifdef __win32__ |
23743 | 5668 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5669 |
# endif |
23743 | 5670 |
error = __mkSmallInteger(__threadErrno); |
5671 |
} else /* ret == 0 */ { |
|
5672 |
__INST(hitEOF) = true; |
|
5673 |
} |
|
5674 |
} |
|
1 | 5675 |
} |
159 | 5676 |
%}. |
21139 | 5677 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 5678 |
error notNil ifTrue:[ |
23743 | 5679 |
lastErrorNumber := error. |
5680 |
^ self readError:error. |
|
16296 | 5681 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5682 |
handle isNil ifTrue:[^ self errorNotOpen]. |
5420 | 5683 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
5684 |
||
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5685 |
readAhead isNil ifTrue:[ |
23743 | 5686 |
readAhead := self nextOrNil. |
5687 |
readAhead isNil ifTrue:[ |
|
5688 |
^ self pastEndRead. |
|
5689 |
]. |
|
5420 | 5690 |
]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5691 |
^ readAhead |
23538 | 5692 |
|
5693 |
"Modified: / 22-11-2018 / 14:50:10 / Stefan Vogel" |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5694 |
! |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5695 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5696 |
peekOrNil |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5697 |
"return the element to be read next without advancing read position. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5698 |
In binary mode, an integer is returned, otherwise a character. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5699 |
If there are no more elements, nil is returned. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5700 |
Same as #atEnd and #peek in a single operation - speeding up some code" |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5701 |
|
16296 | 5702 |
|error| |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5703 |
%{ |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5704 |
FILEPOINTER f; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5705 |
unsigned char c; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5706 |
int ret, _buffered; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5707 |
OBJ fp; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5708 |
OBJ ra; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5709 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5710 |
if ((ra = __INST(readAhead)) != nil) { |
23743 | 5711 |
if (__INST(binary) == true) { |
5712 |
RETURN ( ra ); |
|
5713 |
} |
|
5714 |
c = __intVal(ra); |
|
5715 |
RETURN ( __MKCHARACTER(c) ); |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5716 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5717 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5718 |
__INST(lastErrorNumber) = nil; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5719 |
|
12548 | 5720 |
if ((__INST(handleType) == nil) |
5721 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5722 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5723 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5724 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5725 |
if (((fp = __INST(handle)) != nil) |
5726 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5727 |
) { |
|
5728 |
f = __FILEVal(fp); |
|
5729 |
_buffered = (__INST(buffered) == true); |
|
5730 |
if (_buffered) { |
|
5731 |
__READING__(f) |
|
5732 |
} |
|
5733 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
|
5734 |
||
5735 |
if (ret > 0) { |
|
5736 |
__UNGETC__(c, f, _buffered); |
|
5737 |
||
5738 |
if (__INST(binary) == true) { |
|
5739 |
RETURN ( __mkSmallInteger(c) ); |
|
5740 |
} |
|
5741 |
RETURN ( __MKCHARACTER(c) ); |
|
5742 |
} |
|
5743 |
if (ret < 0) { |
|
23538 | 5744 |
# ifdef __win32__ |
23743 | 5745 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5746 |
# endif |
23743 | 5747 |
error = __mkSmallInteger(__threadErrno); |
5748 |
} else /* ret == 0 */ { |
|
5749 |
__INST(hitEOF) = true; |
|
5750 |
} |
|
5751 |
} |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5752 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5753 |
%}. |
21139 | 5754 |
hitEOF ifTrue:[^ nil]. |
16296 | 5755 |
error notNil ifTrue:[ |
23743 | 5756 |
lastErrorNumber := error. |
5757 |
^ self readError:error. |
|
16296 | 5758 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5759 |
handle isNil ifTrue:[^ self errorNotOpen]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5760 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5761 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5762 |
readAhead isNil ifTrue:[ |
23743 | 5763 |
readAhead := self nextOrNil. |
5420 | 5764 |
]. |
5765 |
^ readAhead |
|
23538 | 5766 |
|
5767 |
"Modified: / 22-11-2018 / 14:50:22 / Stefan Vogel" |
|
1295 | 5768 |
! |
5769 |
||
5770 |
upToEnd |
|
5771 |
"return a collection of the elements up-to the end. |
|
20092 | 5772 |
Return an empty collection, if the stream-end is already at the end." |
5773 |
||
22849 | 5774 |
|chunkSize chunksAndCounts byteCount data offset contentsSpecies| |
20092 | 5775 |
|
5776 |
"adding to a ByteArray produces quadratic time-space |
|
5777 |
behavior - therefore we allocate chunks, and concatenate them |
|
5778 |
at the end." |
|
5779 |
||
5780 |
chunkSize := 4096. |
|
5781 |
byteCount := 0. |
|
22849 | 5782 |
contentsSpecies := self contentsSpecies. |
5783 |
||
1295 | 5784 |
[self atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5785 |
|chunk cnt| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5786 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5787 |
chunk := contentsSpecies uninitializedNew:chunkSize. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5788 |
cnt := self nextBytes:chunkSize into:chunk startingAt:1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5789 |
cnt ~~ 0 ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5790 |
chunksAndCounts isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5791 |
(cnt < chunkSize and:[self atEnd]) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5792 |
"all data is in a single chunk, so we are done" |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5793 |
^ chunk copyFrom:1 to:cnt. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5794 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5795 |
chunksAndCounts := OrderedCollection new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5796 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5797 |
chunksAndCounts add:chunk; add:cnt. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5798 |
byteCount := byteCount + cnt. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5799 |
] |
1295 | 5800 |
]. |
20092 | 5801 |
|
5802 |
"now, create one big array" |
|
22849 | 5803 |
data := contentsSpecies uninitializedNew:byteCount. |
20092 | 5804 |
offset := 1. |
22849 | 5805 |
1 to:chunksAndCounts size by:2 do:[:index | |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5806 |
|chunk cnt| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5807 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5808 |
chunk := chunksAndCounts at:index. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5809 |
cnt := chunksAndCounts at:index+1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5810 |
data replaceFrom:offset to:(offset + cnt - 1) with:chunk startingAt:1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5811 |
offset := offset + cnt |
20092 | 5812 |
]. |
5813 |
^ data |
|
5814 |
||
1295 | 5815 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
5816 |
" |
20092 | 5817 |
'/dev/null' asFilename readStream upToEnd |
5818 |
'/proc/self/stat' asFilename readStream upToEnd |
|
22849 | 5819 |
'librun.so' asFilename readStream binary upToEnd |
20092 | 5820 |
|
20241 | 5821 |
self assert:('smalltalk.rc' asFilename readStream upToEnd size) |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5822 |
= ('smalltalk.rc' asFilename readStream size) |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
5823 |
" |
22849 | 5824 |
|
5825 |
"Modified (format): / 09-05-2018 / 20:09:31 / stefan" |
|
612 | 5826 |
! ! |
5827 |
||
5420 | 5828 |
!ExternalStream methodsFor:'rel5 protocol'! |
5829 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5830 |
atEndFile:handle |
5420 | 5831 |
"for migration to rel5 only" |
5832 |
||
5833 |
self primitiveFailed |
|
5834 |
! |
|
5835 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5836 |
nextByteFromFile:handle |
5420 | 5837 |
"for migration to rel5 only" |
5838 |
||
5839 |
self primitiveFailed |
|
5840 |
! |
|
5841 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5842 |
nextPutByte:aByte toFile:handle |
5420 | 5843 |
"for migration to rel5 only" |
5844 |
||
5845 |
self primitiveFailed |
|
5846 |
! ! |
|
5847 |
||
612 | 5848 |
!ExternalStream methodsFor:'testing'! |
5849 |
||
5850 |
atEnd |
|
20675 | 5851 |
"return true, if position is at end. |
21032 | 5852 |
If a stream is at the end, the next read operation |
5853 |
would return or raise an exception immediately without waiting. |
|
5854 |
If a stream is not at the end, this may be a blocking operation |
|
5855 |
(see NonPositionableExternalStream)" |
|
612 | 5856 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5857 |
%{ |
21221 | 5858 |
OBJ fp, lim; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5859 |
char c; |
612 | 5860 |
|
1133 | 5861 |
if (__INST(hitEOF) == true) { |
23743 | 5862 |
RETURN (true); |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5863 |
} |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5864 |
lim = __INST(readLimit); |
21221 | 5865 |
if (lim != nil && __signedLongIntVal(__INST(position)) >= __signedLongIntVal(lim)) { |
23743 | 5866 |
RETURN (true); |
612 | 5867 |
} |
5868 |
||
1133 | 5869 |
__INST(lastErrorNumber) = nil; |
5870 |
||
12548 | 5871 |
if ((__INST(handleType) == nil) |
5872 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5873 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5874 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5875 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5876 |
if ((fp = __INST(handle)) != nil) { |
5877 |
int _buffered = (__INST(buffered) == true); |
|
5878 |
int ret; |
|
5879 |
FILEPOINTER f = __FILEVal(fp); |
|
5880 |
||
5881 |
if (_buffered) { |
|
5882 |
__READING__(f); |
|
5883 |
} else if (__INST(readAhead) != nil) { |
|
5884 |
RETURN (false); |
|
5885 |
} |
|
5886 |
||
5887 |
/* |
|
5888 |
* read ahead ... |
|
5889 |
*/ |
|
5890 |
do { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5891 |
#ifdef __win32__ |
23743 | 5892 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5893 |
#else /* not __win32__ */ |
23743 | 5894 |
__BEGIN_INTERRUPTABLE__ |
5895 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
|
5896 |
__END_INTERRUPTABLE__ |
|
21221 | 5897 |
#endif /* not __win32__ */ |
23743 | 5898 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
5899 |
if (ret > 0) { |
|
5900 |
__UNGETC__(c&0xff, f, _buffered); |
|
5901 |
RETURN (false); |
|
5902 |
} |
|
5903 |
if (ret == 0) { |
|
5904 |
__INST(hitEOF) = true; |
|
5905 |
RETURN (true); |
|
5906 |
} |
|
5907 |
/* ret < 0 -> error */ |
|
23538 | 5908 |
# ifdef __win32__ |
23743 | 5909 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5910 |
# endif |
23743 | 5911 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
5912 |
} |
|
5913 |
// we do not raise an error here - the next read operation will raise the error. |
|
5914 |
RETURN(false); |
|
612 | 5915 |
} |
5916 |
%}. |
|
20675 | 5917 |
|
22578 | 5918 |
"/ we come here if the handle type is unknown |
5420 | 5919 |
"/ migration support |
20675 | 5920 |
^ self atEndFile:handle |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5921 |
|
23538 | 5922 |
"Modified: / 30-10-1998 / 20:16:06 / cg" |
5923 |
"Modified: / 22-11-2018 / 14:39:54 / Stefan Vogel" |
|
612 | 5924 |
! |
5925 |
||
10995 | 5926 |
gotErrorOrEOF |
20675 | 5927 |
"answer true, if amn error or eof has been occurred on the stream" |
10995 | 5928 |
|
21139 | 5929 |
^ hitEOF or:[lastErrorNumber notNil] |
10995 | 5930 |
! |
5931 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5932 |
isBinary |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5933 |
"return true, if the stream is in binary (as opposed to text-) mode. |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5934 |
The default when created is false." |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5935 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5936 |
^ binary |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5937 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5938 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5939 |
isBlocking |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5940 |
"return true, if O_NONBLOCK is NOT set in the fileDescriptor (probably UNIX specific)" |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5941 |
|
22195 | 5942 |
|fd| |
5943 |
||
5944 |
fd := self fileDescriptor. |
|
5945 |
"self fileDescriptor may set handle to nil" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5946 |
handle isNil ifTrue:[^ self errorNotOpen]. |
22195 | 5947 |
^ OperatingSystem isBlockingOn:fd |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5948 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5949 |
|
22694 | 5950 |
isExecutor |
5951 |
"am I an executor and no real stream object?" |
|
5952 |
||
5953 |
^ mode == #executor. |
|
5954 |
||
5955 |
"Created: / 23-04-2018 / 18:17:40 / stefan" |
|
5956 |
! |
|
5957 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5958 |
isExternalStream |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5959 |
"return true, if the receiver is some kind of externalStream; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5960 |
true is returned here - the method redefined from Object." |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5961 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5962 |
^ true |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5963 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5964 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5965 |
isOpen |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5966 |
"return true, if this stream is open" |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5967 |
|
22694 | 5968 |
"executors are only used to finalize - they are not really open and are closed with #closeFile, |
5969 |
which does not check for #isOpen" |
|
5970 |
^ handle notNil and:[self isExecutor not] |
|
5971 |
||
5972 |
"Modified: / 23-04-2018 / 18:28:07 / stefan" |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5973 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5974 |
|
22978 | 5975 |
isPipeStream |
5976 |
"return true, if this stream is a pipe" |
|
5977 |
||
5978 |
^ false |
|
5979 |
! |
|
5980 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5981 |
isReadable |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5982 |
"return true, if this stream can be read from" |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5983 |
|
21139 | 5984 |
^ mode ~~ #writeonly |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5985 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5986 |
|
22978 | 5987 |
isSocket |
5988 |
"return true, if this stream is a socket" |
|
5989 |
||
5990 |
^ false |
|
5991 |
! |
|
5992 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5993 |
isWritable |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5994 |
"return true, if this stream can be written to" |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5995 |
|
21139 | 5996 |
^ mode ~~ #readonly |
612 | 5997 |
! ! |
5998 |
||
5999 |
!ExternalStream methodsFor:'waiting for I/O'! |
|
6000 |
||
5101 | 6001 |
canBeSelected |
6002 |
"return true, if this stream can be selected upon" |
|
6003 |
||
6004 |
^ OperatingSystem supportsSelect |
|
6005 |
! |
|
6006 |
||
20104 | 6007 |
numAvailableForRead |
20241 | 6008 |
"answer the number of bytes available for reading" |
6009 |
||
20104 | 6010 |
|available| |
6011 |
||
6012 |
handle isNil ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6013 |
^ self errorNotOpen |
20104 | 6014 |
]. |
6015 |
mode == #writeonly ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6016 |
^ self errorWriteOnly |
20104 | 6017 |
]. |
21238 | 6018 |
available := OperatingSystem numAvailableForReadOn:self fileHandle. |
20104 | 6019 |
readAhead notNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6020 |
available := available + 1 |
20104 | 6021 |
]. |
6022 |
^ available. |
|
6023 |
||
6024 |
" |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6025 |
'/etc/hosts' asFilename readStream numAvailableForRead |
21130 | 6026 |
" |
20104 | 6027 |
! |
6028 |
||
18327 | 6029 |
readWaitWithTimeoutMs:timeoutOrNil |
612 | 6030 |
"suspend the current process, until the receiver |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6031 |
becomes ready for reading or a timeout (in milliseconds) expired. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6032 |
If data is already available, return immediate. |
20259 | 6033 |
Return true if a timeout occurred (i.e. false, if data is available). |
612 | 6034 |
The other threads are not affected by the wait." |
6035 |
||
16480 | 6036 |
|fd inputSema hasTimedout wasBlocked| |
612 | 6037 |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
6038 |
readAhead notNil ifTrue:[^ false]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
6039 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6040 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 6041 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
6042 |
||
21238 | 6043 |
fd := self fileHandle. |
612 | 6044 |
(OperatingSystem readCheck:fd) ifTrue:[^ false]. |
6045 |
||
20104 | 6046 |
"cannot do a readWait (which means possible suspend), |
6047 |
if the processor is not yet initialized; i.e. if a read is attempted |
|
6048 |
during early startup. |
|
6049 |
This may happen, for example, if a MiniDebugger is entered, before |
|
6050 |
process scheduling has been setup. |
|
6051 |
In this case, all I/O operations here will be blocking." |
|
6052 |
||
23726 | 6053 |
Smalltalk isInitialized ifFalse:[ |
23743 | 6054 |
^ false |
23726 | 6055 |
]. |
20104 | 6056 |
|
612 | 6057 |
wasBlocked := OperatingSystem blockInterrupts. |
22177 | 6058 |
inputSema := Semaphore name:'readWait'. |
23726 | 6059 |
hasTimedout := [ |
23743 | 6060 |
Processor signal:inputSema onInput:fd. |
6061 |
(inputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
16463 | 6062 |
] ifCurtailed:[ |
23743 | 6063 |
Processor disableSemaphore:inputSema. |
6064 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
612 | 6065 |
]. |
22683 | 6066 |
hasTimedout ifTrue:[ |
23743 | 6067 |
Processor disableSemaphore:inputSema. |
16480 | 6068 |
]. |
612 | 6069 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
16480 | 6070 |
^ hasTimedout |
22177 | 6071 |
|
6072 |
"Modified: / 09-08-2017 / 11:53:58 / cg" |
|
23726 | 6073 |
"Modified: / 12-02-2019 / 20:56:53 / Stefan Vogel" |
612 | 6074 |
! |
6075 |
||
22683 | 6076 |
readWriteWaitWithTimeoutMs:timeoutOrNil |
6077 |
"suspend the current process, until the receiver |
|
6078 |
becomes ready for reading or writing or a timeout (in milliseconds) expired. |
|
6079 |
Return true if a timeout occurred (i.e. false, if data is available). |
|
6080 |
Return immediate if the receiver is already ready. |
|
6081 |
The other threads are not affected by the wait." |
|
6082 |
||
6083 |
|fd sema hasTimedout wasBlocked| |
|
6084 |
||
6085 |
readAhead notNil ifTrue:[^ false]. |
|
6086 |
handle isNil ifTrue:[ |
|
23743 | 6087 |
^ self errorNotOpen |
22683 | 6088 |
]. |
6089 |
||
6090 |
fd := self fileHandle. |
|
6091 |
(OperatingSystem readWriteCheck:fd) ifTrue:[^ false]. |
|
6092 |
||
6093 |
wasBlocked := OperatingSystem blockInterrupts. |
|
6094 |
sema := Semaphore name:'readWriteWait'. |
|
23726 | 6095 |
hasTimedout := [ |
23743 | 6096 |
Processor |
6097 |
signal:sema onOutput:fd; |
|
6098 |
signal:sema onInput:fd. |
|
6099 |
(sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
22683 | 6100 |
] ifCurtailed:[ |
23743 | 6101 |
Processor disableSemaphore:sema. |
6102 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
22683 | 6103 |
]. |
6104 |
hasTimedout ifTrue:[ |
|
23743 | 6105 |
Processor disableSemaphore:sema. |
22683 | 6106 |
]. |
6107 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
6108 |
^ hasTimedout |
|
6109 |
||
6110 |
"Modified: / 09-08-2017 / 11:54:03 / cg" |
|
23726 | 6111 |
"Modified: / 12-02-2019 / 20:23:41 / Stefan Vogel" |
22683 | 6112 |
! |
6113 |
||
6114 |
writeExceptionWaitWithTimeoutMs:timeoutOrNil |
|
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
6115 |
"suspend the current process, until the receiver |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6116 |
becomes ready for reading or writing or a timeout (in milliseconds) expired. |
20259 | 6117 |
Return true if a timeout occurred (i.e. false, if data is available). |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6118 |
Return immediate if the receiver is already ready. |
5506 | 6119 |
The other threads are not affected by the wait." |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
6120 |
|
16480 | 6121 |
|fd sema hasTimedout wasBlocked| |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
6122 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6123 |
handle isNil ifTrue:[ |
23743 | 6124 |
^ self errorNotOpen |
18956 | 6125 |
]. |
6126 |
||
21238 | 6127 |
fd := self fileHandle. |
18956 | 6128 |
(OperatingSystem writeExceptionCheck:fd) ifTrue:[^ false]. |
6129 |
||
6130 |
wasBlocked := OperatingSystem blockInterrupts. |
|
22177 | 6131 |
sema := Semaphore name:'writeExceptionWait'. |
23726 | 6132 |
hasTimedout := [ |
23743 | 6133 |
Processor |
6134 |
signal:sema onOutput:fd; |
|
6135 |
signal:sema onException:fd. |
|
6136 |
(sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
18956 | 6137 |
] ifCurtailed:[ |
23743 | 6138 |
Processor disableSemaphore:sema. |
6139 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
18956 | 6140 |
]. |
22683 | 6141 |
hasTimedout ifTrue:[ |
23743 | 6142 |
Processor disableSemaphore:sema. |
18956 | 6143 |
]. |
6144 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
6145 |
^ hasTimedout |
|
22177 | 6146 |
|
6147 |
"Modified: / 09-08-2017 / 11:54:10 / cg" |
|
23726 | 6148 |
"Modified: / 12-02-2019 / 20:24:03 / Stefan Vogel" |
18956 | 6149 |
! |
6150 |
||
22683 | 6151 |
writeWaitWithTimeoutMs:timeoutOrNil |
612 | 6152 |
"suspend the current process, until the receiver |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6153 |
becomes ready for writing or a timeout (in milliseconds) expired. |
20259 | 6154 |
Return true if a timeout occurred (i.e. false, if data is available). |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6155 |
Return immediate if the receiver is already ready. |
612 | 6156 |
The other threads are not affected by the wait." |
6157 |
||
16480 | 6158 |
|fd outputSema hasTimedout wasBlocked| |
612 | 6159 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6160 |
handle isNil ifTrue:[ |
23743 | 6161 |
^ self errorNotOpen |
612 | 6162 |
]. |
6163 |
mode == #readonly ifTrue:[ |
|
23743 | 6164 |
^ self errorReadOnly |
612 | 6165 |
]. |
6166 |
||
21238 | 6167 |
fd := self fileHandle. |
612 | 6168 |
(OperatingSystem writeCheck:fd) ifTrue:[^ false]. |
6169 |
||
6170 |
wasBlocked := OperatingSystem blockInterrupts. |
|
22177 | 6171 |
outputSema := Semaphore name:'writeWait'. |
23726 | 6172 |
hasTimedout := [ |
23743 | 6173 |
Processor signal:outputSema onOutput:fd. |
6174 |
(outputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
16463 | 6175 |
] ifCurtailed:[ |
23743 | 6176 |
Processor disableSemaphore:outputSema. |
6177 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
612 | 6178 |
]. |
22683 | 6179 |
hasTimedout ifTrue:[ |
23743 | 6180 |
Processor disableSemaphore:outputSema. |
16480 | 6181 |
]. |
612 | 6182 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
16480 | 6183 |
^ hasTimedout |
22177 | 6184 |
|
6185 |
"Modified: / 09-08-2017 / 11:54:14 / cg" |
|
23726 | 6186 |
"Modified: / 12-02-2019 / 20:25:09 / Stefan Vogel" |
612 | 6187 |
! ! |
6188 |
||
6189 |
!ExternalStream methodsFor:'writing'! |
|
6190 |
||
6191 |
cr |
|
6192 |
"append an end-of-line character (or CRLF if in crlf mode). |
|
6193 |
reimplemented for speed" |
|
6194 |
||
23538 | 6195 |
|error| |
6196 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
6197 |
%{ |
12548 | 6198 |
if ((__INST(handleType) == nil) |
6199 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
6200 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 6201 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
6202 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6203 |
OBJ fp; |
6204 |
||
6205 |
__INST(lastErrorNumber) = nil; |
|
6206 |
if (((fp = __INST(handle)) != nil) |
|
6207 |
&& (__INST(mode) != @symbol(readonly)) |
|
6208 |
&& (__INST(binary) != true) |
|
6209 |
) { |
|
6210 |
FILEPOINTER f = __FILEVal(fp); |
|
6211 |
int _buffered = (__INST(buffered) == true); |
|
6212 |
int len, cnt; |
|
6213 |
char *cp; |
|
6214 |
||
6215 |
if (_buffered) { |
|
6216 |
__WRITING__(f) |
|
6217 |
} |
|
6218 |
{ |
|
6219 |
OBJ mode = __INST(eolMode); |
|
6220 |
||
6221 |
if (mode == @symbol(cr)) { |
|
6222 |
cp = "\r"; len = 1; |
|
6223 |
} else if (mode == @symbol(crlf)) { |
|
6224 |
cp = "\r\n"; len = 2; |
|
6225 |
} else if (mode == @symbol(eot)) { |
|
6226 |
cp = "\004"; len = 1; |
|
6227 |
} else if (mode == @symbol(etx)) { |
|
6228 |
cp = "\003"; len = 1; |
|
6229 |
} else { |
|
6230 |
cp = "\n"; len = 1; |
|
6231 |
} |
|
6232 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6233 |
#ifdef __win32__ |
23743 | 6234 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6235 |
cnt = __win32_fwrite(cp, 1, len, f); |
|
6236 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6237 |
#endif |
23743 | 6238 |
{ |
6239 |
__WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType)); |
|
6240 |
} |
|
6241 |
if (cnt == len) { |
|
6242 |
if (__isSmallInteger(__INST(position))) { |
|
6243 |
INT np = __intVal(__INST(position)) + len; |
|
6244 |
OBJ t; |
|
6245 |
||
6246 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6247 |
} else { |
|
6248 |
__INST(position) = nil; /* i.e: don't know */ |
|
6249 |
} |
|
6250 |
RETURN ( self ); |
|
6251 |
} |
|
23538 | 6252 |
# ifdef __win32__ |
23743 | 6253 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6254 |
# endif |
23743 | 6255 |
error = __mkSmallInteger(__threadErrno); |
6256 |
} |
|
612 | 6257 |
} |
6258 |
%}. |
|
23538 | 6259 |
error notNil ifTrue:[ |
23743 | 6260 |
lastErrorNumber := error. |
6261 |
self writeError:error. |
|
6262 |
^ self |
|
23538 | 6263 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6264 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
2326 | 6265 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
21139 | 6266 |
binary ifTrue:[self errorBinary. ^ self]. |
5414 | 6267 |
|
17426
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
6268 |
(eolMode == #cr) ifTrue:[ |
23743 | 6269 |
self nextPut:(Character return). |
6270 |
^ self |
|
17426
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
6271 |
]. |
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
6272 |
(eolMode == #crlf) ifTrue:[ |
23743 | 6273 |
self nextPut:(Character return). |
17426
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
6274 |
]. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6275 |
self nextPut:(Character nl). |
5414 | 6276 |
^ self |
23538 | 6277 |
|
6278 |
"Modified: / 22-11-2018 / 14:41:46 / Stefan Vogel" |
|
612 | 6279 |
! |
6280 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6281 |
flush |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6282 |
"write all buffered data - ignored if unbuffered" |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6283 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6284 |
%{ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6285 |
__INST(lastErrorNumber) = nil; |
12548 | 6286 |
if ((__INST(handleType) == nil) |
6287 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6288 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6289 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
24045 | 6290 |
OBJ fp; |
6291 |
int _buffered = (__INST(buffered) == true); |
|
6292 |
||
6293 |
if ((fp = __INST(handle)) != nil) { |
|
6294 |
if (__INST(mode) != @symbol(readonly)) { |
|
6295 |
if (1 /* _buffered */) { |
|
6296 |
FILEPOINTER f = __FILEVal(fp); |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6297 |
#ifdef __win32__ |
24045 | 6298 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6299 |
__win32_fflush(f); |
|
6300 |
} else { |
|
6301 |
int rslt; |
|
6302 |
||
6303 |
do { |
|
6304 |
__threadErrno = 0; |
|
6305 |
rslt = __STX_C_CALL1("fflush", fflush, f); |
|
6306 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
6307 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6308 |
#else /* ! __win32__ */ |
24045 | 6309 |
__BEGIN_INTERRUPTABLE__ |
6310 |
FFLUSH(f); |
|
6311 |
__END_INTERRUPTABLE__ |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6312 |
#endif /* ! __win32__ */ |
24045 | 6313 |
} |
6314 |
} |
|
6315 |
} |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6316 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6317 |
%} |
24045 | 6318 |
|
6319 |
"Modified: / 03-04-2019 / 16:15:11 / Claus Gittinger" |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6320 |
! |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6321 |
|
612 | 6322 |
nextPut:aCharacter |
24628 | 6323 |
"write the argument, aCharacter - raise an error if failed. |
612 | 6324 |
Only single-byte characters are currently supported" |
6325 |
||
16296 | 6326 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
6327 |
%{ |
18364 | 6328 |
#ifdef __SCHTEAM__ |
6329 |
STObject handle = self.instVarAt(I_handle); |
|
6330 |
||
6331 |
if ((handle != STObject.Nil) |
|
6332 |
&& (aCharacter.isSTCharacter())) { |
|
24628 | 6333 |
handle.writeChar( aCharacter ); |
6334 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6335 |
return __c__._RETURN_self(); |
|
18364 | 6336 |
} |
6337 |
#else |
|
17332 | 6338 |
__INST(lastErrorNumber) = nil; |
6339 |
if ((__INST(handleType) == nil) |
|
6340 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6341 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6342 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6343 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
24628 | 6344 |
OBJ fp; |
6345 |
||
6346 |
if (((fp = __INST(handle)) != nil) |
|
6347 |
&& (__INST(mode) != @symbol(readonly)) |
|
6348 |
) { |
|
6349 |
FILEPOINTER f = __FILEVal(fp); |
|
6350 |
int _buffered = (__INST(buffered) == true); |
|
6351 |
int cnt; |
|
6352 |
char buff[2]; |
|
6353 |
int nBytes = 1; |
|
6354 |
||
6355 |
if (__INST(binary) != true) { |
|
6356 |
if (__isCharacter(aCharacter)) { |
|
6357 |
unsigned int codePoint = __intVal(__characterVal(aCharacter)); |
|
6358 |
if (codePoint <= 0xFF) { |
|
6359 |
unsigned char c = codePoint; |
|
6360 |
buff[0] = c; nBytes = 1; |
|
6361 |
||
6362 |
if (c == '\n') { |
|
6363 |
OBJ mode = __INST(eolMode); |
|
6364 |
if (mode == @symbol(nl)) { |
|
6365 |
// no EOL translation |
|
6366 |
} else if (mode == nil) { |
|
6367 |
// no EOL translation |
|
6368 |
} else if (mode == @symbol(cr)) { |
|
6369 |
buff[0] = '\r'; |
|
6370 |
} else if (mode == @symbol(eot)) { |
|
6371 |
buff[0] = '\004'; |
|
6372 |
} else if (mode == @symbol(etx)) { |
|
6373 |
buff[0] = '\003'; |
|
6374 |
} else if (mode == @symbol(crlf)) { |
|
6375 |
buff[0] = '\r'; |
|
6376 |
buff[1] = '\n'; |
|
6377 |
nBytes = 2; |
|
6378 |
} |
|
6379 |
} |
|
17332 | 6380 |
doWrite: |
24628 | 6381 |
if (! f) { |
6382 |
fprintf(stderr, "oops - fileHandle is NULL in nextPut:\n"); |
|
6383 |
__INST(handle) = nil; |
|
6384 |
goto out; |
|
6385 |
} |
|
6386 |
||
6387 |
if (_buffered) { |
|
6388 |
__WRITING__(f) |
|
6389 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6390 |
# ifdef __win32__ |
24628 | 6391 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6392 |
cnt = __win32_fwrite(buff, 1, nBytes, f); |
|
6393 |
} else |
|
18364 | 6394 |
# endif |
24628 | 6395 |
{ |
6396 |
__WRITEBYTES__(cnt, f, buff, nBytes, _buffered, __INST(handleType)); |
|
6397 |
} |
|
6398 |
if (cnt == nBytes) { |
|
6399 |
if (__isSmallInteger(__INST(position))) { |
|
6400 |
INT np = __intVal(__INST(position)) + nBytes; |
|
6401 |
OBJ t; |
|
6402 |
||
6403 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6404 |
} else { |
|
6405 |
__INST(position) = nil; /* i.e. do not know */ |
|
6406 |
} |
|
6407 |
RETURN ( self ); |
|
6408 |
} |
|
23538 | 6409 |
# ifdef __win32__ |
24628 | 6410 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6411 |
# endif |
24628 | 6412 |
error = __mkSmallInteger(__threadErrno); |
6413 |
} |
|
6414 |
} |
|
6415 |
} else { |
|
6416 |
if (__isSmallInteger(aCharacter)) { |
|
6417 |
unsigned char c = __intVal(aCharacter); |
|
6418 |
buff[0] = c; nBytes = 1; |
|
6419 |
goto doWrite; |
|
6420 |
} |
|
6421 |
} |
|
6422 |
} |
|
17332 | 6423 |
} |
6424 |
out: ; |
|
18364 | 6425 |
#endif /* not SCHTEAM */ |
17332 | 6426 |
%}. |
6427 |
error notNil ifTrue:[ |
|
24628 | 6428 |
lastErrorNumber := error. |
6429 |
self writeError:error. |
|
6430 |
^ self |
|
17332 | 6431 |
]. |
6432 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
|
6433 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
21139 | 6434 |
binary == true ifTrue:[ |
24628 | 6435 |
aCharacter isInteger ifFalse:[ |
6436 |
self argumentMustBeInteger. |
|
6437 |
^ self. |
|
6438 |
]. |
|
21139 | 6439 |
] ifFalse:[ |
24628 | 6440 |
(aCharacter isCharacter not |
6441 |
or:[aCharacter codePoint > 16rFF]) ifTrue:[ |
|
6442 |
self argumentMustBeCharacter. |
|
6443 |
^ self. |
|
6444 |
]. |
|
17332 | 6445 |
]. |
6446 |
"/ migration support |
|
6447 |
self |
|
24628 | 6448 |
nextPutByte:aCharacter asInteger |
6449 |
toFile:handle |
|
23538 | 6450 |
|
6451 |
"Modified: / 22-11-2018 / 14:47:13 / Stefan Vogel" |
|
17332 | 6452 |
! |
6453 |
||
17418 | 6454 |
nextPutAll:aCollection |
6455 |
"write all elements of the argument, aCollection. |
|
6456 |
Reimplemented for speed when writing strings or byteArrays. |
|
6457 |
For others, falls back to general method in superclass." |
|
6458 |
||
6459 |
|error| |
|
6460 |
%{ |
|
18364 | 6461 |
#ifdef __SCHTEAM__ |
6462 |
STObject handle = self.instVarAt(I_handle); |
|
6463 |
||
6464 |
if ((handle != STObject.Nil) |
|
6465 |
&& (aCollection.isSTString())) { |
|
24628 | 6466 |
handle.writeCharacters( aCollection.asSTString().characters ); |
6467 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6468 |
return __c__._RETURN_self(); |
|
18364 | 6469 |
} |
6470 |
#else |
|
17418 | 6471 |
|
6472 |
__INST(lastErrorNumber) = nil; |
|
6473 |
||
6474 |
if ((__INST(handleType) == nil) |
|
6475 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6476 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6477 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6478 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
24628 | 6479 |
OBJ fp; |
6480 |
||
6481 |
if (((fp = __INST(handle)) != nil) |
|
6482 |
&& (__INST(mode) != @symbol(readonly)) |
|
6483 |
) { |
|
6484 |
INT len, cnt; |
|
6485 |
INT o_offs; |
|
6486 |
FILEPOINTER f = __FILEVal(fp); |
|
6487 |
int _buffered = (__INST(buffered) == true); |
|
6488 |
||
6489 |
if (! f) { |
|
6490 |
fprintf(stderr, "oops - fileHandle is NULL in nextPutAll:\n"); |
|
6491 |
__INST(handle) = nil; |
|
6492 |
goto out; |
|
6493 |
} |
|
6494 |
if (_buffered) { |
|
6495 |
__WRITING__(f) |
|
6496 |
} |
|
6497 |
||
6498 |
if (__isStringLike(aCollection)) { |
|
6499 |
OBJ mode = __INST(eolMode); |
|
6500 |
char *stringP = __stringVal(aCollection); |
|
6501 |
len = __stringSize(aCollection); |
|
6502 |
||
6503 |
if (__INST(binary) != true |
|
6504 |
&& ((mode == @symbol(cr)) |
|
6505 |
|| (mode == @symbol(etx)) |
|
6506 |
|| (mode == @symbol(eot)) |
|
6507 |
|| (mode == @symbol(crlf))) |
|
6508 |
&& memchr(stringP, '\n', len) != NULL) |
|
6509 |
{ |
|
6510 |
// there is a '\n' to be translated, replace it into a buffer |
|
6511 |
||
6512 |
char *end; |
|
6513 |
char sep[2]; |
|
6514 |
int sepLen = 1; |
|
6515 |
int bufLen; |
|
6516 |
char *buf, *endBuf, *sp, *dp; |
|
6517 |
||
6518 |
sep[0] = '\n'; |
|
6519 |
if (mode == @symbol(crlf)) { |
|
6520 |
sep[0] = '\r'; sep[1] = '\n'; sepLen = 2; |
|
6521 |
} else if (mode == @symbol(cr)) { |
|
6522 |
sep[0] = '\r'; |
|
6523 |
} else if (mode == @symbol(eot)) { |
|
6524 |
sep[0] = '\004'; |
|
6525 |
} else if (mode == @symbol(etx)) { |
|
6526 |
sep[0] = '\003'; |
|
6527 |
} |
|
6528 |
||
6529 |
// estimate size of buffer - assume every 4th char is a separator |
|
6530 |
bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen); |
|
6531 |
buf = (char *)malloc(bufLen); |
|
6532 |
if (buf == NULL) { |
|
6533 |
error = __mkSmallInteger(ENOMEM); |
|
6534 |
goto out; |
|
6535 |
} |
|
6536 |
||
6537 |
endBuf = buf + bufLen; |
|
6538 |
end = stringP + len; |
|
6539 |
for (sp = stringP, dp = buf; sp < end; sp++) { |
|
6540 |
char c; |
|
6541 |
||
6542 |
if ((dp+sepLen) >= endBuf) { |
|
6543 |
char *newBuf; |
|
6544 |
||
6545 |
bufLen = bufLen * 2; |
|
6546 |
newBuf = (char *)realloc(buf, bufLen); |
|
6547 |
if (newBuf == NULL) { |
|
6548 |
free(buf); |
|
6549 |
error = __mkSmallInteger(ENOMEM); |
|
6550 |
goto out; |
|
6551 |
} |
|
6552 |
endBuf = newBuf + bufLen; |
|
6553 |
dp = newBuf + (dp-buf); |
|
6554 |
buf = newBuf; |
|
6555 |
} |
|
6556 |
||
6557 |
if ((c = *sp) != '\n') { |
|
6558 |
*dp++ = c; |
|
6559 |
} else { |
|
6560 |
*dp++ = sep[0]; |
|
6561 |
if (sepLen == 2) { |
|
6562 |
*dp++ = sep[1]; |
|
6563 |
}; |
|
6564 |
} |
|
6565 |
} |
|
6566 |
||
6567 |
len = dp - buf; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6568 |
# ifdef __win32__ |
24628 | 6569 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6570 |
cnt = __win32_fwrite(buf, 1, len, f); |
|
6571 |
} else |
|
18364 | 6572 |
# endif |
24628 | 6573 |
{ |
6574 |
__WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType)); |
|
6575 |
} |
|
6576 |
free(buf); |
|
6577 |
} else { // No EOL conversion needed |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6578 |
# ifdef __win32__ |
24628 | 6579 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6580 |
cnt = __win32_fwrite(stringP, 1, len, f); |
|
6581 |
} else |
|
18364 | 6582 |
# endif |
24628 | 6583 |
{ |
6584 |
o_offs = stringP - (char *)__InstPtr(aCollection); |
|
6585 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType)); |
|
6586 |
} |
|
6587 |
} |
|
6588 |
} else { // Not a String |
|
6589 |
if (__INST(binary) == true) { |
|
6590 |
INT offs; |
|
6591 |
||
6592 |
if (__isByteArrayLike(aCollection)) { |
|
6593 |
offs = 0; |
|
6594 |
len = __byteArraySize(aCollection); |
|
6595 |
} else if (__isBytes(aCollection)) { |
|
6596 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
6597 |
len = __byteArraySize(aCollection) - offs; |
|
6598 |
} else |
|
6599 |
goto out; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6600 |
# ifdef __win32__ |
24628 | 6601 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6602 |
cnt = __win32_fwrite(__stringVal(aCollection), 1, len, f); |
|
6603 |
} else |
|
18364 | 6604 |
# endif |
24628 | 6605 |
{ |
6606 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection); |
|
6607 |
o_offs += offs; |
|
6608 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType)); |
|
6609 |
} |
|
6610 |
} else // Not binary mode |
|
6611 |
goto out; |
|
6612 |
} |
|
6613 |
||
6614 |
// Now check for errors |
|
6615 |
if (cnt == len) { |
|
6616 |
if (__isSmallInteger(__INST(position))) { |
|
6617 |
INT np = __intVal(__INST(position)) + len; |
|
6618 |
OBJ t; |
|
6619 |
||
6620 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6621 |
} else { |
|
6622 |
__INST(position) = nil; /* i.e. do not know */ |
|
6623 |
} |
|
6624 |
RETURN (self); |
|
6625 |
} |
|
23538 | 6626 |
# ifdef __win32__ |
24628 | 6627 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6628 |
# endif |
24628 | 6629 |
error = __mkSmallInteger(__threadErrno); |
6630 |
fprintf(stderr, "cnt=%"_ld_" len=%"_ld_"\n", (INT)cnt, (INT)len); |
|
6631 |
} |
|
17418 | 6632 |
} |
6633 |
out: ; |
|
18364 | 6634 |
#endif /* not SCHTEAM */ |
17418 | 6635 |
%}. |
6636 |
error notNil ifTrue:[ |
|
24628 | 6637 |
lastErrorNumber := error. |
6638 |
self writeError:error. |
|
6639 |
^ self |
|
17418 | 6640 |
]. |
6641 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
|
6642 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
6643 |
||
24628 | 6644 |
super nextPutAll:aCollection |
23538 | 6645 |
|
6646 |
"Modified: / 22-11-2018 / 11:16:12 / Stefan Vogel" |
|
17418 | 6647 |
! |
6648 |
||
17608 | 6649 |
nextPutAll:initialWriteCount from:buffer startingAt:initialOffset |
22232 | 6650 |
"append count elements with index starting at initialOffset |
6651 |
of the argument, buffer onto the receiver. |
|
6652 |
This is only allowed, if the receiver supports writing. |
|
6653 |
Answer the number of elements that were appended. |
|
6654 |
Buffer should be a byte collection. |
|
20270 | 6655 |
I don't know how to write non-bytes to an external stream, but let superclass handle this." |
17608 | 6656 |
|
22234 | 6657 |
buffer isSingleByteCollection ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6658 |
^ self nextPutBytes:initialWriteCount from:buffer startingAt:initialOffset. |
17608 | 6659 |
]. |
6660 |
||
6661 |
^ super nextPutAll:initialWriteCount from:buffer startingAt:initialOffset |
|
6662 |
! |
|
6663 |
||
17418 | 6664 |
nextPutAll:aCollection startingAt:start to:stop |
6665 |
"write a range of elements of the argument, aCollection. |
|
6666 |
Reimplemented for speed when writing strings or byteArrays. |
|
6667 |
For others, falls back to general method in superclass." |
|
6668 |
||
6669 |
|error| |
|
6670 |
||
6671 |
%{ |
|
6672 |
__INST(lastErrorNumber) = nil; |
|
6673 |
if ((__INST(handleType) == nil) |
|
6674 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6675 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6676 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6677 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6678 |
OBJ fp = __INST(handle); |
6679 |
||
6680 |
if ((fp != nil) |
|
6681 |
&& (__INST(mode) != @symbol(readonly)) |
|
6682 |
&& __bothSmallInteger(start, stop) |
|
6683 |
) { |
|
6684 |
int _buffered = (__INST(buffered) == true); |
|
6685 |
FILEPOINTER f = __FILEVal(fp); |
|
6686 |
int offs, len, cnt; |
|
6687 |
int iStart = __intVal(start); |
|
6688 |
int iStop = __intVal(stop); |
|
6689 |
int o_offs; |
|
6690 |
||
6691 |
if (_buffered ) { |
|
6692 |
__WRITING__(f) |
|
6693 |
} |
|
6694 |
||
6695 |
if ((iStart < 1) || (iStop < iStart)) { |
|
6696 |
RETURN(self); |
|
6697 |
} |
|
6698 |
if (__isStringLike(aCollection)) { |
|
6699 |
char *stringP; |
|
6700 |
OBJ mode = __INST(eolMode); |
|
6701 |
||
6702 |
len = __stringSize(aCollection); |
|
6703 |
if (iStop > len) { |
|
6704 |
RETURN(self); |
|
6705 |
} |
|
6706 |
if (iStop > len) |
|
6707 |
iStop = len; |
|
6708 |
len = iStop - iStart + 1; |
|
6709 |
stringP = __stringVal(aCollection) + iStart - 1; |
|
6710 |
||
6711 |
if (__INST(binary) != true |
|
6712 |
&& ((mode == @symbol(cr)) |
|
6713 |
|| (mode == @symbol(etx)) |
|
6714 |
|| (mode == @symbol(eot)) |
|
6715 |
|| (mode == @symbol(crlf))) |
|
6716 |
&& memchr(stringP, '\n', len) != NULL) |
|
6717 |
{ |
|
6718 |
// see if there is a \n which needs to be translated, replace it |
|
6719 |
||
6720 |
char *end = stringP + len; |
|
6721 |
char sep[2]; |
|
6722 |
int sepLen = 1; |
|
6723 |
int bufLen; |
|
6724 |
char *buf, *endBuf, *sp, *dp; |
|
6725 |
||
6726 |
sep[0] = '\n'; |
|
6727 |
if (mode == @symbol(crlf)) { |
|
6728 |
sep[0] = '\r'; sep[1] = '\n'; sepLen = 2; |
|
6729 |
} else if (mode == @symbol(cr)) { |
|
6730 |
sep[0] = '\r'; |
|
6731 |
} else if (mode == @symbol(eot)) { |
|
6732 |
sep[0] = '\004'; |
|
6733 |
} else if (mode == @symbol(etx)) { |
|
6734 |
sep[0] = '\003'; |
|
6735 |
} |
|
6736 |
||
6737 |
// estimate size of buffer - assume every 4th char is a separator |
|
6738 |
bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen); |
|
6739 |
buf = (char *)malloc(bufLen); |
|
6740 |
if (buf == NULL) { |
|
6741 |
error = __mkSmallInteger(ENOMEM); |
|
6742 |
goto out; |
|
6743 |
} |
|
6744 |
||
6745 |
endBuf = buf + bufLen; |
|
6746 |
||
6747 |
for (sp = stringP, dp = buf; sp < end; sp++) { |
|
6748 |
char c; |
|
6749 |
||
6750 |
if ((dp+sepLen) >= endBuf) { |
|
6751 |
char *newBuf; |
|
6752 |
||
6753 |
bufLen = bufLen * 2; |
|
6754 |
newBuf = (char *)realloc(buf, bufLen); |
|
6755 |
if (newBuf == NULL) { |
|
6756 |
free(buf); |
|
6757 |
error = __mkSmallInteger(ENOMEM); |
|
6758 |
goto out; |
|
6759 |
} |
|
6760 |
endBuf = newBuf + bufLen; |
|
6761 |
dp = newBuf + (dp-buf); |
|
6762 |
buf = newBuf; |
|
6763 |
} |
|
6764 |
||
6765 |
if ((c = *sp) == '\n') { |
|
6766 |
*dp++ = sep[0]; |
|
6767 |
if (sepLen == 2) { |
|
6768 |
*dp++ = sep[1]; |
|
6769 |
}; |
|
6770 |
} else { |
|
6771 |
*dp++ = c; |
|
6772 |
} |
|
6773 |
} |
|
6774 |
||
6775 |
len = dp - buf; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6776 |
#ifdef __win32__ |
23743 | 6777 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6778 |
cnt = __win32_fwrite(buf, 1, len, f); |
|
6779 |
} else |
|
17420 | 6780 |
#endif |
23743 | 6781 |
{ |
6782 |
__WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType)); |
|
6783 |
} |
|
6784 |
free(buf); |
|
6785 |
} else { // No EOL conversion needed |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6786 |
#ifdef __win32__ |
23743 | 6787 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6788 |
cnt = __win32_fwrite(stringP, 1, len, f); |
|
6789 |
} else |
|
17420 | 6790 |
#endif |
23743 | 6791 |
{ |
6792 |
o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection); |
|
6793 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+iStart-1, len, _buffered, __INST(handleType)); |
|
6794 |
} |
|
6795 |
} |
|
6796 |
} else { // Not a string |
|
6797 |
if (__INST(binary) == true) { |
|
6798 |
int offs; |
|
6799 |
||
6800 |
if (__isByteArrayLike(aCollection)) { |
|
6801 |
offs = 0; |
|
6802 |
len = __byteArraySize(aCollection); |
|
6803 |
} else if (__isBytes(aCollection)) { |
|
6804 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
6805 |
len = __byteArraySize(aCollection) - offs; |
|
6806 |
} else |
|
6807 |
goto out; |
|
6808 |
||
6809 |
if (iStop > len) { |
|
6810 |
RETURN(self); |
|
6811 |
} |
|
6812 |
if (iStop > len) |
|
6813 |
iStop = len; |
|
6814 |
len = iStop - iStart + 1; |
|
6815 |
offs += iStart - 1; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6816 |
#ifdef __win32__ |
23743 | 6817 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6818 |
cnt = __win32_fwrite(__stringVal(aCollection)+iStart-1, 1, len, f); |
|
6819 |
} else |
|
17418 | 6820 |
#endif |
23743 | 6821 |
{ |
6822 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element)-(char *)__InstPtr(aCollection); |
|
6823 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+offs, len, _buffered, __INST(handleType)); |
|
6824 |
} |
|
6825 |
} else |
|
6826 |
goto out; |
|
6827 |
} |
|
6828 |
if (cnt == len) { |
|
6829 |
if (__isSmallInteger(__INST(position))) { |
|
6830 |
INT np = __intVal(__INST(position)) + len; |
|
6831 |
OBJ t; |
|
6832 |
||
6833 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6834 |
} else { |
|
6835 |
__INST(position) = nil; /* i.e. do not know */ |
|
6836 |
} |
|
6837 |
RETURN (self); |
|
6838 |
} |
|
23538 | 6839 |
# ifdef __win32__ |
23743 | 6840 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6841 |
# endif |
23743 | 6842 |
error = __mkSmallInteger(__threadErrno); |
6843 |
} |
|
17418 | 6844 |
} |
6845 |
out: ; |
|
6846 |
%}. |
|
6847 |
error notNil ifTrue:[ |
|
23743 | 6848 |
lastErrorNumber := error. |
6849 |
self writeError:error. |
|
6850 |
^ self |
|
17418 | 6851 |
]. |
23538 | 6852 |
super nextPutAll:aCollection startingAt:start to:stop |
6853 |
||
6854 |
"Modified: / 22-11-2018 / 12:52:13 / Stefan Vogel" |
|
17418 | 6855 |
! |
6856 |
||
6857 |
nextPutAllUnicode:aString |
|
6858 |
"normal streams can not handle multi-byte characters, so convert them to utf8. |
|
6859 |
This is needed, so that you can do ('something' asUnicode16String errorPrintCR)" |
|
6860 |
||
6861 |
aString do:[:eachCharacter| |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6862 |
self nextPutUtf8:eachCharacter. |
17418 | 6863 |
]. |
6864 |
||
6865 |
" |
|
24628 | 6866 |
'Bönnigheim' asUnicode16String errorPrintCR |
17418 | 6867 |
" |
6868 |
! |
|
6869 |
||
17608 | 6870 |
nextPutBytes:count from:anObject startingAt:start |
6871 |
"write count bytes from an object starting at index start. |
|
6872 |
return the number of bytes written - which could be 0. |
|
6873 |
The object must have non-pointer indexed instvars |
|
6874 |
(i.e. be a ByteArray, String, Float- or DoubleArray), |
|
6875 |
or an externalBytes object (with known size). |
|
6876 |
||
6877 |
Use with care - non object oriented i/o. |
|
6878 |
Warning: |
|
23743 | 6879 |
in general, you cannot use this method to pass non-byte data to other |
6880 |
architectures (unless you prepared the buffer with care), |
|
6881 |
since it does not care for byte order or float representation." |
|
17608 | 6882 |
|
6883 |
|error| |
|
6884 |
||
6885 |
%{ |
|
18312 | 6886 |
#ifdef __SCHTEAM__ |
6887 |
byte[] bytes; |
|
6888 |
STObject handle = self.instVarAt(I_handle); |
|
6889 |
||
6890 |
if (anObject.isSTString()) { |
|
23743 | 6891 |
char[] chars = anObject.asSTString().characters; |
6892 |
handle.writeCharacters(chars, start.intValue()-1, count.intValue()); |
|
6893 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6894 |
return context._RETURN(count); |
|
18364 | 6895 |
} |
6896 |
if (anObject.isSymbol()) { |
|
23743 | 6897 |
java.lang.String chars = anObject.asSTSymbol().characters; |
6898 |
handle.writeString(chars, start.intValue()-1, count.intValue()); |
|
6899 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6900 |
return context._RETURN(count); |
|
18312 | 6901 |
} |
6902 |
#else |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
6903 |
int ret; |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
6904 |
int objSize, nInstBytes; |
17608 | 6905 |
char *extPtr; |
6906 |
OBJ fp; |
|
6907 |
||
6908 |
__INST(lastErrorNumber) = nil; |
|
6909 |
if ((__INST(handleType) == nil) |
|
6910 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6911 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6912 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6913 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6914 |
if (((fp = __INST(handle)) != nil) |
6915 |
&& (__INST(mode) != @symbol(readonly)) |
|
6916 |
&& __bothSmallInteger(count, start) |
|
6917 |
) { |
|
6918 |
int _buffered = (__INST(buffered) == true); |
|
6919 |
FILEPOINTER f = __FILEVal(fp); |
|
6920 |
int len = __intVal(count); |
|
6921 |
int offs = __intVal(start) - 1; |
|
6922 |
||
6923 |
if (__isExternalBytesLike(anObject)) { |
|
6924 |
OBJ sz; |
|
6925 |
||
6926 |
nInstBytes = 0; |
|
6927 |
extPtr = (char *)__externalBytesAddress(anObject); |
|
6928 |
if (extPtr == NULL) goto bad; |
|
6929 |
sz = __externalBytesSize(anObject); |
|
6930 |
if (__isSmallInteger(sz)) { |
|
6931 |
objSize = __intVal(sz); |
|
6932 |
} else { |
|
6933 |
objSize = 0; /* unknown */ |
|
6934 |
} |
|
6935 |
} else { |
|
6936 |
OBJ oClass = __Class(anObject); |
|
6937 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
6938 |
||
6939 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
6940 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
6941 |
case BYTEARRAY: |
|
6942 |
case WORDARRAY: |
|
6943 |
case LONGARRAY: |
|
6944 |
case SWORDARRAY: |
|
6945 |
case SLONGARRAY: |
|
6946 |
case FLOATARRAY: |
|
6947 |
break; |
|
6948 |
case DOUBLEARRAY: |
|
18312 | 6949 |
# ifdef __NEED_DOUBLE_ALIGN |
23743 | 6950 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
18312 | 6951 |
# endif |
23743 | 6952 |
break; |
6953 |
case LONGLONGARRAY: |
|
6954 |
case SLONGLONGARRAY: |
|
18312 | 6955 |
# ifdef __NEED_LONGLONG_ALIGN |
23743 | 6956 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
18312 | 6957 |
# endif |
23743 | 6958 |
break; |
6959 |
default: |
|
6960 |
goto bad; |
|
6961 |
} |
|
6962 |
extPtr = (char *)0; |
|
6963 |
objSize = __Size(anObject) - nInstBytes; |
|
6964 |
} |
|
6965 |
if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) { |
|
6966 |
int cnt; |
|
6967 |
||
6968 |
if (_buffered) { |
|
6969 |
__WRITING__(f) |
|
6970 |
} |
|
6971 |
||
6972 |
if (extPtr) { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6973 |
# ifdef __win32__ |
23743 | 6974 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6975 |
cnt = __win32_fwrite(extPtr+offs, 1, len, f); |
|
6976 |
} else |
|
18312 | 6977 |
# endif |
23743 | 6978 |
{ |
6979 |
__WRITEBYTES__(cnt, f, extPtr+offs, len, _buffered, __INST(handleType)); |
|
6980 |
} |
|
6981 |
} else { |
|
6982 |
/* |
|
6983 |
* on interrupt, anObject may be moved to another location. |
|
6984 |
* So we pass anObject, and the offset to the __WRITEBYTES_OBJ__ macro. |
|
6985 |
*/ |
|
6986 |
offs += nInstBytes; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6987 |
# ifdef __win32__ |
23743 | 6988 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6989 |
cnt = __win32_fwrite((char *)anObject+offs, 1, len, f); |
|
6990 |
} else |
|
18312 | 6991 |
# endif |
23743 | 6992 |
{ |
6993 |
__WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered, __INST(handleType)); |
|
6994 |
} |
|
6995 |
} |
|
6996 |
||
6997 |
if (cnt >= 0) { |
|
6998 |
if (__isSmallInteger(__INST(position))) { |
|
6999 |
INT np = __intVal(__INST(position)) + cnt; |
|
7000 |
OBJ t; |
|
7001 |
||
7002 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
7003 |
} else { |
|
7004 |
__INST(position) = nil; /* i.e. do not know */ |
|
7005 |
} |
|
7006 |
RETURN ( __mkSmallInteger(cnt) ); |
|
7007 |
} else /* cnt < 0 */ { |
|
7008 |
if ( |
|
18312 | 7009 |
# ifdef EWOULDBLOCK |
23743 | 7010 |
(__threadErrno == EWOULDBLOCK) || |
18312 | 7011 |
# endif |
23743 | 7012 |
(__threadErrno == EAGAIN) |
7013 |
) { |
|
7014 |
RETURN ( __mkSmallInteger(0) ); |
|
7015 |
} |
|
7016 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 7017 |
# ifdef __win32__ |
23743 | 7018 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 7019 |
# endif |
23743 | 7020 |
error = __mkSmallInteger(__threadErrno); |
7021 |
} |
|
7022 |
} |
|
7023 |
} |
|
17608 | 7024 |
} |
7025 |
bad: ; |
|
18312 | 7026 |
#endif /* not SCHTEAM */ |
17608 | 7027 |
%}. |
7028 |
error notNil ifTrue:[ |
|
23743 | 7029 |
lastErrorNumber := error. |
7030 |
self writeError:error. |
|
7031 |
^ 0 |
|
17608 | 7032 |
]. |
17634 | 7033 |
handle isNil ifTrue:[self errorNotOpen. ^ 0]. |
7034 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ 0]. |
|
7035 |
self primitiveFailed. |
|
7036 |
^ 0. |
|
23538 | 7037 |
|
7038 |
"Modified: / 22-11-2018 / 14:47:58 / Stefan Vogel" |
|
17608 | 7039 |
! |
7040 |
||
17418 | 7041 |
nextPutUnicode:aCharacter |
7042 |
"normal streams can not handle multi-byte characters, so convert them to utf8" |
|
7043 |
||
7044 |
self nextPutUtf8:aCharacter. |
|
612 | 7045 |
! ! |
7046 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
7047 |
!ExternalStream class methodsFor:'documentation'! |
730 | 7048 |
|
7049 |
version |
|
18636 | 7050 |
^ '$Header$' |
12398 | 7051 |
! |
7052 |
||
7053 |
version_CVS |
|
18636 | 7054 |
^ '$Header$' |
730 | 7055 |
! ! |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
7056 |
|
14603 | 7057 |
|
612 | 7058 |
ExternalStream initialize! |