ExternalStream.st
changeset 2861 c098e5766682
parent 2854 3c8bf66e4e7d
child 2874 020627074c9e
--- a/ExternalStream.st	Mon Aug 18 12:34:45 1997 +0200
+++ b/ExternalStream.st	Tue Aug 19 11:16:52 1997 +0200
@@ -10,6 +10,8 @@
  hereby transferred.
 "
 
+'From Smalltalk/X, Version:3.1.9 on 19-aug-1997 at 10:14:54'                    !
+
 ReadWriteStream subclass:#ExternalStream
 	instanceVariableNames:'filePointer mode buffered binary useCRLF hitEOF didWrite
 		lastErrorNumber readAhead'
@@ -2056,63 +2058,57 @@
 
     __INST(lastErrorNumber) = nil;
     if (((fp = __INST(filePointer)) != nil)
-	&& (__INST(mode) != @symbol(writeonly))
-	&& __bothSmallInteger(count, start)
+        && (__INST(mode) != @symbol(writeonly))
+        && __bothSmallInteger(count, start)
     ) {
-	f = __FILEVal(fp);
-
-	oClass = __Class(anObject);
-	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
-	    case BYTEARRAY:
-	    case WORDARRAY:
-	    case LONGARRAY:
-	    case SWORDARRAY:
-	    case SLONGARRAY:
-	    case FLOATARRAY:
-	    case DOUBLEARRAY:
-		break;
-	    default:
-		goto bad;
-	}
-	cnt = __intVal(count);
-	offs = __intVal(start) - 1;
-	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
-	nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
-	objSize = __Size(anObject) - nInstBytes;
-	if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
-	    char *cp;
-
-	    /* 
-	     * mhmh - since we are interruptable, anObject may move.
-	     * therefore, fetch the cp-pointer within the loop
-	     */
-	    _buffered = (__INST(buffered) == true);
-	    if (_buffered) {
-		__READING__(f);
-	    }
-
-	    /*
-	     * on interrupt, anObject may be moved to another location.
-	     * So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__,
-	     * to get a new address.
-	     */
-	    o_offs = nInstBytes+offs;
-	    __READBYTES_OBJ__(ret, f, anObject, o_offs, cnt, _buffered);
-
-	    if (ret > 0) {
-		pos = __INST(position);
-		if (pos != nil) {
-		    __INST(position) = __MKSMALLINT(__intVal(pos) + ret);
-		}
-		RETURN (__MKSMALLINT(ret));
-	    }
-	    if (ret == 0) { 
-		__INST(hitEOF) = true;
-	    } else /* ret < 0 */ {
-		__INST(position) = nil;
-		__INST(lastErrorNumber) = __MKSMALLINT(errno);
-	    }
-	}
+        f = __FILEVal(fp);
+
+        oClass = __Class(anObject);
+        switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+            case BYTEARRAY:
+            case WORDARRAY:
+            case LONGARRAY:
+            case SWORDARRAY:
+            case SLONGARRAY:
+            case FLOATARRAY:
+            case DOUBLEARRAY:
+                break;
+            default:
+                goto bad;
+        }
+        cnt = __intVal(count);
+        offs = __intVal(start) - 1;
+        nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+        nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
+        objSize = __Size(anObject) - nInstBytes;
+        if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
+            _buffered = (__INST(buffered) == true);
+            if (_buffered) {
+                __READING__(f);
+            }
+
+            /*
+             * on interrupt, anObject may be moved to another location.
+             * So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__,
+             * to get a new address.
+             */
+            o_offs = nInstBytes+offs;
+            __READBYTES_OBJ__(ret, f, anObject, o_offs, cnt, _buffered);
+
+            if (ret > 0) {
+                pos = __INST(position);
+                if (pos != nil) {
+                    __INST(position) = __MKSMALLINT(__intVal(pos) + ret);
+                }
+                RETURN (__MKSMALLINT(ret));
+            }
+            if (ret == 0) { 
+                __INST(hitEOF) = true;
+            } else /* ret < 0 */ {
+                __INST(position) = nil;
+                __INST(lastErrorNumber) = __MKSMALLINT(errno);
+            }
+        }
     }
 bad: ;
 %}.
@@ -3466,7 +3462,7 @@
     FILEPOINTER f;
     OBJ fp;
     char c;
-    int ret;
+    int ret, _buffered;
 
     if (__INST(hitEOF) == true) {
         RETURN (true);
@@ -3477,35 +3473,20 @@
     if ((fp = __INST(filePointer)) != nil) {
         f = __FILEVal(fp);
 
-        if (__INST(buffered) == false) {
+        if (_buffered = (__INST(buffered) == true)) {
+            __READING__(f);
+        } else {
             if (__INST(readAhead) != nil) {
                 RETURN (false);
             }
-            /*
-             * read ahead ...
-             */
-            __READBYTE__(ret, f, &c, 0);
-            if (ret > 0) {
-                __UNGETC__(c, f, 0);
-            }
-        } else {
-            /*
-             * This does not work:
-             *  RETURN ( feof(f) ? true : false );
-             *     libc tests, if EOF has already bean read,
-             *     smallatalk asks, if next read will return EOF
-             */
-
-            __READING__(f)
-            __BEGIN_INTERRUPTABLE__
-            __READBYTE__(ret, f, &c, 1);
-            __END_INTERRUPTABLE__
-            if (ret > 0) {
-                __UNGETC__(c, f, 1);
-            }
         }
 
+        /*
+         * read ahead ...
+         */
+        __READBYTE__(ret, f, &c, _buffered);
         if (ret > 0) {
+            __UNGETC__(c&0xff, f, _buffered);
             RETURN (false);
         }
 
@@ -3950,6 +3931,6 @@
 !ExternalStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.136 1997-08-12 00:30:45 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.137 1997-08-19 09:16:52 stefan Exp $'
 ! !
 ExternalStream initialize!