--- a/ExternalStream.st Mon Mar 19 12:55:25 2018 +0100
+++ b/ExternalStream.st Mon Mar 19 14:48:53 2018 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1988 by Claus Gittinger
All Rights Reserved
@@ -4723,7 +4725,7 @@
"
(FileStream newTemporary
nextPutUtf16:$B;
- nextPutUtf16:$Ä;
+ nextPutUtf16:$Ä;
nextPutUtf16:(Character codePoint:16r10CCCC);
reset;
binary;
@@ -4773,7 +4775,7 @@
|fp error|
handle isNil ifTrue:[
- ^ self.
+ ^ self.
].
fp := handle.
"/ (didWrite==true and:[binary ~~ true and:[eolMode = #crlf]]) ifTrue: [ self breakPoint:#sr ].
@@ -4782,90 +4784,92 @@
int rslt;
if (__INST(handleType) == @symbol(socketHandle)) {
- SOCKET sock = (SOCKET)(__FILEVal(fp));
-
- if (@global(FileOpenTrace) == true) {
- fprintf(stderr, "close socket [ExternalStream] %"_lx_"\n", (INT)sock);
- }
-
- // whether the close() will be successful or not - the handle is invalid now!
- __INST(handle) = nil;
- do {
+ SOCKET sock = (SOCKET)(__FILEVal(fp));
+
+ if (@global(FileOpenTrace) == true) {
+ fprintf(stderr, "close socket [ExternalStream] %"_lx_"\n", (INT)sock);
+ }
+
+ // whether the close() will be successful or not - the handle is invalid now!
+ __INST(handle) = nil;
+ do {
#ifdef __win32__
- rslt = __STX_WSA_NOINT_CALL1("closesocket", closesocket, sock);
+ rslt = __STX_WSA_NOINT_CALL1("closesocket", closesocket, sock);
#else
- rslt = close(sock);
+ rslt = close(sock);
#endif
- } while((rslt < 0) && (__threadErrno == EINTR));
+ } while((rslt < 0) && (__threadErrno == EINTR));
} else if ((__INST(handleType) == nil)
- || (__INST(handleType) == @symbol(filePointer))
- || (__INST(handleType) == @symbol(socketFilePointer))
- || (__INST(handleType) == @symbol(pipeFilePointer)))
+ || (__INST(handleType) == @symbol(filePointer))
+ || (__INST(handleType) == @symbol(socketFilePointer))
+ || (__INST(handleType) == @symbol(pipeFilePointer)))
{
- FILEPOINTER f = __FILEVal(fp);
-
- if (@global(FileOpenTrace) == true) {
- fprintf(stderr, "fclose [ExternalStream] %"_lx_"\n", (INT)f);
- }
- // whether the close() will be successful or not - the handle is invalid now!
- __INST(handle) = nil;
+ FILEPOINTER f = __FILEVal(fp);
+
+ if (@global(FileOpenTrace) == true) {
+ fprintf(stderr, "fclose [ExternalStream] %"_lx_"\n", (INT)f);
+ }
+ // whether the close() will be successful or not - the handle is invalid now!
+ __INST(handle) = nil;
#ifdef __win32__
- if (__INST(mode) != @symbol(readonly) && __INST(buffered) != false) {
- // do a fflush() first, so that fclose() doesn't block
- // we suspect, that EINTR causes problems in fclose()
- do {
- __threadErrno = 0;
- rslt = __STX_C_CALL1("fflush", fflush, f);
- } while((rslt < 0) && (__threadErrno == EINTR));
- }
- do {
- __threadErrno = 0;
- rslt = __STX_C_NOINT_CALL1("fclose", fclose, f);
- } while((rslt < 0) && (__threadErrno == EINTR));
+ if (__INST(mode) != @symbol(readonly) && __INST(buffered) != false) {
+ // do a fflush() first, so that fclose() doesn't block
+ // we suspect, that EINTR causes problems in fclose()
+ do {
+ __threadErrno = 0;
+ rslt = __STX_C_CALL1("fflush", fflush, f);
+ } while((rslt < 0) && (__threadErrno == EINTR));
+ }
+ do {
+ __threadErrno = 0;
+ rslt = __STX_C_NOINT_CALL1("fclose", fclose, f);
+ } while((rslt < 0) && (__threadErrno == EINTR));
#else
# ifdef __osx__
- // cg: not sure why, but on osx, I get blocked occasionally in fclose
- // lets try this:
- if (__INST(mode) != @symbol(readonly) && __INST(buffered) != false) {
- // do a fflush() first, so that fclose() doesn't block
- // we suspect, that EINTR causes problems in fclose()
- do {
- __threadErrno = 0;
- __BEGIN_INTERRUPTABLE__
- rslt = fflush(f);
- __END_INTERRUPTABLE__
- } while((rslt < 0) && (__threadErrno == EINTR));
- }
- do {
- __threadErrno = 0;
- __BEGIN_INTERRUPTABLE__
- rslt = fclose(f);
- __END_INTERRUPTABLE__
- } while((rslt < 0) && (__threadErrno == EINTR));
+ // cg: not sure why, but on osx, I get blocked occasionally in fclose
+ // lets try this:
+ if ((__INST(mode) != @symbol(readonly)) && (__INST(buffered) != false)) {
+ // do a fflush() first, so that fclose() doesn't block
+ // we suspect, that EINTR causes problems in fclose()
+ do {
+ clearerr(f);
+ __threadErrno = 0;
+ __BEGIN_INTERRUPTABLE__
+ rslt = fflush(f);
+ __END_INTERRUPTABLE__
+ } while((rslt < 0) && (__threadErrno == EINTR));
+ }
+ do {
+ clearerr(f);
+ __threadErrno = 0;
+ __BEGIN_INTERRUPTABLE__
+ rslt = fclose(f);
+ __END_INTERRUPTABLE__
+ } while((rslt < 0) && (__threadErrno == EINTR));
# else
- // cg: the pre Nov2014 code always did the fclose interruptable;
- // I am not sure, if fclose is actually prepared to do this;
- // at least when only reading, this should not block, and we
- // should be able to do it without being interruptable.
- // Must watch this - if it leads to blockings, change and think about it.
- if (__INST(mode) == @symbol(readonly)) {
- rslt = fclose(f);
- } else {
- __BEGIN_INTERRUPTABLE__
- rslt = fclose(f);
- __END_INTERRUPTABLE__
- }
+ // cg: the pre Nov2014 code always did the fclose interruptable;
+ // I am not sure, if fclose is actually prepared to do this;
+ // at least when only reading, this should not block, and we
+ // should be able to do it without being interruptable.
+ // Must watch this - if it leads to blockings, change and think about it.
+ if (__INST(mode) == @symbol(readonly)) {
+ rslt = fclose(f);
+ } else {
+ __BEGIN_INTERRUPTABLE__
+ rslt = fclose(f);
+ __END_INTERRUPTABLE__
+ }
# endif
#endif
} else {
- error = @symbol(badHandleType);
- goto out;
+ error = @symbol(badHandleType);
+ goto out;
}
if (rslt < 0) {
- error = __mkSmallInteger(__threadErrno);
- goto out;
+ error = __mkSmallInteger(__threadErrno);
+ goto out;
}
RETURN (self);
@@ -4873,25 +4877,25 @@
%}.
error notNil ifTrue:[
- error isInteger ifTrue:[
- lastErrorNumber := error.
- mode == #readonly ifTrue:[
- self ioError:error.
- ] ifFalse:[
- self writeError:error.
- ].
- ^ self.
- ].
- self primitiveFailed:error.
- ^ self.
+ error isInteger ifTrue:[
+ lastErrorNumber := error.
+ mode == #readonly ifTrue:[
+ self ioError:error.
+ ] ifFalse:[
+ self writeError:error.
+ ].
+ ^ self.
+ ].
+ self primitiveFailed:error.
+ ^ self.
].
"/ fallback for rel5
fp := handle.
fp notNil ifTrue:[
- handle := nil.
- self closeFile:fp
+ handle := nil.
+ self closeFile:fp
]
!
@@ -6599,7 +6603,7 @@
].
"
- 'Bönnigheim' asUnicode16String errorPrintCR
+ 'Bönnigheim' asUnicode16String errorPrintCR
"
!