ExtStream.st
changeset 362 4131e87e79ec
parent 360 90c3608b92a3
child 369 730e0f5d2404
--- a/ExtStream.st	Mon Jul 03 04:38:27 1995 +0200
+++ b/ExtStream.st	Sat Jul 22 21:25:26 1995 +0200
@@ -24,7 +24,7 @@
 COPYRIGHT (c) 1988 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/Attic/ExtStream.st,v 1.40 1995-07-02 01:06:38 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/ExtStream.st,v 1.41 1995-07-22 19:22:27 claus Exp $
 '!
 
 !ExternalStream primitiveDefinitions!
@@ -58,7 +58,6 @@
 	fseek(f, 0L, 1); /* needed in stdio */  \
     }
 
-extern int __immediateInterrupt__;
 /*
  * on some systems errno is a macro ... check for it here
  */
@@ -87,7 +86,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/Attic/ExtStream.st,v 1.40 1995-07-02 01:06:38 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/ExtStream.st,v 1.41 1995-07-22 19:22:27 claus Exp $
 "
 !
 
@@ -369,9 +368,9 @@
 
     if ((fp = _INST(filePointer)) != nil) {
 	_INST(filePointer) = nil;
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 	fclose(MKFD(fp));
-	__immediateInterrupt__ = 0;
+	__END_INTERRUPTABLE__
     }
 %}
 !
@@ -389,10 +388,10 @@
 
     if ((fp = _INST(filePointer)) != nil) {
 	_INST(filePointer) = nil;
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 	f = MKFD(fp);
 	close(fileno(f));
-	__immediateInterrupt__ = 0;
+	__END_INTERRUPTABLE__
     }
 %}
 ! !
@@ -809,11 +808,11 @@
 	    ioNum = __intVal(ioctlNumber);
 	    f = MKFD(fp);
 
-	    __immediateInterrupt__ = 1;
+	    __BEGIN_INTERRUPTABLE__
 	    do {
 		ret = ioctl(fileno(f), ioNum);
 	    } while ((ret < 0) && (errno == EINTR));
