author | Claus Gittinger <cg@exept.de> |
Mon, 24 Nov 2014 15:37:58 +0100 | |
changeset 17115 | 2ef08a902c34 |
parent 17078 | f3ded8a6f9d9 |
child 17332 | f223abac93ca |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
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 |
||
1 | 14 |
ReadWriteStream subclass:#ExternalStream |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
15 |
instanceVariableNames:'handleType handle mode buffered binary eolMode hitEOF didWrite |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
16 |
lastErrorNumber readAhead' |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
17 |
classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
18 |
InvalidModeSignal OpenErrorSignal StreamNotOpenSignal |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
19 |
InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
20 |
WriteMode AppendMode CreateReadWriteMode StreamIOErrorSignal |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
21 |
FileOpenTrace' |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
22 |
poolDictionaries:'' |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
23 |
category:'Streams-External' |
1 | 24 |
! |
25 |
||
216 | 26 |
!ExternalStream primitiveDefinitions! |
1 | 27 |
%{ |
10328
ad731a7584a3
ensure that win32_fwrite is used for stdout and stderr
Claus Gittinger <cg@exept.de>
parents:
9053
diff
changeset
|
28 |
#undef fwrite |
ad731a7584a3
ensure that win32_fwrite is used for stdout and stderr
Claus Gittinger <cg@exept.de>
parents:
9053
diff
changeset
|
29 |
|
17078 | 30 |
#include "stxOSDefs.h" |
31 |
||
1 | 32 |
#include <stdio.h> |
437 | 33 |
#define _STDIO_H_INCLUDED_ |
34 |
||
2903 | 35 |
#ifndef NO_FCNTL_H |
36 |
# include <fcntl.h> |
|
37 |
# define _FCNTL_H_INCLUDED_ |
|
38 |
#endif |
|
437 | 39 |
|
10 | 40 |
#include <errno.h> |
437 | 41 |
#define _ERRNO_H_INCLUDED_ |
42 | 42 |
|
1141 | 43 |
#ifdef LINUX |
44 |
/* use inline string macros */ |
|
45 |
# define __STRINGDEFS__ |
|
46 |
# include <linuxIntern.h> |
|
47 |
#endif |
|
48 |
||
16508 | 49 |
#if !defined(MSDOS_LIKE) && !defined(__openVMS__) |
50 |
# include <termios.h> |
|
51 |
#endif |
|
52 |
||
42 | 53 |
#ifdef hpux |
54 |
# define fileno(f) ((f->__fileH << 8) | (f->__fileL)) |
|
55 |
#endif |
|
216 | 56 |
|
933
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
57 |
#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
|
58 |
# 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
|
59 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
60 |
#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
|
61 |
# 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
|
62 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
63 |
#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
|
64 |
# 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
|
65 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
66 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
67 |
#if defined(__VMS__) || defined(__sparc__) || defined(WIN32) |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
5101
diff
changeset
|
68 |
# define CLEAR_ERRNO __threadErrno = 0; |
2961 | 69 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
70 |
# define CLEAR_ERRNO /* nothing */ |
2961 | 71 |
#endif |
72 |
||
3420 | 73 |
#ifdef LATER |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
74 |
# define __isFilePointer(x) (__Class(x) == ExternalStream__FilePointer) |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
75 |
# define __CHANGECLASS(o, x) (__qClass(o) = (x), o) |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
76 |
# define __MKFILEPOINTER(f) __CHANGECLASS(__MKEXTERNALADDRESS(f), ExternalStream__FilePointer) |
3420 | 77 |
#else |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
78 |
# define __MKFILEPOINTER(f) __MKEXTERNALADDRESS(f) |
3420 | 79 |
#endif |
80 |
||
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
81 |
#ifdef WIN32 |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
82 |
# define NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
83 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
84 |
# undef __HANDLE_INTERRUPTS__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
85 |
# define __HANDLE_INTERRUPTS__ /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
86 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
87 |
# undef __BEGIN_INTERRUPTABLE__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
88 |
# define __BEGIN_INTERRUPTABLE__ /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
89 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
90 |
# undef __END_INTERRUPTABLE__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
91 |
# define __END_INTERRUPTABLE__ /* nothing */ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
92 |
#endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
93 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
94 |
# ifdef __i386__ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
95 |
# define _X86_ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
96 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
97 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
98 |
#ifdef WIN32 |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
99 |
# undef INT |
14644 | 100 |
# undef UINT |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
101 |
# undef Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
102 |
# undef Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
103 |
# undef Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
104 |
# undef Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
105 |
# undef Rectangle |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
106 |
# undef Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
107 |
# undef Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
108 |
# undef Date |
7832 | 109 |
# undef Delay |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
110 |
# undef Set |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
111 |
# undef Signal |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
112 |
# undef Context |
9023 | 113 |
# undef Message |
9024 | 114 |
# undef Process |
10339 | 115 |
# undef Processor |
14632 | 116 |
# undef String |
117 |
# undef Character |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
118 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
119 |
# define NOATOM |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
120 |
# define NOGDICAPMASKS |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
121 |
# define NOMETAFILE |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
122 |
# define NOMINMAX |
14068 | 123 |
//# define NOOPENFILE |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
124 |
# define NOSOUND |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
125 |
# define NOWH |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
126 |
//# define NOCOMM |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
127 |
# define NOKANJI |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
128 |
# define NOCRYPT |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
129 |
//# define NOMCX |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
130 |
# define WIN32_LEAN_AND_MEAN |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
131 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
132 |
# include <windows.h> |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
133 |
# include <winsock2.h> |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
134 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
135 |
# ifdef __DEF_Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
136 |
# define Array __DEF_Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
137 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
138 |
# ifdef __DEF_Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
139 |
# define Number __DEF_Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
140 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
141 |
# ifdef __DEF_Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
142 |
# define Method __DEF_Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
143 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
144 |
# ifdef __DEF_Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
145 |
# define Point __DEF_Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
146 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
147 |
# ifdef __DEF_Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
148 |
# define Block __DEF_Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
149 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
150 |
# ifdef __DEF_Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
151 |
# define Time __DEF_Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
152 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
153 |
# ifdef __DEF_Date |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
154 |
# define Date __DEF_Date |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
155 |
# endif |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
156 |
# ifdef __DEF_Set |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
157 |
# define Set __DEF_Set |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
158 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
159 |
# ifdef __DEF_Signal |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
160 |
# define Signal __DEF_Signal |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
161 |
# endif |
7832 | 162 |
# ifdef __DEF_Delay |
163 |
# define Delay __DEF_Delay |
|
164 |
# endif |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
165 |
# ifdef __DEF_Context |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
166 |
# define Context __DEF_Context |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
167 |
# endif |
9023 | 168 |
# ifdef __DEF_Message |
169 |
# define Message __DEF_Message |
|
170 |
# endif |
|
9024 | 171 |
# ifdef __DEF_Process |
172 |
# define Process __DEF_Process |
|
173 |
# endif |
|
10339 | 174 |
# ifdef __DEF_Processor |
175 |
# define Processor __DEF_Processor |
|
176 |
# endif |
|
14632 | 177 |
# ifdef __DEF_String |
178 |
# define String __DEF_String |
|
179 |
# endif |
|
180 |
# ifdef __DEF_Character |
|
181 |
# define Character __DEF_Character |
|
182 |
# endif |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
183 |
|
14644 | 184 |
# define INT STX_INT |
185 |
# define UINT STX_UINT |
|
186 |
# ifndef off_t |
|
187 |
# define off_t long |
|
188 |
# endif |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
189 |
#endif /* WIN32 */ |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
190 |
|
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
191 |
#ifndef NO_STDIO /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
192 |
# define STDIO_NEEDS_FSEEK |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
193 |
# define FILEPOINTER FILE * |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
194 |
# define READ(f, cp, n) read(f, cp, n) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
195 |
# define WRITE(f, cp, n) write(f, cp, n) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
196 |
# define FFLUSH(fp) fflush(fp) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
197 |
# define FILENO(f) fileno(f) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
198 |
#endif /* use STDIO */ |
3681 | 199 |
|
3682 | 200 |
#ifdef DEBUGGING |
4092 | 201 |
extern char *__survStartPtr, *__survEndPtr; |
3682 | 202 |
# define DEBUGBUFFER(buf) \ |
3681 | 203 |
if (((char *)(buf) >= __survStartPtr) \ |
204 |
&& ((char *)(buf) < __survEndPtr)) { \ |
|
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
|
205 |
__fatal0("read into survivor\n"); \ |
3681 | 206 |
} |
207 |
||
3682 | 208 |
#else |
209 |
# define DEBUGBUFFER(buf) /* nothing */ |
|
210 |
#endif |
|
211 |
||
216 | 212 |
/* |
213 |
* stdio library requires an fseek before reading whenever a file |
|
214 |
* is open for read/write and the last operation was a write. |
|
215 |
* (also vice-versa). |
|
216 |
* All code should use the following macro before doing reads: |
|
217 |
*/ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
218 |
#ifdef STDIO_NEEDS_FSEEK |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
219 |
# 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
|
220 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
221 |
# 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
|
222 |
#endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
223 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
224 |
#ifdef WIN32 |
16912 | 225 |
// Win returns from ReadFile() with false and _threadErrno == 0 on end of pipe. |
226 |
// We don't know why |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
227 |
# define READ(ret, f, cp, n, handleType) { \ |
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
|
228 |
if (handleType == @symbol(socketHandle)) { \ |
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
|
229 |
(ret) = __STX_WSA_NOINT_CALL4("recv", recv, (f), (cp), (n), 0); \ |
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
|
230 |
} else { \ |
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
|
231 |
HANDLE h = _get_osfhandle(fileno(f)); \ |
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
|
232 |
if (handleType == @symbol(socketFilePointer)) { \ |
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
|
233 |
(ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\ |
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
|
234 |
} else { \ |
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
|
235 |
int __res; \ |
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
|
236 |
(ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\ |
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
|
237 |
(ret) = (ret) ? __res : ((__threadErrno == EPIPE || __threadErrno == 0) ? 0 : -1); \ |
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
|
238 |
} \ |
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
|
239 |
} \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
240 |
} |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
241 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
242 |
# define WRITE(ret, f, cp, n, handleType) { \ |
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
|
243 |
if (handleType == @symbol(socketHandle)) { \ |
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
|
244 |
(ret) = __STX_WSA_NOINT_CALL4("send", send, (f), (cp), (n), 0); \ |
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
|
245 |
} else {\ |
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
|
246 |
HANDLE h = _get_osfhandle(fileno(f)); \ |
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
|
247 |
if (handleType == @symbol(socketFilePointer)) { \ |
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
|
248 |
(ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\ |
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
|
249 |
} else {\ |
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
|
250 |
int __res; \ |
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
|
251 |
(ret) = __STX_API_NOINT_CALL5("WriteFile", WriteFile, h, (cp), (n), &__res, 0);\ |
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
|
252 |
(ret) = (ret) ? __res : -1; \ |
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
|
253 |
} \ |
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
|
254 |
} \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
255 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
256 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
257 |
# define FFLUSH(fp) fflush(fp) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
258 |
# undef STDIO_NEEDS_FSEEK |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
259 |
# define FILEPOINTER FILE * |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
260 |
# define FILENO(f) fileno(f) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
261 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
262 |
# define __READING__(f) \ |
1133 | 263 |
if ((__INST(didWrite) != false) \ |
264 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
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
|
265 |
__INST(didWrite) = false; \ |
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
|
266 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
216 | 267 |
} |
268 |
||
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
269 |
# define __WRITING__(f) \ |
1133 | 270 |
if ((__INST(didWrite) != true) \ |
271 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
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
|
272 |
__INST(didWrite) = true; \ |
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
|
273 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
216 | 274 |
} |
275 |
||
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
276 |
# define __UNGETC__(c, f, isBuffered) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
277 |
if (isBuffered) { \ |
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
|
278 |
ungetc((c), (f)); \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
279 |
} else { \ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
280 |
__INST(readAhead) = __mkSmallInteger((c)); \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
281 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
282 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
283 |
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
284 |
if (isBuffered) { \ |
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
|
285 |
for (;;) { \ |
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
|
286 |
CLEAR_ERRNO; \ |
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
|
287 |
(ret) = getc(f); \ |
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
|
288 |
if ((ret) >= 0) { \ |
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
|
289 |
*(buf) = (ret); \ |
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
|
290 |
(ret) = 1; \ |
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
|
291 |
} else if (ferror(f)) { \ |
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
|
292 |
if (__threadErrno == EINTR) { \ |
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
|
293 |
clearerr(f); \ |
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
|
294 |
continue; \ |
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
|
295 |
} \ |
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
|
296 |
} else { \ |
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
|
297 |
(ret) = 0; \ |
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
|
298 |
} \ |
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
|
299 |
break; \ |
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
|
300 |
} \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
301 |
} else { \ |
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
|
302 |
OBJ rA = __INST(readAhead); \ |
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
|
303 |
if (rA != nil) { \ |
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
|
304 |
*(buf) = (char)__intVal(rA); \ |
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
|
305 |
__INST(readAhead) = nil; \ |
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
|
306 |
(ret) = 1; \ |
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
|
307 |
} else { \ |
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
|
308 |
for (;;) { \ |
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
|
309 |
CLEAR_ERRNO; \ |
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
|
310 |
READ((ret), f, buf, 1, handleType); \ |
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
|
311 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
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
|
312 |
break; \ |
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
|
313 |
} \ |
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
|
314 |
} \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
315 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
316 |
|
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 |
* read_bytes into a c-buffer |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
319 |
* (which may NOT move) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
320 |
*/ |
12548 | 321 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
322 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
323 |
if (isBuffered) { \ |
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
|
324 |
int __offs = 0; \ |
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
|
325 |
while (__offs < (cnt)) { \ |
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
|
326 |
CLEAR_ERRNO; \ |
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
|
327 |
(ret) = getc(f); \ |
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
|
328 |
if ((ret) < 0) { \ |
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
|
329 |
if (ferror(f)) { \ |
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
|
330 |
if (__threadErrno == EINTR) { \ |
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
|
331 |
clearerr(f); \ |
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
|
332 |
continue; \ |
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
|
333 |
} \ |
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
|
334 |
} else { \ |
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
|
335 |
(ret) = 0; \ |
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
|
336 |
} \ |
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
|
337 |
break; \ |
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
|
338 |
} \ |
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
|
339 |
(buf)[__offs++] = (ret); \ |
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
|
340 |
} \ |
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
|
341 |
if (__offs > 0) \ |
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
|
342 |
(ret) = __offs; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
343 |
} else { \ |
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
|
344 |
int __offs = 0; \ |
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
|
345 |
\ |
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
|
346 |
while (__offs < (cnt)) { \ |
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
|
347 |
OBJ rA = __INST(readAhead); \ |
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
|
348 |
if (rA != nil) { \ |
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
|
349 |
(buf)[__offs] = __intVal(rA); \ |
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
|
350 |
__INST(readAhead) = nil; \ |
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
|
351 |
(ret) = 1; \ |
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
|
352 |
} else { \ |
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
|
353 |
CLEAR_ERRNO; \ |
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
|
354 |
READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \ |
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
|
355 |
if ((ret) <= 0) { \ |
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
|
356 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
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
|
357 |
continue; \ |
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
|
358 |
} \ |
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
|
359 |
break; \ |
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
|
360 |
} \ |
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
|
361 |
} \ |
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
|
362 |
__offs += (ret); \ |
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
|
363 |
} \ |
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
|
364 |
if (__offs > 0) \ |
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
|
365 |
(ret) = __offs; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
366 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
367 |
|
12548 | 368 |
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
369 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
370 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
371 |
int oldFlags; \ |
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
|
372 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
373 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
374 |
if (isBuffered) { \ |
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
|
375 |
while (__offs < (cnt)) { \ |
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
|
376 |
CLEAR_ERRNO; \ |
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
|
377 |
(ret) = getc(f); \ |
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
|
378 |
if ((ret) < 0) { \ |
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
|
379 |
if (ferror(f)) { \ |
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
|
380 |
if (__threadErrno == EINTR) { \ |
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
|
381 |
clearerr(f); \ |
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
|
382 |
continue; \ |
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
|
383 |
} \ |
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
|
384 |
} else { \ |
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
|
385 |
(ret) = 0; \ |
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
|
386 |
} \ |
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
|
387 |
break; \ |
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
|
388 |
} \ |
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
|
389 |
(buf)[__offs++] = (ret); \ |
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
|
390 |
} \ |
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
|
391 |
(ret) = __offs; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
392 |
} else { \ |
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
|
393 |
while (__offs < (cnt)) { \ |
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
|
394 |
OBJ rA = __INST(readAhead); \ |
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
|
395 |
if (rA != nil) { \ |
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
|
396 |
(buf)[__offs] = __intVal(rA); \ |
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
|
397 |
__INST(readAhead) = nil; \ |
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
|
398 |
(ret) = 1; \ |
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
|
399 |
__offs ++; \ |
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
|
400 |
continue; \ |
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
|
401 |
} \ |
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
|
402 |
CLEAR_ERRNO; \ |
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
|
403 |
{ \ |
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
|
404 |
int res = 0; \ |
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
|
405 |
if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res), 1)) \ |
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
|
406 |
|| (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \ |
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
|
407 |
|| (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0), 1))) { \ |
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
|
408 |
if (res > 0) { \ |
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
|
409 |
if (res > ((cnt)-__offs)) \ |
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
|
410 |
res = (cnt)-__offs; \ |
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
|
411 |
READ((ret), f, (buf)+__offs, res, handleType); \ |
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
|
412 |
} else { \ |
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
|
413 |
(ret) = 0; \ |
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
|
414 |
break; \ |
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
|
415 |
} \ |
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
|
416 |
} else { \ |
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
|
417 |
READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \ |
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
|
418 |
} \ |
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
|
419 |
} \ |
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
|
420 |
if ((ret) <= 0) { \ |
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
|
421 |
if (ret < 0 && __threadErrno == EINTR) \ |
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
|
422 |
continue; \ |
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
|
423 |
break; \ |
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
|
424 |
} \ |
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
|
425 |
__offs += (ret); \ |
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
|
426 |
} \ |
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
|
427 |
(ret) = __offs; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
428 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
429 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
430 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
431 |
# define IO_BUFFER_SIZE (8*1024) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
432 |
|
12548 | 433 |
# 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
|
434 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
435 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
436 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
437 |
char *buf = (char *)(obj); \ |
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
|
438 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
439 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
440 |
if (isBuffered) { \ |
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
|
441 |
while (__offs < (cnt)) { \ |
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
|
442 |
CLEAR_ERRNO; \ |
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
|
443 |
(ret) = getc(f); \ |
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
|
444 |
if ((ret) < 0) { \ |
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
|
445 |
if (ferror(f)) { \ |
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
|
446 |
if (__threadErrno == EINTR) { \ |
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
|
447 |
clearerr(f); \ |
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
|
448 |
/* refetch */ \ |
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
|
449 |
buf = (char *)(obj); \ |
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
|
450 |
continue; \ |
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
|
451 |
} \ |
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
|
452 |
} else { \ |
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
|
453 |
(ret) = 0; \ |
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
|
454 |
} \ |
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
|
455 |
break; \ |
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
|
456 |
} \ |
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
|
457 |
(buf)[__ooffs+__offs] = (ret); \ |
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
|
458 |
__offs++; \ |
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
|
459 |
} \ |
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
|
460 |
if (__offs > 0) \ |
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
|
461 |
(ret) = __offs; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
462 |
} else { \ |
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
|
463 |
while (__offs < (cnt)) { \ |
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
|
464 |
char __buf[IO_BUFFER_SIZE]; \ |
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
|
465 |
OBJ rA = __INST(readAhead); \ |
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
|
466 |
if (rA != nil) { \ |
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
|
467 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
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
|
468 |
__INST(readAhead) = nil; \ |
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
|
469 |
(ret) = 1; \ |
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
|
470 |
} else { \ |
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
|
471 |
int l; \ |
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
|
472 |
CLEAR_ERRNO; \ |
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
|
473 |
l = (cnt)-__offs; \ |
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
|
474 |
if ( l > IO_BUFFER_SIZE) \ |
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
|
475 |
l = IO_BUFFER_SIZE; \ |
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
|
476 |
READ((ret),f, __buf, l, handleType); \ |
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
|
477 |
if ((ret) <= 0) { \ |
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
|
478 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
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
|
479 |
continue; \ |
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
|
480 |
} \ |
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
|
481 |
break; \ |
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
|
482 |
} \ |
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
|
483 |
} \ |
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
|
484 |
if ((ret) > 0 ) { \ |
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
|
485 |
/* refetch */ \ |
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
|
486 |
buf = (char *)(obj); \ |
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
|
487 |
memcpy((buf)+__ooffs+__offs,__buf,(ret)); \ |
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
|
488 |
__offs += (ret); \ |
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
|
489 |
} else { \ |
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
|
490 |
(ret) = 0; \ |
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
|
491 |
} \ |
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
|
492 |
} \ |
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
|
493 |
if (__offs > 0) \ |
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
|
494 |
(ret) = __offs; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
495 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
496 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
497 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
498 |
# 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
|
499 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
500 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
501 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
502 |
char *buf = (char *)(obj); \ |
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
|
503 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
504 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
505 |
if (isBuffered) { \ |
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
|
506 |
while (__offs < (cnt)) { \ |
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
|
507 |
CLEAR_ERRNO; \ |
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
|
508 |
(ret) = getc(f); \ |
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
|
509 |
if ((ret) < 0) { \ |
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
|
510 |
if (ferror(f)) { \ |
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
|
511 |
if (__threadErrno == EINTR) { \ |
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
|
512 |
clearerr(f); \ |
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
|
513 |
/* refetch */ \ |
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
|
514 |
buf = (char *)(obj);\ |
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
|
515 |
continue; \ |
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
|
516 |
} \ |
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
|
517 |
} else { \ |
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
|
518 |
(ret) = 0; \ |
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
|
519 |
} \ |
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
|
520 |
break; \ |
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
|
521 |
} \ |
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
|
522 |
(buf)[__ooffs+__offs] = (ret); \ |
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
|
523 |
__offs++; \ |
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
|
524 |
} \ |
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
|
525 |
if (__offs > 0) \ |
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
|
526 |
(ret) = __offs; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
527 |
} else { \ |
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
|
528 |
while (__offs < (cnt)) { \ |
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
|
529 |
char __buf[IO_BUFFER_SIZE]; \ |
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
|
530 |
OBJ rA = __INST(readAhead); \ |
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
|
531 |
if (rA != nil) { \ |
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
|
532 |
(buf)[__ooffs+__offs] = __intVal(rA);\ |
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
|
533 |
__INST(readAhead) = nil; \ |
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
|
534 |
(ret) = 1; \ |
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
|
535 |
__offs++; \ |
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
|
536 |
continue; \ |
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
|
537 |
} \ |
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
|
538 |
{ \ |
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
|
539 |
int res = 0; \ |
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
|
540 |
int l = (cnt)-__offs; \ |
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
|
541 |
CLEAR_ERRNO; \ |
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
|
542 |
if (l > IO_BUFFER_SIZE) \ |
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
|
543 |
l = IO_BUFFER_SIZE; \ |
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
|
544 |
if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)), FIONREAD, &res), 1)) \ |
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
|
545 |
|| (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \ |
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
|
546 |
|| (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0,0,0,&res,0), 1))) { \ |
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
|
547 |
if (res > 0) { \ |
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
|
548 |
if (res > l) res = l; \ |
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
|
549 |
READ((ret), f, __buf, res, handleType); \ |
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
|
550 |
} else { \ |
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
|
551 |
(ret) = 0; \ |
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
|
552 |
break; \ |
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
|
553 |
} \ |
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
|
554 |
} else { \ |
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
|
555 |
READ((ret), f, __buf, l, handleType); \ |
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
|
556 |
} \ |
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
|
557 |
if ((ret) <= 0) { \ |
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
|
558 |
if (ret < 0 && __threadErrno == EINTR) \ |
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
|
559 |
continue; \ |
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
|
560 |
break; \ |
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
|
561 |
} \ |
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
|
562 |
} \ |
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
|
563 |
if ((ret) > 0) { \ |
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
|
564 |
buf = (char *)(obj); \ |
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
|
565 |
memcpy((buf)+__ooffs+__offs, __buf, (ret)); \ |
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
|
566 |
__offs += (ret); \ |
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
|
567 |
} else { \ |
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
|
568 |
(ret) = 0; \ |
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
|
569 |
} \ |
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
|
570 |
} \ |
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
|
571 |
if (__offs > 0) \ |
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
|
572 |
(ret) = __offs; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
573 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
574 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
575 |
|
12548 | 576 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
577 |
if (isBuffered) { \ |
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
|
578 |
for (;;) { \ |
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
|
579 |
CLEAR_ERRNO; \ |
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
|
580 |
ret = putc(*(buf), f); \ |
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
|
581 |
if ((ret) >= 0) { \ |
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
|
582 |
(ret) = 1; \ |
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
|
583 |
} else if (ferror(f)) { \ |
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
|
584 |
if (__threadErrno == EINTR) { \ |
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
|
585 |
clearerr(f); \ |
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
|
586 |
continue; \ |
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
|
587 |
} \ |
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
|
588 |
} else \ |
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
|
589 |
(ret) = 0; \ |
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
|
590 |
break; \ |
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
|
591 |
} \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
592 |
} else { \ |
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
|
593 |
for (;;) { \ |
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
|
594 |
CLEAR_ERRNO; \ |
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
|
595 |
WRITE(ret,f, buf, 1, handleType); \ |
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
|
596 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
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
|
597 |
break; \ |
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
|
598 |
} \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
599 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
600 |
|
12548 | 601 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
602 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
603 |
if (isBuffered) { \ |
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
|
604 |
int __offs = 0; \ |
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
|
605 |
while (__offs < (cnt)) { \ |
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
|
606 |
CLEAR_ERRNO; \ |
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
|
607 |
(ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
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
|
608 |
if ((ret) <= 0) { \ |
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
|
609 |
if (ferror(f)) { \ |
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
|
610 |
if (__threadErrno == EINTR) { \ |
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
|
611 |
clearerr(f); \ |
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
|
612 |
continue; \ |
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
|
613 |
} \ |
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
|
614 |
break; \ |
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
|
615 |
} else { \ |
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
|
616 |
(ret) = 0; \ |
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
|
617 |
} \ |
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
|
618 |
} \ |
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
|
619 |
__offs += (ret); \ |
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
|
620 |
} \ |
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
|
621 |
if (__offs > 0) \ |
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
|
622 |
(ret) = __offs; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
623 |
} else { \ |
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
|
624 |
int __offs = 0; \ |
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
|
625 |
while (__offs < (cnt)) { \ |
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
|
626 |
CLEAR_ERRNO; \ |
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
|
627 |
WRITE(ret,f, (buf)+__offs, (cnt)-__offs, handleType); \ |
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
|
628 |
if (ret <= 0) { \ |
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
|
629 |
if (ret < 0 && __threadErrno == EINTR) { \ |
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
|
630 |
continue; \ |
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
|
631 |
} \ |
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
|
632 |
break; \ |
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
|
633 |
} \ |
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
|
634 |
__offs += (ret); \ |
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
|
635 |
} \ |
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
|
636 |
if (__offs > 0) \ |
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
|
637 |
(ret) = __offs; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
638 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
639 |
|
12548 | 640 |
# 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
|
641 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
642 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
643 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
644 |
char *buf = (char *)(obj); \ |
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
|
645 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
646 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
647 |
if (isBuffered) { \ |
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
|
648 |
while (__offs < (cnt)) { \ |
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
|
649 |
CLEAR_ERRNO; \ |
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
|
650 |
ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
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
|
651 |
if ((ret) <= 0) { \ |
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
|
652 |
if (ferror(f)) { \ |
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
|
653 |
if (__threadErrno == EINTR) { \ |
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
|
654 |
/* refetch */ \ |
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
|
655 |
buf = (char *)(obj); \ |
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
|
656 |
clearerr(f); \ |
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
|
657 |
continue; \ |
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
|
658 |
} \ |
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
|
659 |
break; \ |
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
|
660 |
} else { \ |
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
|
661 |
(ret) = 0; \ |
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
|
662 |
} \ |
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
|
663 |
} \ |
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
|
664 |
__offs += (ret); \ |
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
|
665 |
} \ |
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
|
666 |
if (__offs > 0) \ |
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
|
667 |
(ret) = __offs; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
668 |
} else { \ |
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
|
669 |
while (__offs < (cnt)) { \ |
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
|
670 |
char __buf[IO_BUFFER_SIZE]; \ |
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
|
671 |
int l; \ |
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
|
672 |
CLEAR_ERRNO; \ |
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
|
673 |
l = (cnt)-__offs; \ |
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
|
674 |
if ( l > IO_BUFFER_SIZE) \ |
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
|
675 |
l = IO_BUFFER_SIZE; \ |
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
|
676 |
/* refetch */ \ |
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
|
677 |
buf = (char *)(obj); \ |
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
|
678 |
memcpy(__buf,(buf)+__ooffs+__offs,l); \ |
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
|
679 |
WRITE(ret,f, __buf, l, handleType); \ |
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
|
680 |
if (ret <= 0) { \ |
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
|
681 |
if (ret < 0 && __threadErrno == EINTR) { \ |
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
|
682 |
continue; \ |
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
|
683 |
} \ |
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
|
684 |
break; \ |
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
|
685 |
} \ |
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
|
686 |
__offs += (ret); \ |
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
|
687 |
} \ |
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
|
688 |
if (__offs > 0) \ |
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
|
689 |
(ret) = __offs; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
690 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
691 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
692 |
|
16296 | 693 |
#else /* ! WIN32 */ |
694 |
/* ======================== UNIX / LINUX ====================================================== */ |
|
16373
9b9827530bf4
Adapt previous change for linux
Stefan Vogel <sv@exept.de>
parents:
16368
diff
changeset
|
695 |
typedef int SOCKET; |
9b9827530bf4
Adapt previous change for linux
Stefan Vogel <sv@exept.de>
parents:
16368
diff
changeset
|
696 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
697 |
# define __READING__(f) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
698 |
if ((__INST(didWrite) != false) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
699 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
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
|
700 |
__INST(didWrite) = false; \ |
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
|
701 |
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
|
702 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
703 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
704 |
# define __WRITING__(f) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
705 |
if ((__INST(didWrite) != true) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
706 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
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
|
707 |
__INST(didWrite) = true; \ |
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
|
708 |
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
|
709 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
710 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
711 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
712 |
# ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
713 |
# define __UNGETC__(c, f, isBuffered) \ |
8913 | 714 |
__INST(readAhead) = __mkSmallInteger((c)); |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
715 |
# else /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
716 |
# define __UNGETC__(c, f, isBuffered) \ |
2264 | 717 |
if (isBuffered) { \ |
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
|
718 |
ungetc((c), (f)); \ |
2264 | 719 |
} else { \ |
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
|
720 |
__INST(readAhead) = __mkSmallInteger((c)); \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
721 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
722 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
723 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
724 |
# ifdef NO_STDIO |
12548 | 725 |
# 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
|
726 |
{ \ |
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
|
727 |
OBJ rA = __INST(readAhead); \ |
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
|
728 |
if (rA != nil) { \ |
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
|
729 |
*(buf) = __intVal(rA); \ |
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
|
730 |
DEBUGBUFFER(buf); \ |
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
|
731 |
__INST(readAhead) = nil; \ |
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
|
732 |
(ret) = 1; \ |
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
|
733 |
} else { \ |
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
|
734 |
for (;;) { \ |
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
|
735 |
CLEAR_ERRNO; \ |
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
|
736 |
(ret) = READ(f, buf, 1, handleType); \ |
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
|
737 |
DEBUGBUFFER(buf); \ |
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
|
738 |
if ((ret) >= 0) break; \ |
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
|
739 |
if (errno != EINTR) { \ |
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
|
740 |
break; \ |
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
|
741 |
} \ |
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
|
742 |
__HANDLE_INTERRUPTS__; \ |
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
|
743 |
} \ |
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
|
744 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
745 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
746 |
# else /* use STDIO */ |
12548 | 747 |
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \ |
2264 | 748 |
if (isBuffered) { \ |
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
|
749 |
for (;;) { \ |
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
|
750 |
CLEAR_ERRNO; \ |
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
|
751 |
(ret) = getc(f); \ |
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
|
752 |
if ((ret) >= 0) { \ |
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
|
753 |
DEBUGBUFFER(buf); \ |
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
|
754 |
*(buf) = (ret); \ |
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
|
755 |
(ret) = 1; \ |
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
|
756 |
} else if (ferror(f)) { \ |
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
|
757 |
if (errno == EINTR) { \ |
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
|
758 |
__HANDLE_INTERRUPTS__; \ |
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
|
759 |
clearerr(f); \ |
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
|
760 |
continue; \ |
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
|
761 |
} \ |
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
|
762 |
} else \ |
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
|
763 |
(ret) = 0; \ |
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
|
764 |
break; \ |
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
|
765 |
} \ |
2264 | 766 |
} else { \ |
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
|
767 |
OBJ rA = __INST(readAhead); \ |
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
|
768 |
if (rA != nil) { \ |
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
|
769 |
*(buf) = __intVal(rA); \ |
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
|
770 |
DEBUGBUFFER(buf); \ |
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
|
771 |
__INST(readAhead) = nil; \ |
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
|
772 |
(ret) = 1; \ |
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
|
773 |
} else { \ |
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
|
774 |
for (;;) { \ |
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
|
775 |
CLEAR_ERRNO; \ |
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
|
776 |
(ret) = read(fileno(f), buf, 1); \ |
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
|
777 |
DEBUGBUFFER(buf); \ |
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
|
778 |
if ((ret) >= 0) break; \ |
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
|
779 |
if (errno != EINTR) { \ |
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
|
780 |
break; \ |
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
|
781 |
} \ |
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
|
782 |
__HANDLE_INTERRUPTS__; \ |
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
|
783 |
} \ |
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
|
784 |
} \ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
785 |
} |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
786 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
787 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
788 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
789 |
* 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
|
790 |
* (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
|
791 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
792 |
# ifdef NO_STDIO |
12548 | 793 |
# 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
|
794 |
{ \ |
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
|
795 |
int __offs = 0, __cnt; \ |
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
|
796 |
\ |
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
|
797 |
while (__offs < (cnt)) { \ |
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
|
798 |
OBJ rA = __INST(readAhead); \ |
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
|
799 |
if (rA != nil) { \ |
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
|
800 |
(buf)[__offs] = __intVal(rA); \ |
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
|
801 |
DEBUGBUFFER(buf); \ |
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
|
802 |
__INST(readAhead) = nil; \ |
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
|
803 |
__offs++; \ |
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
|
804 |
} else { \ |
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
|
805 |
CLEAR_ERRNO; \ |
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
|
806 |
__cnt = READ(f, (buf)+__offs, (cnt)-__offs, handleType); \ |
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
|
807 |
DEBUGBUFFER(buf); \ |
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
|
808 |
if (__cnt <= 0) { \ |
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
|
809 |
if (__cnt < 0 && errno == EINTR) { \ |
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
|
810 |
__HANDLE_INTERRUPTS__; \ |
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
|
811 |
continue; \ |
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
|
812 |
} \ |
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
|
813 |
break; \ |
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
|
814 |
} \ |
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
|
815 |
__offs += __cnt; \ |
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
|
816 |
} \ |
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
|
817 |
} \ |
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
|
818 |
if (__offs > 0) \ |
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
|
819 |
(ret) = __offs; \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
820 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
821 |
# else /* use STDIO */ |
12548 | 822 |
# 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
|
823 |
(ret) = 0; \ |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
824 |
if (isBuffered) { \ |
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
|
825 |
int __offs = 0; \ |
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
|
826 |
while (__offs < (cnt)) { \ |
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
|
827 |
CLEAR_ERRNO; \ |
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
|
828 |
(ret) = getc(f); \ |
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
|
829 |
if ((ret) < 0) { \ |
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
|
830 |
if (ferror(f)) { \ |
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
|
831 |
if (errno == EINTR) { \ |
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
|
832 |
__HANDLE_INTERRUPTS__; \ |
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
|
833 |
clearerr(f); \ |
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
|
834 |
continue; \ |
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
|
835 |
} \ |
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
|
836 |
} else { \ |
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
|
837 |
(ret) = 0; \ |
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
|
838 |
} \ |
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
|
839 |
break; \ |
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
|
840 |
} \ |
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
|
841 |
DEBUGBUFFER(buf); \ |
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
|
842 |
(buf)[__offs++] = (ret); \ |
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
|
843 |
} \ |
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
|
844 |
if (__offs > 0) \ |
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
|
845 |
(ret) = __offs; \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
846 |
} else { \ |
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
|
847 |
int __offs = 0, __cnt; \ |
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
|
848 |
int fd = fileno(f); \ |
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
|
849 |
\ |
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
|
850 |
while (__offs < (cnt)) { \ |
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
|
851 |
OBJ rA = __INST(readAhead); \ |
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
|
852 |
if (rA != nil) { \ |
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
|
853 |
DEBUGBUFFER(buf); \ |
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
|
854 |
(buf)[__offs] = __intVal(rA); \ |
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
|
855 |
__INST(readAhead) = nil; \ |
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
|
856 |
__offs++; \ |
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
|
857 |
} else { \ |
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
|
858 |
CLEAR_ERRNO; \ |
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
|
859 |
__cnt = read(fd, (buf)+__offs, (cnt)-__offs); \ |
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
|
860 |
DEBUGBUFFER(buf); \ |
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
|
861 |
if (__cnt <= 0) { \ |
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
|
862 |
if (__cnt < 0 && errno == EINTR) { \ |
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
|
863 |
__HANDLE_INTERRUPTS__; \ |
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
|
864 |
continue; \ |
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
|
865 |
} \ |
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
|
866 |
break; \ |
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
|
867 |
} \ |
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
|
868 |
__offs += __cnt; \ |
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
|
869 |
} \ |
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
|
870 |
} \ |
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
|
871 |
if (__offs > 0) \ |
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
|
872 |
(ret) = __offs; \ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
873 |
} |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
874 |
|
6563
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
875 |
|
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
876 |
/* |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
877 |
* 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
|
878 |
*/ |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
879 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
880 |
# 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
|
881 |
# define SETFLAGS(fd, flags) \ |
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
|
882 |
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
|
883 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
884 |
# if defined(O_NONBLOCK) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
885 |
# define __STX_NONBLOCK_FLAG O_NONBLOCK |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
886 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
887 |
# if defined(O_NDELAY) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
888 |
# define __STX_NONBLOCK_FLAG O_NDELAY |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
889 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
890 |
# define __STX_NONBLOCK_FLAG FNDELAY |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
891 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
892 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
893 |
|
15342 | 894 |
# define SETNONBLOCKING(fd, oldFlags) \ |
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
|
895 |
{ \ |
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
|
896 |
int flags = fcntl(fd, F_GETFL, 0); \ |
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
|
897 |
if (flags >= 0) { \ |
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
|
898 |
fcntl(fd, F_SETFL, flags | __STX_NONBLOCK_FLAG); \ |
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
|
899 |
} \ |
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
|
900 |
oldFlags = flags; \ |
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
|
901 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
902 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
903 |
# define SETFLAGS(fd, flags) /* nothing */ |
15342 | 904 |
# define SETNONBLOCKING(fd, oldFlags) /* nothing */ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
905 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
906 |
|
12548 | 907 |
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
908 |
{ \ |
15342 | 909 |
int __offs = 0, __cnt; \ |
3681 | 910 |
int oldFlags; \ |
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
|
911 |
\ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
912 |
(ret) = 0; \ |
15342 | 913 |
SETNONBLOCKING(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
914 |
if (isBuffered) { \ |
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
|
915 |
while (__offs < (cnt)) { \ |
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
|
916 |
CLEAR_ERRNO; \ |
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
|
917 |
(ret) = getc(f); \ |
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
|
918 |
if ((ret) < 0) { \ |
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
|
919 |
if (ferror(f)) { \ |
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
|
920 |
if (errno == EINTR) { \ |
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
|
921 |
(ret) = 0; \ |
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
|
922 |
clearerr(f); \ |
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
|
923 |
break; \ |
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
|
924 |
} \ |
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
|
925 |
} else { \ |
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
|
926 |
(ret) = 0; \ |
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
|
927 |
} \ |
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
|
928 |
break; \ |
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
|
929 |
} \ |
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
|
930 |
(buf)[__offs++] = (ret); \ |
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
|
931 |
DEBUGBUFFER(buf); \ |
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
|
932 |
} \ |
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
|
933 |
if (__offs > 0) \ |
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
|
934 |
(ret) = __offs; \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
935 |
} else { \ |
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
|
936 |
int fd = fileno(f); \ |
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
|
937 |
\ |
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
|
938 |
while (__offs < (cnt)) { \ |
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
|
939 |
OBJ rA = __INST(readAhead); \ |
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
|
940 |
if (rA != nil) { \ |
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
|
941 |
(buf)[__offs] = __intVal(rA); \ |
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
|
942 |
DEBUGBUFFER(buf); \ |
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
|
943 |
__INST(readAhead) = nil; \ |
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
|
944 |
__offs++; \ |
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
|
945 |
continue; \ |
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
|
946 |
} \ |
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
|
947 |
CLEAR_ERRNO; \ |
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
|
948 |
__cnt = read(fd, (buf)+__offs, (cnt)-__offs); \ |
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
|
949 |
DEBUGBUFFER(buf); \ |
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
|
950 |
if (__cnt > 0) { \ |
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
|
951 |
__offs += __cnt; \ |
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
|
952 |
} \ |
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
|
953 |
break; \ |
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
|
954 |
} \ |
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
|
955 |
if (__offs > 0) \ |
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
|
956 |
(ret) = __offs; \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
957 |
} \ |
3681 | 958 |
SETFLAGS(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
959 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
960 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
961 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
962 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
963 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
964 |
* 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
|
965 |
* (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
|
966 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
967 |
# ifdef NO_STDIO |
12548 | 968 |
# 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
|
969 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
970 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
971 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
972 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
973 |
char *buf = (char *)(obj); \ |
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
|
974 |
\ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
975 |
(ret) = 0; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
976 |
{ \ |
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
|
977 |
while (__offs < (cnt)) { \ |
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
|
978 |
OBJ rA = __INST(readAhead); \ |
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
|
979 |
if (rA != nil) { \ |
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
|
980 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
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
|
981 |
DEBUGBUFFER(buf); \ |
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
|
982 |
__INST(readAhead) = nil; \ |
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
|
983 |
__offs++; \ |
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
|
984 |
} else { \ |
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
|
985 |
CLEAR_ERRNO; \ |
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
|
986 |
__cnt = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \ |
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
|
987 |
DEBUGBUFFER(buf); \ |
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
|
988 |
if (__cnt <= 0) { \ |
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
|
989 |
if (__cnt < 0 && errno == EINTR) { \ |
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
|
990 |
__HANDLE_INTERRUPTS__; \ |
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
|
991 |
/* refetch */ \ |
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
|
992 |
buf = (char *)(obj); \ |
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
|
993 |
continue; \ |
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
|
994 |
} \ |
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
|
995 |
break; \ |
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
|
996 |
} \ |
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
|
997 |
__offs += __cnt; \ |
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
|
998 |
} \ |
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
|
999 |
} \ |
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
|
1000 |
if (__offs > 0) \ |
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
|
1001 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1002 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1003 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
1004 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1005 |
# else /* use STDIO */ |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
1006 |
|
12548 | 1007 |
# 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
|
1008 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1009 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1010 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1011 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1012 |
char *buf = (char *)(obj); \ |
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
|
1013 |
\ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1014 |
(ret) = 0; \ |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1015 |
if (isBuffered) { \ |
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
|
1016 |
while (__offs < (cnt)) { \ |
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
|
1017 |
CLEAR_ERRNO; \ |
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
|
1018 |
(ret) = getc(f); \ |
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
|
1019 |
if ((ret) < 0) { \ |
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
|
1020 |
if (ferror(f)) { \ |
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
|
1021 |
if (errno == EINTR) { \ |
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
|
1022 |
__HANDLE_INTERRUPTS__; \ |
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
|
1023 |
clearerr(f); \ |
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
|
1024 |
/* refetch */ \ |
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
|
1025 |
buf = (char *)(obj); \ |
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
|
1026 |
DEBUGBUFFER(buf); \ |
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
|
1027 |
continue; \ |
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
|
1028 |
} \ |
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
|
1029 |
} else { \ |
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
|
1030 |
(ret) = 0; \ |
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
|
1031 |
} \ |
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
|
1032 |
break; \ |
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
|
1033 |
} \ |
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
|
1034 |
(buf)[__ooffs+__offs] = (ret); \ |
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
|
1035 |
DEBUGBUFFER(buf); \ |
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
|
1036 |
__offs++; \ |
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
|
1037 |
} \ |
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
|
1038 |
if (__offs > 0) \ |
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
|
1039 |
(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
|
1040 |
} else { \ |
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
|
1041 |
int fd = fileno(f); \ |
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
|
1042 |
\ |
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
|
1043 |
while (__offs < (cnt)) { \ |
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
|
1044 |
OBJ rA = __INST(readAhead); \ |
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
|
1045 |
if (rA != nil) { \ |
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
|
1046 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
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
|
1047 |
DEBUGBUFFER(buf); \ |
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
|
1048 |
__INST(readAhead) = nil; \ |
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
|
1049 |
__offs++; \ |
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
|
1050 |
} else { \ |
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
|
1051 |
CLEAR_ERRNO; \ |
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
|
1052 |
__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
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
|
1053 |
DEBUGBUFFER(buf); \ |
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
|
1054 |
if (__cnt <= 0) { \ |
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
|
1055 |
if (__cnt < 0 && errno == EINTR) { \ |
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
|
1056 |
__HANDLE_INTERRUPTS__; \ |
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
|
1057 |
/* refetch */ \ |
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
|
1058 |
buf = (char *)(obj); \ |
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
|
1059 |
continue; \ |
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
|
1060 |
} \ |
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
|
1061 |
break; \ |
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
|
1062 |
} \ |
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
|
1063 |
__offs += __cnt; \ |
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
|
1064 |
} \ |
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
|
1065 |
} \ |
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
|
1066 |
if (__offs > 0) \ |
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
|
1067 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1068 |
} \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1069 |
} |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1070 |
|
12548 | 1071 |
# 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
|
1072 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1073 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1074 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1075 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1076 |
char *buf = (char *)(obj); \ |
15342 | 1077 |
int oldFlags; \ |
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
|
1078 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1079 |
(ret) = 0; \ |
15342 | 1080 |
SETNONBLOCKING(fileno(f), oldFlags); \ |
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
|
1081 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1082 |
if (isBuffered) { \ |
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
|
1083 |
while (__offs < (cnt)) { \ |
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
|
1084 |
CLEAR_ERRNO; \ |
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
|
1085 |
(ret) = getc(f); \ |
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
|
1086 |
if ((ret) < 0) { \ |
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
|
1087 |
if (ferror(f)) { \ |
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
|
1088 |
if (errno == EINTR) { \ |
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
|
1089 |
clearerr(f); \ |
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
|
1090 |
/* refetch */ \ |
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
|
1091 |
buf = (char *)(obj); \ |
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
|
1092 |
(ret) = 0; \ |
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
|
1093 |
break; \ |
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
|
1094 |
} \ |
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
|
1095 |
} else { \ |
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
|
1096 |
(ret) = 0; \ |
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
|
1097 |
} \ |
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
|
1098 |
break; \ |
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
|
1099 |
} \ |
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
|
1100 |
(buf)[__ooffs+__offs] = (ret); \ |
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
|
1101 |
DEBUGBUFFER(buf); \ |
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
|
1102 |
__offs++; \ |
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
|
1103 |
} \ |
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
|
1104 |
if (__offs > 0) \ |
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
|
1105 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1106 |
} else { \ |
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
|
1107 |
int fd = fileno(f); \ |
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
|
1108 |
\ |
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
|
1109 |
while (__offs < (cnt)) { \ |
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
|
1110 |
OBJ rA = __INST(readAhead); \ |
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
|
1111 |
if (rA != nil) { \ |
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
|
1112 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
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
|
1113 |
DEBUGBUFFER(buf); \ |
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
|
1114 |
__INST(readAhead) = nil; \ |
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
|
1115 |
__offs++; \ |
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
|
1116 |
continue; \ |
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
|
1117 |
} \ |
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
|
1118 |
CLEAR_ERRNO; \ |
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
|
1119 |
__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
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
|
1120 |
DEBUGBUFFER(buf); \ |
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
|
1121 |
if (__cnt > 0) { \ |
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
|
1122 |
__offs += __cnt; \ |
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
|
1123 |
} \ |
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
|
1124 |
break; \ |
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
|
1125 |
} \ |
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
|
1126 |
if (__offs > 0) \ |
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
|
1127 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1128 |
} \ |
15342 | 1129 |
SETFLAGS(fileno(f), oldFlags); \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1130 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1131 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1132 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1133 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1134 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1135 |
# ifdef NO_STDIO |
12548 | 1136 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
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
|
1137 |
for (;;) { \ |
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
|
1138 |
CLEAR_ERRNO; \ |
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
|
1139 |
(ret) = WRITE(f, buf, 1, handleType); \ |
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
|
1140 |
if ((ret) >= 0) break; \ |
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
|
1141 |
if (errno != EINTR) { \ |
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
|
1142 |
break; \ |
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
|
1143 |
} \ |
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
|
1144 |
__HANDLE_INTERRUPTS__; \ |
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
|
1145 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1146 |
# else /* use STDIO */ |
12548 | 1147 |
# 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
|
1148 |
if (isBuffered) { \ |
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
|
1149 |
for (;;) { \ |
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
|
1150 |
CLEAR_ERRNO; \ |
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
|
1151 |
ret = putc(*(buf), f); \ |
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
|
1152 |
if ((ret) >= 0) { \ |
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
|
1153 |
(ret) = 1; \ |
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
|
1154 |
} else if (ferror(f)) { \ |
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
|
1155 |
/* SOLARIS/SPARC (2.6) generates spurious errors with errno = 0 */ \ |
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
|
1156 |
if (errno == EINTR || errno == 0) { \ |
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
|
1157 |
__HANDLE_INTERRUPTS__; \ |
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
|
1158 |
clearerr(f); \ |
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
|
1159 |
continue; \ |
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
|
1160 |
} \ |
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
|
1161 |
} else \ |
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
|
1162 |
(ret) = 0; \ |
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
|
1163 |
break; \ |
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
|
1164 |
} \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1165 |
} else { \ |
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
|
1166 |
for (;;) { \ |
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
|
1167 |
CLEAR_ERRNO; \ |
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
|
1168 |
(ret) = write(fileno(f), buf, 1); \ |
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
|
1169 |
if ((ret) >= 0) break; \ |
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
|
1170 |
if (errno != EINTR) { \ |
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
|
1171 |
break; \ |
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
|
1172 |
} \ |
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
|
1173 |
__HANDLE_INTERRUPTS__; \ |
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
|
1174 |
} \ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1175 |
} |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1176 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1177 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1178 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1179 |
* 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
|
1180 |
* (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
|
1181 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1182 |
# ifdef NO_STDIO |
12548 | 1183 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2961 | 1184 |
(ret) = 0; \ |
1185 |
{ \ |
|
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
|
1186 |
int __offs = 0; \ |
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
|
1187 |
while (__offs < (cnt)) { \ |
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
|
1188 |
CLEAR_ERRNO; \ |
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
|
1189 |
ret = WRITE(f, (buf)+__offs, (cnt)-__offs, handleType); \ |
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
|
1190 |
if (ret <= 0) { \ |
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
|
1191 |
if (ret < 0 && errno == EINTR) { \ |
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
|
1192 |
__HANDLE_INTERRUPTS__; \ |
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
|
1193 |
continue; \ |
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
|
1194 |
} \ |
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
|
1195 |
break; \ |
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
|
1196 |
} \ |
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
|
1197 |
__offs += (ret); \ |
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
|
1198 |
} \ |
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
|
1199 |
if (__offs > 0) \ |
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
|
1200 |
(ret) = __offs; \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1201 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1202 |
# else /* use STDIO */ |
12548 | 1203 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2961 | 1204 |
(ret) = 0; \ |
1205 |
if (isBuffered) { \ |
|
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
|
1206 |
int __offs = 0; \ |
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
|
1207 |
while (__offs < (cnt)) { \ |
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
|
1208 |
CLEAR_ERRNO; \ |
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
|
1209 |
(ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
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
|
1210 |
if ((ret) <= 0) { \ |
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
|
1211 |
if (ferror(f)) { \ |
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
|
1212 |
if (errno == EINTR) { \ |
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
|
1213 |
__HANDLE_INTERRUPTS__; \ |
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
|
1214 |
clearerr(f); \ |
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
|
1215 |
continue; \ |
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
|
1216 |
} \ |
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
|
1217 |
} else { \ |
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
|
1218 |
(ret) = 0; \ |
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
|
1219 |
} \ |
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
|
1220 |
break; \ |
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
|
1221 |
} \ |
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
|
1222 |
__offs += (ret); \ |
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
|
1223 |
} \ |
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
|
1224 |
if (__offs > 0) \ |
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
|
1225 |
(ret) = __offs; \ |
2961 | 1226 |
} else { \ |
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
|
1227 |
int __offs = 0; \ |
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
|
1228 |
while (__offs < (cnt)) { \ |
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
|
1229 |
CLEAR_ERRNO; \ |
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
|
1230 |
(ret) = write(fileno(f), (buf)+__offs, (cnt)-__offs);\ |
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
|
1231 |
if ((ret) <= 0) { \ |
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
|
1232 |
if ((ret) < 0) { \ |
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
|
1233 |
if (errno == EINTR) { \ |
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
|
1234 |
__HANDLE_INTERRUPTS__; \ |
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
|
1235 |
continue; \ |
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
|
1236 |
} \ |
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
|
1237 |
} \ |
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
|
1238 |
break; \ |
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
|
1239 |
} \ |
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
|
1240 |
__offs += (ret); \ |
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
|
1241 |
} \ |
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
|
1242 |
if (__offs > 0) \ |
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
|
1243 |
(ret) = __offs; \ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1244 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1245 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1246 |
|
223 | 1247 |
/* |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1248 |
* 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
|
1249 |
* (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
|
1250 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1251 |
# ifdef NO_STDIO |
12548 | 1252 |
# 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
|
1253 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1254 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1255 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1256 |
char *buf = (char *)(obj); \ |
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
|
1257 |
\ |
2961 | 1258 |
(ret) = 0; \ |
1259 |
{ \ |
|
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
|
1260 |
while (__offs < (cnt)) { \ |
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
|
1261 |
CLEAR_ERRNO; \ |
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
|
1262 |
ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \ |
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
|
1263 |
if (ret <= 0) { \ |
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
|
1264 |
if (ret < 0 && errno == EINTR) { \ |
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
|
1265 |
__HANDLE_INTERRUPTS__; \ |
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
|
1266 |
/* refetch */ \ |
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
|
1267 |
buf = (char *)(obj); \ |
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
|
1268 |
continue; \ |
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
|
1269 |
} \ |
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
|
1270 |
break; \ |
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
|
1271 |
} \ |
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
|
1272 |
__offs += (ret); \ |
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
|
1273 |
} \ |
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
|
1274 |
if (__offs > 0) \ |
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
|
1275 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1276 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1277 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1278 |
# else /* use STDIO */ |
12548 | 1279 |
# 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
|
1280 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1281 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1282 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1283 |
char *buf = (char *)(obj); \ |
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
|
1284 |
\ |
2961 | 1285 |
(ret) = 0; \ |
1286 |
if (isBuffered) { \ |
|
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
|
1287 |
while (__offs < (cnt)) { \ |
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
|
1288 |
CLEAR_ERRNO; \ |
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
|
1289 |
(ret) = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
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
|
1290 |
if ((ret) <= 0) { \ |
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
|
1291 |
if (ferror(f)) { \ |
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
|
1292 |
if (errno == EINTR) { \ |
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
|
1293 |
__HANDLE_INTERRUPTS__; \ |
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
|
1294 |
/* refetch */ \ |
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
|
1295 |
buf = (char *)(obj); \ |
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
|
1296 |
clearerr(f); \ |
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
|
1297 |
continue; \ |
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
|
1298 |
} \ |
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
|
1299 |
break; \ |
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
|
1300 |
} else { \ |
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
|
1301 |
(ret) = 0; \ |
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
|
1302 |
} \ |
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
|
1303 |
} \ |
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
|
1304 |
__offs += (ret); \ |
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
|
1305 |
} \ |
2961 | 1306 |
} else { \ |
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
|
1307 |
while (__offs < (cnt)) { \ |
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
|
1308 |
CLEAR_ERRNO; \ |
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
|
1309 |
(ret) = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs); \ |
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
|
1310 |
if ((ret) <= 0) { \ |
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
|
1311 |
if ((ret) < 0) { \ |
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
|
1312 |
if (errno == EINTR){ \ |
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
|
1313 |
__HANDLE_INTERRUPTS__; \ |
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
|
1314 |
/* refetch */ \ |
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
|
1315 |
buf = (char *)(obj); \ |
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
|
1316 |
continue; \ |
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
|
1317 |
} \ |
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
|
1318 |
} \ |
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
|
1319 |
break; \ |
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
|
1320 |
} \ |
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
|
1321 |
__offs += (ret); \ |
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
|
1322 |
} \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1323 |
} \ |
15845 | 1324 |
if (__offs > 0) \ |
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
|
1325 |
(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
|
1326 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1327 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1328 |
#endif /* unix */ |
1 | 1329 |
%} |
188 | 1330 |
! ! |
1 | 1331 |
|
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1332 |
!ExternalStream class methodsFor:'documentation'! |
22 | 1333 |
|
88 | 1334 |
copyright |
1335 |
" |
|
1336 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1337 |
All Rights Reserved |
88 | 1338 |
|
1339 |
This software is furnished under a license and may be used |
|
1340 |
only in accordance with the terms of that license and with the |
|
1341 |
inclusion of the above copyright notice. This software may not |
|
1342 |
be provided or otherwise made available to, or used by, any |
|
1343 |
other person. No title to or ownership of the software is |
|
1344 |
hereby transferred. |
|
1345 |
" |
|
1346 |
! |
|
1347 |
||
22 | 1348 |
documentation |
1349 |
" |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1350 |
ExternalStream defines protocol common to Streams which have a file-descriptor and |
68 | 1351 |
represent some file or communicationChannel of the underlying OperatingSystem. |
1352 |
ExternalStream is abstract; concrete classes are FileStream, PipeStream etc. |
|
77 | 1353 |
|
159 | 1354 |
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
|
1355 |
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
|
1356 |
while in binary-mode the basic elements are bytes which read/write as SmallIntegers |
68 | 1357 |
in the range 0..255. |
22 | 1358 |
|
68 | 1359 |
Also, the stream can be either in buffered or unbuffered mode. In buffered mode, |
1360 |
data is not written until either a cr is written (in text mode) or a synchronizeOutput |
|
1361 |
is sent (in both modes). |
|
22 | 1362 |
|
77 | 1363 |
The underlying OperatingSystem streams may either be closed explicitely (sending a close) |
68 | 1364 |
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
|
1365 |
object AND a close will be performed automatically (but you will NOT know when this |
77 | 1366 |
happens - so it is recommended, that you close your files when no longer needed). |
159 | 1367 |
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
|
1368 |
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
|
1369 |
All streams understand the close message, so it never hurts to use it (it is defined as |
77 | 1370 |
a noop in one of the superclasses). |
22 | 1371 |
|
68 | 1372 |
Most of the methods found here redefine inherited methods for better performance, |
1373 |
since I/O from/to files should be fast. |
|
22 | 1374 |
|
68 | 1375 |
Recovering a snapshot: |
1295 | 1376 |
not all streams can be restored to the state they had before - see the implementation of |
1377 |
reOpen in subclasses for more information. |
|
1378 |
For streams sitting on some communication channel (i.e. Pipes and Sockets) you should |
|
1379 |
reestablish the stream upon image restart (make someone dependent on ObjectMemory). |
|
1380 |
FileStreams are reopened and positioned to their offset they had at snapshot time. |
|
1381 |
This may fail, if the file was removed or renamed - or lead to confusion |
|
1382 |
if the contents changed in the meantime. |
|
1383 |
Therefore, it is a good idea to reopen files and check for these things at restart time. |
|
1384 |
||
1385 |
[Instance variables:] |
|
1386 |
||
16508 | 1387 |
handleType <Symbol> desribes what handle is: |
1388 |
win32: #fileHandle, #socketHandle, |
|
1389 |
#filePointer, #socketFilePointer, #pipeFilePointer |
|
1390 |
unix: #filePointer, #socketFilePointer, #pipeFilePointer |
|
1391 |
needed for win32, which uses different APIs for the different handles (sigh) |
|
1392 |
handle <Integer> used to be always a filePointer somehow mapped to an integer (FILE* - not the fd); |
|
1393 |
now, either a filePointer or a handle (win32) |
|
1394 |
mode <Symbol> #readwrite, #readonly or #writeonly |
|
1395 |
buffered <Boolean> true, if buffered (i.e. collects characters - does |
|
1396 |
not output immediately) |
|
1397 |
binary <Boolean> true if in binary mode (reads bytes instead of chars) |
|
1398 |
eolMode <Symbol> one of nil, #cr or #crlf. |
|
1399 |
determines how lines should be terminated. |
|
1400 |
nil -> newLine (as in Unix); |
|
1401 |
#crlf -> with cr-lf (as in MSDOS) |
|
1402 |
#cr -> with cr (as in VMS) |
|
1403 |
hitEOF <Boolean> true, if EOF was reached |
|
1404 |
||
1405 |
lastErrorNumber <Integer> the value of errno (only valid right after the error - |
|
1406 |
updated with next i/o operation) |
|
1295 | 1407 |
|
1408 |
[Class variables:] |
|
16508 | 1409 |
Lobby <Registry> keeps track of used ext-streams (to free up FILE*'s) |
1410 |
||
1411 |
StreamErrorSignal <Signal> parent of all stream errors (see Stream class) |
|
1412 |
InvalidReadSignal <Signal> raised on read from writeonly stream |
|
1413 |
InvalidWriteSignal <Signal> raised on write to readonly stream |
|
1414 |
InvalidModeSignal <Signal> raised on text I/O with binary-stream |
|
1415 |
or binary I/O with text-stream |
|
1416 |
OpenErrorSignal <Signal> raised if open fails |
|
1417 |
StreamNotOpenSignal <Signal> raised on I/O with non-open stream |
|
159 | 1418 |
|
1419 |
Additional notes: |
|
1420 |
This class is implemented using the underlying stdio-c library package, which |
|
1421 |
has both advantages and disadvantages: since it is portable (posix defined), porting |
|
1422 |
ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library |
|
1423 |
has big problems handling unbounded Streams, since the EOF handling in stdio is |
|
1424 |
not prepared for data to arrive after EOF has been reached - time will show, if we need |
|
1425 |
a complete rewrite for UnboundedStream ... |
|
325 | 1426 |
|
188 | 1427 |
Also, depending on the system, the stdio library behaves infriendly when signals |
1428 |
occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal |
|
1429 |
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
|
1430 |
an error and errno is set to EINTR. |
1295 | 1431 |
Thats what the ugly code around all getc-calls is for ... |
1432 |
Since things get more and more ugly - we will rewrite ExternalStream |
|
1433 |
completely, to NOT use any stdio stuff (and do its buffering itself). |
|
325 | 1434 |
|
1435 |
Notice that typical stdio's use a single errno global variable to return an error code, |
|
16508 | 1436 |
this was bad design in the stdio lib (right from the very beginning), since it's much |
325 | 1437 |
harder to deal with this in the presence of lightweight processes, where errno gets |
1438 |
overwritten by an I/O operation done in another thread. (stdio should have been written |
|
1439 |
to return errno as a negative number ...). |
|
1440 |
To deal with this, the scheduler treats errno like a per-thread private variable, |
|
1441 |
and saves/restores the errno setting when switching to another thread. |
|
1442 |
(Notice that some thread packages do this also, but ST/X's thread implementation |
|
1443 |
does not depend on those, but instead uses a portable private package). |
|
1444 |
||
216 | 1445 |
Finally, if an stdio-stream is open for both reading and writing, we have to call |
1446 |
fseek whenever we are about to read after write and vice versa. |
|
1447 |
Two macros (__READING__ and __WRITING__) have been defined to be used before every |
|
1448 |
fread/fgetc and fwrite/putc respectively. |
|
1295 | 1449 |
|
1450 |
[author:] |
|
16508 | 1451 |
Claus Gittinger |
1452 |
Stefan Vogel (many, many fixes ...) |
|
1295 | 1453 |
|
1454 |
[see also:] |
|
16508 | 1455 |
FileStream Socket PipeStream |
1456 |
Filename OperatingSystem |
|
22 | 1457 |
" |
3255 | 1458 |
! |
1459 |
||
1460 |
examples |
|
1461 |
" |
|
1462 |
open a file, read the contents and display it in a textView: |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1463 |
[exBegin] |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1464 |
|topView scrollPane textView fileStream text| |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1465 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1466 |
topView := StandardSystemView new. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1467 |
topView label:'contents of Makefile'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1468 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1469 |
scrollPane := HVScrollableView in:topView. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1470 |
scrollPane origin:0.0@0.0 corner:1.0@1.0. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1471 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1472 |
textView := EditTextView new. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1473 |
scrollPane scrolledView:textView. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1474 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1475 |
fileStream := 'Makefile' asFilename readStream. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1476 |
text := fileStream upToEnd. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1477 |
fileStream close. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1478 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1479 |
textView contents:text. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1480 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1481 |
topView open. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1482 |
[exEnd] |
3255 | 1483 |
|
1484 |
||
1485 |
Notice, all of the above can also be done (simply) as: |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1486 |
[exBegin] |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1487 |
EditTextView openOn:'Makefile' |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1488 |
[exEnd] |
3255 | 1489 |
" |
22 | 1490 |
! ! |
1491 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1492 |
!ExternalStream class methodsFor:'initialization'! |
1 | 1493 |
|
2920 | 1494 |
initDefaultEOLMode |
1495 |
OperatingSystem isUNIXlike ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1496 |
"/ unix EOL conventions |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1497 |
DefaultEOLMode := #nl |
2920 | 1498 |
] ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1499 |
OperatingSystem isVMSlike ifTrue:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1500 |
"/ vms EOL conventions |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1501 |
DefaultEOLMode := #cr |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1502 |
] ifFalse:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1503 |
"/ msdos EOL conventions |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1504 |
DefaultEOLMode := #crlf |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1505 |
] |
2920 | 1506 |
] |
1507 |
! |
|
1508 |
||
1509 |
initModeStrings |
|
1510 |
"initialize modeStrings which are passed down to the underlying |
|
1511 |
fopen/fdopen functions." |
|
1512 |
||
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1513 |
OperatingSystem isMSDOSlike ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1514 |
ReadMode := 'rb'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1515 |
ReadWriteMode := 'rb+'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1516 |
WriteMode := 'wb'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1517 |
AppendMode := 'ab+'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1518 |
CreateReadWriteMode := 'wb+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1519 |
] ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1520 |
ReadMode := 'r'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1521 |
ReadWriteMode := 'r+'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1522 |
WriteMode := 'w'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1523 |
AppendMode := 'a+'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1524 |
CreateReadWriteMode := 'w+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1525 |
] |
2920 | 1526 |
! |
1527 |
||
1 | 1528 |
initialize |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
1529 |
OpenErrorSignal isNil ifTrue:[ |
8066
0dbcbe8989b8
OpenError is now a class based exception
Claus Gittinger <cg@exept.de>
parents:
8008
diff
changeset
|
1530 |
"/ OpenErrorSignal := OpenError. |
0dbcbe8989b8
OpenError is now a class based exception
Claus Gittinger <cg@exept.de>
parents:
8008
diff
changeset
|
1531 |
"/ OpenErrorSignal nameClass:self message:#openErrorSignal. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1532 |
OpenErrorSignal := OpenError. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1533 |
OpenErrorSignal notifierString:'open error'. |
8074 | 1534 |
|
1535 |
"/ InvalidReadSignal := ReadErrorSignal newSignalMayProceed:false. |
|
1536 |
"/ InvalidReadSignal nameClass:self message:#invalidReadSignal. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1537 |
InvalidReadSignal := InvalidReadError. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1538 |
InvalidReadSignal notifierString:'stream does not support reading'. |
8074 | 1539 |
|
1540 |
"/ InvalidWriteSignal := WriteErrorSignal newSignalMayProceed:false. |
|
1541 |
"/ InvalidWriteSignal nameClass:self message:#invalidWriteSignal. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1542 |
InvalidWriteSignal := InvalidWriteError. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1543 |
InvalidWriteSignal notifierString:'stream does not support writing'. |
8074 | 1544 |
|
1545 |
"/ InvalidModeSignal := StreamErrorSignal newSignalMayProceed:false. |
|
1546 |
"/ InvalidModeSignal nameClass:self message:#invalidModeSignal. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1547 |
InvalidModeSignal := InvalidModeError. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1548 |
InvalidModeSignal notifierString:'binary/text mode mismatch'. |
8074 | 1549 |
|
1550 |
"/ InvalidOperationSignal := StreamErrorSignal newSignalMayProceed:false. |
|
1551 |
"/ InvalidOperationSignal nameClass:self message:#invalidOperationSignal. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1552 |
InvalidOperationSignal := InvalidOperationError. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1553 |
InvalidOperationSignal notifierString:'unsupported file operation'. |
8074 | 1554 |
|
1555 |
"/ StreamNotOpenSignal := StreamErrorSignal newSignalMayProceed:false. |
|
1556 |
"/ StreamNotOpenSignal nameClass:self message:#streamNotOpenSignal. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1557 |
StreamNotOpenSignal := StreamNotOpenError. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1558 |
StreamNotOpenSignal notifierString:'stream is not open'. |
8074 | 1559 |
|
1560 |
"/ StreamIOErrorSignal := StreamErrorSignal newSignalMayProceed:false. |
|
1561 |
"/ StreamIOErrorSignal nameClass:self message:#streamIOErrorSignal. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1562 |
StreamIOErrorSignal := StreamIOError. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1563 |
StreamIOErrorSignal notifierString:'I/O error'. |
159 | 1564 |
]. |
1565 |
||
31 | 1566 |
Lobby isNil ifTrue:[ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1567 |
Lobby := Registry new. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1568 |
|
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1569 |
"want to get informed when returning from snapshot" |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1570 |
ObjectMemory addDependent:self |
2920 | 1571 |
]. |
5442 | 1572 |
DefaultEOLMode isNil ifTrue:[ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1573 |
self initDefaultEOLMode. |
5442 | 1574 |
]. |
1575 |
ReadMode isNil ifTrue:[ |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1576 |
self initModeStrings. |
5442 | 1577 |
]. |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1578 |
"Modified: / 21.5.1998 / 16:33:53 / cg" |
1 | 1579 |
! |
1580 |
||
1581 |
reOpenFiles |
|
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1582 |
"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
|
1583 |
This is invoked via the #earlyRestart change notification." |
1 | 1584 |
|
301 | 1585 |
Lobby do:[:aFileStream | |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1586 |
aFileStream reOpen |
2920 | 1587 |
]. |
1 | 1588 |
! |
1589 |
||
1469 | 1590 |
update:something with:aParameter from:changedObject |
1 | 1591 |
"have to reopen files when returning from snapshot" |
1592 |
||
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1593 |
something == #earlyRestart ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1594 |
self reOpenFiles. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1595 |
self initDefaultEOLMode |
1 | 1596 |
] |
1469 | 1597 |
|
1598 |
"Created: 15.6.1996 / 15:19:59 / cg" |
|
1 | 1599 |
! ! |
1600 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1601 |
!ExternalStream class methodsFor:'instance creation'! |
612 | 1602 |
|
12706 | 1603 |
forFileDescriptor:aFileDescriptor mode:modeSymbol |
2920 | 1604 |
"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
|
1605 |
to operate on this fd. |
12706 | 1606 |
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
|
1607 |
This may be used to wrap fd's as returned by user |
2920 | 1608 |
primitive code, or to wrap pipe-fds into externalStreams." |
1609 |
||
12706 | 1610 |
^ self forFileDescriptor:aFileDescriptor mode:modeSymbol buffered:true handleType:nil |
7002 | 1611 |
|
1612 |
" |
|
1613 |
the example below will probably fail (15 is a random FD): |
|
1614 |
||
1615 |
|s| |
|
1616 |
||
1617 |
s := ExternalStream forFileDescriptor:15 mode:'r'. |
|
1618 |
s next. |
|
1619 |
" |
|
1620 |
||
1621 |
"Created: 29.2.1996 / 18:05:00 / cg" |
|
1622 |
"Modified: 29.2.1996 / 18:17:07 / cg" |
|
1623 |
! |
|
1624 |
||
12706 | 1625 |
forFileDescriptor:aFileDescriptor mode:modeSymbol buffered:buffered handleType:handleTypeSymbol |
7002 | 1626 |
"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
|
1627 |
to operate on this fd. |
12706 | 1628 |
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
|
1629 |
This may be used to wrap fd's as returned by user |
7002 | 1630 |
primitive code, or to wrap pipe-fds into externalStreams." |
1631 |
||
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1632 |
|newStream| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1633 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1634 |
newStream := self basicNew. |
7002 | 1635 |
newStream text; buffered:buffered; eolMode:DefaultEOLMode; clearEOF. |
12706 | 1636 |
^ newStream connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol |
2920 | 1637 |
|
1638 |
" |
|
1639 |
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
|
1640 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1641 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1642 |
|
12706 | 1643 |
s := ExternalStream forFileDescriptor:15 mode:#radonly handleType:#filePointer. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1644 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1645 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1646 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1647 |
"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
|
1648 |
"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
|
1649 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1650 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1651 |
forReadWriteToFileDescriptor:aFileDescriptor |
2920 | 1652 |
"given a fileDescriptor, create an ExternalStream object |
1653 |
to read/write from/to this fd. This may be used to wrap fd's |
|
1654 |
as returned by user primitive code, or to wrap pipe- |
|
1655 |
filedescriptors into externalStreams." |
|
1656 |
||
12706 | 1657 |
^ self forFileDescriptor:aFileDescriptor mode:#readWrite |
2920 | 1658 |
|
1659 |
" |
|
1660 |
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
|
1661 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1662 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1663 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1664 |
s := ExternalStream forReadWriteToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1665 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1666 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1667 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1668 |
"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
|
1669 |
"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
|
1670 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1671 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1672 |
forReadingFromFileDescriptor:aFileDescriptor |
2920 | 1673 |
"given a fileDescriptor, create an ExternalStream object |
1674 |
to read from this fd. This may be used to wrap fd's |
|
1675 |
as returned by user primitive code, or to wrap pipe- |
|
1676 |
filedescriptors into externalStreams." |
|
1677 |
||
12706 | 1678 |
^ self forFileDescriptor:aFileDescriptor mode:#readonly |
2920 | 1679 |
|
1680 |
" |
|
1681 |
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
|
1682 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1683 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1684 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1685 |
s := ExternalStream forReadingFromFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1686 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1687 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1688 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1689 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1690 |
|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
|
1691 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1692 |
'create OS pipe ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1693 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1694 |
pipe := OperatingSystem makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1695 |
readFd := pipe at:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1696 |
writeFd := pipe at:2. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1697 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1698 |
'connect Smalltalk streams ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1699 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1700 |
rs := ExternalStream forReadingFromFileDescriptor:readFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1701 |
ws := ExternalStream forWritingToFileDescriptor:writeFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1702 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1703 |
'read ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1704 |
[ |
14068 | 1705 |
1 to:10 do:[:i | |
1706 |
Transcript showCR:rs nextLine |
|
1707 |
]. |
|
1708 |
rs close. |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1709 |
] forkAt:7. |
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 |
'write ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1712 |
[ |
14068 | 1713 |
1 to:10 do:[:i | |
1714 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
|
1715 |
]. |
|
1716 |
ws close. |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1717 |
] fork. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1718 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1719 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1720 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1721 |
"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
|
1722 |
"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
|
1723 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1724 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1725 |
forWritingToFileDescriptor:aFileDescriptor |
2920 | 1726 |
"given a fileDescriptor, create an ExternalStream object |
1727 |
to write to this fd. This may be used to wrap fd's |
|
1728 |
as returned by user primitive code, or to wrap pipe- |
|
1729 |
filedescriptors into externalStreams." |
|
1730 |
||
12706 | 1731 |
^ self forFileDescriptor:aFileDescriptor mode:#writeonly |
2920 | 1732 |
|
1733 |
" |
|
1734 |
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
|
1735 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1736 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1737 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1738 |
s := ExternalStream forWritingToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1739 |
s binary. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1740 |
s nextPut:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1741 |
" |
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 |
"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
|
1744 |
"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
|
1745 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1746 |
|
612 | 1747 |
new |
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
1748 |
"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
|
1749 |
|
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
1750 |
^ self basicNew initialize. |
612 | 1751 |
! ! |
1752 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1753 |
!ExternalStream class methodsFor:'Signal constants'! |
159 | 1754 |
|
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1755 |
inaccessibleSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1756 |
"ST-80 compatibility: return openErrorSignal" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1757 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1758 |
^ self openErrorSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1759 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1760 |
"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
|
1761 |
! |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1762 |
|
612 | 1763 |
invalidModeSignal |
1764 |
"return the signal raised when doing text-I/O with a binary stream |
|
1765 |
or binary-I/O with a text stream" |
|
1766 |
||
8074 | 1767 |
^ InvalidModeError |
159 | 1768 |
! |
1769 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1770 |
invalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1771 |
"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
|
1772 |
I/O operation is attempted" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1773 |
|
8074 | 1774 |
^ InvalidOperationError |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1775 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1776 |
|
159 | 1777 |
invalidReadSignal |
1778 |
"return the signal raised when reading from writeonly streams" |
|
1779 |
||
8074 | 1780 |
^ InvalidReadError |
159 | 1781 |
! |
1782 |
||
1783 |
invalidWriteSignal |
|
1784 |
"return the signal raised when writing to readonly streams" |
|
1785 |
||
8074 | 1786 |
^ InvalidWriteError |
159 | 1787 |
! |
1788 |
||
612 | 1789 |
openErrorSignal |
1790 |
"return the signal raised when a file open failed" |
|
1791 |
||
1792 |
^ OpenErrorSignal |
|
1793 |
! |
|
1794 |
||
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1795 |
streamIOErrorSignal |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1796 |
"return the signal raised when an I/O error occurs. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1797 |
(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
|
1798 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1799 |
|
8074 | 1800 |
^ StreamIOError |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1801 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1802 |
"Created: / 21.5.1998 / 16:32:55 / cg" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1803 |
! |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1804 |
|
159 | 1805 |
streamNotOpenSignal |
1806 |
"return the signal raised on I/O with closed streams" |
|
1807 |
||
8074 | 1808 |
^ StreamNotOpenError |
2 | 1809 |
! ! |
1810 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1811 |
!ExternalStream class methodsFor:'error handling'! |
92 | 1812 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1813 |
errorReporter |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1814 |
"I know about error codes" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1815 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1816 |
^ self |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1817 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1818 |
|
92 | 1819 |
lastErrorNumber |
159 | 1820 |
"return the errno of the last error" |
92 | 1821 |
|
1822 |
^ LastErrorNumber |
|
159 | 1823 |
|
1824 |
" |
|
1825 |
ExternalStream lastErrorNumber |
|
1826 |
" |
|
92 | 1827 |
! |
1828 |
||
1829 |
lastErrorString |
|
1830 |
"return a message string describing the last error" |
|
1831 |
||
1832 |
^ OperatingSystem errorTextForNumber:LastErrorNumber |
|
1833 |
||
1834 |
" |
|
1835 |
ExternalStream lastErrorString |
|
1836 |
" |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1837 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1838 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1839 |
reportOn:anErrorSymbolOrNumber |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1840 |
"an error occured. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1841 |
Report it via an Exception" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1842 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1843 |
anErrorSymbolOrNumber isInteger ifTrue:[ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1844 |
StreamError |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1845 |
raiseRequestWith:anErrorSymbolOrNumber |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1846 |
errorString:(' - os error:' , (OperatingSystem errorTextForNumber:anErrorSymbolOrNumber)) |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1847 |
]. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1848 |
(self respondsTo:anErrorSymbolOrNumber) ifTrue:[ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1849 |
self perform:anErrorSymbolOrNumber |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1850 |
] ifFalse:[ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1851 |
StreamError |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1852 |
raiseRequestWith:anErrorSymbolOrNumber |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1853 |
errorString:(' - ' , anErrorSymbolOrNumber printString) |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1854 |
]. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1855 |
^ false |
92 | 1856 |
! ! |
1857 |
||
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1858 |
!ExternalStream class methodsFor:'obsolete'! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1859 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1860 |
makePTYPair |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1861 |
"obsolete since 12-07-2003" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1862 |
<resource:#obsolete> |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1863 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1864 |
self obsoleteMethodWarning:'use NonPositionableExternalStream makePTYPair'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1865 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1866 |
^ NonPositionableExternalStream makePTYPair. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1867 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1868 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1869 |
makePipe |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1870 |
"obsolete since 12-07-2003" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1871 |
<resource:#obsolete> |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1872 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1873 |
self obsoleteMethodWarning:'use NonPositionableExternalStream makePipe'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1874 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1875 |
^ NonPositionableExternalStream makePipe. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1876 |
! ! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1877 |
|
7261 | 1878 |
!ExternalStream methodsFor:'Compatibility-Dolphin'! |
6474 | 1879 |
|
1880 |
beText |
|
1881 |
self text |
|
1882 |
! ! |
|
1883 |
||
7261 | 1884 |
!ExternalStream methodsFor:'Compatibility-Squeak'! |
3044 | 1885 |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1886 |
nextInto:aByteArrayOrString |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1887 |
"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
|
1888 |
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
|
1889 |
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
|
1890 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1891 |
|n nWanted| |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1892 |
|
4368 | 1893 |
nWanted := aByteArrayOrString byteSize. |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1894 |
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
|
1895 |
n == nWanted ifTrue:[^ aByteArrayOrString]. |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1896 |
^ aByteArrayOrString copyTo:n |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1897 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1898 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1899 |
|
4368 | 1900 |
readInto:aContainer startingAt:index count:nElements |
1901 |
"same as #nextBytes:into:startingAt: for ByteArrays; |
|
1902 |
for LongArrays, nelements longs are read. |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1903 |
Squeak compatibility." |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1904 |
|
4368 | 1905 |
|elementSize n| |
1906 |
||
1907 |
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
|
1908 |
n := self nextBytes:nElements*elementSize into:aContainer startingAt:(index-1)*elementSize+1. |
4368 | 1909 |
^ n // elementSize |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1910 |
|
13940
12eb1c056d5e
fixed: #readInto:startingAt:count:; offset was wrong for non-byte elements
Claus Gittinger <cg@exept.de>
parents:
13927
diff
changeset
|
1911 |
"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
|
1912 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1913 |
|
3044 | 1914 |
readOnly |
1915 |
"Squeak compatibility: make the stream readOnly" |
|
1916 |
||
1917 |
mode := #readonly |
|
1918 |
||
1919 |
"Modified: 20.10.1997 / 19:23:04 / cg" |
|
1920 |
"Created: 20.10.1997 / 19:23:19 / cg" |
|
1921 |
! ! |
|
1922 |
||
5187 | 1923 |
!ExternalStream methodsFor:'Signal constants'! |
1924 |
||
1925 |
invalidReadSignal |
|
1926 |
^ self class invalidReadSignal |
|
1927 |
||
1928 |
"Created: / 3.12.1998 / 15:12:06 / cg" |
|
1929 |
! |
|
1930 |
||
1931 |
invalidWriteSignal |
|
1932 |
^ self class invalidWriteSignal |
|
1933 |
||
1934 |
"Created: / 3.12.1998 / 15:12:10 / cg" |
|
1935 |
! ! |
|
1936 |
||
1 | 1937 |
!ExternalStream methodsFor:'accessing'! |
1938 |
||
612 | 1939 |
binary |
1940 |
"switch to binary mode - default is text" |
|
1941 |
||
1942 |
binary := true |
|
1 | 1943 |
! |
1944 |
||
1945 |
buffered:aBoolean |
|
10 | 1946 |
"turn buffering on or off - default is on" |
1 | 1947 |
|
10 | 1948 |
buffered := aBoolean |
1 | 1949 |
! |
1950 |
||
1951 |
contents |
|
2 | 1952 |
"return the contents of the file from the current position up-to |
1953 |
the end. If the stream is in binary mode, a ByteArray containing |
|
1954 |
the byte values is returned. |
|
1955 |
In text-mode, a collection of strings, each representing one line, |
|
1956 |
is returned." |
|
1957 |
||
1958 |
|text l chunks sizes chunk byteCount cnt bytes offset| |
|
1959 |
||
1960 |
binary ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1961 |
"adding to a ByteArray produces quadratic time-space |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1962 |
behavior - therefore we allocate chunks, and concatenate them |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1963 |
at the end." |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1964 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1965 |
chunks := OrderedCollection new. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1966 |
sizes := OrderedCollection new. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1967 |
byteCount := 0. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1968 |
[self atEnd] whileFalse:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1969 |
chunk := ByteArray uninitializedNew:4096. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1970 |
cnt := self nextBytes:(chunk size) into:chunk. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1971 |
cnt notNil ifTrue:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1972 |
chunks add:chunk. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1973 |
sizes add:cnt. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1974 |
byteCount := byteCount + cnt |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1975 |
] |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1976 |
]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1977 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1978 |
"now, create one big ByteArray" |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1979 |
bytes := ByteArray uninitializedNew:byteCount. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1980 |
offset := 1. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1981 |
1 to:chunks size do:[:index | |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1982 |
chunk := chunks at:index. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1983 |
cnt := sizes at:index. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1984 |
bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1985 |
offset := offset + cnt |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1986 |
]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1987 |
^ bytes |
2 | 1988 |
]. |
1 | 1989 |
|
244 | 1990 |
text := StringCollection new. |
1 | 1991 |
[self atEnd] whileFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1992 |
l := self nextLine. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1993 |
l isNil ifTrue:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1994 |
^ text |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1995 |
]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1996 |
text add:l |
1 | 1997 |
]. |
1998 |
^ text |
|
1999 |
! |
|
2000 |
||
11751
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2001 |
contentsAsString |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2002 |
"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
|
2003 |
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
|
2004 |
|
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2005 |
^ self contentsOfEntireFile |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2006 |
! |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2007 |
|
612 | 2008 |
contentsOfEntireFile |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
2009 |
"ST-80 compatibility: return contents as a String (or byteArray, if in binary mode). |
3876 | 2010 |
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
|
2011 |
|
6305 | 2012 |
binary ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2013 |
^ self contents. |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
2014 |
]. |
6305 | 2015 |
^ self upToEnd |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
2016 |
|
3876 | 2017 |
"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
|
2018 |
"Modified: / 27.11.1998 / 16:29:43 / cg" |
2 | 2019 |
! |
2020 |
||
612 | 2021 |
contentsSpecies |
2022 |
"return the kind of object to be returned by sub-collection builders |
|
2023 |
(such as upTo)" |
|
159 | 2024 |
|
5441 | 2025 |
binary == true ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2026 |
^ ByteArray |
159 | 2027 |
]. |
612 | 2028 |
^ String |
2 | 2029 |
! |
2030 |
||
16776 | 2031 |
eolMode |
2032 |
"return how end-of-line (EOL) is to be marked. |
|
2033 |
Returns one one of: |
|
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
|
2034 |
#crlf -> add a CR-NL, as in MSDOS |
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
|
2035 |
#cr -> add a CR, as in VMS |
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
|
2036 |
#nl -> add a NL, as in Unix |
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
|
2037 |
nil -> transparent |
16776 | 2038 |
" |
2039 |
||
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
|
2040 |
^ eolMode |
16776 | 2041 |
! |
2042 |
||
2920 | 2043 |
eolMode:aSymbolOrNil |
2044 |
"specify how end-of-line (EOL) is to be marked. |
|
2045 |
The argument may be one of: |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2046 |
#crlf -> add a CR-NL, as in MSDOS |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2047 |
#cr -> add a CR, as in VMS |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2048 |
#nl -> add a NL, as in Unix |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2049 |
anyOther -> like #nl |
2920 | 2050 |
" |
2051 |
||
2052 |
eolMode := aSymbolOrNil |
|
2053 |
! |
|
2054 |
||
612 | 2055 |
fileDescriptor |
2056 |
"return the fileDescriptor of the receiver - |
|
2057 |
notice: this one returns the underlying OSs fileDescriptor - |
|
2058 |
this may not be available on all platforms (i.e. non unix systems)." |
|
1 | 2059 |
|
3971 | 2060 |
%{ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2061 |
OBJ _handle = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2062 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2063 |
if (_handle != nil) { |
16508 | 2064 |
if (__INST(handleType) == @symbol(socketHandle)) { |
2065 |
RETURN (_handle); |
|
2066 |
} else if ((__INST(handleType) == nil) |
|
2067 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2068 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
2069 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
2070 |
RETURN ( __MKINT(fileno(__FILEVal(_handle)))); |
|
2071 |
} |
|
1 | 2072 |
} |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2073 |
%}. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2074 |
handle isNil ifTrue:[^ self errorNotOpen]. |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2075 |
^ self fileDescriptorOfFile:handle |
5852 | 2076 |
! |
2077 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2078 |
fileDescriptorOfFile:handle |
5852 | 2079 |
"for migration to rel5 only: |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2080 |
return the fileDescriptor of the argument handle - |
5852 | 2081 |
notice: this one returns the underlying OSs fileDescriptor - |
2082 |
this may not be available on all platforms (i.e. non unix systems)." |
|
2083 |
||
2084 |
self primitiveFailed |
|
612 | 2085 |
! |
2086 |
||
10455 | 2087 |
fileHandle |
2088 |
"return the fileHandle of the receiver. |
|
2089 |
Under unix, this is the fileDescriptor; under windows, this is the Handle." |
|
2090 |
||
2091 |
%{ |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2092 |
OBJ _handle = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2093 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2094 |
if (_handle != nil) { |
16508 | 2095 |
if ((__INST(handleType) == @symbol(fileHandle)) |
2096 |
|| (__INST(handleType) == @symbol(socketHandle))) { |
|
2097 |
RETURN (_handle); |
|
2098 |
} else if ((__INST(handleType) == nil) |
|
2099 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2100 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
2101 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
10455 | 2102 |
#ifdef WIN32 |
16508 | 2103 |
RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileno(__FILEVal(_handle))))); |
10455 | 2104 |
#else |
16508 | 2105 |
RETURN (__MKINT(fileno(__FILEVal(_handle)))); |
10455 | 2106 |
#endif |
16508 | 2107 |
} |
10455 | 2108 |
} |
2109 |
%}. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2110 |
handle isNil ifTrue:[^ self errorNotOpen]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2111 |
^ handle |
10455 | 2112 |
! |
2113 |
||
612 | 2114 |
filePointer |
2115 |
"return the filePointer of the receiver - |
|
2116 |
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
|
2117 |
a FILE * - not a fileDescriptor. |
612 | 2118 |
(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
|
2119 |
You cannot do much with the returned value |
612 | 2120 |
- except passing it to a primitive, for example." |
2121 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2122 |
(handleType isNil or:[handleType == #filePointer]) ifTrue:[ |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2123 |
^ handle |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2124 |
]. |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2125 |
^ self error:'not a FILE*' |
612 | 2126 |
! |
2127 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2128 |
handleType |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2129 |
^ handleType |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2130 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2131 |
|
5323 | 2132 |
lineEndCRLF |
2133 |
eolMode := #crlf |
|
2134 |
! |
|
2135 |
||
3016 | 2136 |
lineEndTransparent |
2137 |
eolMode := #cr |
|
2138 |
! |
|
2139 |
||
8069
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2140 |
pathName |
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2141 |
"answer the pathName of the stream. |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2142 |
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
|
2143 |
|
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2144 |
^ '' |
8069
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2145 |
! |
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2146 |
|
612 | 2147 |
readonly |
2148 |
"set access mode to readonly" |
|
2149 |
||
2150 |
mode := #readonly |
|
2151 |
! |
|
2152 |
||
2153 |
readwrite |
|
2154 |
"set access mode to readwrite" |
|
2155 |
||
2156 |
mode := #readwrite |
|
2157 |
! |
|
2158 |
||
2159 |
text |
|
2160 |
"switch to text mode - default is text" |
|
2161 |
||
2162 |
binary := false |
|
2163 |
! |
|
2164 |
||
2165 |
useCRLF:aBoolean |
|
2920 | 2166 |
"turn on or off CRLF sending (instead of LF only) - default is off. |
2167 |
This method is provided for backward compatibility - see #eolMode: |
|
2168 |
which offers another choice." |
|
2169 |
||
2170 |
aBoolean ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2171 |
eolMode := #crlf |
2920 | 2172 |
] ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2173 |
eolMode := #nl |
2920 | 2174 |
]. |
1 | 2175 |
! |
2176 |
||
612 | 2177 |
writeonly |
2178 |
"set access mode to writeonly" |
|
2179 |
||
2180 |
mode := #writeonly |
|
2181 |
! ! |
|
2182 |
||
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2183 |
!ExternalStream methodsFor:'closing'! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2184 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2185 |
close |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2186 |
"close the stream. |
16300 | 2187 |
No error of the stream is not open." |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2188 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2189 |
self isOpen ifTrue:[ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2190 |
Lobby unregister:self. |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2191 |
self closeFile. |
16300 | 2192 |
]. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2193 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2194 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2195 |
shutDown |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2196 |
"close the stream - added for protocol compatibility with PipeStream. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2197 |
see comment there" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2198 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2199 |
self isOpen ifTrue:[ |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2200 |
Lobby unregister:self. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2201 |
self closeFile |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2202 |
] |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2203 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2204 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2205 |
! ! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2206 |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2207 |
!ExternalStream methodsFor:'copying'! |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2208 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2209 |
copy |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2210 |
"answer a copy of myself. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2211 |
Have to dup the filedescriptor" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2212 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2213 |
|copy| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2214 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2215 |
copy := super copy. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2216 |
copy dupFd. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2217 |
Lobby register:copy. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2218 |
^ copy |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2219 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2220 |
" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2221 |
|stream1 stream2| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2222 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2223 |
stream1 := Filename newTemporary writeStream. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2224 |
stream2 := stream1 copy. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2225 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2226 |
stream1 inspect. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2227 |
stream2 inspect. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2228 |
" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2229 |
! ! |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2230 |
|
612 | 2231 |
!ExternalStream methodsFor:'error handling'! |
2232 |
||
2233 |
argumentMustBeCharacter |
|
14440 | 2234 |
"report an error, that the argument must be a character in 0..FF" |
2235 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2236 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2237 |
|
14440 | 2238 |
ArgumentError raiseErrorString:' - argument must be a single byte character' |
612 | 2239 |
! |
2240 |
||
2241 |
argumentMustBeInteger |
|
14440 | 2242 |
"report an error, that the argument must be an integer" |
2243 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2244 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2245 |
|
14440 | 2246 |
ArgumentError raiseErrorString:' - argument must be an integer' |
77 | 2247 |
! |
2248 |
||
612 | 2249 |
argumentMustBeString |
14440 | 2250 |
"report an error, that the argument must be a string" |
2251 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2252 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2253 |
|
14440 | 2254 |
ArgumentError raiseErrorString:' - argument must be a string' |
612 | 2255 |
! |
2256 |
||
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2257 |
errorAlreadyOpen |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2258 |
"{ Pragma: +optSpace }" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2259 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2260 |
"report an error, that the stream is already opened" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2261 |
|
8074 | 2262 |
^ OpenError |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2263 |
raiseRequestWith:self |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2264 |
errorString:' - stream is already open' |
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2265 |
|
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2266 |
" |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2267 |
self new errorAlreadyOpen |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2268 |
" |
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2269 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2270 |
"Modified: / 8.5.1999 / 20:12:30 / cg" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2271 |
! |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2272 |
|
612 | 2273 |
errorBinary |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2274 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2275 |
|
612 | 2276 |
"report an error, that the stream is in binary mode" |
2277 |
||
8074 | 2278 |
^ InvalidModeError |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2279 |
raiseRequestWith:self |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2280 |
errorString:(self class name , ' is in binary mode') |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2281 |
"/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2282 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2283 |
"Modified: / 8.5.1999 / 20:12:43 / cg" |
612 | 2284 |
! |
2285 |
||
2286 |
errorNotBinary |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2287 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2288 |
|
612 | 2289 |
"report an error, that the stream is not in binary mode" |
2290 |
||
8074 | 2291 |
^ InvalidModeError |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2292 |
raiseRequestWith:self |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2293 |
errorString:(self class name , ' is not in binary mode') |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2294 |
"/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2295 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2296 |
"Modified: / 8.5.1999 / 20:12:40 / cg" |
1 | 2297 |
! |
2298 |
||
612 | 2299 |
errorNotBuffered |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2300 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2301 |
|
612 | 2302 |
"report an error, that the stream is not in buffered mode" |
2303 |
||
8074 | 2304 |
^ StreamError |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2305 |
raiseRequestWith:self |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2306 |
errorString:(self class name , ' is unbuffered - operation not allowed') |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2307 |
"/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2308 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2309 |
"Modified: / 8.5.1999 / 20:12:36 / cg" |
612 | 2310 |
! |
2311 |
||
2312 |
errorNotOpen |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2313 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2314 |
|
612 | 2315 |
"report an error, that the stream has not been opened" |
2316 |
||
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2317 |
^ StreamNotOpenError raiseRequestWith:self "/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2318 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2319 |
"Modified: / 8.5.1999 / 20:12:33 / cg" |
612 | 2320 |
! |
2321 |
||
2322 |
errorReadOnly |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2323 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2324 |
|
612 | 2325 |
"report an error, that the stream is a readOnly stream" |
2326 |
||
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2327 |
^ 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
|
2328 |
|
4468 | 2329 |
"Modified: / 30.7.1999 / 17:08:19 / cg" |
612 | 2330 |
! |
2331 |
||
6255
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2332 |
errorReporter |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2333 |
"ST-80 mimicry." |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2334 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
2335 |
^ self class |
6255
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2336 |
! |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2337 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2338 |
errorUnsupportedOperation |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2339 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2340 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2341 |
"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
|
2342 |
|
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2343 |
^ 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
|
2344 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2345 |
"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
|
2346 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2347 |
|
612 | 2348 |
errorWriteOnly |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2349 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2350 |
|
612 | 2351 |
"report an error, that the stream is a writeOnly stream" |
2352 |
||
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2353 |
^ 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
|
2354 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2355 |
"Modified: / 8.5.1999 / 20:12:20 / cg" |
2 | 2356 |
! |
2357 |
||
612 | 2358 |
ioError |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2359 |
"report an error, that some I/O error occured. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2360 |
(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
|
2361 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2362 |
|
16296 | 2363 |
"{ Pragma: +optSpace }" |
2364 |
||
2365 |
self ioError:lastErrorNumber |
|
2366 |
||
2367 |
"Modified: / 8.5.1999 / 20:12:16 / cg" |
|
2368 |
! |
|
2369 |
||
2370 |
ioError:errorNumber |
|
2371 |
"report an error, that some I/O error occured. |
|
2372 |
(for example, a device-IO-error, or reading an NFS-dir, |
|
2373 |
which is no longer available and has been mounted soft)" |
|
2374 |
||
2375 |
"{ Pragma: +optSpace }" |
|
2376 |
||
2377 |
^ StreamIOError newException |
|
2378 |
errorCode:errorNumber; |
|
2379 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
|
2380 |
parameter:self; |
|
2381 |
raiseRequest |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2382 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2383 |
"Modified: / 8.5.1999 / 20:12:16 / cg" |
612 | 2384 |
! |
2385 |
||
2386 |
lastErrorNumber |
|
2387 |
"return the last error" |
|
2388 |
||
2389 |
^ lastErrorNumber |
|
2390 |
! |
|
2391 |
||
2392 |
lastErrorString |
|
2393 |
"return a message string describing the last error" |
|
2394 |
||
2395 |
(lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2396 |
^ 'I/O error' |
612 | 2397 |
]. |
2398 |
^ OperatingSystem errorTextForNumber:lastErrorNumber |
|
2 | 2399 |
! |
2400 |
||
10932 | 2401 |
lastErrorSymbol |
2402 |
"return an error symbol describing the last error" |
|
2403 |
||
2404 |
^ OperatingSystem errorSymbolForNumber:lastErrorNumber |
|
2405 |
! |
|
2406 |
||
612 | 2407 |
openError |
12688 | 2408 |
"report an error, that the open failed" |
2409 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2410 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2411 |
|
14438 | 2412 |
^ self openError:lastErrorNumber. |
612 | 2413 |
! |
2414 |
||
12688 | 2415 |
openError:errorNumber |
2416 |
"report an error, that the open failed" |
|
2417 |
||
2418 |
"{ Pragma: +optSpace }" |
|
2419 |
||
15496 | 2420 |
|exClass errorHolder| |
2421 |
||
2422 |
errorHolder := OperatingSystem errorHolderForNumber:errorNumber. |
|
2423 |
||
2424 |
exClass := (errorHolder errorCategory == #nonexistentSignal) |
|
16296 | 2425 |
ifTrue:[ FileDoesNotExistException ] |
2426 |
ifFalse:[ OpenError ]. |
|
13673 | 2427 |
|
2428 |
^ exClass newException |
|
16296 | 2429 |
errorCode:errorNumber; |
2430 |
osErrorHolder:errorHolder; |
|
2431 |
"/ cg: initialized lazyly - see OpenError>>#description |
|
2432 |
"/ errorString:(' : ' , errorHolder errorString); |
|
2433 |
parameter:self; |
|
2434 |
raiseRequest |
|
2435 |
"/ in:thisContext sender |
|
13673 | 2436 |
|
2437 |
"Modified: / 09-09-2011 / 07:22:49 / cg" |
|
12688 | 2438 |
! |
2439 |
||
612 | 2440 |
readError |
15845 | 2441 |
"report an error, that some read error occured" |
2442 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2443 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2444 |
|
15845 | 2445 |
^ self readError:lastErrorNumber |
2446 |
! |
|
2447 |
||
2448 |
readError:errorNumber |
|
612 | 2449 |
"report an error, that some read error occured" |
2450 |
||
15845 | 2451 |
"{ Pragma: +optSpace }" |
2452 |
||
2453 |
^ ReadError newException |
|
16296 | 2454 |
errorCode:errorNumber; |
2455 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
|
2456 |
parameter:self; |
|
2457 |
raiseRequest |
|
612 | 2458 |
! |
2459 |
||
2460 |
writeError |
|
15845 | 2461 |
"report an error, that some write error occured" |
2462 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2463 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2464 |
|
15845 | 2465 |
^ self writeError:lastErrorNumber |
2466 |
! |
|
2467 |
||
2468 |
writeError:errorNumber |
|
612 | 2469 |
"report an error, that some write error occured" |
2470 |
||
15845 | 2471 |
"{ Pragma: +optSpace }" |
2472 |
||
2473 |
^ WriteError newException |
|
16296 | 2474 |
errorCode:errorNumber; |
2475 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
|
2476 |
parameter:self; |
|
2477 |
raiseRequest |
|
612 | 2478 |
! ! |
2479 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2480 |
!ExternalStream methodsFor:'finalization'! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2481 |
|
15468 | 2482 |
executor |
2483 |
"return a copy for finalization-registration; |
|
2484 |
since all we need at finalization time is the fileDescriptor, |
|
2485 |
a cheaper copy is possible." |
|
2486 |
||
2487 |
^ self class basicNew setAccessor:handleType to:handle |
|
2488 |
! |
|
2489 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2490 |
finalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2491 |
"answer the registry used for finalization. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2492 |
ExternalStreams have their own Registry" |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2493 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2494 |
^ Lobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2495 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2496 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2497 |
finalize |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2498 |
"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
|
2499 |
|
16551 | 2500 |
"/ with timeout to avoid blocking in a bad pty/socket |
2501 |
[ |
|
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
|
2502 |
self closeFile |
16551 | 2503 |
] valueWithTimeout:30 seconds. |
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2504 |
! ! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2505 |
|
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2506 |
!ExternalStream methodsFor:'initialization'! |
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2507 |
|
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2508 |
initialize |
15921 | 2509 |
position := 0. |
2510 |
binary := false. |
|
2511 |
buffered := true. |
|
2512 |
eolMode := DefaultEOLMode. |
|
2513 |
hitEOF := false. |
|
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2514 |
! ! |
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2515 |
|
2 | 2516 |
!ExternalStream methodsFor:'line reading/writing'! |
1 | 2517 |
|
2518 |
nextLine |
|
2519 |
"read the next line (characters up to newline). |
|
2520 |
Return a string containing those characters excluding the newline. |
|
2521 |
If the previous-to-last character is a cr, this is also removed, |
|
16508 | 2522 |
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
|
2523 |
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
|
2524 |
|
16296 | 2525 |
|line error| |
971
eb70f5674303
max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents:
933
diff
changeset
|
2526 |
|
12873 | 2527 |
%{ /* STACK:100000 */ |
1 | 2528 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2529 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2530 |
int len, ret; |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
2531 |
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
|
2532 |
char *rslt, *nextPtr, *limit; |
22 | 2533 |
int fd, ch; |
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
2534 |
int _buffered; |
216 | 2535 |
OBJ fp; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2536 |
int lineTooLong = 0; |
2920 | 2537 |
int cutOff = 0; |
1 | 2538 |
|
1133 | 2539 |
__INST(lastErrorNumber) = nil; |
12548 | 2540 |
if ((__INST(handleType) == nil) |
2541 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2542 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2543 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 2544 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
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
|
2545 |
if (((fp = __INST(handle)) != nil) |
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
|
2546 |
&& (__INST(mode) != @symbol(writeonly)) |
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
|
2547 |
&& (__INST(binary) != true) |
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
|
2548 |
) { |
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
|
2549 |
f = __FILEVal(fp); |
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
|
2550 |
buffer[0] = '\0'; |
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
|
2551 |
|
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
|
2552 |
_buffered = (__INST(buffered) == true); |
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
|
2553 |
if (_buffered) { |
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
|
2554 |
__READING__(f); |
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
|
2555 |
} |
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
|
2556 |
|
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
|
2557 |
rslt = nextPtr = buffer; |
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
|
2558 |
limit = buffer + sizeof(buffer) - 2; |
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
|
2559 |
|
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
|
2560 |
for (;;) { |
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
|
2561 |
__READBYTE__(ret, f, nextPtr, _buffered, __INST(handleType)); |
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
|
2562 |
if (ret <= 0) { |
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
|
2563 |
if (nextPtr == buffer) |
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
|
2564 |
rslt = NULL; |
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
|
2565 |
if (ret == 0) { |
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
|
2566 |
__INST(hitEOF) = true; |
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
|
2567 |
break; |
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
|
2568 |
} else { |
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
|
2569 |
error = __mkSmallInteger(__threadErrno); |
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
|
2570 |
goto err; |
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
|
2571 |
} |
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
|
2572 |
} |
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
|
2573 |
|
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
|
2574 |
if (*nextPtr == '\n') { |
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
|
2575 |
cutOff = 1; |
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
|
2576 |
*nextPtr = '\0'; |
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
|
2577 |
break; |
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
|
2578 |
} |
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
|
2579 |
if (*nextPtr == '\r') { |
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
|
2580 |
char peekChar; |
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
|
2581 |
|
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
|
2582 |
/* |
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
|
2583 |
* peek ahead for a newLine ... |
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
|
2584 |
*/ |
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
|
2585 |
__READBYTE__(ret, f, &peekChar, _buffered, __INST(handleType)); |
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
|
2586 |
if (ret <= 0) { |
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
|
2587 |
cutOff = 1; |
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
|
2588 |
*nextPtr = '\0'; |
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
|
2589 |
if (ret == 0) { |
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
|
2590 |
__INST(hitEOF) = true; |
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
|
2591 |
break; |
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
|
2592 |
} |
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
|
2593 |
error = __mkSmallInteger(__threadErrno); |
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
|
2594 |
goto err; |
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
|
2595 |
} |
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
|
2596 |
|
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
|
2597 |
if (peekChar == '\n') { |
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
|
2598 |
cutOff = 2; |
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
|
2599 |
*nextPtr = '\0'; |
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
|
2600 |
break; |
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
|
2601 |
} |
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
|
2602 |
|
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
|
2603 |
__UNGETC__(peekChar, f, _buffered); |
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
|
2604 |
|
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
|
2605 |
cutOff = 1; |
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
|
2606 |
*nextPtr = '\0'; |
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
|
2607 |
break; |
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
|
2608 |
} |
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
|
2609 |
|
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
|
2610 |
nextPtr++; |
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
|
2611 |
if (nextPtr >= limit) { |
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
|
2612 |
*nextPtr = '\0'; |
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
|
2613 |
lineTooLong = 1; |
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
|
2614 |
if (@global(InfoPrinting) == true) { |
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
|
2615 |
fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n"); |
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
|
2616 |
} |
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
|
2617 |
break; |
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
|
2618 |
} |
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
|
2619 |
} |
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
|
2620 |
|
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
|
2621 |
if (rslt != NULL) { |
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
|
2622 |
len = nextPtr-buffer; |
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
|
2623 |
|
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
|
2624 |
if (__isSmallInteger(__INST(position))) { |
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
|
2625 |
INT np = __intVal(__INST(position)) + len + cutOff; |
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
|
2626 |
OBJ t; |
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
|
2627 |
|
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
|
2628 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
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
|
2629 |
} else { |
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
|
2630 |
__INST(position) = nil; /* i.e. do not know */ |
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
|
2631 |
} |
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
|
2632 |
/* remove any EOL character */ |
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
|
2633 |
if (len != 0) { |
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
|
2634 |
if (buffer[len-1] == '\n') { |
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
|
2635 |
buffer[--len] = '\0'; |
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
|
2636 |
} |
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
|
2637 |
if ((len != 0) && (buffer[len-1] == '\r')) { |
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
|
2638 |
buffer[--len] = '\0'; |
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
|
2639 |
} |
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
|
2640 |
} |
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
|
2641 |
line = __MKSTRING_L(buffer, len); |
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
|
2642 |
if (! lineTooLong) { |
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
|
2643 |
RETURN ( line ); |
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
|
2644 |
} |
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
|
2645 |
} |
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
|
2646 |
} |
1 | 2647 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
2648 |
err: ; |
159 | 2649 |
%}. |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2650 |
line notNil ifTrue:[ |
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
|
2651 |
"/ the line as read is longer than 32k characters (boy - what a line) |
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
|
2652 |
"/ The exception could be handled by reading more and returning the |
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
|
2653 |
"/ concatenation in your exception handler (the receiver and the partial |
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
|
2654 |
"/ line are passed as parameter) |
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
|
2655 |
|
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
|
2656 |
LineTooLongErrorSignal isHandled ifTrue:[ |
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
|
2657 |
^ LineTooLongErrorSignal |
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
|
2658 |
raiseRequestWith:(Array with:self with:line) |
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
|
2659 |
errorString:('line too long read error') |
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
|
2660 |
]. |
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
|
2661 |
^ line , self nextLine |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2662 |
]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2663 |
|
8614 | 2664 |
(hitEOF == true) ifTrue:[^ self pastEndRead]. |
16296 | 2665 |
error notNil ifTrue:[ |
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
|
2666 |
lastErrorNumber := error. |
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
|
2667 |
^ self readError:error |
16296 | 2668 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2669 |
handle isNil ifTrue:[^ self errorNotOpen]. |
1 | 2670 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
5431 | 2671 |
(binary == true) ifTrue:[^ self errorBinary]. |
2672 |
^ super nextLine |
|
1 | 2673 |
! |
2674 |
||
2675 |
nextPutLine:aString |
|
2920 | 2676 |
"write the characters in aString and append an end-of-Line marker |
2677 |
(LF, CR or CRLF - depending in the setting of eolMode)" |
|
1 | 2678 |
|
16296 | 2679 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2680 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2681 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2682 |
int len, cnt, len1, _buffered; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
2683 |
OBJ fp; |
537
dc4dad8a5ddd
many ExtStream rewrites - has to be reevaluated in all platforms
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2684 |
char *cp; |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
2685 |
int o_offs; |
1 | 2686 |
|
1133 | 2687 |
__INST(lastErrorNumber) = nil; |
12548 | 2688 |
if ((__INST(handleType) == nil) |
2689 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2690 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2691 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 2692 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 2693 |
if (((fp = __INST(handle)) != nil) |
2694 |
&& (__INST(mode) != @symbol(readonly)) |
|
2695 |
&& (__INST(binary) != true) |
|
2696 |
&& __isStringLike(aString) |
|
2697 |
) { |
|
2698 |
f = __FILEVal(fp); |
|
2699 |
len = __stringSize(aString); |
|
2700 |
||
2701 |
if (_buffered = (__INST(buffered) == true)) { |
|
2702 |
__WRITING__(f) |
|
2703 |
} |
|
9053
f3f3d48d6f44
fix writing to stdout/stderr for winstx non-console operation
Claus Gittinger <cg@exept.de>
parents:
9024
diff
changeset
|
2704 |
#ifdef WIN32 |
16508 | 2705 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
2706 |
cnt = __win32_fwrite(__stringVal(aString), 1, len, f); |
|
2707 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2708 |
#endif |
16508 | 2709 |
{ |
2710 |
o_offs = (char *)__stringVal(aString)-(char *)aString; |
|
2711 |
__WRITEBYTES_OBJ__(cnt, f, aString, o_offs, len, _buffered, __INST(handleType)); |
|
2712 |
} |
|
2713 |
if (cnt == len) { |
|
2714 |
OBJ mode = __INST(eolMode); |
|
2715 |
||
2716 |
len1 = len; |
|
2717 |
||
2718 |
if (mode == @symbol(cr)) { |
|
2719 |
cp = "\r"; len = 1; |
|
2720 |
} else if (mode == @symbol(crlf)) { |
|
2721 |
cp = "\r\n"; len = 2; |
|
2722 |
} else { |
|
2723 |
cp = "\n"; len = 1; |
|
2724 |
} |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2725 |
#ifdef WIN32 |
16508 | 2726 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
2727 |
cnt = __win32_fwrite(cp, 1, len, f); |
|
2728 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2729 |
#endif |
16508 | 2730 |
{ |
2731 |
__WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType)); |
|
2732 |
} |
|
2733 |
if (cnt > 0) { |
|
2734 |
if (__isSmallInteger(__INST(position))) { |
|
2735 |
INT np = __intVal(__INST(position)) + cnt; |
|
2736 |
OBJ t; |
|
2737 |
||
2738 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
2739 |
} else { |
|
2740 |
__INST(position) = nil; /* i.e. do not know */ |
|
2741 |
} |
|
2742 |
RETURN ( self ); |
|
2743 |
} |
|
2744 |
} |
|
2745 |
error = __mkSmallInteger(__threadErrno); |
|
2746 |
} |
|
1 | 2747 |
} |
159 | 2748 |
%}. |
16296 | 2749 |
error notNil ifTrue:[ |
16508 | 2750 |
lastErrorNumber := error. |
2751 |
self writeError:error. |
|
2752 |
^ self |
|
16296 | 2753 |
]. |
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
2754 |
super nextPutLine:aString. |
1 | 2755 |
! |
2756 |
||
2757 |
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil |
|
68 | 2758 |
"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
|
2759 |
and append all lines to self. |
159 | 2760 |
Can be used to copy/create large files or copy from a pipe/socket. |
68 | 2761 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2762 |
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
|
2763 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2764 |
|line| |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2765 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2766 |
[aStream atEnd] whileFalse:[ |
8070 | 2767 |
line := aStream nextLine. |
2768 |
line isNil ifTrue:[ |
|
2769 |
^ self. |
|
2770 |
]. |
|
2771 |
self nextPutLine:line. |
|
2772 |
(aStringOrNil notNil and:[line startsWith:aStringOrNil]) ifTrue:[ |
|
2773 |
^ self |
|
2774 |
] |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2775 |
]. |
1 | 2776 |
! |
2777 |
||
2778 |
peekForLineStartingWith:aString |
|
2779 |
"read ahead for next line starting with aString; |
|
159 | 2780 |
return the line-string if found, or nil if EOF is encountered. |
7118 | 2781 |
If matched, do not advance position beyond that line |
159 | 2782 |
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
|
2783 |
If not matched, reposition to original position for further reading." |
1 | 2784 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2785 |
|firstPos lastPos line| |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2786 |
|
1 | 2787 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2788 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2 | 2789 |
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
|
2790 |
buffered ifFalse:[^ self errorNotBuffered]. |
12 | 2791 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2792 |
firstPos := self position. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2793 |
[self atEnd] whileFalse:[ |
8070 | 2794 |
lastPos := self position. |
2795 |
line := self nextLine. |
|
2796 |
line isNil ifTrue:[ |
|
2797 |
self position:firstPos. |
|
2798 |
^ nil |
|
2799 |
]. |
|
2800 |
(line startsWith:aString) ifTrue:[ |
|
2801 |
self position:lastPos. |
|
2802 |
^ line |
|
2803 |
] |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2804 |
]. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2805 |
self position:firstPos. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2806 |
^ nil |
1 | 2807 |
! |
2808 |
||
2809 |
peekForLineStartingWithAny:aCollectionOfStrings |
|
2810 |
"read ahead for next line starting with any of aCollectionOfStrings; |
|
2811 |
return the index in aCollection if found, nil otherwise.. |
|
2812 |
If no match, do not change position; otherwise advance right before the |
|
2813 |
matched line so that nextLine will return this line." |
|
2814 |
||
2815 |
|line startPos linePos index| |
|
2816 |
||
2817 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2818 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2 | 2819 |
binary ifTrue:[^ self errorBinary]. |
2820 |
||
1 | 2821 |
startPos := self position. |
2822 |
[self atEnd] whileFalse:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2823 |
linePos := self position. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2824 |
line := self nextLine. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2825 |
line notNil ifTrue:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2826 |
index := 1. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2827 |
aCollectionOfStrings do:[:prefix | |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2828 |
(line startsWith:prefix) ifTrue:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2829 |
self position:linePos. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2830 |
^ index |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2831 |
]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2832 |
index := index + 1 |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2833 |
] |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2834 |
] |
1 | 2835 |
]. |
2836 |
self position:startPos. |
|
2837 |
^ nil |
|
2838 |
! ! |
|
2839 |
||
612 | 2840 |
!ExternalStream methodsFor:'misc functions'! |
2841 |
||
2842 |
async:aBoolean |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2843 |
"set/clear the async attribute - if set, the availability of data on |
612 | 2844 |
the receiver will trigger an ioInterrupt. |
779 | 2845 |
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
|
2846 |
Notice: |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2847 |
not every OS supports this |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2848 |
- check with OS>>supportsIOInterrupts before using" |
92 | 2849 |
|
2850 |
|fd| |
|
2851 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2852 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2853 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2854 |
OperatingSystem supportsIOInterrupts ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2855 |
^ self errorUnsupportedOperation |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2856 |
]. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2857 |
|
92 | 2858 |
fd := self fileDescriptor. |
612 | 2859 |
aBoolean ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2860 |
^ OperatingSystem enableIOInterruptsOn:fd |
612 | 2861 |
]. |
2862 |
^ OperatingSystem disableIOInterruptsOn:fd |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2863 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2864 |
"Modified: 11.1.1997 / 17:50:21 / cg" |
92 | 2865 |
! |
2866 |
||
612 | 2867 |
blocking:aBoolean |
2868 |
"set/clear the blocking attribute - if set (which is the default) |
|
2869 |
a read (using next) on the receiver will block until data is available. |
|
2870 |
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
|
2871 |
nil. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2872 |
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
|
2873 |
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
|
2874 |
in advance. However, the data must then be read using #nextBytes: |
8616 | 2875 |
methods, in order to avoid other (pastEndRead) exceptions." |
92 | 2876 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2877 |
handle isNil ifTrue:[^ self errorNotOpen]. |
7499
53b7a86e1f0b
ExternalStream>>blocking: returns previous blocking status
Stefan Vogel <sv@exept.de>
parents:
7497
diff
changeset
|
2878 |
^ OperatingSystem setBlocking:aBoolean on:self fileDescriptor. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2879 |
|
3174 | 2880 |
"Modified: / 11.1.1997 / 17:48:01 / cg" |
2881 |
"Modified: / 15.1.1998 / 11:49:48 / stefan" |
|
612 | 2882 |
! |
2883 |
||
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2884 |
copyToEndInto:outStream |
7017
03f1bd57c001
no one cares about the signal in copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
7013
diff
changeset
|
2885 |
"copy the data into another stream." |
03f1bd57c001
no one cares about the signal in copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
7013
diff
changeset
|
2886 |
|
8362 | 2887 |
|bufferSize| |
7700
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2888 |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2889 |
OperatingSystem isMSDOSlike ifTrue:[ |
16296 | 2890 |
"/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ? |
2891 |
bufferSize := 1 * 1024. |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2892 |
] ifFalse:[ |
16296 | 2893 |
bufferSize := 8 * 1024. |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2894 |
]. |
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2895 |
|
7017
03f1bd57c001
no one cares about the signal in copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
7013
diff
changeset
|
2896 |
^ self copyToEndInto:outStream bufferSize:bufferSize |
7700
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2897 |
|
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2898 |
" |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2899 |
|in out| |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2900 |
|
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2901 |
in := 'Makefile' asFilename readStream. |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2902 |
out := Stdout. |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2903 |
in copyToEndInto:out. |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2904 |
in close. |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2905 |
" |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2906 |
! |
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2907 |
|
612 | 2908 |
create |
2909 |
"create the stream |
|
2910 |
- this must be redefined in subclass" |
|
2911 |
||
2912 |
^ self subclassResponsibility |
|
2913 |
! |
|
2914 |
||
2915 |
ioctl:ioctlNumber |
|
2916 |
"to provide a simple ioctl facility - an ioctl is performed |
|
2917 |
on the underlying file; no arguments are passed." |
|
2918 |
||
2920 | 2919 |
^ self ioctl:ioctlNumber with:nil |
2920 |
! |
|
2921 |
||
2922 |
ioctl:ioctlNumber with:arg |
|
2923 |
"to provide a simple ioctl facility - an ioctl is performed |
|
2924 |
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
|
2925 |
This is not used by ST/X, but provided for special situations |
2920 | 2926 |
- for example, to control proprietrary I/O devices. |
2927 |
||
2928 |
Since the type of the argument depends on the ioctl being |
|
2929 |
performed, different arg types are allowed here. |
|
2930 |
If the argument is nil, an ioctl without argument is performed. |
|
16508 | 2931 |
If the argument is an integral number, it's directly passed; |
2932 |
if it's a kind of ByteArray (ByteArray, String or Structure), |
|
2920 | 2933 |
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
|
2934 |
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
|
2935 |
This allows performing most ioctls |
2920 | 2936 |
- however, it might be tricky to setup the buffer. |
2937 |
Be careful in what you pass - ST/X cannot validate its correctness." |
|
2938 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2939 |
|error| |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2940 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2941 |
%{ |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2942 |
#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
|
2943 |
int fd; |
10552
d52aa8e066e5
#ioctl:with: accept 32-bit integers as arguments
Stefan Vogel <sv@exept.de>
parents:
10469
diff
changeset
|
2944 |
int ret; |
d52aa8e066e5
#ioctl:with: accept 32-bit integers as arguments
Stefan Vogel <sv@exept.de>
parents:
10469
diff
changeset
|
2945 |
unsigned int ioNum; |
2920 | 2946 |
INT ioArg; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2947 |
OBJ fp = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2948 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2949 |
if (fp == nil) |
16508 | 2950 |
goto out; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2951 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2952 |
if (!__isInteger(ioctlNumber) |
16508 | 2953 |
|| (!__isInteger(arg) |
2954 |
&& (arg != nil) |
|
2955 |
&& !__isBytes(arg) |
|
2956 |
&& !__isExternalBytesLike(arg) |
|
2957 |
&& !__isExternalAddress(arg))) { |
|
2958 |
error = @symbol(badArgument); |
|
2959 |
goto out; |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2960 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2961 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2962 |
if (__INST(handleType) == @symbol(socketHandle)) { |
16508 | 2963 |
fd = __FILEVal(fp); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2964 |
} else if ((__INST(handleType) == nil) |
16508 | 2965 |
|| (__INST(handleType) == @symbol(filePointer)) |
2966 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
2967 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
2968 |
fd = fileno(__FILEVal(fp)); |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2969 |
} else { |
16508 | 2970 |
error = @symbol(badHandleType); |
2971 |
goto out; |
|
612 | 2972 |
} |
16508 | 2973 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2974 |
ioNum = __unsignedLongIntVal(ioctlNumber); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2975 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2976 |
__BEGIN_INTERRUPTABLE__ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2977 |
do { |
16508 | 2978 |
__threadErrno = 0; |
2979 |
if (arg == nil) { |
|
2980 |
ioArg = 0; |
|
2981 |
} else if (__isSmallInteger(arg)) { |
|
2982 |
ioArg = __intVal(arg); |
|
2983 |
} else if (__isInteger(arg)) { |
|
2984 |
ioArg = __unsignedLongIntVal(arg); |
|
2985 |
} else if (__isExternalBytesLike(arg)) { |
|
2986 |
ioArg = (INT)(__externalBytesAddress(arg)); |
|
2987 |
} else if (__isExternalAddress(arg)) { |
|
2988 |
ioArg = (INT)(__externalAddressVal(arg)); |
|
2989 |
} else { |
|
2990 |
ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element); |
|
2991 |
} |
|
2992 |
ret = ioctl(fd, ioNum, ioArg); |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2993 |
} while (ret < 0 && __threadErrno == EINTR); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2994 |
__END_INTERRUPTABLE__ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2995 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2996 |
if (ret >= 0) { |
16508 | 2997 |
RETURN ( __mkSmallInteger(ret) ); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2998 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2999 |
error = __mkSmallInteger(__threadErrno); |
791 | 3000 |
#endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3001 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3002 |
out:; |
612 | 3003 |
%}. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3004 |
error notNil ifTrue:[ |
16508 | 3005 |
lastErrorNumber := error. |
3006 |
^ self ioError:error. |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3007 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3008 |
handle isNil ifTrue:[^ self errorNotOpen]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3009 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3010 |
"/ the system does not support ioctl (MSDOS or VMS) |
2920 | 3011 |
^ self errorUnsupportedOperation |
612 | 3012 |
! |
3013 |
||
16551 | 3014 |
reset |
3015 |
"set the read position to the beginning of the collection" |
|
3016 |
||
3017 |
self position:0 |
|
3018 |
! |
|
3019 |
||
3020 |
setToEnd |
|
3021 |
"redefined since it must be implemented differently" |
|
3022 |
||
3023 |
^ self subclassResponsibility |
|
3024 |
! |
|
3025 |
||
3026 |
sync |
|
3027 |
"make sure, that the OS writes cached data to the disk" |
|
3028 |
||
3029 |
|error| |
|
3030 |
||
3031 |
self flush. |
|
3032 |
||
3033 |
%{ |
|
3034 |
#if !defined(__openVMS__) |
|
3035 |
int fd; |
|
3036 |
int ret; |
|
3037 |
OBJ fp = __INST(handle); |
|
3038 |
||
3039 |
if (fp == nil) |
|
3040 |
goto out; |
|
3041 |
||
3042 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
3043 |
fd = __FILEVal(fp); |
|
3044 |
} else if ((__INST(handleType) == nil) |
|
3045 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3046 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3047 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3048 |
fd = fileno(__FILEVal(fp)); |
|
3049 |
} else { |
|
3050 |
error = @symbol(badHandleType); |
|
3051 |
goto out; |
|
3052 |
} |
|
3053 |
||
3054 |
#ifdef WIN32 |
|
3055 |
__threadErrno = 0; |
|
3056 |
ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd)); |
|
3057 |
if (ret) { |
|
3058 |
RETURN (self); |
|
3059 |
} |
|
3060 |
#else |
|
3061 |
__BEGIN_INTERRUPTABLE__ |
|
3062 |
do { |
|
3063 |
ret = fsync(fd); |
|
3064 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
|
3065 |
__END_INTERRUPTABLE__ |
|
3066 |
||
3067 |
if (ret >= 0) { |
|
3068 |
RETURN (self); |
|
3069 |
} |
|
3070 |
#endif /* ! WIN32 */ |
|
3071 |
error = __mkSmallInteger(__threadErrno); |
|
3072 |
#endif /* ! __openVMS__ */ |
|
3073 |
out:; |
|
3074 |
%}. |
|
3075 |
error notNil ifTrue:[ |
|
3076 |
lastErrorNumber := error. |
|
3077 |
self ioError:error. |
|
3078 |
^ self. |
|
3079 |
]. |
|
3080 |
handle isNil ifTrue:[self errorNotOpen]. |
|
3081 |
||
3082 |
" |
|
3083 |
|f| |
|
3084 |
f := 'x' asFilename writeStream. |
|
3085 |
f nextPutAll:'hallo'; sync; syncData; close |
|
3086 |
" |
|
3087 |
! |
|
3088 |
||
3089 |
syncData |
|
3090 |
"make sure, that the OS writes cached data to the disk. |
|
3091 |
In this case, metadata is only written, if it is |
|
3092 |
required to read the file's data (so metadata will not be written, |
|
3093 |
if only access/modification time has changed)." |
|
3094 |
|error| |
|
3095 |
||
3096 |
self flush. |
|
3097 |
||
3098 |
%{ |
|
3099 |
#if !defined(__openVMS__) |
|
3100 |
int fd; |
|
3101 |
int ret; |
|
3102 |
OBJ fp = __INST(handle); |
|
3103 |
||
3104 |
if (fp == nil) |
|
3105 |
goto out; |
|
3106 |
||
3107 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
3108 |
fd = __FILEVal(fp); |
|
3109 |
} else if ((__INST(handleType) == nil) |
|
3110 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3111 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3112 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3113 |
fd = fileno(__FILEVal(fp)); |
|
3114 |
} else { |
|
3115 |
error = @symbol(badHandleType); |
|
3116 |
goto out; |
|
3117 |
} |
|
3118 |
||
3119 |
#ifdef WIN32 |
|
3120 |
__threadErrno = 0; |
|
3121 |
ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd)); |
|
3122 |
if (ret) { |
|
3123 |
RETURN (self); |
|
3124 |
} |
|
3125 |
#else |
|
3126 |
__BEGIN_INTERRUPTABLE__ |
|
3127 |
do { |
|
3128 |
ret = fdatasync(fd); |
|
3129 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
|
3130 |
__END_INTERRUPTABLE__ |
|
3131 |
||
3132 |
if (ret >= 0) { |
|
3133 |
RETURN (self); |
|
3134 |
} |
|
3135 |
#endif /* ! WIN32 */ |
|
3136 |
error = __mkSmallInteger(__threadErrno); |
|
3137 |
#endif /* ! __openVMS__ */ |
|
3138 |
out:; |
|
3139 |
%}. |
|
3140 |
||
3141 |
error notNil ifTrue:[ |
|
3142 |
lastErrorNumber := error. |
|
3143 |
self ioError:error. |
|
3144 |
^ self. |
|
3145 |
]. |
|
3146 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3147 |
||
3148 |
"if notdef HAS_DATASYNC, fall back" |
|
3149 |
self sync. |
|
3150 |
||
3151 |
" |
|
3152 |
|f| |
|
3153 |
f := 'x' asFilename writeStream. |
|
3154 |
f nextPutAll:'hallo'; sync; syncData; close |
|
3155 |
" |
|
3156 |
! |
|
3157 |
||
16508 | 3158 |
tcgetattr |
3159 |
"unix only: |
|
3160 |
provide the information of a tcgetattr call as a dictionary. |
|
3161 |
This provides terminal setting values of a tty or pty. |
|
3162 |
Used by terminal emulators. |
|
3163 |
On non-unix systems, an unsupported operation error is raised" |
|
3164 |
||
3165 |
|error ret |
|
3166 |
iflags "/ input flags |
|
3167 |
ignbrk brkint ignpar parmrk inpck istrip inlcr igncr |
|
16509
2cf139885242
Fixed ExternalStream>>tcgetattr
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16508
diff
changeset
|
3168 |
icrnl iuclc ixon ixoff ixany imaxbel iutf8 |
16508 | 3169 |
oflags "/ output flags |
3170 |
opost onlcr ocrnl olcuc onocr onlret oxtabs onoteot |
|
3171 |
cflags "/ control flags |
|
3172 |
csize cstopb cread parenb parodd hupcl clocal |
|
3173 |
lflags "/ local flags |
|
3174 |
echoke echoe echok echo echonl echoprt echoctl |
|
3175 |
isig icanon altwerase iexten extproc tostop |
|
3176 |
| |
|
3177 |
||
3178 |
%{ |
|
3179 |
#if !defined(MSDOS_LIKE) && !defined(__openVMS__) |
|
3180 |
int fd; |
|
3181 |
int _ret; |
|
3182 |
OBJ fp = __INST(handle); |
|
3183 |
struct termios t; |
|
3184 |
int sz; |
|
3185 |
||
3186 |
if (fp == nil) |
|
3187 |
goto out; |
|
3188 |
||
3189 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
3190 |
fd = __FILEVal(fp); |
|
3191 |
} else if ((__INST(handleType) == nil) |
|
3192 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3193 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3194 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3195 |
fd = fileno(__FILEVal(fp)); |
|
3196 |
} else { |
|
3197 |
error = @symbol(badHandleType); |
|
3198 |
goto out; |
|
3199 |
} |
|
3200 |
||
3201 |
__BEGIN_INTERRUPTABLE__ |
|
3202 |
do { |
|
3203 |
__threadErrno = 0; |
|
3204 |
_ret = tcgetattr(fd, &t); |
|
3205 |
} while (_ret < 0 && __threadErrno == EINTR); |
|
3206 |
__END_INTERRUPTABLE__ |
|
3207 |
||
3208 |
if (_ret < 0) { |
|
3209 |
error = __mkSmallInteger(__threadErrno); |
|
3210 |
} |
|
3211 |
ignbrk = t.c_iflag & IGNBRK ? true : false; |
|
3212 |
brkint = t.c_iflag & BRKINT ? true : false; |
|
3213 |
ignpar = t.c_iflag & IGNPAR ? true : false; |
|
3214 |
parmrk = t.c_iflag & PARMRK ? true : false; |
|
3215 |
inpck = t.c_iflag & INPCK ? true : false; |
|
3216 |
istrip = t.c_iflag & ISTRIP ? true : false; |
|
3217 |
inlcr = t.c_iflag & INLCR ? true : false; |
|
3218 |
ixon = t.c_iflag & IXON ? true : false; |
|
3219 |
ixoff = t.c_iflag & IXOFF ? true : false; |
|
3220 |
ixany = t.c_iflag & IXANY ? true : false; |
|
3221 |
#ifdef IMAXBEL |
|
3222 |
imaxbel = t.c_iflag & IMAXBEL ? true : false; |
|
3223 |
#endif |
|
3224 |
#ifdef IUCLC |
|
3225 |
iuclc = t.c_iflag & IUCLC ? true : false; |
|
3226 |
#endif |
|
3227 |
||
3228 |
opost = t.c_oflag & OPOST ? true : false; |
|
3229 |
onlcr = t.c_oflag & ONLCR ? true : false; |
|
3230 |
#ifdef OXTABS |
|
3231 |
oxtabs = t.c_oflag & OXTABS ? true : false; |
|
3232 |
#endif |
|
3233 |
#ifdef ONOTEOT |
|
3234 |
onoteot = t.c_oflag & ONOTEOT ? true : false; |
|
3235 |
#endif |
|
3236 |
ocrnl = t.c_oflag & OCRNL ? true : false; |
|
3237 |
#ifdef OLCUC |
|
3238 |
olcuc = t.c_oflag & OLCUC ? true : false; |
|
3239 |
#endif |
|
3240 |
onocr = t.c_oflag & ONOCR ? true : false; |
|
3241 |
onlret = t.c_oflag & ONLRET ? true : false; |
|
3242 |
||
3243 |
sz = t.c_cflag & CSIZE; |
|
3244 |
switch (sz) { |
|
3245 |
case CS5: |
|
3246 |
csize = @symbol(cs5); |
|
3247 |
break; |
|
3248 |
case CS6: |
|
3249 |
csize = @symbol(cs6); |
|
3250 |
break; |
|
3251 |
case CS7: |
|
3252 |
csize = @symbol(cs7); |
|
3253 |
break; |
|
3254 |
case CS8: |
|
3255 |
csize = @symbol(cs8); |
|
3256 |
break; |
|
3257 |
} |
|
3258 |
cstopb = t.c_cflag & CSTOPB ? true : false; |
|
3259 |
cread = t.c_cflag & CREAD ? true : false; |
|
3260 |
parenb = t.c_cflag & PARENB ? true : false; |
|
3261 |
parodd = t.c_cflag & PARODD ? true : false; |
|
3262 |
hupcl = t.c_cflag & HUPCL ? true : false; |
|
3263 |
clocal = t.c_cflag & CLOCAL ? true : false; |
|
3264 |
||
3265 |
echoke = t.c_lflag & ECHOKE ? true : false; |
|
3266 |
echoe = t.c_lflag & ECHOE ? true : false; |
|
3267 |
echo = t.c_lflag & ECHO ? true : false; |
|
3268 |
echonl = t.c_lflag & ECHONL ? true : false; |
|
3269 |
echoctl = t.c_lflag & ECHOCTL ? true : false; |
|
3270 |
isig = t.c_lflag & ISIG ? true : false; |
|
3271 |
icanon = t.c_lflag & ICANON ? true : false; |
|
3272 |
#ifdef ALTWERASE |
|
3273 |
altwerase = t.c_lflag & ALTWERASE ? true : false; |
|
3274 |
#endif |
|
3275 |
#ifdef IEXTEN |
|
3276 |
iexten = t.c_lflag & IEXTEN ? true : false; |
|
3277 |
#endif |
|
3278 |
#ifdef EXTPROC |
|
3279 |
extproc = t.c_lflag & EXTPROC ? true : false; |
|
3280 |
#endif |
|
3281 |
#ifdef TOSTOP |
|
3282 |
tostop = t.c_lflag & TOSTOP ? true : false; |
|
3283 |
#endif |
|
3284 |
||
3285 |
#else |
|
3286 |
error = @symbol(unsupportedOperation); |
|
3287 |
#endif |
|
3288 |
||
3289 |
out:; |
|
3290 |
%}. |
|
3291 |
error notNil ifTrue:[ |
|
3292 |
error == #unsupportedOperation ifTrue:[ |
|
3293 |
"/ the system does not support tcgetattr |
|
3294 |
^ self errorUnsupportedOperation |
|
3295 |
]. |
|
3296 |
lastErrorNumber := error. |
|
3297 |
^ self ioError:error. |
|
3298 |
]. |
|
3299 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3300 |
||
3301 |
"/ construct a dictionary... |
|
3302 |
ret := Dictionary new. |
|
3303 |
ret at:#iflags put:(iflags := Dictionary new). |
|
3304 |
ret at:#oflags put:(oflags := Dictionary new). |
|
3305 |
ret at:#cflags put:(cflags := Dictionary new). |
|
3306 |
ret at:#lflags put:(lflags := Dictionary new). |
|
3307 |
iflags at:#ignbrk put:ignbrk. |
|
3308 |
iflags at:#brkint put:brkint. |
|
3309 |
iflags at:#ignpar put:ignpar. |
|
3310 |
iflags at:#parmrk put:parmrk. |
|
3311 |
iflags at:#inpck put:inpck. |
|
3312 |
iflags at:#istrip put:istrip. |
|
3313 |
iflags at:#inlcr put:inlcr. |
|
3314 |
iflags at:#igncr put:igncr. |
|
3315 |
iflags at:#icrnl put:icrnl. |
|
16509
2cf139885242
Fixed ExternalStream>>tcgetattr
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16508
diff
changeset
|
3316 |
iflags at:#uiclc put:iuclc. |
16508 | 3317 |
iflags at:#ixon put:ixon. |
3318 |
iflags at:#ixoff put:ixoff. |
|
3319 |
iflags at:#ixany put:ixany. |
|
3320 |
iflags at:#imaxbel put:imaxbel. |
|
3321 |
iflags at:#iutf8 put:iutf8. |
|
3322 |
||
3323 |
oflags at:#opost put:opost. |
|
3324 |
oflags at:#onlcr put:onlcr. |
|
3325 |
oflags at:#oxtabs put:oxtabs. |
|
3326 |
oflags at:#onoteot put:onoteot. |
|
3327 |
||
3328 |
cflags at:#csize put:csize. |
|
3329 |
cflags at:#cstopb put:cstopb. |
|
3330 |
cflags at:#cread put:cread. |
|
3331 |
cflags at:#parenb put:parenb. |
|
3332 |
cflags at:#parodd put:parodd. |
|
3333 |
cflags at:#hupcl put:hupcl. |
|
3334 |
cflags at:#clocal put:clocal. |
|
3335 |
||
3336 |
lflags at:#echoke put:echoke. |
|
3337 |
lflags at:#echoe put:echoe. |
|
3338 |
lflags at:#echok put:echok. |
|
3339 |
lflags at:#echo put:echo. |
|
3340 |
lflags at:#echonl put:echonl. |
|
3341 |
lflags at:#echoprt put:echoprt. |
|
3342 |
lflags at:#echoctl put:echoctl. |
|
3343 |
lflags at:#isig put:isig. |
|
3344 |
lflags at:#icanon put:icanon. |
|
3345 |
lflags at:#altwerase put:altwerase. |
|
3346 |
lflags at:#iexten put:iexten. |
|
3347 |
lflags at:#extproc put:extproc. |
|
3348 |
lflags at:#tostop put:tostop. |
|
3349 |
^ ret |
|
612 | 3350 |
! ! |
3351 |
||
3352 |
!ExternalStream methodsFor:'non homogenous reading'! |
|
3353 |
||
15254 | 3354 |
next:count into:anObject startingAt:start |
3355 |
"read the next count bytes into an object and return the number of |
|
3356 |
bytes read or the number of bytes read, if EOF is encountered before. |
|
3357 |
If the receiver is some socket/pipe-like stream, an exception |
|
3358 |
is raised if the connection is broken. |
|
3359 |
||
3360 |
Warning: if used with a pipe/socket, this blocks until the requested number |
|
3361 |
of bytes have been read. See #nextAvailableBytes:into:startingAt: |
|
3362 |
to only read whats there. |
|
3363 |
||
3364 |
Notice, that in contrast to other methods, |
|
3365 |
this does NOT return nil on EOF, but the actual count. |
|
3366 |
Thus allowing read of partial blocks. |
|
3367 |
||
3368 |
The object must have non-pointer indexed instvars |
|
3369 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray), |
|
3370 |
or an externalBytes object (with known size). |
|
3371 |
If anObject is a string or byteArray and reused, this provides the |
|
3372 |
fastest possible physical I/O (since no new objects are allocated). |
|
3373 |
||
3374 |
Use with care - non object oriented I/O. |
|
3375 |
Warning: in general, you cannot use this method to pass data from other |
|
3376 |
architectures (unless you prepared the buffer with care), |
|
3377 |
since it does not care for byte order or float representation." |
|
3378 |
||
3379 |
^ self nextBytes:count into:anObject startingAt:start |
|
3380 |
! |
|
3381 |
||
3674 | 3382 |
nextAvailable:count |
3383 |
"return the next count elements of the stream as aCollection. |
|
3384 |
If the stream reaches the end before count elements have been read, |
|
3385 |
return what is available. (i.e. a shorter collection). |
|
3386 |
The type of collection is specified in #contentsSpecies." |
|
3387 |
||
3956
51f1a9a4d63f
changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents:
3949
diff
changeset
|
3388 |
|buffer n| |
3674 | 3389 |
|
3390 |
binary ifTrue:[ |
|
7832 | 3391 |
buffer := ByteArray uninitializedNew:count |
3674 | 3392 |
] ifFalse:[ |
7832 | 3393 |
buffer := String uninitializedNew:count |
3674 | 3394 |
]. |
3395 |
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
|
3396 |
n == 0 ifTrue:[ |
7832 | 3397 |
binary ifTrue:[ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3398 |
^ #[] |
7832 | 3399 |
]. |
3400 |
^ '' |
|
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3401 |
]. |
3674 | 3402 |
|
3403 |
n ~~ count ifTrue:[ |
|
7832 | 3404 |
^ buffer copyTo:n |
3674 | 3405 |
]. |
3406 |
^ buffer. |
|
3407 |
||
3408 |
" |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3409 |
(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
|
3410 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
3674 | 3411 |
(ReadStream on:'hello') nextAvailable:3 |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3412 |
(ReadStream on:'hello') nextAvailable:10 |
3674 | 3413 |
" |
3414 |
||
3415 |
"Modified: / 16.6.1998 / 15:52:41 / cg" |
|
3416 |
! |
|
3417 |
||
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3418 |
nextAvailableBytes:count into:anObject startingAt:start |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3419 |
"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
|
3420 |
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
|
3421 |
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
|
3422 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3423 |
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
|
3424 |
is raised if the connection is broken. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3425 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3426 |
Notice, that in contrast to other methods, |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3427 |
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
|
3428 |
Thus allowing read of partial blocks. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3429 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3430 |
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
|
3431 |
(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
|
3432 |
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
|
3433 |
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
|
3434 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3435 |
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
|
3436 |
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
|
3437 |
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
|
3438 |
|
16296 | 3439 |
|error| |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3440 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3441 |
%{ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3442 |
FILEPOINTER f; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3443 |
int cnt, offs, ret, _buffered; |
15987 | 3444 |
int objSize, nInstBytes; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3445 |
char *cp; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3446 |
char *extPtr; |
7195
755c46f9b774
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7118
diff
changeset
|
3447 |
OBJ fp; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3448 |
int o_offs; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3449 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3450 |
__INST(lastErrorNumber) = nil; |
12548 | 3451 |
if ((__INST(handleType) == nil) |
3452 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3453 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3454 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3455 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 3456 |
if (((fp = __INST(handle)) != nil) |
3457 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3458 |
&& __bothSmallInteger(count, start) |
|
3459 |
) { |
|
3460 |
f = __FILEVal(fp); |
|
3461 |
||
3462 |
cnt = __intVal(count); |
|
3463 |
offs = __intVal(start) - 1; |
|
3464 |
||
3465 |
if (__isExternalBytesLike(anObject)) { |
|
3466 |
OBJ sz; |
|
3467 |
||
3468 |
nInstBytes = 0; |
|
3469 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
|
3470 |
if (extPtr == NULL) goto bad; |
|
3471 |
sz = __externalBytesSize(anObject); |
|
3472 |
if (__isSmallInteger(sz)) { |
|
3473 |
objSize = __intVal(sz); |
|
3474 |
} else { |
|
3475 |
objSize = 0; /* unknown */ |
|
3476 |
} |
|
3477 |
} else { |
|
3478 |
OBJ oClass = __Class(anObject); |
|
3479 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3480 |
||
3481 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3482 |
||
3483 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3484 |
case BYTEARRAY: |
|
3485 |
case WORDARRAY: |
|
3486 |
case LONGARRAY: |
|
3487 |
case SWORDARRAY: |
|
3488 |
case SLONGARRAY: |
|
3489 |
case FLOATARRAY: |
|
3490 |
break; |
|
3491 |
case DOUBLEARRAY: |
|
15987 | 3492 |
#ifdef __NEED_DOUBLE_ALIGN |
16508 | 3493 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
15987 | 3494 |
#endif |
16508 | 3495 |
break; |
3496 |
case LONGLONGARRAY: |
|
3497 |
case SLONGLONGARRAY: |
|
16296 | 3498 |
#ifdef __NEED_LONGLONG_ALIGN |
16508 | 3499 |
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
|
3500 |
#endif |
16508 | 3501 |
break; |
3502 |
default: |
|
3503 |
goto bad; |
|
3504 |
} |
|
3505 |
extPtr = (char *)0; |
|
3506 |
objSize = __Size(anObject) - nInstBytes; |
|
3507 |
} |
|
3508 |
||
3509 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
3510 |
_buffered = (__INST(buffered) == true); |
|
3511 |
if (_buffered) { |
|
3512 |
__READING__(f); |
|
3513 |
} |
|
3514 |
||
3515 |
if (extPtr) { |
|
3516 |
__READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType)); |
|
3517 |
} else { |
|
3518 |
/* |
|
3519 |
* on interrupt, anObject may be moved to another location. |
|
3520 |
* So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__, |
|
3521 |
* to get a new address. |
|
3522 |
*/ |
|
3523 |
offs += nInstBytes; |
|
3524 |
__READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType)); |
|
3525 |
} |
|
3526 |
/* 0 is NOT an EOF condition here ... */ |
|
3527 |
if (ret >= 0) { |
|
3528 |
if (__isSmallInteger(__INST(position))) { |
|
3529 |
INT np = __intVal(__INST(position)) + ret; |
|
3530 |
OBJ t; |
|
3531 |
||
3532 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3533 |
} else { |
|
3534 |
__INST(position) = nil; /* i.e. do not know */ |
|
3535 |
} |
|
3536 |
RETURN (__mkSmallInteger(ret)); |
|
3537 |
} |
|
3538 |
__INST(position) = nil; |
|
3539 |
error = __mkSmallInteger(__threadErrno); |
|
3540 |
} |
|
3541 |
} |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3542 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3543 |
bad: ; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3544 |
%}. |
8614 | 3545 |
(hitEOF and:[self pastEndRead isNil]) ifTrue:[^ 0]. |
16296 | 3546 |
error notNil ifTrue:[ |
16508 | 3547 |
lastErrorNumber := error. |
3548 |
^ self readError:error |
|
16296 | 3549 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3550 |
handle isNil ifTrue:[^ self errorNotOpen]. |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3551 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3552 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3553 |
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
|
3554 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3555 |
^ self primitiveFailed |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3556 |
! |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3557 |
|
612 | 3558 |
nextByte |
3559 |
"read the next byte and return it as an Integer; return nil on error. |
|
3560 |
This is allowed in both text and binary modes, always returning the |
|
3561 |
bytes binary value as an integer in 0..255." |
|
3562 |
||
16296 | 3563 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3564 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3565 |
FILEPOINTER f; |
612 | 3566 |
unsigned char byte; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3567 |
int ret, _buffered; |
612 | 3568 |
OBJ fp; |
3569 |
||
1133 | 3570 |
__INST(lastErrorNumber) = nil; |
12548 | 3571 |
if ((__INST(handleType) == nil) |
3572 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3573 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3574 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3575 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 3576 |
if (((fp = __INST(handle)) != nil) |
3577 |
&& (__INST(mode) != @symbol(writeonly))) { |
|
3578 |
f = __FILEVal(fp); |
|
3579 |
||
3580 |
_buffered = (__INST(buffered) == true); |
|
3581 |
if (_buffered) { |
|
3582 |
__READING__(f) |
|
3583 |
} |
|
3584 |
__READBYTE__(ret, f, &byte, _buffered, __INST(handleType)); |
|
3585 |
if (ret > 0) { |
|
3586 |
if (__isSmallInteger(__INST(position))) { |
|
3587 |
INT np = __intVal(__INST(position)) + 1; |
|
3588 |
OBJ t; |
|
3589 |
||
3590 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3591 |
} else { |
|
3592 |
__INST(position) = nil; /* i.e. do not know */ |
|
3593 |
} |
|
3594 |
RETURN (__mkSmallInteger(byte)); |
|
3595 |
} |
|
3596 |
||
3597 |
if (ret == 0) { |
|
3598 |
__INST(hitEOF) = true; |
|
3599 |
} else /* ret < 0 */ { |
|
3600 |
__INST(position) = nil; |
|
3601 |
error = __mkSmallInteger(__threadErrno); |
|
3602 |
} |
|
3603 |
} |
|
612 | 3604 |
} |
3605 |
%}. |
|
8614 | 3606 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 3607 |
error notNil ifTrue:[ |
16508 | 3608 |
lastErrorNumber := error. |
3609 |
^ self readError:error |
|
16296 | 3610 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3611 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 3612 |
^ self errorWriteOnly |
3613 |
! |
|
3614 |
||
3615 |
nextBytes:count into:anObject startingAt:start |
|
3616 |
"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
|
3617 |
bytes read or the number of bytes read, if EOF is encountered before. |
612 | 3618 |
If the receiver is some socket/pipe-like stream, an exception |
3619 |
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
|
3620 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3621 |
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
|
3622 |
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
|
3623 |
to only read whats there. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3624 |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3625 |
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
|
3626 |
this does NOT return nil on EOF, but the actual count. |
612 | 3627 |
Thus allowing read of partial blocks. |
3628 |
||
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3629 |
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
|
3630 |
(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
|
3631 |
or an externalBytes object (with known size). |
612 | 3632 |
If anObject is a string or byteArray and reused, this provides the |
3633 |
fastest possible physical I/O (since no new objects are allocated). |
|
3634 |
||
3635 |
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
|
3636 |
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
|
3637 |
architectures (unless you prepared the buffer with care), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3638 |
since it does not care for byte order or float representation." |
612 | 3639 |
|
16296 | 3640 |
|error| |
612 | 3641 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3642 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3643 |
int cnt, offs, ret, _buffered; |
15987 | 3644 |
int objSize, nInstBytes; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3645 |
char *extPtr; |
7195
755c46f9b774
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7118
diff
changeset
|
3646 |
OBJ fp; |
612 | 3647 |
|
1133 | 3648 |
__INST(lastErrorNumber) = nil; |
12548 | 3649 |
if ((__INST(handleType) == nil) |
3650 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3651 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3652 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3653 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 3654 |
if (((fp = __INST(handle)) != nil) |
3655 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3656 |
&& __bothSmallInteger(count, start) |
|
3657 |
) { |
|
3658 |
f = __FILEVal(fp); |
|
3659 |
||
3660 |
cnt = __intVal(count); |
|
3661 |
offs = __intVal(start) - 1; |
|
3662 |
||
3663 |
if (__isExternalBytesLike(anObject)) { |
|
3664 |
OBJ sz; |
|
3665 |
||
3666 |
nInstBytes = 0; |
|
3667 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
|
3668 |
if (extPtr == NULL) goto bad; |
|
3669 |
sz = __externalBytesSize(anObject); |
|
3670 |
if (__isSmallInteger(sz)) { |
|
3671 |
objSize = __intVal(sz); |
|
3672 |
} else { |
|
3673 |
objSize = 0; /* unknown */ |
|
3674 |
} |
|
3675 |
} else { |
|
3676 |
OBJ oClass = __Class(anObject); |
|
3677 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3678 |
||
3679 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3680 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3681 |
case BYTEARRAY: |
|
3682 |
case WORDARRAY: |
|
3683 |
case LONGARRAY: |
|
3684 |
case SWORDARRAY: |
|
3685 |
case SLONGARRAY: |
|
3686 |
case FLOATARRAY: |
|
3687 |
break; |
|
3688 |
case DOUBLEARRAY: |
|
15987 | 3689 |
#ifdef __NEED_DOUBLE_ALIGN |
16508 | 3690 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
15987 | 3691 |
#endif |
16508 | 3692 |
break; |
3693 |
case LONGLONGARRAY: |
|
3694 |
case SLONGLONGARRAY: |
|
16296 | 3695 |
#ifdef __NEED_LONGLONG_ALIGN |
16508 | 3696 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
16296 | 3697 |
#endif |
16508 | 3698 |
break; |
3699 |
default: |
|
3700 |
goto bad; |
|
3701 |
} |
|
3702 |
extPtr = (char *)0; |
|
3703 |
objSize = __Size(anObject) - nInstBytes; |
|
3704 |
} |
|
3705 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
3706 |
_buffered = (__INST(buffered) == true); |
|
3707 |
if (_buffered) { |
|
3708 |
__READING__(f); |
|
3709 |
} |
|
3710 |
||
3711 |
if (extPtr) { |
|
3712 |
__READBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType)); |
|
3713 |
} else { |
|
3714 |
/* |
|
3715 |
* on interrupt, anObject may be moved to another location. |
|
3716 |
* So we pass anObject, and the offset to the __READBYTES_OBJ__ macro. |
|
3717 |
*/ |
|
3718 |
offs += nInstBytes; |
|
3719 |
__READBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType)); |
|
3720 |
} |
|
3721 |
||
3722 |
if (ret > 0) { |
|
3723 |
if (__isSmallInteger(__INST(position))) { |
|
3724 |
INT np = __intVal(__INST(position)) + ret; |
|
3725 |
OBJ t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3726 |
} else { |
|
3727 |
__INST(position) = nil; /* i.e. do not know */ |
|
3728 |
} |
|
3729 |
RETURN (__mkSmallInteger(ret)); |
|
3730 |
} |
|
3731 |
if (ret == 0) { |
|
3732 |
__INST(hitEOF) = true; |
|
3733 |
} else /* ret < 0 */ { |
|
3734 |
__INST(position) = nil; |
|
3735 |
error = __mkSmallInteger(__threadErrno); |
|
3736 |
} |
|
3737 |
} |
|
3738 |
} |
|
612 | 3739 |
} |
3740 |
bad: ; |
|
3741 |
%}. |
|
8614 | 3742 |
(hitEOF and:[self pastEndRead isNil]) ifTrue:[^ 0]. |
16296 | 3743 |
error notNil ifTrue:[ |
16508 | 3744 |
lastErrorNumber := error. |
3745 |
^ self readError:error |
|
16296 | 3746 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3747 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 3748 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
3749 |
" |
|
3750 |
count not integer or arg not bit-like (String, ByteArray etc) |
|
3751 |
" |
|
3752 |
^ self primitiveFailed |
|
92 | 3753 |
! |
3754 |
||
612 | 3755 |
nextLong |
3756 |
"Read four bytes (msb-first) and return the value as a 32-bit signed Integer. |
|
3757 |
The returned value may be a LargeInteger. |
|
3758 |
(msb-first for compatibility with other smalltalks)" |
|
3759 |
||
3760 |
^ self nextUnsignedLongMSB:true |
|
3761 |
! |
|
3762 |
||
3763 |
nextLongMSB:msbFlag |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3764 |
"Read four bytes and return the value as a 32-bit signed Integer, |
612 | 3765 |
which may be a LargeInteger. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3766 |
If msbFlag is true, value is read with most-significant byte first, |
612 | 3767 |
otherwise least-significant byte comes first. |
3768 |
A nil is returned, if EOF is hit before all 4 bytes have been read. |
|
3769 |
Works in both binary and text modes." |
|
3770 |
||
16296 | 3771 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3772 |
%{ |
612 | 3773 |
OBJ fp; |
3774 |
||
1133 | 3775 |
__INST(lastErrorNumber) = nil; |
12548 | 3776 |
if ((__INST(handleType) == nil) |
3777 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3778 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3779 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3780 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 3781 |
if (((fp = __INST(handle)) != nil) |
3782 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3783 |
) { |
|
3784 |
FILEPOINTER f; |
|
3785 |
int ret, _buffered; |
|
3786 |
int value; |
|
3787 |
union { |
|
3788 |
unsigned char buffer[4]; |
|
3789 |
int intVal; |
|
3790 |
} u; |
|
3791 |
||
3792 |
f = __FILEVal(fp); |
|
3793 |
_buffered = (__INST(buffered) == true); |
|
3794 |
if (_buffered) { |
|
3795 |
__READING__(f) |
|
3796 |
} |
|
3797 |
__READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType)); |
|
3798 |
||
3799 |
if (ret == 4) { |
|
3800 |
if (__isSmallInteger(__INST(position))) { |
|
3801 |
INT np = __intVal(__INST(position)) + 4; |
|
3802 |
OBJ t; |
|
3803 |
||
3804 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3805 |
} else { |
|
3806 |
__INST(position) = nil; /* i.e. do not know */ |
|
3807 |
} |
|
3808 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
3809 |
#if defined(__MSBFIRST__) |
16508 | 3810 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3811 |
#else |
16508 | 3812 |
value = (u.buffer[0] & 0xFF); |
3813 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
|
3814 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
|
3815 |
value = (value << 8) | (u.buffer[3] & 0xFF); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3816 |
#endif |
16508 | 3817 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
3818 |
#if defined(__LSBFIRST__) |
16508 | 3819 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3820 |
#else |
16508 | 3821 |
value = (u.buffer[3] & 0xFF); |
3822 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
|
3823 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
|
3824 |
value = (value << 8) | (u.buffer[0] & 0xFF); |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3825 |
#endif |
16508 | 3826 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3827 |
#if __POINTER_SIZE__ == 8 |
16508 | 3828 |
RETURN ( __mkSmallInteger(value)); |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3829 |
#else |
16508 | 3830 |
if ((value >= _MIN_INT) && (value <= _MAX_INT)) { |
3831 |
RETURN ( __mkSmallInteger(value)); |
|
3832 |
} |
|
3833 |
RETURN ( __MKLARGEINT(value) ); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3834 |
#endif |
16508 | 3835 |
} |
3836 |
||
3837 |
if (ret < 0) { |
|
3838 |
__INST(position) = nil; |
|
3839 |
error = __mkSmallInteger(__threadErrno); |
|
3840 |
} else /* ret == 0 */ { |
|
3841 |
__INST(hitEOF) = true; |
|
3842 |
} |
|
3843 |
} |
|
612 | 3844 |
} |
3845 |
%}. |
|
8614 | 3846 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3847 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 3848 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 3849 |
lastErrorNumber := error. |
3850 |
^ self readError:error. |
|
362 | 3851 |
! |
3852 |
||
612 | 3853 |
nextShortMSB:msbFlag |
3854 |
"Read two bytes and return the value as a 16-bit signed Integer. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3855 |
If msbFlag is true, value is read with most-significant byte first, |
612 | 3856 |
otherwise least-significant byte comes first. |
3857 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
3858 |
Works in both binary and text modes." |
|
3859 |
||
16296 | 3860 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3861 |
%{ |
612 | 3862 |
OBJ fp; |
3863 |
||
1133 | 3864 |
__INST(lastErrorNumber) = nil; |
12548 | 3865 |
if ((__INST(handleType) == nil) |
3866 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3867 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3868 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3869 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 3870 |
if (((fp = __INST(handle)) != nil) |
3871 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3872 |
) { |
|
3873 |
FILEPOINTER f; |
|
3874 |
int ret, _buffered; |
|
3875 |
short value; |
|
3876 |
union { |
|
3877 |
unsigned char buffer[2]; |
|
3878 |
short shortVal; |
|
3879 |
} u; |
|
3880 |
||
3881 |
f = __FILEVal(fp); |
|
3882 |
_buffered = (__INST(buffered) == true); |
|
3883 |
if (_buffered) { |
|
3884 |
__READING__(f) |
|
3885 |
} |
|
3886 |
__READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType)); |
|
3887 |
||
3888 |
if (ret == 2) { |
|
3889 |
if (__isSmallInteger(__INST(position))) { |
|
3890 |
INT np = __intVal(__INST(position)) + 2; |
|
3891 |
OBJ t; |
|
3892 |
||
3893 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3894 |
} else { |
|
3895 |
__INST(position) = nil; /* i.e. do not know */ |
|
3896 |
} |
|
3897 |
if (msbFlag == true) { |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3898 |
#if defined(__MSBFIRST__) |
16508 | 3899 |
value = u.shortVal; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3900 |
#else |
16508 | 3901 |
value = ((u.buffer[0] & 0xFF) << 8) | (u.buffer[1] & 0xFF); |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3902 |
#endif |
16508 | 3903 |
} else { |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3904 |
#if defined(__LSBFIRST__) |
16508 | 3905 |
value = u.shortVal; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3906 |
#else |
16508 | 3907 |
value = ((u.buffer[1] & 0xFF) << 8) | (u.buffer[0] & 0xFF); |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3908 |
#endif |
16508 | 3909 |
} |
3910 |
RETURN (__mkSmallInteger(value)); |
|
3911 |
} |
|
3912 |
||
3913 |
if (ret < 0) { |
|
3914 |
__INST(position) = nil; /* i.e. do not know */ |
|
3915 |
error = __mkSmallInteger(__threadErrno); |
|
3916 |
} else /* ret == 0 */ { |
|
3917 |
__INST(hitEOF) = true; |
|
3918 |
} |
|
3919 |
} |
|
612 | 3920 |
} |
3921 |
%}. |
|
8614 | 3922 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3923 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 3924 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 3925 |
lastErrorNumber := error. |
3926 |
^ self readError:error. |
|
612 | 3927 |
! |
3928 |
||
3929 |
nextUnsignedLongMSB:msbFlag |
|
3930 |
"Read four bytes and return the value as a 32-bit unsigned Integer, which may be |
|
3931 |
a LargeInteger. |
|
3932 |
If msbFlag is true, value is read with most-significant byte first, otherwise |
|
3933 |
least-significant byte comes first. |
|
3934 |
A nil is returned, if endOfFile occurs before all 4 bytes have been read. |
|
3935 |
Works in both binary and text modes." |
|
3936 |
||
16296 | 3937 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3938 |
%{ |
612 | 3939 |
OBJ fp; |
3940 |
||
1133 | 3941 |
__INST(lastErrorNumber) = nil; |
12548 | 3942 |
if ((__INST(handleType) == nil) |
3943 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3944 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3945 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3946 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 3947 |
if (((fp = __INST(handle)) != nil) |
3948 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3949 |
) { |
|
3950 |
FILEPOINTER f; |
|
3951 |
int ret, _buffered; |
|
3952 |
unsigned INT value; |
|
3953 |
union { |
|
3954 |
unsigned char buffer[4]; |
|
3955 |
unsigned int intVal; |
|
3956 |
} u; |
|
3957 |
||
3958 |
f = __FILEVal(fp); |
|
3959 |
_buffered = (__INST(buffered) == true); |
|
3960 |
if (_buffered) { |
|
3961 |
__READING__(f) |
|
3962 |
} |
|
3963 |
__READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType)); |
|
3964 |
||
3965 |
if (ret == 4) { |
|
3966 |
if (__isSmallInteger(__INST(position))) { |
|
3967 |
INT np = __intVal(__INST(position)) + 4; |
|
3968 |
OBJ t; |
|
3969 |
||
3970 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3971 |
} else { |
|
3972 |
__INST(position) = nil; /* i.e. do not know */ |
|
3973 |
} |
|
3974 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
3975 |
#if defined(__MSBFIRST__) |
16508 | 3976 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3977 |
#else |
16508 | 3978 |
value = u.buffer[0]; |
3979 |
value = (value << 8) | u.buffer[1]; |
|
3980 |
value = (value << 8) | u.buffer[2]; |
|
3981 |
value = (value << 8) | u.buffer[3]; |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3982 |
#endif |
16508 | 3983 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
3984 |
#if defined(__LSBFIRST__) |
16508 | 3985 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3986 |
#else |
16508 | 3987 |
value = u.buffer[3]; |
3988 |
value = (value << 8) | u.buffer[2]; |
|
3989 |
value = (value << 8) | u.buffer[1]; |
|
3990 |
value = (value << 8) | u.buffer[0]; |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3991 |
#endif |
16508 | 3992 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3993 |
#if __POINTER_SIZE__ == 8 |
16508 | 3994 |
value &= 0xFFFFFFFF; |
3995 |
RETURN (__mkSmallInteger(value)); |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3996 |
#else |
16508 | 3997 |
if (value <= _MAX_INT) { |
3998 |
RETURN (__mkSmallInteger(value)); |
|
3999 |
} |
|
4000 |
RETURN (__MKULARGEINT(value) ); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4001 |
#endif |
16508 | 4002 |
} |
4003 |
||
4004 |
if (ret < 0) { |
|
4005 |
__INST(position) = nil; /* i.e. do not know */ |
|
4006 |
error = __mkSmallInteger(__threadErrno); |
|
4007 |
} else /* ret == 0 */ { |
|
4008 |
__INST(hitEOF) = true; |
|
4009 |
} |
|
4010 |
} |
|
612 | 4011 |
} |
4012 |
%}. |
|
8614 | 4013 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4014 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4015 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4016 |
lastErrorNumber := error. |
4017 |
^ self readError:error. |
|
612 | 4018 |
! |
4019 |
||
4020 |
nextUnsignedShortMSB:msbFlag |
|
4021 |
"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
|
4022 |
If msbFlag is true, value is read with most-significant byte first, |
1079 | 4023 |
otherwise least-significant byte comes first. |
612 | 4024 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
4025 |
Works in both binary and text modes." |
|
4026 |
||
16296 | 4027 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4028 |
%{ |
612 | 4029 |
OBJ fp; |
4030 |
||
1133 | 4031 |
__INST(lastErrorNumber) = nil; |
12548 | 4032 |
if ((__INST(handleType) == nil) |
4033 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4034 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4035 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4036 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 4037 |
if (((fp = __INST(handle)) != nil) |
4038 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4039 |
) { |
|
4040 |
FILEPOINTER f; |
|
4041 |
int ret, _buffered; |
|
4042 |
unsigned int value; |
|
4043 |
union { |
|
4044 |
unsigned char buffer[2]; |
|
4045 |
unsigned short shortVal; |
|
4046 |
} u; |
|
4047 |
||
4048 |
f = __FILEVal(fp); |
|
4049 |
_buffered = (__INST(buffered) == true); |
|
4050 |
if (_buffered) { |
|
4051 |
__READING__(f) |
|
4052 |
} |
|
4053 |
__READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType)); |
|
4054 |
||
4055 |
if (ret == 2) { |
|
4056 |
if (__isSmallInteger(__INST(position))) { |
|
4057 |
INT np = __intVal(__INST(position)) + 2; |
|
4058 |
OBJ t; |
|
4059 |
||
4060 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4061 |
} else { |
|
4062 |
__INST(position) = nil; /* i.e. do not know */ |
|
4063 |
} |
|
4064 |
if (msbFlag == true) { |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4065 |
#if defined(__MSBFIRST__) |
16508 | 4066 |
value = u.shortVal; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4067 |
#else |
16508 | 4068 |
value = (u.buffer[0] << 8) | u.buffer[1]; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4069 |
#endif |
16508 | 4070 |
} else { |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4071 |
#if defined(__LSBFIRST__) |
16508 | 4072 |
value = u.shortVal; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4073 |
#else |
16508 | 4074 |
value = (u.buffer[1] << 8) | u.buffer[0]; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4075 |
#endif |
16508 | 4076 |
} |
4077 |
RETURN (__mkSmallInteger(value)); |
|
4078 |
} |
|
4079 |
||
4080 |
if (ret < 0) { |
|
4081 |
__INST(position) = nil; /* i.e. do not know */ |
|
4082 |
error = __mkSmallInteger(__threadErrno); |
|
4083 |
} else /* ret == 0 */ { |
|
4084 |
__INST(hitEOF) = true; |
|
4085 |
} |
|
4086 |
} |
|
612 | 4087 |
} |
4088 |
%}. |
|
8614 | 4089 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4090 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4091 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4092 |
lastErrorNumber := error. |
4093 |
^ self readError:error. |
|
612 | 4094 |
! |
4095 |
||
4096 |
nextWord |
|
15452 | 4097 |
<resource: #obsolete> |
612 | 4098 |
"in text-mode: |
14632 | 4099 |
read the alphaNumeric next word (i.e. up to non letter-or-digit). |
4100 |
return a string containing those characters. |
|
612 | 4101 |
in binary-mode: |
14632 | 4102 |
read two bytes (msb-first) and return the value as a 16-bit |
4103 |
unsigned Integer (for compatibility with other smalltalks)" |
|
612 | 4104 |
|
4105 |
binary ifTrue:[ |
|
14632 | 4106 |
^ self nextUnsignedShortMSB:true |
92 | 4107 |
]. |
14518 | 4108 |
self obsoleteMethodWarning:'use #nextAlphaNumericWord'. |
612 | 4109 |
^ self nextAlphaNumericWord |
4110 |
! ! |
|
4111 |
||
4112 |
!ExternalStream methodsFor:'non homogenous writing'! |
|
4113 |
||
4114 |
nextPutByte:aByteValue |
|
4115 |
"write a byte. |
|
4116 |
Works in both binary and text modes." |
|
4117 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4118 |
|error| |
16296 | 4119 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4120 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4121 |
FILEPOINTER f; |
612 | 4122 |
char c; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
4123 |
OBJ fp; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4124 |
int cnt, _buffered; |
612 | 4125 |
|
1133 | 4126 |
__INST(lastErrorNumber) = nil; |
12548 | 4127 |
if ((__INST(handleType) == nil) |
4128 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4129 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4130 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4131 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 4132 |
if (((fp = __INST(handle)) != nil) |
4133 |
&& (__INST(mode) != @symbol(readonly)) |
|
4134 |
&& __isSmallInteger(aByteValue) |
|
4135 |
||
4136 |
) { |
|
4137 |
c = __intVal(aByteValue); |
|
4138 |
f = __FILEVal(fp); |
|
4139 |
if (_buffered = (__INST(buffered) == true)) { |
|
4140 |
__WRITING__(f) |
|
4141 |
} |
|
9053
f3f3d48d6f44
fix writing to stdout/stderr for winstx non-console operation
Claus Gittinger <cg@exept.de>
parents:
9024
diff
changeset
|
4142 |
#ifdef WIN32 |
16508 | 4143 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
4144 |
cnt = __win32_fwrite(&c, 1, 1, f); |
|
4145 |
} else |
|
9053
f3f3d48d6f44
fix writing to stdout/stderr for winstx non-console operation
Claus Gittinger <cg@exept.de>
parents:
9024
diff
changeset
|
4146 |
#endif |
16508 | 4147 |
{ |
4148 |
__WRITEBYTE__(cnt, f, &c, _buffered, __INST(handleType)); |
|
4149 |
} |
|
4150 |
if (cnt == 1) { |
|
4151 |
if (__isSmallInteger(__INST(position))) { |
|
4152 |
INT np = __intVal(__INST(position)) + 1; |
|
4153 |
OBJ t; |
|
4154 |
||
4155 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4156 |
} else { |
|
4157 |
__INST(position) = nil; /* i.e. do not know */ |
|
4158 |
} |
|
4159 |
RETURN (self); |
|
4160 |
} |
|
4161 |
if (cnt < 0) { |
|
4162 |
__INST(position) = nil; /* i.e. do not know */ |
|
4163 |
} |
|
4164 |
error = __mkSmallInteger(__threadErrno); |
|
4165 |
} |
|
612 | 4166 |
} |
4167 |
%}. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4168 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4169 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
16296 | 4170 |
lastErrorNumber := error. |
4171 |
self writeError:error. |
|
612 | 4172 |
! |
4173 |
||
4174 |
nextPutBytes:count from:anObject startingAt:start |
|
4175 |
"write count bytes from an object starting at index start. |
|
4176 |
return the number of bytes written - which could be 0. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
4177 |
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
|
4178 |
(i.e. be a ByteArray, String, Float- or DoubleArray), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
4179 |
or an externalBytes object (with known size). |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
4180 |
|
612 | 4181 |
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
|
4182 |
Warning: |
16508 | 4183 |
in general, you cannot use this method to pass non-byte data to other |
4184 |
architectures (unless you prepared the buffer with care), |
|
4185 |
since it does not care for byte order or float representation." |
|
16296 | 4186 |
|
4187 |
|error| |
|
612 | 4188 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4189 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4190 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4191 |
int cnt, len, offs, ret; |
15987 | 4192 |
int objSize, nInstBytes, _buffered; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
4193 |
char *extPtr; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
4194 |
OBJ fp; |
612 | 4195 |
|
1133 | 4196 |
__INST(lastErrorNumber) = nil; |
12548 | 4197 |
if ((__INST(handleType) == nil) |
4198 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4199 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4200 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4201 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 4202 |
if (((fp = __INST(handle)) != nil) |
4203 |
&& (__INST(mode) != @symbol(readonly)) |
|
4204 |
&& __bothSmallInteger(count, start) |
|
4205 |
) { |
|
4206 |
len = __intVal(count); |
|
4207 |
offs = __intVal(start) - 1; |
|
4208 |
f = __FILEVal(fp); |
|
4209 |
||
4210 |
if (__isExternalBytesLike(anObject)) { |
|
4211 |
OBJ sz; |
|
4212 |
||
4213 |
nInstBytes = 0; |
|
4214 |
extPtr = (char *)__externalBytesAddress(anObject); |
|
4215 |
if (extPtr == NULL) goto bad; |
|
4216 |
sz = __externalBytesSize(anObject); |
|
4217 |
if (__isSmallInteger(sz)) { |
|
4218 |
objSize = __intVal(sz); |
|
4219 |
} else { |
|
4220 |
objSize = 0; /* unknown */ |
|
4221 |
} |
|
4222 |
} else { |
|
4223 |
OBJ oClass = __Class(anObject); |
|
4224 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
4225 |
||
4226 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
4227 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
4228 |
case BYTEARRAY: |
|
4229 |
case WORDARRAY: |
|
4230 |
case LONGARRAY: |
|
4231 |
case SWORDARRAY: |
|
4232 |
case SLONGARRAY: |
|
4233 |
case FLOATARRAY: |
|
4234 |
break; |
|
4235 |
case DOUBLEARRAY: |
|
15987 | 4236 |
#ifdef __NEED_DOUBLE_ALIGN |
16508 | 4237 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
15987 | 4238 |
#endif |
16508 | 4239 |
break; |
4240 |
case LONGLONGARRAY: |
|
4241 |
case SLONGLONGARRAY: |
|
15987 | 4242 |
#ifdef __NEED_LONGLONG_ALIGN |
16508 | 4243 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
15987 | 4244 |
#endif |
16508 | 4245 |
break; |
4246 |
default: |
|
4247 |
goto bad; |
|
4248 |
} |
|
4249 |
extPtr = (char *)0; |
|
4250 |
objSize = __Size(anObject) - nInstBytes; |
|
4251 |
} |
|
4252 |
if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) { |
|
4253 |
if (_buffered = (__INST(buffered) == true)) { |
|
4254 |
__WRITING__(f) |
|
4255 |
} |
|
4256 |
||
4257 |
if (extPtr) { |
|
4258 |
__WRITEBYTES__(cnt, f, extPtr+offs, len, _buffered, __INST(handleType)); |
|
4259 |
} else { |
|
4260 |
/* |
|
4261 |
* on interrupt, anObject may be moved to another location. |
|
4262 |
* So we pass anObject, and the offset to the __WRITEBYTES_OBJ__ macro. |
|
4263 |
*/ |
|
4264 |
offs += nInstBytes; |
|
4265 |
__WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered, __INST(handleType)); |
|
4266 |
} |
|
4267 |
||
4268 |
if (cnt >= 0) { |
|
4269 |
if (__isSmallInteger(__INST(position))) { |
|
4270 |
INT np = __intVal(__INST(position)) + cnt; |
|
4271 |
OBJ t; |
|
4272 |
||
4273 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4274 |
} else { |
|
4275 |
__INST(position) = nil; /* i.e. do not know */ |
|
4276 |
} |
|
4277 |
RETURN ( __mkSmallInteger(cnt) ); |
|
4278 |
} else /* cnt < 0 */ { |
|
4279 |
if ( |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4280 |
#ifdef EWOULDBLOCK |
16508 | 4281 |
(__threadErrno == EWOULDBLOCK) || |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4282 |
#endif |
16508 | 4283 |
(__threadErrno == EAGAIN) |
4284 |
) { |
|
4285 |
RETURN ( __mkSmallInteger(0) ); |
|
4286 |
} |
|
4287 |
__INST(position) = nil; /* i.e. do not know */ |
|
4288 |
error = __mkSmallInteger(__threadErrno); |
|
4289 |
} |
|
4290 |
} |
|
4291 |
} |
|
612 | 4292 |
} |
4293 |
bad: ; |
|
4294 |
%}. |
|
16296 | 4295 |
error notNil ifTrue:[ |
16508 | 4296 |
lastErrorNumber := error. |
4297 |
self writeError:error. |
|
4298 |
^ self |
|
16296 | 4299 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4300 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4301 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
4302 |
^ self primitiveFailed |
|
4303 |
! |
|
4304 |
||
4305 |
nextPutLong:aNumber MSB:msbFlag |
|
4306 |
"Write the argument, aNumber as a long (four bytes). If msbFlag is |
|
4307 |
true, data is written most-significant byte first; otherwise least |
|
4308 |
first. |
|
4309 |
Works in both binary and text modes." |
|
4310 |
||
16296 | 4311 |
|error| |
4312 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4313 |
%{ |
612 | 4314 |
int num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4315 |
union { |
16508 | 4316 |
char bytes[4]; |
4317 |
int intVal; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4318 |
} u; |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4319 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4320 |
int cnt, _buffered; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4321 |
OBJ fp; |
612 | 4322 |
|
1133 | 4323 |
__INST(lastErrorNumber) = nil; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4324 |
if (__isSmallInteger(aNumber)) { |
16508 | 4325 |
num = __intVal(aNumber); |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4326 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4327 |
#if __POINTER_SIZE__ == 8 |
16508 | 4328 |
goto badArg; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4329 |
#else |
16508 | 4330 |
num = __longIntVal(aNumber); |
4331 |
if (num == 0) { |
|
4332 |
num = __signedLongIntVal(aNumber); |
|
4333 |
if (num == 0) { |
|
4334 |
/* bad arg or out-of-range integer |
|
4335 |
* (handled by the fallBack code) |
|
4336 |
*/ |
|
4337 |
goto badArg; |
|
4338 |
} |
|
4339 |
} |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4340 |
#endif |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4341 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4342 |
|
12548 | 4343 |
if ((__INST(handleType) == nil) |
4344 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4345 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4346 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4347 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 4348 |
if (((fp = __INST(handle)) != nil) |
4349 |
&& (__INST(mode) != @symbol(readonly)) |
|
4350 |
) { |
|
4351 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4352 |
#if defined(__MSBFIRST__) |
16508 | 4353 |
u.intVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4354 |
#else |
16508 | 4355 |
u.bytes[0] = (num >> 24) & 0xFF; |
4356 |
u.bytes[1] = (num >> 16) & 0xFF; |
|
4357 |
u.bytes[2] = (num >> 8) & 0xFF; |
|
4358 |
u.bytes[3] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4359 |
#endif |
16508 | 4360 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4361 |
#if defined(__LSBFIRST__) |
16508 | 4362 |
u.intVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4363 |
#else |
16508 | 4364 |
u.bytes[3] = (num >> 24) & 0xFF; |
4365 |
u.bytes[2] = (num >> 16) & 0xFF; |
|
4366 |
u.bytes[1] = (num >> 8) & 0xFF; |
|
4367 |
u.bytes[0] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4368 |
#endif |
16508 | 4369 |
} |
4370 |
||
4371 |
f = __FILEVal(fp); |
|
4372 |
if (_buffered = (__INST(buffered) == true)) { |
|
4373 |
__WRITING__(f) |
|
4374 |
} |
|
4375 |
__WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType)); |
|
4376 |
||
4377 |
if (cnt == 4) { |
|
4378 |
if (__isSmallInteger(__INST(position))) { |
|
4379 |
INT np = __intVal(__INST(position)) + 4; |
|
4380 |
OBJ t; |
|
4381 |
||
4382 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4383 |
} else { |
|
4384 |
__INST(position) = nil; /* i.e. do not know */ |
|
4385 |
} |
|
4386 |
RETURN ( self ); |
|
4387 |
} |
|
4388 |
__INST(position) = nil; /* i.e. do not know */ |
|
4389 |
error = __mkSmallInteger(__threadErrno); |
|
4390 |
} |
|
612 | 4391 |
} |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4392 |
badArg: ; |
612 | 4393 |
%}. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4394 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4395 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
16296 | 4396 |
error notNil ifTrue:[ |
16508 | 4397 |
lastErrorNumber := error. |
4398 |
self writeError:error. |
|
4399 |
^ self |
|
16296 | 4400 |
]. |
612 | 4401 |
|
4402 |
aNumber isInteger ifTrue:[ |
|
16508 | 4403 |
^ super nextPutLong:aNumber MSB:msbFlag |
92 | 4404 |
]. |
612 | 4405 |
self argumentMustBeInteger |
4406 |
! |
|
4407 |
||
15655 | 4408 |
nextPutShort:anIntegerOrCharacter MSB:msbFlag |
4409 |
"Write the argument, anIntegerOrCharacter as a short (two bytes). If msbFlag is |
|
612 | 4410 |
true, data is written most-significant byte first; otherwise least |
4411 |
first. |
|
4412 |
Works in both binary and text modes." |
|
4413 |
||
16296 | 4414 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4415 |
%{ |
612 | 4416 |
int num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4417 |
union { |
16508 | 4418 |
char bytes[2]; |
4419 |
short shortVal; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4420 |
} u; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4421 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4422 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4423 |
int cnt, _buffered; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4424 |
OBJ fp; |
612 | 4425 |
|
1133 | 4426 |
__INST(lastErrorNumber) = nil; |
12548 | 4427 |
if ((__INST(handleType) == nil) |
4428 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4429 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4430 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4431 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 4432 |
if (((fp = __INST(handle)) != nil) |
4433 |
&& (__INST(mode) != @symbol(readonly)) |
|
4434 |
) { |
|
4435 |
if (__isSmallInteger(anIntegerOrCharacter)) { |
|
4436 |
num = __intVal(anIntegerOrCharacter); |
|
4437 |
} else if (__isCharacter(anIntegerOrCharacter)) { |
|
4438 |
num = __smallIntegerVal(__characterVal(anIntegerOrCharacter)); |
|
4439 |
} else |
|
4440 |
goto out; |
|
4441 |
||
4442 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4443 |
#if defined(__MSBFIRST__) |
16508 | 4444 |
u.shortVal = num; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4445 |
#else |
16508 | 4446 |
u.bytes[0] = (num >> 8) & 0xFF; |
4447 |
u.bytes[1] = num & 0xFF; |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4448 |
#endif |
16508 | 4449 |
} else { |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4450 |
#if defined(__LSBFIRST__) |
16508 | 4451 |
u.shortVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4452 |
#else |
16508 | 4453 |
u.bytes[1] = (num >> 8) & 0xFF; |
4454 |
u.bytes[0] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4455 |
#endif |
16508 | 4456 |
} |
4457 |
||
4458 |
f = __FILEVal(fp); |
|
4459 |
if (_buffered = (__INST(buffered) == true)) { |
|
4460 |
__WRITING__(f) |
|
4461 |
} |
|
4462 |
__WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType)); |
|
4463 |
||
4464 |
if (cnt == 2) { |
|
4465 |
if (__isSmallInteger(__INST(position))) { |
|
4466 |
INT np = __intVal(__INST(position)) + 2; |
|
4467 |
OBJ t; |
|
4468 |
||
4469 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4470 |
} else { |
|
4471 |
__INST(position) = nil; /* i.e. do not know */ |
|
4472 |
} |
|
4473 |
RETURN ( self ); |
|
4474 |
} |
|
4475 |
__INST(position) = nil; /* i.e. do not know */ |
|
4476 |
error = __mkSmallInteger(__threadErrno); |
|
4477 |
} |
|
612 | 4478 |
} |
15655 | 4479 |
out:; |
612 | 4480 |
%}. |
16296 | 4481 |
error notNil ifTrue:[ |
16508 | 4482 |
lastErrorNumber := error. |
4483 |
self writeError:error. |
|
4484 |
^ self |
|
16296 | 4485 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4486 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4487 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
612 | 4488 |
self argumentMustBeInteger |
10 | 4489 |
! ! |
612 | 4490 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4491 |
!ExternalStream methodsFor:'positioning'! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4492 |
|
15619 | 4493 |
position |
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4494 |
self subclassResponsibility |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4495 |
! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4496 |
|
15619 | 4497 |
position:index0Based |
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4498 |
self subclassResponsibility |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4499 |
! ! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4500 |
|
12631 | 4501 |
!ExternalStream methodsFor:'printing & storing'! |
4502 |
||
4503 |
printOn:aStream |
|
14068 | 4504 |
aStream |
4505 |
nextPutAll:self className; |
|
4506 |
nextPutAll:'(handle:('. |
|
12631 | 4507 |
handle printOn:aStream. |
4508 |
aStream nextPutAll:'))' |
|
4509 |
! ! |
|
4510 |
||
612 | 4511 |
!ExternalStream methodsFor:'private'! |
4512 |
||
4513 |
clearEOF |
|
4514 |
hitEOF := false |
|
16300 | 4515 |
! ! |
4516 |
||
4517 |
!ExternalStream protectedMethodsFor:'private'! |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4518 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4519 |
closeFile |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4520 |
"low level close - may be redefined in subclasses |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4521 |
Don't send this message, send #close instead" |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4522 |
|
12674 | 4523 |
|fp error| |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4524 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4525 |
fp := handle. |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4526 |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4527 |
%{ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4528 |
int rslt; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4529 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4530 |
if (fp == nil) { |
16508 | 4531 |
error = @symbol(errorNotOpen); |
4532 |
goto out; |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4533 |
} |
16508 | 4534 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4535 |
if (__INST(handleType) == @symbol(socketHandle)) { |
16508 | 4536 |
SOCKET sock = __FILEVal(fp); |
4537 |
||
4538 |
if (@global(FileOpenTrace) == true) { |
|
4539 |
fprintf(stderr, "close socket [ExternalStream] %"_lx_"\n", (INT)sock); |
|
4540 |
} |
|
4541 |
||
4542 |
// whether the close() will be successful or not - the handle is invalid now! |
|
4543 |
__INST(handle) = nil; |
|
4544 |
do { |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4545 |
#ifdef WIN32 |
16508 | 4546 |
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
|
4547 |
#else |
16508 | 4548 |
rslt = close(sock); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4549 |
#endif |
16508 | 4550 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4551 |
} else if ((__INST(handleType) == nil) |
16508 | 4552 |
|| (__INST(handleType) == @symbol(filePointer)) |
4553 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4554 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4555 |
{ |
16508 | 4556 |
FILEPOINTER f = __FILEVal(fp); |
4557 |
||
4558 |
if (@global(FileOpenTrace) == true) { |
|
4559 |
fprintf(stderr, "fclose [ExternalStream] %"_lx_"\n", (INT)f); |
|
4560 |
} |
|
4561 |
// whether the close() will be successful or not - the handle is invalid now! |
|
4562 |
__INST(handle) = nil; |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4563 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4564 |
#ifdef WIN32 |
16508 | 4565 |
if (__INST(mode) != @symbol(readonly) && __INST(buffered) != false) { |
4566 |
// do a fflush() first, so that fclose() doesn't block |
|
4567 |
// we suspect, that EINTR causes problems in fclose() |
|
4568 |
do { |
|
4569 |
__threadErrno = 0; |
|
4570 |
rslt = __STX_C_CALL1("fflush", fflush, f); |
|
4571 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
4572 |
} |
|
4573 |
do { |
|
4574 |
__threadErrno = 0; |
|
4575 |
rslt = __STX_C_NOINT_CALL1("fclose", fclose, f); |
|
4576 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4577 |
#else |
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
|
4578 |
// cg: the pre Nov2014 code always did the fclose interruptable; |
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
|
4579 |
// I am not sure, if fclose is actually prepared to do this; |
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
|
4580 |
// at least when only reading, this should not block, and we |
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
|
4581 |
// should be ableto do it without being interruptable. |
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
|
4582 |
// Must watch this - if it leads to blockings, change and think about it. |
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
|
4583 |
if (__INST(mode) != @symbol(readonly)) { |
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
|
4584 |
__BEGIN_INTERRUPTABLE__ |
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
|
4585 |
rslt = fclose(f); |
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
|
4586 |
__END_INTERRUPTABLE__ |
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
|
4587 |
} else { |
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
|
4588 |
rslt = fclose(f); |
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
|
4589 |
} |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4590 |
#endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4591 |
} else { |
16508 | 4592 |
error = @symbol(badHandleType); |
4593 |
goto out; |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4594 |
} |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4595 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4596 |
if (rslt < 0) { |
16508 | 4597 |
error = __mkSmallInteger(__threadErrno); |
4598 |
goto out; |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4599 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4600 |
RETURN (self); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4601 |
|
12674 | 4602 |
out:; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4603 |
%}. |
12674 | 4604 |
|
4605 |
error notNil ifTrue:[ |
|
16508 | 4606 |
error == #errorNotOpen ifTrue:[ |
4607 |
self errorNotOpen. |
|
4608 |
]. |
|
4609 |
error isInteger ifTrue:[ |
|
4610 |
lastErrorNumber := error. |
|
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
|
4611 |
mode == #readonly ifTrue:[ |
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
|
4612 |
self ioError:error. |
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
|
4613 |
] ifFalse:[ |
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
|
4614 |
self writeError:error. |
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
|
4615 |
]. |
16508 | 4616 |
^ self. |
4617 |
]. |
|
4618 |
self primitiveFailed:error. |
|
4619 |
^ self. |
|
12674 | 4620 |
]. |
4621 |
||
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4622 |
"/ fallback for rel5 |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4623 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4624 |
fp := handle. |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4625 |
fp notNil ifTrue:[ |
16508 | 4626 |
handle := nil. |
4627 |
self closeFile:fp |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4628 |
] |
16300 | 4629 |
! ! |
4630 |
||
4631 |
!ExternalStream methodsFor:'private'! |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4632 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4633 |
closeFile:handle |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4634 |
"for rel5 only" |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4635 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4636 |
self primitiveFailed |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4637 |
! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4638 |
|
12706 | 4639 |
connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4640 |
"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
|
4641 |
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
|
4642 |
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
|
4643 |
a Stream object. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4644 |
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
|
4645 |
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
|
4646 |
|
12706 | 4647 |
|retVal error openmode| |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4648 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4649 |
handle notNil ifTrue:[^ self errorAlreadyOpen]. |
12706 | 4650 |
mode := modeSymbol. |
4651 |
openmode := self fopenMode. |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4652 |
%{ |
12683 | 4653 |
FILEPOINTER f = 0; |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4654 |
OBJ fp; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4655 |
FILE *fdopen(); |
12683 | 4656 |
int fd = -2; |
4657 |
||
4658 |
if (__isStringLike(openmode)) { |
|
12688 | 4659 |
#ifdef WIN32 |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4660 |
__stxWrapApiEnterCritical(); |
12688 | 4661 |
#endif |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4662 |
if (__isSmallInteger(aFileDescriptor)) { |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4663 |
fd = __intVal(aFileDescriptor); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4664 |
} |
12683 | 4665 |
#ifdef WIN32 |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4666 |
else if (__isExternalAddressLike(aFileDescriptor)) { |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4667 |
fd = _open_osfhandle((long)__externalAddressVal(aFileDescriptor), O_BINARY); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4668 |
if (fd < 0) { |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4669 |
if (__threadErrno == 0) { |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4670 |
// no more file descriptors |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4671 |
__threadErrno = EMFILE; |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4672 |
} |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4673 |
error = __mkSmallInteger(__threadErrno); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4674 |
__stxWrapApiLeaveCritical(); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4675 |
goto out; |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4676 |
} |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4677 |
} |
12683 | 4678 |
#endif |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4679 |
f = (FILEPOINTER) fdopen(fd, (char *)__stringVal(openmode)); |
12688 | 4680 |
#ifdef WIN32 |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4681 |
__stxWrapApiLeaveCritical(); |
12688 | 4682 |
#endif |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4683 |
if (f == NULL) { |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4684 |
error =__mkSmallInteger(__threadErrno); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4685 |
} else { |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4686 |
if (@global(FileOpenTrace) == true) { |
16508 | 4687 |
fprintf(stderr, "fdopen [ExternalStream] %"_ld_" (%"_lx_") -> %"_lx_"\n", (INT)fd, (INT)fd, (INT)f); |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4688 |
} |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4689 |
|
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4690 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4691 |
retVal = self; |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4692 |
} |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4693 |
} |
12688 | 4694 |
out:; |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4695 |
%}. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4696 |
retVal notNil ifTrue:[ |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4697 |
position := 0. |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4698 |
buffered isNil ifTrue:[ |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4699 |
buffered := true. "default is buffered" |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4700 |
]. |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4701 |
handleType := handleTypeSymbol. |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4702 |
Lobby register:self. |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4703 |
^ retVal |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4704 |
]. |
12688 | 4705 |
error notNil ifTrue:[ |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4706 |
OperatingSystem closeFd:aFileDescriptor. |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4707 |
lastErrorNumber := error. |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4708 |
position := nil. |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4709 |
" |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4710 |
the open failed for some reason ... |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4711 |
" |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4712 |
^ self openError:error |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4713 |
]. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4714 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4715 |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4716 |
dupFd |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4717 |
"duplicate my file descriptor" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4718 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4719 |
|fd dupFd| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4720 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4721 |
fd := self fileHandle. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4722 |
dupFd := OperatingSystem dup:fd. |
10989 | 4723 |
self setFileHandle:dupFd mode:self fopenMode. |
10995 | 4724 |
! |
10989 | 4725 |
|
4726 |
fopenMode |
|
4727 |
"answer the mode for fopen. |
|
4728 |
Only used internally" |
|
4729 |
||
4730 |
mode == #readonly ifTrue:[ |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4731 |
^ ReadMode |
10989 | 4732 |
]. |
4733 |
mode == #writeonly ifTrue:[ |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4734 |
^ WriteMode |
10989 | 4735 |
]. |
4736 |
mode == #readWrite ifTrue:[ |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4737 |
^ ReadWriteMode |
10989 | 4738 |
]. |
4739 |
mode == #append ifTrue:[ |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4740 |
^ AppendMode |
10989 | 4741 |
]. |
4742 |
^ ReadWriteMode |
|
10995 | 4743 |
! |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4744 |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4745 |
open:aPath withMode:openModeString |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4746 |
"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
|
4747 |
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
|
4748 |
|
16296 | 4749 |
|ok error| |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4750 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4751 |
ok := false. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4752 |
%{ |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4753 |
FILE *f; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4754 |
OBJ fp; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4755 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4756 |
if (__isStringLike(aPath) && __isStringLike(openModeString)) { |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4757 |
#ifdef WIN32 |
10339 | 4758 |
# if 1 |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4759 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4760 |
# else |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4761 |
__BEGIN_INTERRUPTABLE__ |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4762 |
do { |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4763 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4764 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4765 |
__END_INTERRUPTABLE__ |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4766 |
# endif |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4767 |
#else /* UNIX */ |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4768 |
__BEGIN_INTERRUPTABLE__ |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4769 |
do { |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4770 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4771 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4772 |
__END_INTERRUPTABLE__ |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4773 |
#endif /* UNIX */ |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4774 |
if (f == NULL) { |
16296 | 4775 |
error = __mkSmallInteger(__threadErrno); |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4776 |
} else { |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4777 |
if (@global(FileOpenTrace) == true) { |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4778 |
fprintf(stderr, "fopen %s [ExternalStream] -> %"_lx_"\n", __stringVal(aPath), (INT)f); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4779 |
} |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4780 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4781 |
__INST(handleType) = @symbol(filePointer); |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4782 |
ok = true; |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4783 |
} |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4784 |
} |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4785 |
%}. |
16296 | 4786 |
ok ifTrue:[ |
4787 |
position := 0. |
|
4788 |
Lobby register:self. |
|
4789 |
^ self. |
|
4790 |
]. |
|
4791 |
error notNil ifTrue:[ |
|
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4792 |
" |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4793 |
the open failed for some reason ... |
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4794 |
" |
16296 | 4795 |
lastErrorNumber := error. |
4796 |
self openError:error. |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4797 |
]. |
16296 | 4798 |
self primitiveFailed. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4799 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4800 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4801 |
reOpen |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4802 |
"USERS WILL NEVER INVOKE THIS METHOD |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4803 |
sent after snapin to reopen streams. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4804 |
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
|
4805 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4806 |
self class name errorPrint. ' [warning]: automatic reOpen not supported - stream closed' errorPrintCR. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4807 |
handle := nil. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4808 |
Lobby unregister:self. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4809 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4810 |
"Modified: 10.1.1997 / 17:50:44 / cg" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4811 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
4812 |
|
12398 | 4813 |
setAccessor:what to:something |
4814 |
"set the filePointer/fileHandle to the given one; |
|
4815 |
low level private & friend interface; may also be used to connect to some |
|
4816 |
externally provided handle." |
|
4817 |
||
4818 |
handle := something. |
|
4819 |
handleType := what. |
|
4820 |
! |
|
4821 |
||
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4822 |
setFileDescriptor:anInteger mode:openMode |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4823 |
"set the handle based upon a given fileDescriptor - |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4824 |
notice: this one is based on the underlying OSs fileDescriptor - |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4825 |
this may not be available on all platforms (i.e. non unix systems)." |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4826 |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4827 |
self setFileHandle:anInteger mode:openMode |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4828 |
! |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4829 |
|
12398 | 4830 |
setFileHandle:something |
4831 |
"set the fileHandle to the given one; |
|
4832 |
low level private & friend interface; may also be used to connect to some |
|
4833 |
externally provided file handle." |
|
4834 |
||
4835 |
self setAccessor:#fileHandle to:something |
|
4836 |
! |
|
4837 |
||
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4838 |
setFileHandle:anIntegerOrExternalAddress mode:openMode |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4839 |
"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
|
4840 |
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
|
4841 |
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
|
4842 |
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
|
4843 |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4844 |
%{ |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4845 |
FILEPOINTER f; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4846 |
OBJ fp; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4847 |
FILE *fdopen(); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4848 |
int fd; |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4849 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4850 |
if (!__isStringLike(openMode)) |
14068 | 4851 |
goto err; |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4852 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4853 |
#ifdef WIN32 |
12688 | 4854 |
__stxWrapApiEnterCritical(); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4855 |
if (__isExternalAddressLike(anIntegerOrExternalAddress) ) { |
14068 | 4856 |
HANDLE __fileHandle = (HANDLE)__externalAddressVal(anIntegerOrExternalAddress); |
4857 |
fd = _open_osfhandle((long)__fileHandle, O_BINARY); /* should we handle readonly, append or text mode? */ |
|
4858 |
if (fd < 0) { |
|
4859 |
__stxWrapApiLeaveCritical(); |
|
4860 |
CloseHandle(__fileHandle); |
|
4861 |
goto err; |
|
4862 |
} |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4863 |
} else |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4864 |
#endif |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4865 |
if (__isSmallInteger(anIntegerOrExternalAddress)) { |
14068 | 4866 |
fd = __smallIntegerVal(anIntegerOrExternalAddress); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4867 |
} else { |
12688 | 4868 |
#ifdef WIN32 |
14068 | 4869 |
__stxWrapApiLeaveCritical(); |
12688 | 4870 |
#endif |
14068 | 4871 |
goto err; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4872 |
} |
10997 | 4873 |
f = fdopen(fd, __stringVal(openMode)); |
12688 | 4874 |
#ifdef WIN32 |
4875 |
__stxWrapApiLeaveCritical(); |
|
4876 |
#endif |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4877 |
if (f != NULL) { |
14068 | 4878 |
if (@global(FileOpenTrace) == true) { |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
4879 |
fprintf(stderr, "fdopen [ExternalStream] %d -> %"_lx_"\n", fd, (INT)f); |
14068 | 4880 |
} |
4881 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
|
4882 |
__INST(handleType) = @symbol(filePointer); |
|
4883 |
RETURN (self); |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4884 |
} |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
4885 |
err:; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4886 |
%}. |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4887 |
^ self primitiveFailed |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4888 |
! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4889 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4890 |
setFilePointer:something |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4891 |
"set the filePointer to the given one; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4892 |
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
|
4893 |
externally provided file." |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4894 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4895 |
self setAccessor:#filePointer to:something |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4896 |
! |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4897 |
|
12398 | 4898 |
setLastError:aNumber |
4899 |
lastErrorNumber := aNumber |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4900 |
! |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4901 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4902 |
setSocketHandle:something |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4903 |
"set the socketHandle to the given one; |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4904 |
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
|
4905 |
externally provided socket handle." |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4906 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4907 |
self setAccessor:#socketHandle to:something |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4908 |
! ! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4909 |
|
612 | 4910 |
!ExternalStream methodsFor:'queries'! |
4911 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4912 |
nextError |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4913 |
"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
|
4914 |
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
|
4915 |
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
|
4916 |
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
|
4917 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4918 |
%{ /*NOCONTEXT*/ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4919 |
FILEPOINTER f; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4920 |
int ret, _buffered; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4921 |
OBJ fp; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4922 |
unsigned char ch; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4923 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4924 |
if ((__INST(handleType) == nil) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4925 |
|| (__INST(handleType) == @symbol(filePointer)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4926 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4927 |
|| (__INST(handleType) == @symbol(socketHandle)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4928 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 4929 |
if (((fp = __INST(handle)) != nil) |
4930 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4931 |
) { |
|
4932 |
f = __FILEVal(fp); |
|
4933 |
||
4934 |
_buffered = (__INST(buffered) == true); |
|
4935 |
if (_buffered) { |
|
4936 |
__READING__(f) |
|
4937 |
} |
|
4938 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
4939 |
||
4940 |
if (ret > 0) { |
|
4941 |
RETURN(nil) |
|
4942 |
} |
|
4943 |
if (ret < 0) { |
|
4944 |
RETURN(__mkSmallInteger(__threadErrno)); |
|
4945 |
} else /* ret == 0 */ { |
|
4946 |
RETURN(__mkSmallInteger(0)); /* EOF */ |
|
4947 |
} |
|
4948 |
} |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4949 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4950 |
%}. |
612 | 4951 |
! |
4952 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4953 |
numAvailable |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4954 |
"return the number of bytes available for reading" |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4955 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4956 |
|fd| |
7804 | 4957 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4958 |
handle isNil ifTrue:[^ self errorNotOpen]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4959 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4960 |
fd := self fileDescriptor. |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4961 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4962 |
%{ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4963 |
#ifdef WIN32 |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4964 |
int res = 1; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4965 |
int success = 0; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4966 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4967 |
if (__INST(handleType) == @symbol(socketHandle)) { |
16508 | 4968 |
success = ioctlsocket((SOCKET)__externalAddressVal(fd), FIONREAD, &res) == 0; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4969 |
} else if (__INST(handleType) == @symbol(socketFilePointer)) { |
16508 | 4970 |
success = ioctlsocket((SOCKET)_get_osfhandle(__intVal(fd)), FIONREAD, &res) == 0; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4971 |
} else if (__INST(handleType) == @symbol(pipeFilePointer)) { |
16508 | 4972 |
success = PeekNamedPipe((HANDLE)_get_osfhandle(__intVal(fd)),0,0,0,&res,0); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4973 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4974 |
if (success) { |
16508 | 4975 |
if (__INST(readAhead) != nil) res++; |
4976 |
RETURN(__mkSmallInteger(res)); |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4977 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4978 |
#endif |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4979 |
%}. |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4980 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4981 |
^ (readAhead notNil or:[OperatingSystem readCheck:fd]) ifTrue:[1] ifFalse:[0]. |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4982 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4983 |
"Created: / 4.2.1998 / 16:56:01 / cg" |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4984 |
"Modified: / 4.2.1998 / 17:31:11 / cg" |
612 | 4985 |
! ! |
4986 |
||
4987 |
!ExternalStream methodsFor:'reading'! |
|
4988 |
||
4989 |
next |
|
4990 |
"return the next element; advance read position. |
|
4991 |
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
|
4992 |
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
|
4993 |
- see #pastEndRead." |
1 | 4994 |
|
16296 | 4995 |
|c error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4996 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4997 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4998 |
int ret, _buffered; |
612 | 4999 |
OBJ pos, fp; |
5000 |
unsigned char ch; |
|
5001 |
||
1133 | 5002 |
__INST(lastErrorNumber) = nil; |
12548 | 5003 |
if ((__INST(handleType) == nil) |
5004 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5005 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5006 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5007 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
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
|
5008 |
if (((fp = __INST(handle)) != nil) |
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
|
5009 |
&& (__INST(mode) != @symbol(writeonly)) |
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
|
5010 |
) { |
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
|
5011 |
f = __FILEVal(fp); |
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
|
5012 |
|
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
|
5013 |
_buffered = (__INST(buffered) == true); |
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
|
5014 |
if (_buffered) { |
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
|
5015 |
__READING__(f) |
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
|
5016 |
} |
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
|
5017 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
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
|
5018 |
|
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
|
5019 |
if (ret > 0) { |
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
|
5020 |
pos = __INST(position); |
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
|
5021 |
if (__isSmallInteger(pos)) { |
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
|
5022 |
OBJ t; |
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
|
5023 |
|
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
|
5024 |
t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t); |
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
|
5025 |
} else { |
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
|
5026 |
__INST(position) = nil; /* i.e. do not know */ |
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
|
5027 |
} |
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
|
5028 |
if (__INST(binary) == true) { |
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
|
5029 |
RETURN ( __mkSmallInteger(ch) ); |
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
|
5030 |
} |
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
|
5031 |
RETURN ( __MKCHARACTER(ch) ); |
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
|
5032 |
} |
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
|
5033 |
|
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
|
5034 |
__INST(position) = nil; |
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
|
5035 |
if (ret < 0) { |
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
|
5036 |
error = __mkSmallInteger(__threadErrno); |
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
|
5037 |
} else /* ret == 0 */ { |
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
|
5038 |
__INST(hitEOF) = true; |
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
|
5039 |
} |
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
|
5040 |
} |
612 | 5041 |
} |
5042 |
%}. |
|
8614 | 5043 |
hitEOF == true ifTrue:[^ self pastEndRead]. |
16296 | 5044 |
error notNil ifTrue:[ |
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
|
5045 |
lastErrorNumber := error. |
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
|
5046 |
^ self readError:error |
16296 | 5047 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5048 |
handle isNil ifTrue:[^ self errorNotOpen]. |
5420 | 5049 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
5050 |
||
5051 |
readAhead notNil ifTrue:[ |
|
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
|
5052 |
c := readAhead. |
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
|
5053 |
readAhead := nil. |
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
|
5054 |
^ c. |
5420 | 5055 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5056 |
c := self nextByteFromFile:handle. |
5430 | 5057 |
c isNil ifTrue:[ |
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
|
5058 |
^ self pastEndRead. |
5430 | 5059 |
]. |
5420 | 5060 |
binary == true ifTrue:[ |
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
|
5061 |
^ c |
5420 | 5062 |
]. |
5063 |
^ Character value:c |
|
612 | 5064 |
! |
5065 |
||
5066 |
next:count |
|
5067 |
"return the next count elements of the stream as a collection. |
|
5068 |
Redefined to return a String or ByteArray instead of the default: Array." |
|
5069 |
||
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5070 |
|coll nRead| |
612 | 5071 |
|
5072 |
binary ifTrue:[ |
|
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
|
5073 |
coll := ByteArray uninitializedNew:count |
612 | 5074 |
] ifFalse:[ |
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
|
5075 |
coll := String new:count |
612 | 5076 |
]. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5077 |
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
|
5078 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5079 |
"/ for readStream protocol compatibility, |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5080 |
"/ we must raise an exception here. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5081 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5082 |
nRead < count ifTrue:[ |
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
|
5083 |
^ self pastEndRead |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5084 |
]. |
612 | 5085 |
^ coll |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5086 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5087 |
"Modified: 11.1.1997 / 17:44:17 / cg" |
612 | 5088 |
! |
5089 |
||
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5090 |
nextOrNil |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5091 |
"return the next element; advance read position. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5092 |
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
|
5093 |
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
|
5094 |
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
|
5095 |
|
16296 | 5096 |
|c error| |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5097 |
%{ |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5098 |
FILEPOINTER f; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5099 |
int ret, _buffered; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5100 |
OBJ pos, fp; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5101 |
unsigned char ch; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5102 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5103 |
__INST(lastErrorNumber) = nil; |
12548 | 5104 |
if ((__INST(handleType) == nil) |
5105 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5106 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5107 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5108 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
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
|
5109 |
if (((fp = __INST(handle)) != nil) |
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
|
5110 |
&& (__INST(mode) != @symbol(writeonly)) |
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
|
5111 |
) { |
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
|
5112 |
f = __FILEVal(fp); |
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
|
5113 |
|
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
|
5114 |
_buffered = (__INST(buffered) == true); |
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
|
5115 |
if (_buffered) { |
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
|
5116 |
__READING__(f) |
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
|
5117 |
} |
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
|
5118 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
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
|
5119 |
|
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
|
5120 |
if (ret > 0) { |
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
|
5121 |
pos = __INST(position); |
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
|
5122 |
if (__isSmallInteger(pos)) { |
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
|
5123 |
OBJ t; |
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
|
5124 |
|
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
|
5125 |
t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t); |
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
|
5126 |
} else { |
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
|
5127 |
__INST(position) = nil; /* i.e. do not know */ |
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
|
5128 |
} |
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
|
5129 |
if (__INST(binary) == true) { |
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
|
5130 |
RETURN ( __mkSmallInteger(ch) ); |
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
|
5131 |
} |
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
|
5132 |
RETURN ( __MKCHARACTER(ch) ); |
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
|
5133 |
} |
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
|
5134 |
|
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
|
5135 |
__INST(position) = nil; |
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
|
5136 |
if (ret < 0) { |
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
|
5137 |
error = __mkSmallInteger(__threadErrno); |
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
|
5138 |
} else /* ret == 0 */ { |
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
|
5139 |
__INST(hitEOF) = true; |
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
|
5140 |
} |
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
|
5141 |
} |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5142 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5143 |
%}. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5144 |
hitEOF == true ifTrue:[^ nil]. |
16296 | 5145 |
error notNil ifTrue:[ |
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
|
5146 |
lastErrorNumber := error. |
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
|
5147 |
^ self readError:error. |
16296 | 5148 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5149 |
handle isNil ifTrue:[^ self errorNotOpen]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5150 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5151 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5152 |
readAhead notNil ifTrue:[ |
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
|
5153 |
c := readAhead. |
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
|
5154 |
readAhead := nil. |
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
|
5155 |
^ c. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5156 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5157 |
c := self nextByteFromFile:handle. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5158 |
c isNil ifTrue:[ |
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
|
5159 |
^ nil. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5160 |
]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5161 |
binary == true ifTrue:[ |
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
|
5162 |
^ c |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5163 |
]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5164 |
^ Character value:c |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5165 |
! |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5166 |
|
612 | 5167 |
peek |
5168 |
"return the element to be read next without advancing read position. |
|
5169 |
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
|
5170 |
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
|
5171 |
- see #pastEndRead." |
612 | 5172 |
|
16296 | 5173 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5174 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5175 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5176 |
unsigned char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5177 |
int ret, _buffered; |
216 | 5178 |
OBJ fp; |
3672
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5179 |
OBJ ra; |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5180 |
|
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5181 |
if ((ra = __INST(readAhead)) != nil) { |
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
|
5182 |
if (__INST(binary) == true) { |
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
|
5183 |
RETURN ( ra ); |
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
|
5184 |
} |
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
|
5185 |
c = __intVal(ra); |
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
|
5186 |
RETURN ( __MKCHARACTER(c) ); |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
5187 |
} |
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
5188 |
|
1133 | 5189 |
__INST(lastErrorNumber) = nil; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5190 |
|
12548 | 5191 |
if ((__INST(handleType) == nil) |
5192 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5193 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5194 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5195 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
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
|
5196 |
if (((fp = __INST(handle)) != nil) |
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
|
5197 |
&& (__INST(mode) != @symbol(writeonly)) |
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
|
5198 |
) { |
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
|
5199 |
f = __FILEVal(fp); |
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
|
5200 |
_buffered = (__INST(buffered) == true); |
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
|
5201 |
if (_buffered) { |
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
|
5202 |
__READING__(f) |
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
|
5203 |
} |
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
|
5204 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
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
|
5205 |
|
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
|
5206 |
if (ret > 0) { |
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
|
5207 |
__UNGETC__(c, f, _buffered); |
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
|
5208 |
|
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
|
5209 |
if (__INST(binary) == true) { |
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
|
5210 |
RETURN ( __mkSmallInteger(c) ); |
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
|
5211 |
} |
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
|
5212 |
RETURN ( __MKCHARACTER(c) ); |
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
|
5213 |
} |
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
|
5214 |
if (ret < 0) { |
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
|
5215 |
error = __mkSmallInteger(__threadErrno); |
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
|
5216 |
} else /* ret == 0 */ { |
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
|
5217 |
__INST(hitEOF) = true; |
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
|
5218 |
} |
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
|
5219 |
} |
1 | 5220 |
} |
159 | 5221 |
%}. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5222 |
hitEOF == true ifTrue:[^ self pastEndRead]. |
16296 | 5223 |
error notNil ifTrue:[ |
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
|
5224 |
lastErrorNumber := error. |
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
|
5225 |
^ self readError:error. |
16296 | 5226 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5227 |
handle isNil ifTrue:[^ self errorNotOpen]. |
5420 | 5228 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
5229 |
||
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5230 |
readAhead isNil ifTrue:[ |
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
|
5231 |
readAhead := self nextOrNil. |
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
|
5232 |
readAhead isNil ifTrue:[ |
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
|
5233 |
^ self pastEndRead. |
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
|
5234 |
]. |
5420 | 5235 |
]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5236 |
^ readAhead |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5237 |
! |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5238 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5239 |
peekOrNil |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5240 |
"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
|
5241 |
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
|
5242 |
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
|
5243 |
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
|
5244 |
|
16296 | 5245 |
|error| |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5246 |
%{ |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5247 |
FILEPOINTER f; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5248 |
unsigned char c; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5249 |
int ret, _buffered; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5250 |
OBJ fp; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5251 |
OBJ ra; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5252 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5253 |
if ((ra = __INST(readAhead)) != nil) { |
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
|
5254 |
if (__INST(binary) == true) { |
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
|
5255 |
RETURN ( ra ); |
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
|
5256 |
} |
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
|
5257 |
c = __intVal(ra); |
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
|
5258 |
RETURN ( __MKCHARACTER(c) ); |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5259 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5260 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5261 |
__INST(lastErrorNumber) = nil; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5262 |
|
12548 | 5263 |
if ((__INST(handleType) == nil) |
5264 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5265 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5266 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5267 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
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
|
5268 |
if (((fp = __INST(handle)) != nil) |
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
|
5269 |
&& (__INST(mode) != @symbol(writeonly)) |
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
|
5270 |
) { |
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
|
5271 |
f = __FILEVal(fp); |
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
|
5272 |
_buffered = (__INST(buffered) == true); |
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
|
5273 |
if (_buffered) { |
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
|
5274 |
__READING__(f) |
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
|
5275 |
} |
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
|
5276 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
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
|
5277 |
|
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
|
5278 |
if (ret > 0) { |
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
|
5279 |
__UNGETC__(c, f, _buffered); |
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
|
5280 |
|
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
|
5281 |
if (__INST(binary) == true) { |
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
|
5282 |
RETURN ( __mkSmallInteger(c) ); |
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
|
5283 |
} |
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
|
5284 |
RETURN ( __MKCHARACTER(c) ); |
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
|
5285 |
} |
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
|
5286 |
if (ret < 0) { |
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
|
5287 |
error = __mkSmallInteger(__threadErrno); |
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
|
5288 |
} else /* ret == 0 */ { |
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
|
5289 |
__INST(hitEOF) = true; |
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
|
5290 |
} |
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
|
5291 |
} |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5292 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5293 |
%}. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5294 |
hitEOF == true ifTrue:[^ nil]. |
16296 | 5295 |
error notNil ifTrue:[ |
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
|
5296 |
lastErrorNumber := error. |
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
|
5297 |
^ self readError:error. |
16296 | 5298 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5299 |
handle isNil ifTrue:[^ self errorNotOpen]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5300 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5301 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5302 |
readAhead isNil ifTrue:[ |
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
|
5303 |
readAhead := self nextOrNil. |
5420 | 5304 |
]. |
5305 |
^ readAhead |
|
1295 | 5306 |
! |
5307 |
||
5308 |
upToEnd |
|
5309 |
"return a collection of the elements up-to the end. |
|
5310 |
Return nil if the stream-end is reached before." |
|
5311 |
||
6569 | 5312 |
|answerStream buffer count| |
5313 |
||
5314 |
buffer := self contentsSpecies new:4096. |
|
1295 | 5315 |
[self atEnd] whileFalse:[ |
16296 | 5316 |
count := self nextAvailableBytes:4096 into:buffer startingAt:1. |
5317 |
count ~~ 0 ifTrue:[ |
|
5318 |
answerStream isNil ifTrue:[ |
|
5319 |
answerStream := WriteStream with:buffer. |
|
5320 |
answerStream position:count. |
|
5321 |
buffer := self contentsSpecies new:4096. |
|
5322 |
] ifFalse:[ |
|
5323 |
answerStream nextPutAll:buffer startingAt:1 to:count. |
|
5324 |
]. |
|
5325 |
]. |
|
1295 | 5326 |
]. |
6758
bc933037a1dc
oops - upToEnd failed if already at the end
Claus Gittinger <cg@exept.de>
parents:
6661
diff
changeset
|
5327 |
answerStream isNil ifTrue:[^ self contentsSpecies new]. |
1295 | 5328 |
^ answerStream contents |
5329 |
||
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
5330 |
" |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
5331 |
('smalltalk.rc' asFilename readStream upToEnd) |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
5332 |
= |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
5333 |
('smalltalk.rc' asFilename readStream contentsOfEntireFile) |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
5334 |
" |
612 | 5335 |
! ! |
5336 |
||
5420 | 5337 |
!ExternalStream methodsFor:'rel5 protocol'! |
5338 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5339 |
atEndFile:handle |
5420 | 5340 |
"for migration to rel5 only" |
5341 |
||
5342 |
self primitiveFailed |
|
5343 |
! |
|
5344 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5345 |
nextByteFromFile:handle |
5420 | 5346 |
"for migration to rel5 only" |
5347 |
||
5348 |
self primitiveFailed |
|
5349 |
! |
|
5350 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5351 |
nextPutByte:aByte toFile:handle |
5420 | 5352 |
"for migration to rel5 only" |
5353 |
||
5354 |
self primitiveFailed |
|
5355 |
! ! |
|
5356 |
||
612 | 5357 |
!ExternalStream methodsFor:'testing'! |
5358 |
||
5359 |
atEnd |
|
5360 |
"return true, if position is at end" |
|
5361 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5362 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5363 |
FILEPOINTER f; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5364 |
OBJ fp, pos, lim; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5365 |
char c; |
2861 | 5366 |
int ret, _buffered; |
612 | 5367 |
|
1133 | 5368 |
if (__INST(hitEOF) == true) { |
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
|
5369 |
RETURN (true); |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5370 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5371 |
pos = __INST(position); |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5372 |
lim = __INST(readLimit); |
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5373 |
if (lim != nil) { |
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
|
5374 |
off_t _pos, _readLimit; |
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
|
5375 |
|
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
|
5376 |
_pos = __signedLongIntVal(pos); |
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
|
5377 |
_pos = _pos - __intVal( @global(PositionableStream:ZeroPosition)) + 1; |
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
|
5378 |
_readLimit = __signedLongIntVal(lim); |
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
|
5379 |
if (_pos > _readLimit) { |
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
|
5380 |
RETURN (true); |
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
|
5381 |
} |
612 | 5382 |
} |
5383 |
||
1133 | 5384 |
__INST(lastErrorNumber) = nil; |
5385 |
||
12548 | 5386 |
if ((__INST(handleType) == nil) |
5387 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5388 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5389 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5390 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
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
|
5391 |
if ((fp = __INST(handle)) != nil) { |
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
|
5392 |
f = __FILEVal(fp); |
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
|
5393 |
if (_buffered = (__INST(buffered) == true)) { |
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
|
5394 |
__READING__(f); |
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
|
5395 |
} else { |
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
|
5396 |
if (__INST(readAhead) != nil) { |
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
|
5397 |
RETURN (false); |
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
|
5398 |
} |
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
|
5399 |
} |
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
|
5400 |
|
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
|
5401 |
/* |
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
|
5402 |
* read ahead ... |
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
|
5403 |
*/ |
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
|
5404 |
do { |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5405 |
#ifdef WIN32 |
10339 | 5406 |
# if 1 |
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
|
5407 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5408 |
|
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5409 |
# else |
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
|
5410 |
__BEGIN_INTERRUPTABLE__ |
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
|
5411 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
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
|
5412 |
__END_INTERRUPTABLE__ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5413 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5414 |
#else /* not WIN32 */ |
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
|
5415 |
__BEGIN_INTERRUPTABLE__ |
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
|
5416 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
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
|
5417 |
__END_INTERRUPTABLE__ |
4914 | 5418 |
#endif |
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
|
5419 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
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
|
5420 |
|
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
|
5421 |
if (ret > 0) { |
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
|
5422 |
__UNGETC__(c&0xff, f, _buffered); |
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
|
5423 |
RETURN (false); |
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
|
5424 |
} |
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
|
5425 |
if (ret == 0) { |
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
|
5426 |
__INST(hitEOF) = true; |
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
|
5427 |
RETURN (true); |
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
|
5428 |
} |
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
|
5429 |
|
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
|
5430 |
/* ret < 0 */ |
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
|
5431 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
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
|
5432 |
} |
612 | 5433 |
} |
5434 |
%}. |
|
5435 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5436 |
handle isNil ifTrue:[^ self errorNotOpen]. |
5420 | 5437 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
5438 |
readAhead notNil ifTrue:[^ false]. |
|
5439 |
||
5440 |
"/ migration support |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5441 |
^ self |
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
|
5442 |
atEndFile:handle |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5443 |
|
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5444 |
"Modified: / 30.10.1998 / 20:16:06 / cg" |
612 | 5445 |
! |
5446 |
||
5447 |
canReadWithoutBlocking |
|
5448 |
"return true, if any data is available for reading (i.e. |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5449 |
a read operation will not block the smalltalk process), false otherwise. |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5450 |
We know, that error conditions do not block, so return true for errors." |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5451 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5452 |
^ readAhead notNil |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5453 |
or:[handle isNil] |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5454 |
or:[mode == #writeonly |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5455 |
or:[OperatingSystem readCheck:self fileDescriptor]] |
612 | 5456 |
|
5457 |
" |
|
5458 |
|pipe| |
|
5459 |
||
5460 |
pipe := PipeStream readingFrom:'(sleep 10; echo hello)'. |
|
5461 |
pipe canReadWithoutBlocking ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5462 |
Transcript showCR:'data available' |
612 | 5463 |
] ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5464 |
Transcript showCR:'no data available' |
612 | 5465 |
]. |
5466 |
pipe close |
|
5467 |
" |
|
2986
c6957cf6128f
Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents:
2963
diff
changeset
|
5468 |
|
c6957cf6128f
Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents:
2963
diff
changeset
|
5469 |
"Modified: 25.9.1997 / 13:08:45 / stefan" |
612 | 5470 |
! |
5471 |
||
5472 |
canWriteWithoutBlocking |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5473 |
"return true, if data can be written into the stream |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5474 |
(i.e. a write operation will not block the smalltalk process). |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5475 |
We know, that error conditions do not block, so return true for errors." |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5476 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5477 |
^ handle isNil |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5478 |
or:[mode == #readonly |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5479 |
or:[OperatingSystem writeCheck:self fileDescriptor]] |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5480 |
! |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5481 |
|
10995 | 5482 |
gotErrorOrEOF |
5483 |
"answerv true, if amn error or eof has been occured on the stream" |
|
5484 |
||
5485 |
^ hitEOF == true or:[lastErrorNumber notNil] |
|
5486 |
! |
|
5487 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5488 |
isBinary |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5489 |
"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
|
5490 |
The default when created is false." |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5491 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5492 |
^ binary |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5493 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5494 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5495 |
isBlocking |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5496 |
"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
|
5497 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5498 |
handle isNil ifTrue:[^ self errorNotOpen]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5499 |
^ OperatingSystem isBlockingOn:self fileDescriptor |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5500 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5501 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5502 |
isExternalStream |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5503 |
"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
|
5504 |
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
|
5505 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5506 |
^ true |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5507 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5508 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5509 |
isOpen |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5510 |
"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
|
5511 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5512 |
^ handle notNil |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5513 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5514 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5515 |
isReadable |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5516 |
"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
|
5517 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5518 |
^ (mode ~~ #writeonly) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5519 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5520 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5521 |
isWritable |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5522 |
"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
|
5523 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5524 |
^ (mode ~~ #readonly) |
612 | 5525 |
! ! |
5526 |
||
5527 |
!ExternalStream methodsFor:'waiting for I/O'! |
|
5528 |
||
5101 | 5529 |
canBeSelected |
5530 |
"return true, if this stream can be selected upon" |
|
5531 |
||
5532 |
^ OperatingSystem supportsSelect |
|
5533 |
! |
|
5534 |
||
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5535 |
readWaitWithTimeoutMs:timeout |
612 | 5536 |
"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
|
5537 |
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
|
5538 |
If data is already available, return immediate. |
612 | 5539 |
Return true if a timeout occured (i.e. false, if data is available). |
5540 |
The other threads are not affected by the wait." |
|
5541 |
||
16480 | 5542 |
|fd inputSema hasTimedout wasBlocked| |
612 | 5543 |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5544 |
readAhead notNil ifTrue:[^ false]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5545 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5546 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 5547 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
5548 |
||
5549 |
fd := self fileDescriptor. |
|
5550 |
(OperatingSystem readCheck:fd) ifTrue:[^ false]. |
|
5551 |
||
5552 |
wasBlocked := OperatingSystem blockInterrupts. |
|
16463 | 5553 |
inputSema := Semaphore new name:'readWait'. |
5554 |
[ |
|
16508 | 5555 |
timeout notNil ifTrue:[ |
5556 |
Processor signal:inputSema afterMilliseconds:timeout. |
|
5557 |
]. |
|
5558 |
Processor signal:inputSema onInput:fd. |
|
5559 |
Processor activeProcess state:#ioWait. |
|
5560 |
inputSema wait. |
|
5561 |
hasTimedout := timeout notNil and:[(OperatingSystem readCheck:fd) not]. |
|
16463 | 5562 |
] ifCurtailed:[ |
16508 | 5563 |
Processor disableSemaphore:inputSema. |
5564 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
612 | 5565 |
]. |
16480 | 5566 |
timeout notNil ifTrue:[ |
16508 | 5567 |
Processor disableSemaphore:inputSema. |
16480 | 5568 |
]. |
612 | 5569 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
16480 | 5570 |
^ hasTimedout |
612 | 5571 |
! |
5572 |
||
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5573 |
readWriteWaitWithTimeoutMs:timeout |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5574 |
"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
|
5575 |
becomes ready for reading or writing or a timeout (in milliseconds) expired. |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5576 |
Return true if a timeout occured (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
|
5577 |
Return immediate if the receiver is already ready. |
5506 | 5578 |
The other threads are not affected by the wait." |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5579 |
|
16480 | 5580 |
|fd sema hasTimedout wasBlocked| |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5581 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5582 |
handle isNil ifTrue:[ |
16508 | 5583 |
^ self errorNotOpen |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5584 |
]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5585 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5586 |
fd := self fileDescriptor. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5587 |
(OperatingSystem readWriteCheck:fd) ifTrue:[^ false]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5588 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5589 |
wasBlocked := OperatingSystem blockInterrupts. |
16463 | 5590 |
sema := Semaphore new name:'readWriteWait'. |
5591 |
[ |
|
16508 | 5592 |
timeout notNil ifTrue:[ |
5593 |
Processor signal:sema afterMilliseconds:timeout |
|
5594 |
]. |
|
5595 |
Processor signal:sema onOutput:fd. |
|
5596 |
Processor signal:sema onInput:fd. |
|
5597 |
Processor activeProcess state:#ioWait. |
|
5598 |
sema wait. |
|
5599 |
hasTimedout := timeout notNil and:[(OperatingSystem readWriteCheck:fd) not]. |
|
16463 | 5600 |
] ifCurtailed:[ |
16508 | 5601 |
Processor disableSemaphore:sema. |
5602 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5603 |
]. |
16480 | 5604 |
timeout notNil ifTrue:[ |
16508 | 5605 |
Processor disableSemaphore:sema. |
16480 | 5606 |
]. |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5607 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
16480 | 5608 |
^ hasTimedout |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5609 |
! |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5610 |
|
612 | 5611 |
writeWaitWithTimeoutMs:timeout |
5612 |
"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
|
5613 |
becomes ready for writing or a timeout (in milliseconds) expired. |
612 | 5614 |
Return true if a timeout occured (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
|
5615 |
Return immediate if the receiver is already ready. |
612 | 5616 |
The other threads are not affected by the wait." |
5617 |
||
16480 | 5618 |
|fd outputSema hasTimedout wasBlocked| |
612 | 5619 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5620 |
handle isNil ifTrue:[ |
16508 | 5621 |
^ self errorNotOpen |
612 | 5622 |
]. |
5623 |
mode == #readonly ifTrue:[ |
|
16508 | 5624 |
^ self errorReadOnly |
612 | 5625 |
]. |
5626 |
||
5627 |
fd := self fileDescriptor. |
|
5628 |
(OperatingSystem writeCheck:fd) ifTrue:[^ false]. |
|
5629 |
||
5630 |
wasBlocked := OperatingSystem blockInterrupts. |
|
16463 | 5631 |
outputSema := Semaphore new name:'writeWait'. |
5632 |
[ |
|
16508 | 5633 |
timeout notNil ifTrue:[ |
5634 |
Processor signal:outputSema afterMilliseconds:timeout |
|
5635 |
]. |
|
5636 |
Processor signal:outputSema onOutput:fd. |
|
5637 |
Processor activeProcess state:#ioWait. |
|
5638 |
outputSema wait. |
|
5639 |
hasTimedout := timeout notNil and:[(OperatingSystem writeCheck:fd) not]. |
|
16463 | 5640 |
] ifCurtailed:[ |
16508 | 5641 |
Processor disableSemaphore:outputSema. |
5642 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
612 | 5643 |
]. |
16480 | 5644 |
timeout notNil ifTrue:[ |
16508 | 5645 |
Processor disableSemaphore:outputSema. |
16480 | 5646 |
]. |
612 | 5647 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
16480 | 5648 |
^ hasTimedout |
612 | 5649 |
! ! |
5650 |
||
5651 |
!ExternalStream methodsFor:'writing'! |
|
5652 |
||
5653 |
cr |
|
5654 |
"append an end-of-line character (or CRLF if in crlf mode). |
|
5655 |
reimplemented for speed" |
|
5656 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5657 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5658 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5659 |
int len, cnt, _buffered; |
612 | 5660 |
OBJ fp; |
5661 |
char *cp; |
|
5662 |
||
12548 | 5663 |
if ((__INST(handleType) == nil) |
5664 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5665 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5666 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
5667 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
16508 | 5668 |
__INST(lastErrorNumber) = nil; |
5669 |
if (((fp = __INST(handle)) != nil) |
|
5670 |
&& (__INST(mode) != @symbol(readonly)) |
|
5671 |
&& (__INST(binary) != true) |
|
5672 |
) { |
|
5673 |
f = __FILEVal(fp); |
|
5674 |
||
5675 |
if (_buffered = (__INST(buffered) == true)) { |
|
5676 |
__WRITING__(f) |
|
5677 |
} |
|
5678 |
{ |
|
5679 |
OBJ mode = __INST(eolMode); |
|
5680 |
||
5681 |
if (mode == @symbol(cr)) { |
|
5682 |
cp = "\r"; len = 1; |
|
5683 |
} else if (mode == @symbol(crlf)) { |
|
5684 |
cp = "\r\n"; len = 2; |
|
5685 |
} else { |
|
5686 |
cp = "\n"; len = 1; |
|
5687 |
} |
|
5688 |
} |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5689 |
#ifdef WIN32 |
16508 | 5690 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
5691 |
cnt = __win32_fwrite(cp, 1, len, f); |
|
5692 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5693 |
#endif |
16508 | 5694 |
{ |
5695 |
__WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType)); |
|
5696 |
} |
|
5697 |
if (cnt == len) { |
|
5698 |
if (__isSmallInteger(__INST(position))) { |
|
5699 |
INT np = __intVal(__INST(position)) + len; |
|
5700 |
OBJ t; |
|
5701 |
||
5702 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
5703 |
} else { |
|
5704 |
__INST(position) = nil; /* i.e: dont know */ |
|
5705 |
} |
|
5706 |
RETURN ( self ); |
|
5707 |
} |
|
5708 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
|
5709 |
} |
|
612 | 5710 |
} |
5711 |
%}. |
|
2326 | 5712 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5713 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
2326 | 5714 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
5414 | 5715 |
(binary==true) ifTrue:[self errorBinary. ^ self]. |
5716 |
||
5717 |
(eolMode == #cr) ifTrue:[self nextPut:(Character return). ^ self]. |
|
5718 |
(eolMode ~~ #crlf) ifTrue:[self nextPut:(Character nl). ^ self]. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5719 |
self nextPut:(Character return). |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5720 |
self nextPut:(Character nl). |
5414 | 5721 |
^ self |
612 | 5722 |
! |
5723 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5724 |
flush |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5725 |
"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
|
5726 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5727 |
%{ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5728 |
OBJ fp; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5729 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5730 |
__INST(lastErrorNumber) = nil; |
12548 | 5731 |
if ((__INST(handleType) == nil) |
5732 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5733 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
5734 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
14068 | 5735 |
if ((fp = __INST(handle)) != nil) { |
5736 |
if (__INST(mode) != @symbol(readonly)) { |
|
5737 |
if (__INST(buffered) == true) { |
|
5738 |
FILEPOINTER f = __FILEVal(fp); |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5739 |
#ifdef WIN32 |
14068 | 5740 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
5741 |
__win32_fflush(f); |
|
5742 |
} else { |
|
5743 |
int rslt; |
|
5744 |
||
5745 |
do { |
|
5746 |
__threadErrno = 0; |
|
5747 |
rslt = __STX_C_CALL1("fflush", fflush, f); |
|
5748 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
5749 |
} |
|
12678 | 5750 |
#else /* ! WIN32 */ |
14068 | 5751 |
__BEGIN_INTERRUPTABLE__ |
5752 |
FFLUSH(f); |
|
5753 |
__END_INTERRUPTABLE__ |
|
12678 | 5754 |
#endif /* ! WIN32 */ |
14068 | 5755 |
} |
5756 |
} |
|
5757 |
} |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5758 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5759 |
%} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5760 |
! |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5761 |
|
612 | 5762 |
nextPut:aCharacter |
5763 |
"write the argument, aCharacter - return nil if failed, self if ok. |
|
5764 |
Only single-byte characters are currently supported" |
|
5765 |
||
16296 | 5766 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5767 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5768 |
FILEPOINTER f; |
8209
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5769 |
unsigned codePoint; |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5770 |
unsigned char c; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5771 |
int cnt, _buffered; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5772 |
OBJ fp; |
612 | 5773 |
|
1133 | 5774 |
__INST(lastErrorNumber) = nil; |
12548 | 5775 |
if ((__INST(handleType) == nil) |
5776 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5777 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5778 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5779 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 5780 |
if (((fp = __INST(handle)) != nil) |
5781 |
&& (__INST(mode) != @symbol(readonly)) |
|
5782 |
) { |
|
5783 |
if (__INST(binary) != true) { |
|
5784 |
if (__isCharacter(aCharacter)) { |
|
5785 |
codePoint = __intVal(__characterVal(aCharacter)); |
|
5786 |
if (codePoint <= 0xFF) { |
|
5787 |
c = codePoint; |
|
612 | 5788 |
doWrite: |
16508 | 5789 |
f = __FILEVal(fp); |
5790 |
if (! f) { |
|
5791 |
fprintf(stderr, "oops - fileHandle is NULL in nextPut:\n"); |
|
5792 |
__INST(handle) = nil; |
|
5793 |
goto out; |
|
5794 |
} |
|
5795 |
||
5796 |
if (_buffered = (__INST(buffered) == true)) { |
|
5797 |
__WRITING__(f) |
|
5798 |
} |
|
9053
f3f3d48d6f44
fix writing to stdout/stderr for winstx non-console operation
Claus Gittinger <cg@exept.de>
parents:
9024
diff
changeset
|
5799 |
#ifdef WIN32 |
16508 | 5800 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
5801 |
cnt = __win32_fwrite(&c, 1, 1, f); |
|
5802 |
} else |
|
9053
f3f3d48d6f44
fix writing to stdout/stderr for winstx non-console operation
Claus Gittinger <cg@exept.de>
parents:
9024
diff
changeset
|
5803 |
#endif |
16508 | 5804 |
__WRITEBYTE__(cnt, f, &c, _buffered, __INST(handleType)); |
5805 |
if (cnt == 1) { |
|
5806 |
if (__isSmallInteger(__INST(position))) { |
|
5807 |
INT np = __intVal(__INST(position)) + 1; |
|
5808 |
OBJ t; |
|
5809 |
||
5810 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
5811 |
} else { |
|
5812 |
__INST(position) = nil; /* i.e. do not know */ |
|
5813 |
} |
|
5814 |
RETURN ( self ); |
|
5815 |
} |
|
5816 |
error = __mkSmallInteger(__threadErrno); |
|
5817 |
} |
|
5818 |
} |
|
5819 |
} else { |
|
5820 |
if (__isSmallInteger(aCharacter)) { |
|
5821 |
c = __intVal(aCharacter); |
|
5822 |
goto doWrite; |
|
5823 |
} |
|
5824 |
} |
|
5825 |
} |
|
612 | 5826 |
} |
7737 | 5827 |
out: ; |
612 | 5828 |
%}. |
16296 | 5829 |
error notNil ifTrue:[ |
16508 | 5830 |
lastErrorNumber := error. |
5831 |
self writeError:error. |
|
5832 |
^ self |
|
16296 | 5833 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5834 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
2331 | 5835 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
5417 | 5836 |
binary == true ifFalse:[ |
16508 | 5837 |
(aCharacter isCharacter not |
5838 |
or:[aCharacter codePoint > 16rFF]) ifTrue:[ |
|
5839 |
self argumentMustBeCharacter. |
|
5840 |
^ self. |
|
5841 |
]. |
|
5417 | 5842 |
] ifTrue:[ |
16508 | 5843 |
aCharacter isInteger ifFalse:[ |
5844 |
self argumentMustBeInteger. |
|
5845 |
^ self. |
|
5846 |
]. |
|
5417 | 5847 |
]. |
5848 |
"/ migration support |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
5849 |
self |
16508 | 5850 |
nextPutByte:aCharacter asInteger |
5851 |
toFile:handle |
|
612 | 5852 |
! |
5853 |
||
5854 |
nextPutAll:aCollection |
|
5855 |
"write all elements of the argument, aCollection. |
|
5856 |
Reimplemented for speed when writing strings or byteArrays. |
|
5857 |
For others, falls back to general method in superclass." |
|
5858 |
||
16296 | 5859 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5860 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5861 |
FILEPOINTER f; |
14644 | 5862 |
INT len, cnt; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5863 |
OBJ fp; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5864 |
int _buffered; |
14644 | 5865 |
INT o_offs; |
612 | 5866 |
|
1133 | 5867 |
__INST(lastErrorNumber) = nil; |
5868 |
||
12548 | 5869 |
if ((__INST(handleType) == nil) |
5870 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5871 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5872 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5873 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 5874 |
if (((fp = __INST(handle)) != nil) |
5875 |
&& (__INST(mode) != @symbol(readonly)) |
|
5876 |
) { |
|
5877 |
f = __FILEVal(fp); |
|
5878 |
if (! f) { |
|
5879 |
fprintf(stderr, "oops - fileHandle is NULL in nextPutAll:\n"); |
|
5880 |
__INST(handle) = nil; |
|
5881 |
goto out; |
|
5882 |
} |
|
5883 |
if (_buffered = (__INST(buffered) == true)) { |
|
5884 |
__WRITING__(f) |
|
5885 |
} |
|
5886 |
||
5887 |
if (__isStringLike(aCollection)) { |
|
5888 |
len = __stringSize(aCollection); |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5889 |
#ifdef WIN32 |
16508 | 5890 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
5891 |
cnt = __win32_fwrite(__stringVal(aCollection), 1, len, f); |
|
5892 |
} else |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
5893 |
#endif |
16508 | 5894 |
{ |
5895 |
o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection); |
|
5896 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType)); |
|
5897 |
} |
|
5898 |
} else { |
|
5899 |
if (__INST(binary) == true) { |
|
5900 |
INT offs; |
|
5901 |
||
5902 |
if (__isByteArrayLike(aCollection)) { |
|
5903 |
offs = 0; |
|
5904 |
len = __byteArraySize(aCollection); |
|
5905 |
} else if (__isBytes(aCollection)) { |
|
5906 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
5907 |
len = __byteArraySize(aCollection) - offs; |
|
5908 |
} else |
|
5909 |
goto out; |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5910 |
#ifdef WIN32 |
16508 | 5911 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
5912 |
cnt = __win32_fwrite(__stringVal(aCollection), 1, len, f); |
|
5913 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5914 |
#endif |
16508 | 5915 |
{ |
5916 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection); |
|
5917 |
o_offs += offs; |
|
5918 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType)); |
|
5919 |
} |
|
5920 |
} else |
|
5921 |
goto out; |
|
5922 |
} |
|
5923 |
||
5924 |
if (cnt == len) { |
|
5925 |
if (__isSmallInteger(__INST(position))) { |
|
5926 |
INT np = __intVal(__INST(position)) + len; |
|
5927 |
OBJ t; |
|
5928 |
||
5929 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
5930 |
} else { |
|
5931 |
__INST(position) = nil; /* i.e. do not know */ |
|
5932 |
} |
|
5933 |
RETURN (self); |
|
5934 |
} |
|
5935 |
error = __mkSmallInteger(__threadErrno); |
|
5936 |
} |
|
612 | 5937 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
5938 |
out: ; |
612 | 5939 |
%}. |
16296 | 5940 |
error notNil ifTrue:[ |
16508 | 5941 |
lastErrorNumber := error. |
5942 |
self writeError:error. |
|
5943 |
^ self |
|
16296 | 5944 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5945 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
2331 | 5946 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
612 | 5947 |
|
5948 |
^ super nextPutAll:aCollection |
|
5949 |
! |
|
5950 |
||
5951 |
nextPutAll:aCollection startingAt:start to:stop |
|
5952 |
"write a range of elements of the argument, aCollection. |
|
5953 |
Reimplemented for speed when writing strings or byteArrays. |
|
5954 |
For others, falls back to general method in superclass." |
|
5955 |
||
16296 | 5956 |
|error| |
5957 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5958 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5959 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5960 |
int offs, len, cnt, iStart, iStop, _buffered; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5961 |
OBJ fp; |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
5962 |
int o_offs; |
612 | 5963 |
|
1133 | 5964 |
__INST(lastErrorNumber) = nil; |
12548 | 5965 |
if ((__INST(handleType) == nil) |
5966 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5967 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5968 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5969 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
16508 | 5970 |
if (((fp = __INST(handle)) != nil) |
5971 |
&& (__INST(mode) != @symbol(readonly)) |
|
5972 |
&& __bothSmallInteger(start, stop) |
|
5973 |
) { |
|
5974 |
f = __FILEVal(fp); |
|
5975 |
if (_buffered = (__INST(buffered) == true)) { |
|
5976 |
__WRITING__(f) |
|
5977 |
} |
|
5978 |
iStart = __intVal(start); |
|
5979 |
iStop = __intVal(stop); |
|
5980 |
if ((iStart < 1) || (iStop < iStart)) { |
|
5981 |
RETURN(self); |
|
5982 |
} |
|
5983 |
if (__isStringLike(aCollection)) { |
|
5984 |
len = __stringSize(aCollection); |
|
5985 |
if (iStop > len) { |
|
5986 |
RETURN(self); |
|
5987 |
} |
|
5988 |
if (iStop > len) |
|
5989 |
iStop = len; |
|
5990 |
len = iStop - iStart + 1; |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5991 |
#ifdef WIN32 |
16508 | 5992 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
5993 |
cnt = __win32_fwrite(__stringVal(aCollection)+iStart-1, 1, len, f); |
|
5994 |
} else |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
5995 |
#endif |
16508 | 5996 |
{ |
5997 |
o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection); |
|
5998 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+iStart-1, len, _buffered, __INST(handleType)); |
|
5999 |
} |
|
6000 |
} else { |
|
6001 |
if (__INST(binary) == true) { |
|
6002 |
int offs; |
|
6003 |
||
6004 |
if (__isByteArrayLike(aCollection)) { |
|
6005 |
offs = 0; |
|
6006 |
len = __byteArraySize(aCollection); |
|
6007 |
} else if (__isBytes(aCollection)) { |
|
6008 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
6009 |
len = __byteArraySize(aCollection) - offs; |
|
6010 |
} else |
|
6011 |
goto out; |
|
6012 |
||
6013 |
if (iStop > len) { |
|
6014 |
RETURN(self); |
|
6015 |
} |
|
6016 |
if (iStop > len) |
|
6017 |
iStop = len; |
|
6018 |
len = iStop - iStart + 1; |
|
6019 |
offs += iStart - 1; |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6020 |
#ifdef WIN32 |
16508 | 6021 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6022 |
cnt = __win32_fwrite(__stringVal(aCollection)+iStart-1, 1, len, f); |
|
6023 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6024 |
#endif |
16508 | 6025 |
{ |
6026 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element)-(char *)__InstPtr(aCollection); |
|
6027 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+offs, len, _buffered, __INST(handleType)); |
|
6028 |
} |
|
6029 |
} else |
|
6030 |
goto out; |
|
6031 |
} |
|
6032 |
if (cnt == len) { |
|
6033 |
if (__isSmallInteger(__INST(position))) { |
|
6034 |
INT np = __intVal(__INST(position)) + len; |
|
6035 |
OBJ t; |
|
6036 |
||
6037 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6038 |
} else { |
|
6039 |
__INST(position) = nil; /* i.e. do not know */ |
|
6040 |
} |
|
6041 |
RETURN (self); |
|
6042 |
} |
|
6043 |
error = __mkSmallInteger(__threadErrno); |
|
6044 |
} |
|
612 | 6045 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
6046 |
out: ; |
612 | 6047 |
%}. |
16296 | 6048 |
error notNil ifTrue:[ |
16508 | 6049 |
lastErrorNumber := error. |
6050 |
self writeError:error. |
|
6051 |
^ self |
|
16296 | 6052 |
]. |
612 | 6053 |
^ super nextPutAll:aCollection startingAt:start to:stop |
14662 | 6054 |
! |
6055 |
||
6056 |
nextPutAllUnicode:aString |
|
6057 |
"normal streams can not handle multi-byte characters, so convert them to utf8. |
|
6058 |
This is needed, so that you can do ('something' asUnicode16String errorPrintCR)" |
|
6059 |
||
6060 |
aString do:[:eachCharacter| |
|
16296 | 6061 |
self nextPutUtf8:eachCharacter. |
14662 | 6062 |
]. |
6063 |
||
6064 |
" |
|
16296 | 6065 |
'Bönnigheim' asUnicode16String errorPrintCR |
14662 | 6066 |
" |
6067 |
! |
|
6068 |
||
6069 |
nextPutUnicode:aCharacter |
|
6070 |
"normal streams can not handle multi-byte characters, so convert them to utf8" |
|
6071 |
||
6072 |
self nextPutUtf8:aCharacter. |
|
15655 | 6073 |
! |
6074 |
||
6075 |
nextPutUtf16:aCharacter |
|
6076 |
"append my UTF-16 representation to the argument, aStream. |
|
6077 |
UTF-16 can encode only characters with code points between 0 to 16r10FFFF." |
|
6078 |
||
6079 |
|codePoint| |
|
6080 |
||
6081 |
codePoint := aCharacter codePoint. |
|
6082 |
(codePoint <= 16rD7FF |
|
6083 |
or:[codePoint >= 16rE000 and:[codePoint <= 16rFFFF]]) ifTrue:[ |
|
16296 | 6084 |
self nextPutShort:codePoint MSB:true. |
15655 | 6085 |
] ifFalse:[codePoint <= 16r10FFFF ifTrue:[ |
16296 | 6086 |
|highBits lowBits| |
6087 |
||
6088 |
codePoint := codePoint - 16r100000. |
|
6089 |
highBits := codePoint bitShift:-10. |
|
6090 |
lowBits := codePoint bitAnd:16r3FF. |
|
6091 |
self nextPutShort:highBits+16rD800 MSB:true. |
|
6092 |
self nextPutShort:lowBits+16rDC00 MSB:true. |
|
15655 | 6093 |
] ifFalse:[ |
16296 | 6094 |
EncodingError raiseWith:aCharacter errorString:'Character cannot be encoded as UTF-16'. |
15655 | 6095 |
]]. |
6096 |
||
6097 |
" |
|
16296 | 6098 |
(FileStream newTemporary |
6099 |
nextPutUtf16:$B; |
|
6100 |
nextPutUtf16:$Ä; |
|
6101 |
nextPutUtf16:(Character codePoint:16r10CCCC); |
|
6102 |
reset; |
|
6103 |
binary; |
|
6104 |
contents) |
|
15655 | 6105 |
" |
612 | 6106 |
! ! |
6107 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
6108 |
!ExternalStream class methodsFor:'documentation'! |
730 | 6109 |
|
6110 |
version |
|
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
|
6111 |
^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.398 2014-11-24 14:37:58 cg Exp $' |
12398 | 6112 |
! |
6113 |
||
6114 |
version_CVS |
|
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
|
6115 |
^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.398 2014-11-24 14:37:58 cg Exp $' |
730 | 6116 |
! ! |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
6117 |
|
14603 | 6118 |
|
612 | 6119 |
ExternalStream initialize! |