ExternalStream.st
changeset 25142 bd49177015de
parent 25136 1665620b0c7d
child 25180 965b85dbd676
--- a/ExternalStream.st	Mon Dec 16 23:02:30 2019 +0100
+++ b/ExternalStream.st	Tue Dec 17 00:25:06 2019 +0100
@@ -297,6 +297,7 @@
 		    clearerr(f);                        \
 		    continue;                           \
 		}                                       \
+		(ret) = -1;                              \
 	    } else {                                    \
 		(ret) = 0;                              \
 	    }                                           \
@@ -636,6 +637,7 @@
 			clearerr(f);                    \
 			continue;                       \
 		    }                                   \
+		    (ret) = -1;                          \
 		    break;                              \
 		} else {                                \
 		    (ret) = 0;                          \
@@ -681,6 +683,7 @@
 			clearerr(f);                    \
 			continue;                       \
 		    }                                   \
+		    (ret) = -1;                         \
 		    break;                              \
 		} else {                                \
 		    (ret) = 0;                          \
@@ -2269,29 +2272,29 @@
     OBJ _handle  = __INST(handle);
 
     if (_handle != nil) {
-        if ((__INST(handleType) == @symbol(fileHandle))
-         || (__INST(handleType) == @symbol(socketHandle))) {
-            RETURN (_handle);
-        }
-        if (__INST(handleType) == @symbol(pipeFilePointer)) {
-            RETURN (__MKINT(fileno(__FILEVal(_handle))));
-        }
-        if ((__INST(handleType) == nil)
-         || (__INST(handleType) == @symbol(filePointer))
-         || (__INST(handleType) == @symbol(socketFilePointer))
-         || (__INST(handleType) == @symbol(pipeFilePointer))) {
-            FILE *file = __FILEVal(_handle);
-            if (file != NULL) {
-                int fileNo = fileno(file);
-                if (fileNo >= 0) {
+	if ((__INST(handleType) == @symbol(fileHandle))
+	 || (__INST(handleType) == @symbol(socketHandle))) {
+	    RETURN (_handle);
+	}
+	if (__INST(handleType) == @symbol(pipeFilePointer)) {
+	    RETURN (__MKINT(fileno(__FILEVal(_handle))));
+	}
+	if ((__INST(handleType) == nil)
+	 || (__INST(handleType) == @symbol(filePointer))
+	 || (__INST(handleType) == @symbol(socketFilePointer))
+	 || (__INST(handleType) == @symbol(pipeFilePointer))) {
+	    FILE *file = __FILEVal(_handle);
+	    if (file != NULL) {
+		int fileNo = fileno(file);
+		if (fileNo >= 0) {
 #ifdef __win32__
-                    RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileNo)));
+		    RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileNo)));
 #else
-                    RETURN (__MKINT(fileNo));
+		    RETURN (__MKINT(fileNo));
 #endif
-                }
-            }
-        }
+		}
+	    }
+	}
     }
 %}.
     ^ handle
@@ -6053,24 +6056,24 @@
      In this case, all I/O operations here will be blocking."
 
     Smalltalk isInitialized ifFalse:[
-        ^ false
+	^ false
     ].
 
     wasBlocked := OperatingSystem blockInterrupts.
     (OperatingSystem readCheck:fd) ifTrue:[
-        hasTimedout := false
+	hasTimedout := false
     ] ifFalse:[
-        inputSema := Semaphore name:'readWait'.
-        hasTimedout := [
-            Processor signal:inputSema onInput:fd.
-            (inputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
-        ] ifCurtailed:[
-            Processor disableSemaphore:inputSema.
-            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-        ].
-        hasTimedout ifTrue:[
-            Processor disableSemaphore:inputSema.
-        ].
+	inputSema := Semaphore name:'readWait'.
+	hasTimedout := [
+	    Processor signal:inputSema onInput:fd.
+	    (inputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
+	] ifCurtailed:[
+	    Processor disableSemaphore:inputSema.
+	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+	].
+	hasTimedout ifTrue:[
+	    Processor disableSemaphore:inputSema.
+	].
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
     ^ hasTimedout
@@ -6164,18 +6167,18 @@
     |fd outputSema hasTimedout wasBlocked|
 
     handle isNil ifTrue:[
-        ^ self errorNotOpen
+	^ self errorNotOpen
     ].
     mode == #readonly ifTrue:[
-        ^ self errorReadOnly
+	^ self errorReadOnly
     ].
 %{
 #ifdef __win32__
     {
-        FILEPOINTER f = __FILEVal(__INST(handle));
-        if ((f == __win32_stdout()) || (f == __win32_stderr())) {
-            RETURN(false);
-        }
+	FILEPOINTER f = __FILEVal(__INST(handle));
+	if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+	    RETURN(false);
+	}
     }
 #endif
 %}.
@@ -6186,19 +6189,19 @@
     wasBlocked := OperatingSystem blockInterrupts.
     "/ check again - now inside lock
     (OperatingSystem writeCheck:fd) ifTrue:[
-        hasTimedout := false.
+	hasTimedout := false.
     ] ifFalse:[
-        outputSema := Semaphore name:'writeWait'.
-        hasTimedout := [
-            Processor signal:outputSema onOutput:fd.
-            (outputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
-        ] ifCurtailed:[
-            Processor disableSemaphore:outputSema.
-            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-        ].
-        hasTimedout ifTrue:[
-            Processor disableSemaphore:outputSema.
-        ].
+	outputSema := Semaphore name:'writeWait'.
+	hasTimedout := [
+	    Processor signal:outputSema onOutput:fd.
+	    (outputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
+	] ifCurtailed:[
+	    Processor disableSemaphore:outputSema.
+	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+	].
+	hasTimedout ifTrue:[
+	    Processor disableSemaphore:outputSema.
+	].
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
     ^ hasTimedout