-	    __immediateInterrupt__ = 0;
+	    __END_INTERRUPTABLE__
 
 	    if (ret >= 0) {
 		RETURN ( __MKSMALLINT(ret) );
@@ -851,7 +850,7 @@
 	    f = MKFD(fp);
 	    ioNum = __intVal(ioctlNumber);
 
-	    __immediateInterrupt__ = 1;
+	    __BEGIN_INTERRUPTABLE__
 	    do {
 		if (__isSmallInteger(arg)) {
 		    ret = ioctl(fileno(f), ioNum, __intVal(arg));
@@ -859,7 +858,7 @@
 		    ret = ioctl(fileno(f), ioNum, __ByteArrayInstPtr(arg)->ba_element);
 		}
 	    } while ((ret < 0) && (errno == EINTR));
-	    __immediateInterrupt__ = 0;
+	    __END_INTERRUPTABLE__
 
 	    if (ret >= 0) {
 		RETURN ( __MKSMALLINT(ret) );
@@ -896,7 +895,7 @@
      && (_INST(mode) != @symbol(writeonly))) {
 	f = MKFD(fp);
 
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 	do {
 	    if (_INST(buffered) == false) {
 		cnt = read(fileno(f), &byte, 1);
@@ -905,7 +904,7 @@
 		cnt = fread(&byte, 1, 1, f);
 	    }
 	} while ((cnt < 0) && (errno == EINTR));
-	__immediateInterrupt__ = 0;
+	__END_INTERRUPTABLE__
 
 	if (cnt == 1) {
 	    if (_INST(position) != nil)
@@ -1013,7 +1012,7 @@
 	    if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
 		cp = (char *)__InstPtr(anObject) + nInstBytes + offs;
 
-		__immediateInterrupt__ = 1;
+		__BEGIN_INTERRUPTABLE__
 		do {
 		    if (_INST(buffered) == false) {
 			cnt = read(fileno(f), cp, cnt);
@@ -1022,7 +1021,7 @@
 			cnt = fread(cp, 1, cnt, f);
 		    }
 		} while ((cnt < 0) && (errno == EINTR));
-		__immediateInterrupt__ = 0;
+		__END_INTERRUPTABLE__
 
 		if (cnt >= 0) {
 		    if (cnt == 0)
@@ -1068,7 +1067,7 @@
 	short value;
 
 	f = MKFD(fp);
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 	__READING__(f)
 
 	do {
@@ -1080,7 +1079,7 @@
 		second = getc(f);
 	    } while ((second < 0) && (errno == EINTR));
 
-	    __immediateInterrupt__ = 0;
+	    __END_INTERRUPTABLE__
 	    if (second != EOF) {
 		if (_INST(position) != nil) {
 		    _INST(position) = __MKSMALLINT(__intVal(_INST(position)) + 2);
@@ -1093,7 +1092,7 @@
 		RETURN (__MKSMALLINT(value));
 	    }
 	}
-	__immediateInterrupt__ = 0;
+	__END_INTERRUPTABLE__
 
 	if (ferror(f) && (errno != 0)) {
 	    _INST(position) = nil;
@@ -1127,17 +1126,19 @@
 	unsigned value;
 
 	f = MKFD(fp);
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 	__READING__(f)
 
 	do {
 	    first = getc(f);
 	} while ((first < 0) && (errno == EINTR));
+
 	if (first != EOF) {
 	    do {
 		second = getc(f);
 	    } while ((second < 0) && (errno == EINTR));
-	    __immediateInterrupt__ = 0;
+
+	    __END_INTERRUPTABLE__
 	    if (second != EOF) {
 		if (_INST(position) != nil) {
 		    _INST(position) = __MKSMALLINT(__intVal(_INST(position)) + 2);
@@ -1150,7 +1151,7 @@
 		RETURN (__MKSMALLINT(value));
 	    }
 	}
-	__immediateInterrupt__ = 0;
+	__END_INTERRUPTABLE__
 
 	if (ferror(f) && (errno != 0)) {
 	    _INST(position) = nil;
@@ -1185,7 +1186,7 @@
 	int value;
 
 	f = MKFD(fp);
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 	__READING__(f)
 
 	do {
@@ -1204,7 +1205,8 @@
 			fourth = getc(f);
 		    } while ((fourth < 0) && (errno == EINTR));
 		    if (fourth != EOF) {
-			__immediateInterrupt__ = 0;
+			__END_INTERRUPTABLE__
+
 			if (msbFlag == true) {
 			    value = (first & 0xFF);
 			    value = (value<<8) | (second & 0xFF);
@@ -1227,6 +1229,8 @@
 		}
 	    }
 	}
+	__END_INTERRUPTABLE__
+
 	if (ferror(f) && (errno != 0)) {
 	    _INST(lastErrorNumber) = __MKSMALLINT(errno);
 	    _INST(position) = nil;
@@ -1260,7 +1264,7 @@
 	unsigned int value;
 
 	f = MKFD(fp);
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 	__READING__(f)
 
 	do {
@@ -1279,7 +1283,8 @@
 			fourth = getc(f);
 		    } while ((fourth < 0) && (errno == EINTR));
 		    if (fourth != EOF) {
-			__immediateInterrupt__ = 0;
+			__END_INTERRUPTABLE__
+
 			if (msbFlag == true) {
 			    value = (first & 0xFF);
 			    value = (value<<8) | (second & 0xFF);
@@ -1302,6 +1307,8 @@
 		}
 	    }
 	}
+	__END_INTERRUPTABLE__
+
 	if (ferror(f) && (errno != 0)) {
 	    _INST(lastErrorNumber) = __MKSMALLINT(errno);
 	    _INST(position) = nil;
@@ -1357,7 +1364,7 @@
 	if (__isSmallInteger(aByteValue)) {
 	    c = __intVal(aByteValue);
 	    f = MKFD(fp);
-	    __immediateInterrupt__ = 1;
+	    __BEGIN_INTERRUPTABLE__
 #ifdef OLD
 	    if (_INST(buffered) == false) {
 		cnt = write(fileno(f), &c, 1);
@@ -1372,7 +1379,8 @@
 		}
 #endif
 	    }
-	    __immediateInterrupt__ = 0;
+	    __END_INTERRUPTABLE__
+
 	    if (cnt == 1) {
 		pos = _INST(position);
 		if (pos != nil)
@@ -1456,7 +1464,7 @@
 	    objSize = __Size(anObject) - nInstBytes;
 	    if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
 		cp = (char *)__InstPtr(anObject) + nInstBytes + offs;
-		__immediateInterrupt__ = 1;
+		__BEGIN_INTERRUPTABLE__
 #ifdef OLD
 		if (_INST(buffered) == false) {
 		    cnt = write(fileno(f), cp, cnt);
@@ -1471,7 +1479,8 @@
 		    fflush(f);
 		}
 #endif
-		__immediateInterrupt__ = 0;
+		__END_INTERRUPTABLE__
+
 		if (cnt >= 0) {
 		    pos = _INST(position);
 		    if (pos != nil)
@@ -1518,7 +1527,7 @@
 	}
 
 	f = MKFD(fp);
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 #ifdef OLD
 	if (_INST(buffered) == false) {
 	    cnt = write(fileno(f), bytes, 2);
@@ -1533,7 +1542,8 @@
 	    fflush(f);
 	}
 #endif
-	__immediateInterrupt__ = 0;
+	__END_INTERRUPTABLE__
+
 	if (cnt == 2) {
 	    if (_INST(position) != nil) {
 		_INST(position) = __MKSMALLINT(__intVal(_INST(position)) + 2);
@@ -1581,7 +1591,7 @@
 	}
 
 	f = MKFD(fp);
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 #ifdef OLD
 	if (_INST(buffered) == false) {
 	    cnt = write(fileno(f), bytes, 4);
@@ -1596,7 +1606,8 @@
 	    fflush(f);
 	}
 #endif
-	__immediateInterrupt__ = 0;
+	__END_INTERRUPTABLE__
+
 	if (cnt == 4) {
 	    if (_INST(position) != nil) {
 		_INST(position) = __MKSMALLINT(__intVal(_INST(position)) + 4);
@@ -1645,13 +1656,14 @@
 #endif
 	{
 	    f = MKFD(fp);
-	    __immediateInterrupt__ = 1;
+
+	    __BEGIN_INTERRUPTABLE__
 	    __READING__(f)
 
 	    do {
 		c = getc(f);
 	    } while ((c < 0) && (errno == EINTR));
-	    __immediateInterrupt__ = 0;
+	    __END_INTERRUPTABLE__
 
 	    if (c != EOF) {
 		ungetc(c, f);
@@ -1691,7 +1703,7 @@
     if (((fp = _INST(filePointer)) != nil)
      && (_INST(mode) != @symbol(writeonly))) {
 	f = MKFD(fp);
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 	__READING__(f)
 
 	do {
@@ -1708,7 +1720,7 @@
 	    }
 	} while ((c < 0) && (errno == EINTR));
 
-	__immediateInterrupt__ = 0;
+	__END_INTERRUPTABLE__
 
 	if (c != EOF) {
 	    pos = _INST(position);
@@ -1771,7 +1783,9 @@
     if ((fp = _INST(filePointer)) != nil) {
 	if (_INST(mode) != @symbol(readonly)) {
 	    if (_INST(buffered) == true) {
+		__BEGIN_INTERRUPTABLE__
 		fflush( MKFD(fp) );
+		__END_INTERRUPTABLE__
 	    }
 	}
     }
@@ -1797,7 +1811,7 @@
     doWrite:
 		f = MKFD(fp);
 
-		__immediateInterrupt__ = 1;
+		__BEGIN_INTERRUPTABLE__
 
 		__WRITING__(f)
 
@@ -1809,7 +1823,8 @@
 		    fflush(f);
 		}
 
-		__immediateInterrupt__ = 0;
+		__END_INTERRUPTABLE__
+
 		if (cnt == 1) {
 		    pos = _INST(position);
 		    if (pos != nil) {
@@ -1874,7 +1889,7 @@
 	if (cp != NULL) {
 	    f = MKFD(fp);
 
-	    __immediateInterrupt__ = 1;
+	    __BEGIN_INTERRUPTABLE__
 #ifdef OLD
 	    if (_INST(buffered) == false) {
 		cnt = write(fileno(f), cp, len);
@@ -1895,11 +1910,11 @@
 		} while ((cnt != len) && (errno == EINTR));
 	    }
 #ifndef OLD
-		    if (_INST(buffered) == false) {
-			fflush(f);
-		    }
+	    if (_INST(buffered) == false) {
+		fflush(f);
+	    }
 #endif
-	    __immediateInterrupt__ = 0;
+	    __END_INTERRUPTABLE__
 	    if (cnt == len) {
 		pos = _INST(position);
 		if (pos != nil) {
@@ -1963,7 +1978,7 @@
 		if (index2 > len)
 		    index2 = len;
 
-		__immediateInterrupt__ = 1;
+		__BEGIN_INTERRUPTABLE__
 		len = index2 - index1 + 1;
 
 		__WRITING__(f)
@@ -1984,7 +1999,7 @@
 		    fflush(f);
 		}
 
-		__immediateInterrupt__ = 0;
+		__END_INTERRUPTABLE__
 		if (cnt == len) {
 		    if (_INST(position) != nil) {
 			_INST(position) = __MKSMALLINT(__intVal(_INST(position)) + len);
@@ -2015,7 +2030,7 @@
 	if (_INST(binary) != true) {
 	    f = MKFD(fp);
 
-	    __immediateInterrupt__ = 1;
+	    __BEGIN_INTERRUPTABLE__
 
 	    __WRITING__(f)
 
@@ -2027,7 +2042,7 @@
 		fflush(f);
 	    }
 
-	    __immediateInterrupt__ = 0;
+	    __END_INTERRUPTABLE__
 	    if (cnt == 1) {
 		if (_INST(position) != nil) {
 		    _INST(position) = __MKSMALLINT(__intVal(_INST(position)) + 1);
@@ -2068,7 +2083,7 @@
      && (_INST(mode) != @symbol(writeonly))) {
 	if (_INST(binary) != true) {
 	    f = MKFD(fp);
-	    __immediateInterrupt__ = 1;
+	    __BEGIN_INTERRUPTABLE__
 	    buffer[0] = 0;
 
 	    _buffered = (_INST(buffered) == true);
@@ -2137,7 +2152,7 @@
 		}
 	    }
 #endif
-	    __immediateInterrupt__ = 0;
+	    __END_INTERRUPTABLE__
 	    if (rslt != NULL) {
 		len = strlen(buffer);
 		if (_INST(position) != nil) {
@@ -2186,7 +2201,7 @@
 		s = (char *) _stringVal(aString);
 		len = _stringSize(aString);
 
-		__immediateInterrupt__ = 1;
+		__BEGIN_INTERRUPTABLE__
 #ifdef OLD
 		if (_INST(buffered) == false) {
 		    cnt = write(fileno(f), s, len);
@@ -2215,11 +2230,11 @@
 			if (pos != nil) {
 			    _INST(position) = __MKSMALLINT(__intVal(pos)+len+1);
 			}
-			__immediateInterrupt__ = 0;
+			__END_INTERRUPTABLE__
 			RETURN ( self );
 		    }
 		}
-		__immediateInterrupt__ = 0;
+		__END_INTERRUPTABLE__
 		_INST(lastErrorNumber) = __MKSMALLINT(errno);
 	    }
 	}
@@ -2262,7 +2277,7 @@
 	    }
 	    dst = MKFD(_INST(filePointer));
 	    src = (FILE *)__intVal(srcFilePointer);
-	    __immediateInterrupt__ = 1;
+	    __BEGIN_INTERRUPTABLE__
 	    errno = 0;
 
 	    __WRITING__(dst)
@@ -2271,6 +2286,7 @@
 		if (fgets(buffer, sizeof(buffer), src) == NULL) {
 		    if (ferror(src)) {
 			readError = __MKSMALLINT(errno);
+			__END_INTERRUPTABLE__
 			goto err;
 		    }
 		    break;
@@ -2278,6 +2294,7 @@
 		if (fputs(buffer, dst) == EOF) {
 		    if (ferror(dst)) {
 			_INST(lastErrorNumber) = __MKSMALLINT(errno);
+			__END_INTERRUPTABLE__
 			goto err;
 		    }
 		    break;
@@ -2292,7 +2309,7 @@
 			break;
 		}
 	    }
-	    __immediateInterrupt__ = 0;
+	    __END_INTERRUPTABLE__
 	    _INST(position) = nil;
 	    RETURN (self);
 	}
@@ -2342,11 +2359,11 @@
 	    lastpos = ftell(f);
 	    if (firstpos == -1) firstpos = lastpos;
 
-	    __immediateInterrupt__ = 1;
+	    __BEGIN_INTERRUPTABLE__
 	    do {
 		cp = fgets(buffer, sizeof(buffer), f);
 	    } while ((cp == NULL) && (errno == EINTR));
-	    __immediateInterrupt__ = 0;
+	    __END_INTERRUPTABLE__
 
 	    if (cp == NULL) {
 		if (ferror(f)) {
@@ -2427,11 +2444,11 @@
 #else
 	__READING__(f)
 
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 	do {
 	    c = getc(f);
 	} while ((c < 0) && (errno == EINTR) && (clearerr(f), 1));
-	__immediateInterrupt__ = 0;
+	__END_INTERRUPTABLE__
 
 	if (c != EOF) {
 	    ungetc(c, f);
@@ -2496,14 +2513,24 @@
      return immediate. 
      The other threads are not affected by the wait."
 
-    self readWaitWithTimeout:nil
+    self readWaitWithTimeoutMs:nil
 !
 
 readWaitWithTimeout:timeout
     "suspend the current process, until the receiver
      becomes ready for reading or a timeout (in seconds) expired. 
      If data is already available, return immediate. 
-     Return true if data is available, false if not (i.e. a timeout occured).
+     Return true if a timeout occured (i.e. false, if data is available).
+     The other threads are not affected by the wait."
+
+    ^ self readWaitWithTimeoutMs:timeout * 1000
+!
+
+readWaitWithTimeoutMs:timeout 
+    "suspend the current process, until the receiver
+     becomes ready for reading or a timeout (in milliseconds) expired. 
+     If data is already available, return immediate. 
+     Return true if a timeout occured (i.e. false, if data is available).
      The other threads are not affected by the wait."
 
     |fd inputSema hasData wasBlocked|
@@ -2512,7 +2539,7 @@
     mode == #writeonly ifTrue:[^ self errorWriteOnly].
 
     fd := self fileDescriptor.
-    (OperatingSystem readCheck:fd) ifTrue:[^ true].
+    (OperatingSystem readCheck:fd) ifTrue:[^ false].
 
     wasBlocked := OperatingSystem blockInterrupts.
     hasData := OperatingSystem readCheck:fd.
@@ -2520,7 +2547,7 @@
 	inputSema := Semaphore new.
 	[
 	    timeout notNil ifTrue:[
-		Processor signal:inputSema afterSeconds:timeout
+		Processor signal:inputSema afterMilliseconds:timeout 
 	    ].
 	    Processor signal:inputSema onInput:fd.
 	    Processor activeProcess state:#ioWait.
@@ -2533,7 +2560,7 @@
 	]
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-    ^ hasData
+    ^ hasData not
 !
 
 writeWait
@@ -2542,13 +2569,23 @@
      Return immediate if the receiver is already ready. 
      The other threads are not affected by the wait."
 
-    self writeWaitWithTimeout:nil
+    self writeWaitWithTimeoutMs:nil
 !
 
 writeWaitWithTimeout:timeout
     "suspend the current process, until the receiver
      becomes ready for writing or a timeout (in seconds) expired. 
-     Return true if data can be written, false if not (i.e. a timeout occured).
+     Return true if a timeout occured (i.e. false, if data is available).
+     Return immediate if the receiver is already ready. 
+     The other threads are not affected by the wait."
+
+    ^ self writeWaitWithTimeoutMs:timeout * 1000
+!
+
+writeWaitWithTimeoutMs:timeout
+    "suspend the current process, until the receiver
+     becomes ready for writing or a timeout (in seconds) expired. 
+     Return true if a timeout occured (i.e. false, if data is available).
      Return immediate if the receiver is already ready. 
      The other threads are not affected by the wait."
 
@@ -2562,7 +2599,7 @@
     ].
 
     fd := self fileDescriptor.
-    (OperatingSystem writeCheck:fd) ifTrue:[^ true].
+    (OperatingSystem writeCheck:fd) ifTrue:[^ false].
 
     wasBlocked := OperatingSystem blockInterrupts.
     canWrite := OperatingSystem writeCheck:fd.
@@ -2570,7 +2607,7 @@
 	outputSema := Semaphore new.
 	[
 	    timeout notNil ifTrue:[
-		Processor signal:outputSema afterSeconds:timeout
+		Processor signal:outputSema afterMilliseconds:timeout
 	    ].
 	    Processor signal:outputSema onOutput:fd.
 	    Processor activeProcess state:#ioWait.
@@ -2583,7 +2620,7 @@
 	]
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-    ^ canWrite
+    ^ canWrite not
 ! !
      
 !ExternalStream methodsFor:'reimplemented for speed'!
@@ -2620,11 +2657,11 @@
 	f = MKFD(fp);
 	__READING__(f)
 
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 	do {
 	    c = getc(f);
 	} while ((c < 0) && (errno == EINTR));
-	__immediateInterrupt__ = 0;
+	__END_INTERRUPTABLE__
 
 	if (c == peekValue) {
 	    OBJ pos;
@@ -2682,7 +2719,7 @@
 	if (peekValue >= 0) {
 	    _INST(position) = nil;
 	    f = MKFD(fp);
-	    __immediateInterrupt__ = 1;
+	    __BEGIN_INTERRUPTABLE__
 	    __READING__(f)
 
 	    for (;;) {
@@ -2691,7 +2728,7 @@
 		} while ((c < 0) && (errno == EINTR));
                 
 		if (c == EOF) {
-		    __immediateInterrupt__ = 0;
+		    __END_INTERRUPTABLE__
 		    if (ferror(f) && (errno != 0)) {
 			_INST(lastErrorNumber) = __MKSMALLINT(errno);
 			break;
@@ -2700,7 +2737,7 @@
 		    RETURN (nil);
 		}
 		if (c == peekValue) {
-		    __immediateInterrupt__ = 0;
+		    __END_INTERRUPTABLE__
 		    RETURN (anObject);
 		}
 	    }
@@ -2731,12 +2768,12 @@
             
 	    __READING__(f)
 
-	    __immediateInterrupt__ = 1;
+	    __BEGIN_INTERRUPTABLE__
 	    if (fgets(buffer, sizeof(buffer), f) != NULL) {
-		__immediateInterrupt__ = 0;
+		__END_INTERRUPTABLE__
 		RETURN ( self );
 	    }
-	    __immediateInterrupt__ = 0;
+	    __END_INTERRUPTABLE__
 
 	    if (ferror(f) && (errno != 0)) {
 		_INST(lastErrorNumber) = __MKSMALLINT(errno);
@@ -2851,11 +2888,11 @@
 	f = MKFD(fp);
 	__READING__(f)
 
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 	while (1) {
 #ifdef NOTNEEDED
 	    if (feof(f)) {
-		__immediateInterrupt__ = 0;
+		__END_INTERRUPTABLE__
 		RETURN ( nil );
 	    }
 #endif
@@ -2864,11 +2901,11 @@
 	    } while ((c < 0) && (errno == EINTR));
 
 	    if (c == cSearch) {
-		__immediateInterrupt__ = 0;
+		__END_INTERRUPTABLE__
 		RETURN (self);
 	    }
 	    if (c < 0) {
-		__immediateInterrupt__ = 0;
+		__END_INTERRUPTABLE__
 		if (ferror(f) && (errno != 0)) {
 		    _INST(lastErrorNumber) = __MKSMALLINT(errno);
 		    break;
@@ -2917,10 +2954,10 @@
             
 	    __READING__(f)
 
-	    __immediateInterrupt__ = 1;
+	    __BEGIN_INTERRUPTABLE__
 	    while (1) {
 		if (feof(f)) {
-		    __immediateInterrupt__ = 0;
+		    __END_INTERRUPTABLE__
 		    RETURN ( nil );
 		}
 
@@ -2938,7 +2975,7 @@
 			break;
 
 		    default:
-			__immediateInterrupt__ = 0;
+			__END_INTERRUPTABLE__
 			if (c < 0) {
 			    if (ferror(f) && (errno != 0)) {
 				_INST(lastErrorNumber) = __MKSMALLINT(errno);
@@ -2980,11 +3017,11 @@
 	    f = MKFD(fp);
 	    __READING__(f)
 
-	    __immediateInterrupt__ = 1;
+	    __BEGIN_INTERRUPTABLE__
 	    while (1) {
                 
 		if (feof(f)) {
-		    __immediateInterrupt__ = 0;
+		    __END_INTERRUPTABLE__
 		    RETURN ( nil );
 		}
 
@@ -2999,7 +3036,7 @@
 			break;
 
 		    default:
-			__immediateInterrupt__ = 0;
+			__END_INTERRUPTABLE__
 			if (c < 0) {
 			    if (ferror(f) && (errno != 0)) {
 				_INST(lastErrorNumber) = __MKSMALLINT(errno);
@@ -3037,17 +3074,18 @@
     if (((fp = _INST(filePointer)) != nil)
      && (_INST(mode) != @symbol(writeonly))) {
 	f = MKFD(fp);
-	__immediateInterrupt__ = 1;
+	__BEGIN_INTERRUPTABLE__
 	__READING__(f)
 
 	for (;;) {
 	    do {
 		ch = getc(f);
 	    } while ((ch < 0) && (errno == EINTR));
+
 	    if (ch < 0) {
 		if (ferror(f) && (errno != 0)) {
 		    _INST(lastErrorNumber) = __MKSMALLINT(errno);
-		    __immediateInterrupt__ = 0;
+		    __END_INTERRUPTABLE__
 		    goto err;
 		}
 		_INST(hitEOF) = true;
@@ -3070,7 +3108,7 @@
 	    if (ch < 0) {
 		if (ferror(f) && (errno != 0)) {
 		    _INST(lastErrorNumber) = __MKSMALLINT(errno);
-		    __immediateInterrupt__ = 0;
+		    __END_INTERRUPTABLE__
 		    goto err;
 		}
 		_INST(hitEOF) = true;
@@ -3091,7 +3129,7 @@
 		break;
 	    }
 	}
-	__immediateInterrupt__ = 0;
+	__END_INTERRUPTABLE__
 
 	if (_INST(position) != nil) {
 	    _INST(position) = __MKSMALLINT(__intVal(_INST(position)) + cnt);
@@ -3162,11 +3200,12 @@
     /*
      * skip spaces
      */
-    __immediateInterrupt__ = 1;
     while (! done) {
+	__BEGIN_INTERRUPTABLE__
 	do {
 	    c = getc(f);
 	} while ((c < 0) && (errno == EINTR));
+	__END_INTERRUPTABLE__
 
 	switch (c) {
 	    case ' ':
@@ -3178,7 +3217,6 @@
 		break;
 
 	    case EOF:
-		__immediateInterrupt__ = 0;
 		if (ferror(f) && (errno != 0)) {
 		    _INST(lastErrorNumber) = __MKSMALLINT(errno);
 		    goto err;
@@ -3198,10 +3236,7 @@
      */
     buffer = fastBuffer; fastFlag = 1;
     currSize = sizeof(fastBuffer);
-/*
-    buffer = (char *)malloc(3000);
-    currSize = 3000;
-*/
+
     index = 0;
     while (! feof(f)) {
 	/* 
@@ -3214,7 +3249,6 @@
 		 * mhmh - chunk seems to be very big ....
 		 */
 		outOfMemory = true;
-		__immediateInterrupt__ = 0;
 		goto err;
 	    }
 	    bcopy(buffer, newBuffer, index);
@@ -3226,14 +3260,19 @@
 	    buffer = newBuffer;
 	    currSize = currSize * 2;
 	}
+
+	__BEGIN_INTERRUPTABLE__
 	do {
 	    c = getc(f);
 	} while (c < 0 && (errno == EINTR));
+	__END_INTERRUPTABLE__
 
 	if (c == '%') {
+	    __BEGIN_INTERRUPTABLE__
 	    do {
 		peekC = getc(f);
 	    } while (peekC < 0 && (errno == EINTR));
+	    __END_INTERRUPTABLE__
 	    ungetc(peekC, f);
 	    if (peekC == '{') {
 		inPrimitive++;
@@ -3243,9 +3282,12 @@
 	} else {
 	    if (! inPrimitive) {
 		if (c == '!') {
+		    __BEGIN_INTERRUPTABLE__
 		    do {
 			c = getc(f);
 		    } while (c < 0 && (errno == EINTR));
+		    __END_INTERRUPTABLE__
+
 		    if (c != '!') {
 			ungetc(c, f);
 			break;
@@ -3255,7 +3297,6 @@
 	}
 
 	if (c < 0) {
-	    __immediateInterrupt__ = 0;
 	    if (ferror(f) && (errno != 0)) {
 		_INST(lastErrorNumber) = __MKSMALLINT(errno);
 		goto err;
@@ -3265,7 +3306,6 @@
 	}
 	buffer[index++] = c;
     }
-    __immediateInterrupt__ = 0;
 
     buffer[index] = '\0';
     /*