did report error in close always as writeError - although it could also happen on a readonly stream
authorClaus Gittinger <cg@exept.de>
Mon, 24 Nov 2014 15:37:58 +0100
changeset 17115 2ef08a902c34
parent 17114 592d806673a8
child 17116 9aee397f7f02
did report error in close always as writeError - although it could also happen on a readonly stream
ExternalStream.st
--- a/ExternalStream.st	Sun Nov 23 19:07:17 2014 +0100
+++ b/ExternalStream.st	Mon Nov 24 15:37:58 2014 +0100
@@ -202,7 +202,7 @@
 # define DEBUGBUFFER(buf)  \
     if (((char *)(buf) >= __survStartPtr) \
      && ((char *)(buf) < __survEndPtr)) { \
-        __fatal0("read into survivor\n"); \
+	__fatal0("read into survivor\n"); \
     }
 
 #else
@@ -225,33 +225,33 @@
 // Win returns from ReadFile() with false and _threadErrno == 0 on end of pipe.
 // We don't know why
 #  define READ(ret, f, cp, n, handleType) { \
-        if (handleType == @symbol(socketHandle)) { \
-          (ret) = __STX_WSA_NOINT_CALL4("recv", recv, (f), (cp), (n), 0); \
-        } else { \
-          HANDLE h = _get_osfhandle(fileno(f)); \
-          if (handleType == @symbol(socketFilePointer)) { \
-            (ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\
-          } else { \
-            int __res; \
-            (ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\
-            (ret) = (ret) ? __res : ((__threadErrno == EPIPE || __threadErrno == 0) ? 0 : -1); \
-          } \
-        } \
+	if (handleType == @symbol(socketHandle)) { \
+	  (ret) = __STX_WSA_NOINT_CALL4("recv", recv, (f), (cp), (n), 0); \
+	} else { \
+	  HANDLE h = _get_osfhandle(fileno(f)); \
+	  if (handleType == @symbol(socketFilePointer)) { \
+	    (ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\
+	  } else { \
+	    int __res; \
+	    (ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\
+	    (ret) = (ret) ? __res : ((__threadErrno == EPIPE || __threadErrno == 0) ? 0 : -1); \
+	  } \
+	} \
       }
 
 #  define WRITE(ret, f, cp, n, handleType) { \
-        if (handleType == @symbol(socketHandle)) { \
-          (ret) = __STX_WSA_NOINT_CALL4("send", send, (f), (cp), (n), 0); \
-        } else {\
-          HANDLE h = _get_osfhandle(fileno(f)); \
-          if (handleType == @symbol(socketFilePointer)) { \
-            (ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\
-          } else {\
-            int __res; \
-            (ret) = __STX_API_NOINT_CALL5("WriteFile", WriteFile, h, (cp), (n), &__res, 0);\
-            (ret) = (ret) ? __res : -1; \
-          } \
-        } \
+	if (handleType == @symbol(socketHandle)) { \
+	  (ret) = __STX_WSA_NOINT_CALL4("send", send, (f), (cp), (n), 0); \
+	} else {\
+	  HANDLE h = _get_osfhandle(fileno(f)); \
+	  if (handleType == @symbol(socketFilePointer)) { \
+	    (ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\
+	  } else {\
+	    int __res; \
+	    (ret) = __STX_API_NOINT_CALL5("WriteFile", WriteFile, h, (cp), (n), &__res, 0);\
+	    (ret) = (ret) ? __res : -1; \
+	  } \
+	} \
       }
 
 # define FFLUSH(fp)             fflush(fp)
@@ -262,56 +262,56 @@
 # define __READING__(f)                          \
     if ((__INST(didWrite) != false)              \
      && (__INST(mode) == @symbol(readwrite))) {  \
-        __INST(didWrite) = false;                \
-        OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
+	__INST(didWrite) = false;                \
+	OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
     }
 
 # define __WRITING__(f)                          \
     if ((__INST(didWrite) != true)               \
      && (__INST(mode) == @symbol(readwrite))) {  \
-        __INST(didWrite) = true;                 \
-        OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
+	__INST(didWrite) = true;                 \
+	OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
     }
 
 # define __UNGETC__(c, f, isBuffered)                   \
     if (isBuffered) {                                   \
-        ungetc((c), (f));                               \
+	ungetc((c), (f));                               \
     } else {                                            \
       __INST(readAhead) = __mkSmallInteger((c));        \
     }
 
 # define __READBYTE__(ret, f, buf, isBuffered, handleType) \
     if (isBuffered) {                                   \
-        for (;;) {                                      \
-            CLEAR_ERRNO;                                \
-            (ret) = getc(f);                            \
-            if ((ret) >= 0) {                           \
-                *(buf) = (ret);                         \
-                (ret) = 1;                              \
-            } else if (ferror(f)) {                     \
-                if (__threadErrno == EINTR) {           \
-                    clearerr(f);                        \
-                    continue;                           \
-                }                                       \
-            } else {                                    \
-                (ret) = 0;                              \
-            }                                           \
-            break;                                      \
-        }                                               \
+	for (;;) {                                      \
+	    CLEAR_ERRNO;                                \
+	    (ret) = getc(f);                            \
+	    if ((ret) >= 0) {                           \
+		*(buf) = (ret);                         \
+		(ret) = 1;                              \
+	    } else if (ferror(f)) {                     \
+		if (__threadErrno == EINTR) {           \
+		    clearerr(f);                        \
+		    continue;                           \
+		}                                       \
+	    } else {                                    \
+		(ret) = 0;                              \
+	    }                                           \
+	    break;                                      \
+	}                                               \
     } else {                                            \
-        OBJ rA = __INST(readAhead);                     \
-        if (rA != nil) {                                \
-            *(buf) = (char)__intVal(rA);                \
-            __INST(readAhead) = nil;                    \
-            (ret) = 1;                                  \
-        } else {                                        \
-            for (;;) {                                  \
-                CLEAR_ERRNO;                            \
-                READ((ret), f, buf, 1, handleType);       \
-                if ((ret) >= 0 || __threadErrno != EINTR) \
-                    break;                              \
-            }                                           \
-        }                                               \
+	OBJ rA = __INST(readAhead);                     \
+	if (rA != nil) {                                \
+	    *(buf) = (char)__intVal(rA);                \
+	    __INST(readAhead) = nil;                    \
+	    (ret) = 1;                                  \
+	} else {                                        \
+	    for (;;) {                                  \
+		CLEAR_ERRNO;                            \
+		READ((ret), f, buf, 1, handleType);       \
+		if ((ret) >= 0 || __threadErrno != EINTR) \
+		    break;                              \
+	    }                                           \
+	}                                               \
     }
 
   /*
@@ -321,110 +321,110 @@
 # define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType)    \
     (ret) = 0;                                          \
     if (isBuffered) {                                   \
-        int __offs = 0;                                 \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = getc(f);                            \
-            if ((ret) < 0) {                            \
-                if (ferror(f)) {                        \
-                    if (__threadErrno == EINTR) {       \
-                        clearerr(f);                    \
-                        continue;                       \
-                    }                                   \
-                } else {                                \
-                    (ret) = 0;                          \
-                }                                       \
-                break;                                  \
-            }                                           \
-            (buf)[__offs++] = (ret);                    \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int __offs = 0;                                 \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    (ret) = getc(f);                            \
+	    if ((ret) < 0) {                            \
+		if (ferror(f)) {                        \
+		    if (__threadErrno == EINTR) {       \
+			clearerr(f);                    \
+			continue;                       \
+		    }                                   \
+		} else {                                \
+		    (ret) = 0;                          \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    (buf)[__offs++] = (ret);                    \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     } else {                                            \
-        int __offs = 0;                                 \
-                                                        \
-        while (__offs < (cnt)) {                        \
-            OBJ rA = __INST(readAhead);                 \
-            if (rA != nil) {                            \
-                (buf)[__offs] = __intVal(rA);           \
-                __INST(readAhead) = nil;                \
-                (ret) = 1;                              \
-            } else {                                    \
-                CLEAR_ERRNO;                            \
-                READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \
-                if ((ret) <= 0) {                       \
-                    if ((ret) < 0 && __threadErrno == EINTR) {  \
-                        continue;                       \
-                    }                                   \
-                    break;                              \
-                }                                       \
-            }                                           \
-            __offs += (ret);                            \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int __offs = 0;                                 \
+							\
+	while (__offs < (cnt)) {                        \
+	    OBJ rA = __INST(readAhead);                 \
+	    if (rA != nil) {                            \
+		(buf)[__offs] = __intVal(rA);           \
+		__INST(readAhead) = nil;                \
+		(ret) = 1;                              \
+	    } else {                                    \
+		CLEAR_ERRNO;                            \
+		READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \
+		if ((ret) <= 0) {                       \
+		    if ((ret) < 0 && __threadErrno == EINTR) {  \
+			continue;                       \
+		    }                                   \
+		    break;                              \
+		}                                       \
+	    }                                           \
+	    __offs += (ret);                            \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
    }
 
 # define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \
   {                                                     \
     int __offs = 0;                                     \
     int oldFlags;                                       \
-                                                        \
+							\
     (ret) = 0;                                          \
     if (isBuffered) {                                   \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = getc(f);                            \
-            if ((ret) < 0) {                            \
-                if (ferror(f)) {                        \
-                    if (__threadErrno == EINTR) {       \
-                        clearerr(f);                    \
-                        continue;                       \
-                    }                                   \
-                } else {                                \
-                    (ret) = 0;                          \
-                }                                       \
-                break;                                  \
-            }                                           \
-            (buf)[__offs++] = (ret);                    \
-        }                                               \
-        (ret) = __offs;                                 \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    (ret) = getc(f);                            \
+	    if ((ret) < 0) {                            \
+		if (ferror(f)) {                        \
+		    if (__threadErrno == EINTR) {       \
+			clearerr(f);                    \
+			continue;                       \
+		    }                                   \
+		} else {                                \
+		    (ret) = 0;                          \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    (buf)[__offs++] = (ret);                    \
+	}                                               \
+	(ret) = __offs;                                 \
     } else {                                            \
-        while (__offs < (cnt)) {                        \
-            OBJ rA = __INST(readAhead);                 \
-            if (rA != nil) {                            \
-                (buf)[__offs] = __intVal(rA);           \
-                __INST(readAhead) = nil;                \
-                (ret) = 1;                              \
-                __offs ++;                              \
-                continue;                               \
-            }                                           \
-            CLEAR_ERRNO;                                \
-            {                                           \
-              int res = 0;                              \
-              if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res), 1)) \
-                  || (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \
-                  || (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0), 1))) { \
-                  if (res > 0) {                        \
-                      if (res > ((cnt)-__offs))         \
-                          res = (cnt)-__offs;           \
-                      READ((ret), f, (buf)+__offs, res, handleType); \
-                  } else {                              \
-                      (ret) = 0;                        \
-                      break;                            \
-                  }                                     \
-              } else {                                  \
-                  READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \
-              }                                         \
-            }                                           \
-            if ((ret) <= 0) {                           \
-                if (ret < 0 && __threadErrno == EINTR)  \
-                    continue;                           \
-                break;                                  \
-            }                                           \
-            __offs += (ret);                            \
-        }                                               \
-        (ret) = __offs;                                 \
+	while (__offs < (cnt)) {                        \
+	    OBJ rA = __INST(readAhead);                 \
+	    if (rA != nil) {                            \
+		(buf)[__offs] = __intVal(rA);           \
+		__INST(readAhead) = nil;                \
+		(ret) = 1;                              \
+		__offs ++;                              \
+		continue;                               \
+	    }                                           \
+	    CLEAR_ERRNO;                                \
+	    {                                           \
+	      int res = 0;                              \
+	      if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res), 1)) \
+		  || (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \
+		  || (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0), 1))) { \
+		  if (res > 0) {                        \
+		      if (res > ((cnt)-__offs))         \
+			  res = (cnt)-__offs;           \
+		      READ((ret), f, (buf)+__offs, res, handleType); \
+		  } else {                              \
+		      (ret) = 0;                        \
+		      break;                            \
+		  }                                     \
+	      } else {                                  \
+		  READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \
+	      }                                         \
+	    }                                           \
+	    if ((ret) <= 0) {                           \
+		if (ret < 0 && __threadErrno == EINTR)  \
+		    continue;                           \
+		break;                                  \
+	    }                                           \
+	    __offs += (ret);                            \
+	}                                               \
+	(ret) = __offs;                                 \
     }                                                   \
   }
 
@@ -435,63 +435,63 @@
     int __ooffs = obj_offs;                             \
     int __offs = 0;                                     \
     char *buf = (char *)(obj);                          \
-                                                        \
+							\
     (ret) = 0;                                          \
     if (isBuffered) {                                   \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = getc(f);                            \
-            if ((ret) < 0) {                            \
-                if (ferror(f)) {                        \
-                    if (__threadErrno == EINTR) {       \
-                        clearerr(f);                    \
-                        /* refetch */                   \
-                        buf = (char *)(obj);   \
-                        continue;                       \
-                    }                                   \
-                } else {                                \
-                    (ret) = 0;                          \
-                }                                       \
-                break;                                  \
-            }                                           \
-            (buf)[__ooffs+__offs] = (ret);              \
-            __offs++;                                   \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    (ret) = getc(f);                            \
+	    if ((ret) < 0) {                            \
+		if (ferror(f)) {                        \
+		    if (__threadErrno == EINTR) {       \
+			clearerr(f);                    \
+			/* refetch */                   \
+			buf = (char *)(obj);   \
+			continue;                       \
+		    }                                   \
+		} else {                                \
+		    (ret) = 0;                          \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    (buf)[__ooffs+__offs] = (ret);              \
+	    __offs++;                                   \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     } else {                                            \
-        while (__offs < (cnt)) {                        \
-            char __buf[IO_BUFFER_SIZE];                 \
-            OBJ rA = __INST(readAhead);                 \
-            if (rA != nil) {                            \
-                (buf)[__ooffs+__offs] = __intVal(rA);   \
-                __INST(readAhead) = nil;                \
-                (ret) = 1;                              \
-            } else {                                    \
-                int l;                                  \
-                CLEAR_ERRNO;                            \
-                l = (cnt)-__offs;                       \
-                if ( l > IO_BUFFER_SIZE)                \
-                  l = IO_BUFFER_SIZE;                   \
-                READ((ret),f, __buf, l, handleType);                  \
-                if ((ret) <= 0) {                       \
-                    if ((ret) < 0 && __threadErrno == EINTR) {  \
-                        continue;                       \
-                    }                                   \
-                    break;                              \
-                }                                       \
-            }                                           \
-            if ((ret) > 0 ) {                           \
-                /* refetch */                               \
-                buf = (char *)(obj);               \
-                memcpy((buf)+__ooffs+__offs,__buf,(ret));   \
-                __offs += (ret);                            \
-            } else {                                        \
-                (ret) = 0;                                  \
-            }                                               \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	while (__offs < (cnt)) {                        \
+	    char __buf[IO_BUFFER_SIZE];                 \
+	    OBJ rA = __INST(readAhead);                 \
+	    if (rA != nil) {                            \
+		(buf)[__ooffs+__offs] = __intVal(rA);   \
+		__INST(readAhead) = nil;                \
+		(ret) = 1;                              \
+	    } else {                                    \
+		int l;                                  \
+		CLEAR_ERRNO;                            \
+		l = (cnt)-__offs;                       \
+		if ( l > IO_BUFFER_SIZE)                \
+		  l = IO_BUFFER_SIZE;                   \
+		READ((ret),f, __buf, l, handleType);                  \
+		if ((ret) <= 0) {                       \
+		    if ((ret) < 0 && __threadErrno == EINTR) {  \
+			continue;                       \
+		    }                                   \
+		    break;                              \
+		}                                       \
+	    }                                           \
+	    if ((ret) > 0 ) {                           \
+		/* refetch */                               \
+		buf = (char *)(obj);               \
+		memcpy((buf)+__ooffs+__offs,__buf,(ret));   \
+		__offs += (ret);                            \
+	    } else {                                        \
+		(ret) = 0;                                  \
+	    }                                               \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     }                                                   \
   }
 
@@ -500,141 +500,141 @@
     int __ooffs = obj_offs;                          \
     int __offs = 0;                                  \
     char *buf = (char *)(obj);                       \
-                                                     \
+						     \
     (ret) = 0;                                       \
     if (isBuffered) {                                \
-        while (__offs < (cnt)) {                     \
-            CLEAR_ERRNO;                             \
-            (ret) = getc(f);                         \
-            if ((ret) < 0) {                         \
-                if (ferror(f)) {                     \
-                    if (__threadErrno == EINTR) {    \
-                        clearerr(f);                 \
-                        /* refetch */                \
-                        buf = (char *)(obj);\
-                        continue;                    \
-                    }                                \
-                } else {                             \
-                    (ret) = 0;                       \
-                }                                    \
-                break;                               \
-            }                                        \
-            (buf)[__ooffs+__offs] = (ret);           \
-            __offs++;                                \
-        }                                            \
-        if (__offs > 0)                              \
-            (ret) = __offs;                          \
+	while (__offs < (cnt)) {                     \
+	    CLEAR_ERRNO;                             \
+	    (ret) = getc(f);                         \
+	    if ((ret) < 0) {                         \
+		if (ferror(f)) {                     \
+		    if (__threadErrno == EINTR) {    \
+			clearerr(f);                 \
+			/* refetch */                \
+			buf = (char *)(obj);\
+			continue;                    \
+		    }                                \
+		} else {                             \
+		    (ret) = 0;                       \
+		}                                    \
+		break;                               \
+	    }                                        \
+	    (buf)[__ooffs+__offs] = (ret);           \
+	    __offs++;                                \
+	}                                            \
+	if (__offs > 0)                              \
+	    (ret) = __offs;                          \
     } else {                                         \
-        while (__offs < (cnt)) {                     \
-            char __buf[IO_BUFFER_SIZE];              \
-            OBJ rA = __INST(readAhead);              \
-            if (rA != nil) {                         \
-                (buf)[__ooffs+__offs] = __intVal(rA);\
-                __INST(readAhead) = nil;             \
-                (ret) = 1;                           \
-                __offs++;                            \
-                continue;                            \
-            }                                        \
-            {                                        \
-                int res = 0;                         \
-                int l = (cnt)-__offs;                \
-                CLEAR_ERRNO;                         \
-                if (l > IO_BUFFER_SIZE)              \
-                    l = IO_BUFFER_SIZE;              \
-                if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)), FIONREAD, &res), 1)) \
-                    || (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \
-                    || (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0,0,0,&res,0), 1))) { \
-                    if (res > 0) {                   \
-                        if (res > l) res = l;        \
-                        READ((ret), f, __buf, res, handleType); \
-                    } else {                         \
-                        (ret) = 0;                   \
-                        break;                       \
-                    }                                \
-                } else {                             \
-                    READ((ret), f, __buf, l, handleType); \
-                }                                     \
-                if ((ret) <= 0) {                     \
-                    if (ret < 0 && __threadErrno == EINTR) \
-                        continue;                       \
-                    break;                              \
-                }                                       \
-            }                                           \
-            if ((ret) > 0) {                            \
-                buf = (char *)(obj);                    \
-                memcpy((buf)+__ooffs+__offs, __buf, (ret)); \
-                __offs += (ret);                        \
-            } else {                                    \
-                (ret) = 0;                              \
-            }                                           \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	while (__offs < (cnt)) {                     \
+	    char __buf[IO_BUFFER_SIZE];              \
+	    OBJ rA = __INST(readAhead);              \
+	    if (rA != nil) {                         \
+		(buf)[__ooffs+__offs] = __intVal(rA);\
+		__INST(readAhead) = nil;             \
+		(ret) = 1;                           \
+		__offs++;                            \
+		continue;                            \
+	    }                                        \
+	    {                                        \
+		int res = 0;                         \
+		int l = (cnt)-__offs;                \
+		CLEAR_ERRNO;                         \
+		if (l > IO_BUFFER_SIZE)              \
+		    l = IO_BUFFER_SIZE;              \
+		if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)), FIONREAD, &res), 1)) \
+		    || (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \
+		    || (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0,0,0,&res,0), 1))) { \
+		    if (res > 0) {                   \
+			if (res > l) res = l;        \
+			READ((ret), f, __buf, res, handleType); \
+		    } else {                         \
+			(ret) = 0;                   \
+			break;                       \
+		    }                                \
+		} else {                             \
+		    READ((ret), f, __buf, l, handleType); \
+		}                                     \
+		if ((ret) <= 0) {                     \
+		    if (ret < 0 && __threadErrno == EINTR) \
+			continue;                       \
+		    break;                              \
+		}                                       \
+	    }                                           \
+	    if ((ret) > 0) {                            \
+		buf = (char *)(obj);                    \
+		memcpy((buf)+__ooffs+__offs, __buf, (ret)); \
+		__offs += (ret);                        \
+	    } else {                                    \
+		(ret) = 0;                              \
+	    }                                           \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     }                                                   \
   }
 
 # define __WRITEBYTE__(ret, f, buf, isBuffered, handleType)         \
     if (isBuffered) {                                   \
-        for (;;) {                                      \
-            CLEAR_ERRNO;                                \
-            ret = putc(*(buf), f);                      \
-            if ((ret) >= 0) {                           \
-                (ret) = 1;                              \
-            } else if (ferror(f)) {                     \
-                if (__threadErrno == EINTR) {                   \
-                    clearerr(f);                        \
-                    continue;                           \
-                }                                       \
-            } else                                      \
-                (ret) = 0;                              \
-            break;                                      \
-        }                                               \
+	for (;;) {                                      \
+	    CLEAR_ERRNO;                                \
+	    ret = putc(*(buf), f);                      \
+	    if ((ret) >= 0) {                           \
+		(ret) = 1;                              \
+	    } else if (ferror(f)) {                     \
+		if (__threadErrno == EINTR) {                   \
+		    clearerr(f);                        \
+		    continue;                           \
+		}                                       \
+	    } else                                      \
+		(ret) = 0;                              \
+	    break;                                      \
+	}                                               \
     } else {                                            \
-        for (;;) {                                      \
-            CLEAR_ERRNO;                                \
-            WRITE(ret,f, buf, 1, handleType);                       \
-            if ((ret) >= 0 || __threadErrno != EINTR)           \
-                break;                                  \
-        }                                               \
+	for (;;) {                                      \
+	    CLEAR_ERRNO;                                \
+	    WRITE(ret,f, buf, 1, handleType);                       \
+	    if ((ret) >= 0 || __threadErrno != EINTR)           \
+		break;                                  \
+	}                                               \
    }
 
 # define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType)   \
     (ret) = 0;                                          \
     if (isBuffered) {                                   \
-        int __offs = 0;                                 \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
-            if ((ret) <= 0) {                           \
-                if (ferror(f)) {                        \
-                    if (__threadErrno == EINTR) {               \
-                        clearerr(f);                    \
-                        continue;                       \
-                    }                                   \
-                    break;                              \
-                } else {                                \
-                    (ret) = 0;                          \
-                }                                       \
-            }                                           \
-            __offs += (ret);                            \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int __offs = 0;                                 \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    (ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
+	    if ((ret) <= 0) {                           \
+		if (ferror(f)) {                        \
+		    if (__threadErrno == EINTR) {               \
+			clearerr(f);                    \
+			continue;                       \
+		    }                                   \
+		    break;                              \
+		} else {                                \
+		    (ret) = 0;                          \
+		}                                       \
+	    }                                           \
+	    __offs += (ret);                            \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     } else {                                            \
-        int __offs = 0;                                 \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            WRITE(ret,f, (buf)+__offs, (cnt)-__offs, handleType);   \
-            if (ret <= 0) {                             \
-                if (ret < 0 && __threadErrno == EINTR) { \
-                    continue;                           \
-                }                                       \
-                break;                                  \
-            }                                           \
-            __offs += (ret);                            \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int __offs = 0;                                 \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    WRITE(ret,f, (buf)+__offs, (cnt)-__offs, handleType);   \
+	    if (ret <= 0) {                             \
+		if (ret < 0 && __threadErrno == EINTR) { \
+		    continue;                           \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    __offs += (ret);                            \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
    }
 
 # define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \
@@ -642,51 +642,51 @@
     int __ooffs = obj_offs;                             \
     int __offs = 0;                                     \
     char *buf = (char *)(obj);                          \
-                                                        \
+							\
     (ret) = 0;                                          \
     if (isBuffered) {                                   \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \
-            if ((ret) <= 0) {                           \
-                if (ferror(f)) {                        \
-                    if (__threadErrno == EINTR) {       \
-                        /* refetch */                   \
-                        buf = (char *)(obj);   \
-                        clearerr(f);                    \
-                        continue;                       \
-                    }                                   \
-                    break;                              \
-                } else {                                \
-                    (ret) = 0;                          \
-                }                                       \
-            }                                           \
-            __offs += (ret);                            \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \
+	    if ((ret) <= 0) {                           \
+		if (ferror(f)) {                        \
+		    if (__threadErrno == EINTR) {       \
+			/* refetch */                   \
+			buf = (char *)(obj);   \
+			clearerr(f);                    \
+			continue;                       \
+		    }                                   \
+		    break;                              \
+		} else {                                \
+		    (ret) = 0;                          \
+		}                                       \
+	    }                                           \
+	    __offs += (ret);                            \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     } else {                                            \
-        while (__offs < (cnt)) {                        \
-            char __buf[IO_BUFFER_SIZE];                 \
-            int l;                                      \
-            CLEAR_ERRNO;                                \
-            l = (cnt)-__offs;                           \
-            if ( l > IO_BUFFER_SIZE)                    \
-              l = IO_BUFFER_SIZE;                       \
-            /* refetch */                               \
-            buf = (char *)(obj);               \
-            memcpy(__buf,(buf)+__ooffs+__offs,l);       \
-            WRITE(ret,f, __buf, l, handleType);                     \
-            if (ret <= 0) {                             \
-                if (ret < 0 && __threadErrno == EINTR) {        \
-                    continue;                           \
-                }                                       \
-                break;                                  \
-            }                                           \
-            __offs += (ret);                            \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	while (__offs < (cnt)) {                        \
+	    char __buf[IO_BUFFER_SIZE];                 \
+	    int l;                                      \
+	    CLEAR_ERRNO;                                \
+	    l = (cnt)-__offs;                           \
+	    if ( l > IO_BUFFER_SIZE)                    \
+	      l = IO_BUFFER_SIZE;                       \
+	    /* refetch */                               \
+	    buf = (char *)(obj);               \
+	    memcpy(__buf,(buf)+__ooffs+__offs,l);       \
+	    WRITE(ret,f, __buf, l, handleType);                     \
+	    if (ret <= 0) {                             \
+		if (ret < 0 && __threadErrno == EINTR) {        \
+		    continue;                           \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    __offs += (ret);                            \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     }                                                   \
   }
 
@@ -697,15 +697,15 @@
 # define __READING__(f)                          \
     if ((__INST(didWrite) != false)              \
      && (__INST(mode) == @symbol(readwrite))) {  \
-        __INST(didWrite) = false;                \
-        OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
+	__INST(didWrite) = false;                \
+	OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
     }
 
 # define __WRITING__(f)                          \
     if ((__INST(didWrite) != true)               \
      && (__INST(mode) == @symbol(readwrite))) {  \
-        __INST(didWrite) = true;                 \
-        OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
+	__INST(didWrite) = true;                 \
+	OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
     }
 
 
@@ -715,73 +715,73 @@
 # else /* use STDIO */
 #  define __UNGETC__(c, f, isBuffered)                  \
     if (isBuffered) {                                   \
-        ungetc((c), (f));                               \
+	ungetc((c), (f));                               \
     } else {                                            \
-        __INST(readAhead) = __mkSmallInteger((c));          \
+	__INST(readAhead) = __mkSmallInteger((c));          \
     }
 # endif /* use STDIO */
 
 # ifdef NO_STDIO
 #  define __READBYTE__(ret, f, buf, isBuffered, handleType)         \
     {                                                   \
-        OBJ rA = __INST(readAhead);                     \
-        if (rA != nil) {                                \
-            *(buf) = __intVal(rA);                      \
-            DEBUGBUFFER(buf);                           \
-            __INST(readAhead) = nil;                    \
-            (ret) = 1;                                  \
-        } else {                                        \
-            for (;;) {                                  \
-                CLEAR_ERRNO;                            \
-                (ret) = READ(f, buf, 1, handleType);    \
-                DEBUGBUFFER(buf);                       \
-                if ((ret) >= 0) break;                  \
-                if (errno != EINTR) {                   \
-                    break;                              \
-                }                                       \
-                __HANDLE_INTERRUPTS__;                  \
-            }                                           \
-        }                                               \
+	OBJ rA = __INST(readAhead);                     \
+	if (rA != nil) {                                \
+	    *(buf) = __intVal(rA);                      \
+	    DEBUGBUFFER(buf);                           \
+	    __INST(readAhead) = nil;                    \
+	    (ret) = 1;                                  \
+	} else {                                        \
+	    for (;;) {                                  \
+		CLEAR_ERRNO;                            \
+		(ret) = READ(f, buf, 1, handleType);    \
+		DEBUGBUFFER(buf);                       \
+		if ((ret) >= 0) break;                  \
+		if (errno != EINTR) {                   \
+		    break;                              \
+		}                                       \
+		__HANDLE_INTERRUPTS__;                  \
+	    }                                           \
+	}                                               \
     }
 # else /* use STDIO */
 #  define __READBYTE__(ret, f, buf, isBuffered, handleType)         \
     if (isBuffered) {                                   \
-        for (;;) {                                      \
-            CLEAR_ERRNO;                                \
-            (ret) = getc(f);                            \
-            if ((ret) >= 0) {                           \
-                DEBUGBUFFER(buf);                       \
-                *(buf) = (ret);                         \
-                (ret) = 1;                              \
-            } else if (ferror(f)) {                     \
-                if (errno == EINTR) {                   \
-                    __HANDLE_INTERRUPTS__;              \
-                    clearerr(f);                        \
-                    continue;                           \
-                }                                       \
-            } else                                      \
-                (ret) = 0;                              \
-            break;                                      \
-        }                                               \
+	for (;;) {                                      \
+	    CLEAR_ERRNO;                                \
+	    (ret) = getc(f);                            \
+	    if ((ret) >= 0) {                           \
+		DEBUGBUFFER(buf);                       \
+		*(buf) = (ret);                         \
+		(ret) = 1;                              \
+	    } else if (ferror(f)) {                     \
+		if (errno == EINTR) {                   \
+		    __HANDLE_INTERRUPTS__;              \
+		    clearerr(f);                        \
+		    continue;                           \
+		}                                       \
+	    } else                                      \
+		(ret) = 0;                              \
+	    break;                                      \
+	}                                               \
     } else {                                            \
-        OBJ rA = __INST(readAhead);                     \
-        if (rA != nil) {                                \
-            *(buf) = __intVal(rA);                      \
-            DEBUGBUFFER(buf);                           \
-            __INST(readAhead) = nil;                    \
-            (ret) = 1;                                  \
-        } else {                                        \
-            for (;;) {                                  \
-                CLEAR_ERRNO;                            \
-                (ret) = read(fileno(f), buf, 1);        \
-                DEBUGBUFFER(buf);                       \
-                if ((ret) >= 0) break;                  \
-                if (errno != EINTR) {                   \
-                    break;                              \
-                }                                       \
-                __HANDLE_INTERRUPTS__;                  \
-            }                                           \
-        }                                               \
+	OBJ rA = __INST(readAhead);                     \
+	if (rA != nil) {                                \
+	    *(buf) = __intVal(rA);                      \
+	    DEBUGBUFFER(buf);                           \
+	    __INST(readAhead) = nil;                    \
+	    (ret) = 1;                                  \
+	} else {                                        \
+	    for (;;) {                                  \
+		CLEAR_ERRNO;                            \
+		(ret) = read(fileno(f), buf, 1);        \
+		DEBUGBUFFER(buf);                       \
+		if ((ret) >= 0) break;                  \
+		if (errno != EINTR) {                   \
+		    break;                              \
+		}                                       \
+		__HANDLE_INTERRUPTS__;                  \
+	    }                                           \
+	}                                               \
    }
 # endif /* use STDIO */
 
@@ -792,84 +792,84 @@
 # ifdef NO_STDIO
 #  define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType)   \
     {                                                   \
-        int __offs = 0, __cnt;                          \
-                                                        \
-        while (__offs < (cnt)) {                        \
-            OBJ rA = __INST(readAhead);                 \
-            if (rA != nil) {                            \
-                (buf)[__offs] = __intVal(rA);           \
-                DEBUGBUFFER(buf);                       \
-                __INST(readAhead) = nil;                \
-                __offs++;                               \
-            } else {                                    \
-                CLEAR_ERRNO;                            \
-                __cnt = READ(f, (buf)+__offs, (cnt)-__offs, handleType); \
-                DEBUGBUFFER(buf);                       \
-                if (__cnt <= 0) {                       \
-                    if (__cnt < 0 && errno == EINTR) {  \
-                        __HANDLE_INTERRUPTS__;          \
-                        continue;                       \
-                    }                                   \
-                    break;                              \
-                }                                       \
-                __offs += __cnt;                        \
-            }                                           \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int __offs = 0, __cnt;                          \
+							\
+	while (__offs < (cnt)) {                        \
+	    OBJ rA = __INST(readAhead);                 \
+	    if (rA != nil) {                            \
+		(buf)[__offs] = __intVal(rA);           \
+		DEBUGBUFFER(buf);                       \
+		__INST(readAhead) = nil;                \
+		__offs++;                               \
+	    } else {                                    \
+		CLEAR_ERRNO;                            \
+		__cnt = READ(f, (buf)+__offs, (cnt)-__offs, handleType); \
+		DEBUGBUFFER(buf);                       \
+		if (__cnt <= 0) {                       \
+		    if (__cnt < 0 && errno == EINTR) {  \
+			__HANDLE_INTERRUPTS__;          \
+			continue;                       \
+		    }                                   \
+		    break;                              \
+		}                                       \
+		__offs += __cnt;                        \
+	    }                                           \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
    }
 # else /* use STDIO */
 #  define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType)     \
     (ret) = 0;                                          \
     if (isBuffered) {                                   \
-        int __offs = 0;                                 \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = getc(f);                            \
-            if ((ret) < 0) {                            \
-                if (ferror(f)) {                        \
-                    if (errno == EINTR) {               \
-                        __HANDLE_INTERRUPTS__;          \
-                        clearerr(f);                    \
-                        continue;                       \
-                    }                                   \
-                } else {                                \
-                    (ret) = 0;                          \
-                }                                       \
-                break;                                  \
-            }                                           \
-            DEBUGBUFFER(buf);                           \
-            (buf)[__offs++] = (ret);                    \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int __offs = 0;                                 \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    (ret) = getc(f);                            \
+	    if ((ret) < 0) {                            \
+		if (ferror(f)) {                        \
+		    if (errno == EINTR) {               \
+			__HANDLE_INTERRUPTS__;          \
+			clearerr(f);                    \
+			continue;                       \
+		    }                                   \
+		} else {                                \
+		    (ret) = 0;                          \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    DEBUGBUFFER(buf);                           \
+	    (buf)[__offs++] = (ret);                    \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     } else {                                            \
-        int __offs = 0, __cnt;                          \
-        int fd = fileno(f);                             \
-                                                        \
-        while (__offs < (cnt)) {                        \
-            OBJ rA = __INST(readAhead);                 \
-            if (rA != nil) {                            \
-                DEBUGBUFFER(buf);                       \
-                (buf)[__offs] = __intVal(rA);           \
-                __INST(readAhead) = nil;                \
-                __offs++;                               \
-            } else {                                    \
-                CLEAR_ERRNO;                            \
-                __cnt = read(fd, (buf)+__offs, (cnt)-__offs);  \
-                DEBUGBUFFER(buf);                       \
-                if (__cnt <= 0) {                       \
-                    if (__cnt < 0 && errno == EINTR) {  \
-                        __HANDLE_INTERRUPTS__;          \
-                        continue;                       \
-                    }                                   \
-                    break;                              \
-                }                                       \
-                __offs += __cnt;                        \
-            }                                           \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int __offs = 0, __cnt;                          \
+	int fd = fileno(f);                             \
+							\
+	while (__offs < (cnt)) {                        \
+	    OBJ rA = __INST(readAhead);                 \
+	    if (rA != nil) {                            \
+		DEBUGBUFFER(buf);                       \
+		(buf)[__offs] = __intVal(rA);           \
+		__INST(readAhead) = nil;                \
+		__offs++;                               \
+	    } else {                                    \
+		CLEAR_ERRNO;                            \
+		__cnt = read(fd, (buf)+__offs, (cnt)-__offs);  \
+		DEBUGBUFFER(buf);                       \
+		if (__cnt <= 0) {                       \
+		    if (__cnt < 0 && errno == EINTR) {  \
+			__HANDLE_INTERRUPTS__;          \
+			continue;                       \
+		    }                                   \
+		    break;                              \
+		}                                       \
+		__offs += __cnt;                        \
+	    }                                           \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
    }
 
 
@@ -879,7 +879,7 @@
 
 #  if defined(F_GETFL) && defined(F_SETFL) && (defined(O_NONBLOCK) || defined(O_NDELAY) || defined(FNDELAY))
 #   define SETFLAGS(fd, flags) \
-        fcntl(fd, F_SETFL, flags)
+	fcntl(fd, F_SETFL, flags)
 
 #   if defined(O_NONBLOCK)
 #    define __STX_NONBLOCK_FLAG O_NONBLOCK
@@ -892,13 +892,13 @@
 #   endif
 
 #   define SETNONBLOCKING(fd, oldFlags) \
-        { \
-            int flags = fcntl(fd, F_GETFL, 0); \
-            if (flags >= 0) { \
-                fcntl(fd, F_SETFL, flags | __STX_NONBLOCK_FLAG); \
-            } \
-            oldFlags = flags; \
-        }
+	{ \
+	    int flags = fcntl(fd, F_GETFL, 0); \
+	    if (flags >= 0) { \
+		fcntl(fd, F_SETFL, flags | __STX_NONBLOCK_FLAG); \
+	    } \
+	    oldFlags = flags; \
+	}
 #  else
 #   define SETFLAGS(fd, flags) /* nothing */
 #   define SETNONBLOCKING(fd, oldFlags) /* nothing */
@@ -908,52 +908,52 @@
   {                                                     \
     int __offs = 0, __cnt;                              \
     int oldFlags;                                       \
-                                                        \
+							\
     (ret) = 0;                                          \
     SETNONBLOCKING(fileno(f), oldFlags);                \
     if (isBuffered) {                                   \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = getc(f);                            \
-            if ((ret) < 0) {                            \
-                if (ferror(f)) {                        \
-                    if (errno == EINTR) {               \
-                        (ret) = 0;                      \
-                        clearerr(f);                    \
-                        break;                          \
-                    }                                   \
-                } else {                                \
-                    (ret) = 0;                          \
-                }                                       \
-                break;                                  \
-            }                                           \
-            (buf)[__offs++] = (ret);                    \
-            DEBUGBUFFER(buf);                           \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    (ret) = getc(f);                            \
+	    if ((ret) < 0) {                            \
+		if (ferror(f)) {                        \
+		    if (errno == EINTR) {               \
+			(ret) = 0;                      \
+			clearerr(f);                    \
+			break;                          \
+		    }                                   \
+		} else {                                \
+		    (ret) = 0;                          \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    (buf)[__offs++] = (ret);                    \
+	    DEBUGBUFFER(buf);                           \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     } else {                                            \
-        int fd = fileno(f);                             \
-                                                        \
-        while (__offs < (cnt)) {                        \
-            OBJ rA = __INST(readAhead);                 \
-            if (rA != nil) {                            \
-                (buf)[__offs] = __intVal(rA);           \
-                DEBUGBUFFER(buf);                       \
-                __INST(readAhead) = nil;                \
-                __offs++;                               \
-                continue;                               \
-            }                                           \
-            CLEAR_ERRNO;                                \
-            __cnt = read(fd, (buf)+__offs, (cnt)-__offs); \
-            DEBUGBUFFER(buf);                           \
-            if (__cnt > 0) {                            \
-                __offs += __cnt;                        \
-            }                                           \
-            break;                                      \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int fd = fileno(f);                             \
+							\
+	while (__offs < (cnt)) {                        \
+	    OBJ rA = __INST(readAhead);                 \
+	    if (rA != nil) {                            \
+		(buf)[__offs] = __intVal(rA);           \
+		DEBUGBUFFER(buf);                       \
+		__INST(readAhead) = nil;                \
+		__offs++;                               \
+		continue;                               \
+	    }                                           \
+	    CLEAR_ERRNO;                                \
+	    __cnt = read(fd, (buf)+__offs, (cnt)-__offs); \
+	    DEBUGBUFFER(buf);                           \
+	    if (__cnt > 0) {                            \
+		__offs += __cnt;                        \
+	    }                                           \
+	    break;                                      \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     }                                                   \
     SETFLAGS(fileno(f), oldFlags);                      \
   }
@@ -971,34 +971,34 @@
     int __offs = 0;                                     \
     int __cnt;                                          \
     char *buf = (char *)(obj);                          \
-                                                        \
+							\
     (ret) = 0;                                          \
     {                                                   \
-        while (__offs < (cnt)) {                        \
-            OBJ rA = __INST(readAhead);                 \
-            if (rA != nil) {                            \
-                (buf)[__ooffs+__offs] = __intVal(rA);   \
-                DEBUGBUFFER(buf);                       \
-                __INST(readAhead) = nil;                \
-                __offs++;                               \
-            } else {                                    \
-                CLEAR_ERRNO;                            \
-                __cnt = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \
-                DEBUGBUFFER(buf);                       \
-                if (__cnt <= 0) {                       \
-                    if (__cnt < 0 && errno == EINTR) {  \
-                        __HANDLE_INTERRUPTS__;          \
-                        /* refetch */                   \
-                        buf = (char *)(obj);            \
-                        continue;                       \
-                    }                                   \
-                    break;                              \
-                }                                       \
-                __offs += __cnt;                        \
-            }                                           \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	while (__offs < (cnt)) {                        \
+	    OBJ rA = __INST(readAhead);                 \
+	    if (rA != nil) {                            \
+		(buf)[__ooffs+__offs] = __intVal(rA);   \
+		DEBUGBUFFER(buf);                       \
+		__INST(readAhead) = nil;                \
+		__offs++;                               \
+	    } else {                                    \
+		CLEAR_ERRNO;                            \
+		__cnt = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \
+		DEBUGBUFFER(buf);                       \
+		if (__cnt <= 0) {                       \
+		    if (__cnt < 0 && errno == EINTR) {  \
+			__HANDLE_INTERRUPTS__;          \
+			/* refetch */                   \
+			buf = (char *)(obj);            \
+			continue;                       \
+		    }                                   \
+		    break;                              \
+		}                                       \
+		__offs += __cnt;                        \
+	    }                                           \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     }                                                   \
   }
 
@@ -1010,61 +1010,61 @@
     int __offs = 0;                                     \
     int __cnt;                                          \
     char *buf = (char *)(obj);                          \
-                                                        \
+							\
     (ret) = 0;                                          \
     if (isBuffered) {                                   \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = getc(f);                            \
-            if ((ret) < 0) {                            \
-                if (ferror(f)) {                        \
-                    if (errno == EINTR) {               \
-                        __HANDLE_INTERRUPTS__;          \
-                        clearerr(f);                    \
-                        /* refetch */                   \
-                        buf = (char *)(obj);            \
-                        DEBUGBUFFER(buf);               \
-                        continue;                       \
-                    }                                   \
-                } else {                                \
-                    (ret) = 0;                          \
-                }                                       \
-                break;                                  \
-            }                                           \
-            (buf)[__ooffs+__offs] = (ret);              \
-            DEBUGBUFFER(buf);                           \
-            __offs++;                                   \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    (ret) = getc(f);                            \
+	    if ((ret) < 0) {                            \
+		if (ferror(f)) {                        \
+		    if (errno == EINTR) {               \
+			__HANDLE_INTERRUPTS__;          \
+			clearerr(f);                    \
+			/* refetch */                   \
+			buf = (char *)(obj);            \
+			DEBUGBUFFER(buf);               \
+			continue;                       \
+		    }                                   \
+		} else {                                \
+		    (ret) = 0;                          \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    (buf)[__ooffs+__offs] = (ret);              \
+	    DEBUGBUFFER(buf);                           \
+	    __offs++;                                   \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     } else {                                            \
-        int fd = fileno(f);                             \
-                                                        \
-        while (__offs < (cnt)) {                        \
-            OBJ rA = __INST(readAhead);                 \
-            if (rA != nil) {                            \
-                (buf)[__ooffs+__offs] = __intVal(rA);   \
-                DEBUGBUFFER(buf);                       \
-                __INST(readAhead) = nil;                \
-                __offs++;                               \
-            } else {                                    \
-                CLEAR_ERRNO;                            \
-                __cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
-                DEBUGBUFFER(buf);                       \
-                if (__cnt <= 0) {                       \
-                    if (__cnt < 0 && errno == EINTR) {  \
-                        __HANDLE_INTERRUPTS__;          \
-                        /* refetch */                   \
-                        buf = (char *)(obj);            \
-                        continue;                       \
-                    }                                   \
-                    break;                              \
-                }                                       \
-                __offs += __cnt;                        \
-            }                                           \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int fd = fileno(f);                             \
+							\
+	while (__offs < (cnt)) {                        \
+	    OBJ rA = __INST(readAhead);                 \
+	    if (rA != nil) {                            \
+		(buf)[__ooffs+__offs] = __intVal(rA);   \
+		DEBUGBUFFER(buf);                       \
+		__INST(readAhead) = nil;                \
+		__offs++;                               \
+	    } else {                                    \
+		CLEAR_ERRNO;                            \
+		__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
+		DEBUGBUFFER(buf);                       \
+		if (__cnt <= 0) {                       \
+		    if (__cnt < 0 && errno == EINTR) {  \
+			__HANDLE_INTERRUPTS__;          \
+			/* refetch */                   \
+			buf = (char *)(obj);            \
+			continue;                       \
+		    }                                   \
+		    break;                              \
+		}                                       \
+		__offs += __cnt;                        \
+	    }                                           \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     }                                                   \
   }
 
@@ -1075,56 +1075,56 @@
     int __cnt;                                          \
     char *buf = (char *)(obj);                          \
     int oldFlags;                                       \
-                                                        \
+							\
     (ret) = 0;                                          \
     SETNONBLOCKING(fileno(f), oldFlags);                \
-                                                        \
+							\
     if (isBuffered) {                                   \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = getc(f);                            \
-            if ((ret) < 0) {                            \
-                if (ferror(f)) {                        \
-                    if (errno == EINTR) {               \
-                        clearerr(f);                    \
-                        /* refetch */                   \
-                        buf = (char *)(obj);            \
-                        (ret) = 0;                      \
-                        break;                          \
-                    }                                   \
-                } else {                                \
-                    (ret) = 0;                          \
-                }                                       \
-                break;                                  \
-            }                                           \
-            (buf)[__ooffs+__offs] = (ret);              \
-            DEBUGBUFFER(buf);                           \
-            __offs++;                                   \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    (ret) = getc(f);                            \
+	    if ((ret) < 0) {                            \
+		if (ferror(f)) {                        \
+		    if (errno == EINTR) {               \
+			clearerr(f);                    \
+			/* refetch */                   \
+			buf = (char *)(obj);            \
+			(ret) = 0;                      \
+			break;                          \
+		    }                                   \
+		} else {                                \
+		    (ret) = 0;                          \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    (buf)[__ooffs+__offs] = (ret);              \
+	    DEBUGBUFFER(buf);                           \
+	    __offs++;                                   \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     } else {                                            \
-        int fd = fileno(f);                             \
-                                                        \
-        while (__offs < (cnt)) {                        \
-            OBJ rA = __INST(readAhead);                 \
-            if (rA != nil) {                            \
-                (buf)[__ooffs+__offs] = __intVal(rA);   \
-                DEBUGBUFFER(buf);                       \
-                __INST(readAhead) = nil;                \
-                __offs++;                               \
-                continue;                               \
-            }                                           \
-            CLEAR_ERRNO;                                \
-            __cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
-            DEBUGBUFFER(buf);                           \
-            if (__cnt > 0) {                            \
-                __offs += __cnt;                        \
-            }                                           \
-            break;                                      \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int fd = fileno(f);                             \
+							\
+	while (__offs < (cnt)) {                        \
+	    OBJ rA = __INST(readAhead);                 \
+	    if (rA != nil) {                            \
+		(buf)[__ooffs+__offs] = __intVal(rA);   \
+		DEBUGBUFFER(buf);                       \
+		__INST(readAhead) = nil;                \
+		__offs++;                               \
+		continue;                               \
+	    }                                           \
+	    CLEAR_ERRNO;                                \
+	    __cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
+	    DEBUGBUFFER(buf);                           \
+	    if (__cnt > 0) {                            \
+		__offs += __cnt;                        \
+	    }                                           \
+	    break;                                      \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     }                                                   \
     SETFLAGS(fileno(f), oldFlags);                      \
   }
@@ -1134,44 +1134,44 @@
 
 # ifdef NO_STDIO
 #  define __WRITEBYTE__(ret, f, buf, isBuffered, handleType)          \
-        for (;;) {                                      \
-            CLEAR_ERRNO;                                \
-            (ret) = WRITE(f, buf, 1, handleType);       \
-            if ((ret) >= 0) break;                      \
-            if (errno != EINTR) {                       \
-                break;                                  \
-            }                                           \
-            __HANDLE_INTERRUPTS__;                      \
-        }
+	for (;;) {                                      \
+	    CLEAR_ERRNO;                                \
+	    (ret) = WRITE(f, buf, 1, handleType);       \
+	    if ((ret) >= 0) break;                      \
+	    if (errno != EINTR) {                       \
+		break;                                  \
+	    }                                           \
+	    __HANDLE_INTERRUPTS__;                      \
+	}
 # else /* use STDIO */
 #  define __WRITEBYTE__(ret, f, buf, isBuffered, handleType)        \
     if (isBuffered) {                                   \
-        for (;;) {                                      \
-            CLEAR_ERRNO;                                \
-            ret = putc(*(buf), f);                      \
-            if ((ret) >= 0) {                           \
-                (ret) = 1;                              \
-            } else if (ferror(f)) {                     \
-                /* SOLARIS/SPARC (2.6) generates spurious errors with errno = 0 */ \
-                if (errno == EINTR || errno == 0) {     \
-                    __HANDLE_INTERRUPTS__;              \
-                    clearerr(f);                        \
-                    continue;                           \
-                }                                       \
-            } else                                      \
-                (ret) = 0;                              \
-            break;                                      \
-        }                                               \
+	for (;;) {                                      \
+	    CLEAR_ERRNO;                                \
+	    ret = putc(*(buf), f);                      \
+	    if ((ret) >= 0) {                           \
+		(ret) = 1;                              \
+	    } else if (ferror(f)) {                     \
+		/* SOLARIS/SPARC (2.6) generates spurious errors with errno = 0 */ \
+		if (errno == EINTR || errno == 0) {     \
+		    __HANDLE_INTERRUPTS__;              \
+		    clearerr(f);                        \
+		    continue;                           \
+		}                                       \
+	    } else                                      \
+		(ret) = 0;                              \
+	    break;                                      \
+	}                                               \
     } else {                                            \
-        for (;;) {                                      \
-            CLEAR_ERRNO;                                \
-            (ret) = write(fileno(f), buf, 1);           \
-            if ((ret) >= 0) break;                      \
-            if (errno != EINTR) {                       \
-                break;                                  \
-            }                                           \
-            __HANDLE_INTERRUPTS__;                      \
-        }                                               \
+	for (;;) {                                      \
+	    CLEAR_ERRNO;                                \
+	    (ret) = write(fileno(f), buf, 1);           \
+	    if ((ret) >= 0) break;                      \
+	    if (errno != EINTR) {                       \
+		break;                                  \
+	    }                                           \
+	    __HANDLE_INTERRUPTS__;                      \
+	}                                               \
    }
 # endif /* use STDIO */
 
@@ -1183,64 +1183,64 @@
 #  define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType)    \
     (ret) = 0;                                          \
     {                                                   \
-        int __offs = 0;                                 \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            ret = WRITE(f, (buf)+__offs, (cnt)-__offs, handleType); \
-            if (ret <= 0) {                             \
-                if (ret < 0 && errno == EINTR) {        \
-                    __HANDLE_INTERRUPTS__;              \
-                    continue;                           \
-                }                                       \
-                break;                                  \
-            }                                           \
-            __offs += (ret);                            \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int __offs = 0;                                 \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    ret = WRITE(f, (buf)+__offs, (cnt)-__offs, handleType); \
+	    if (ret <= 0) {                             \
+		if (ret < 0 && errno == EINTR) {        \
+		    __HANDLE_INTERRUPTS__;              \
+		    continue;                           \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    __offs += (ret);                            \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
    }
 # else /* use STDIO */
 #  define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType)    \
     (ret) = 0;                                          \
     if (isBuffered) {                                   \
-        int __offs = 0;                                 \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
-            if ((ret) <= 0) {                            \
-                if (ferror(f)) {                        \
-                    if (errno == EINTR) {               \
-                        __HANDLE_INTERRUPTS__;          \
-                        clearerr(f);                    \
-                        continue;                       \
-                    }                                   \
-                } else {                                \
-                    (ret) = 0;                          \
-                }                                       \
-                break;                                  \
-            }                                           \
-            __offs += (ret);                            \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int __offs = 0;                                 \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    (ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
+	    if ((ret) <= 0) {                            \
+		if (ferror(f)) {                        \
+		    if (errno == EINTR) {               \
+			__HANDLE_INTERRUPTS__;          \
+			clearerr(f);                    \
+			continue;                       \
+		    }                                   \
+		} else {                                \
+		    (ret) = 0;                          \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    __offs += (ret);                            \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     } else {                                            \
-        int __offs = 0;                                 \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = write(fileno(f), (buf)+__offs, (cnt)-__offs);\
-            if ((ret) <= 0) {                           \
-                if ((ret) < 0) {                        \
-                    if (errno == EINTR) {               \
-                        __HANDLE_INTERRUPTS__;          \
-                        continue;                       \
-                    }                                   \
-                }                                       \
-                break;                                  \
-            }                                           \
-            __offs += (ret);                            \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	int __offs = 0;                                 \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    (ret) = write(fileno(f), (buf)+__offs, (cnt)-__offs);\
+	    if ((ret) <= 0) {                           \
+		if ((ret) < 0) {                        \
+		    if (errno == EINTR) {               \
+			__HANDLE_INTERRUPTS__;          \
+			continue;                       \
+		    }                                   \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    __offs += (ret);                            \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
    }
 # endif /* use STDIO */
 
@@ -1254,25 +1254,25 @@
     int __ooffs = obj_offs;                             \
     int __offs = 0;                                     \
     char *buf = (char *)(obj);                          \
-                                                        \
+							\
     (ret) = 0;                                          \
     {                                                   \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \
-            if (ret <= 0) {                             \
-                if (ret < 0 && errno == EINTR) {        \
-                    __HANDLE_INTERRUPTS__;              \
-                    /* refetch */                       \
-                    buf = (char *)(obj);                \
-                    continue;                           \
-                }                                       \
-                break;                                  \
-            }                                           \
-            __offs += (ret);                            \
-        }                                               \
-        if (__offs > 0)                                 \
-            (ret) = __offs;                             \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \
+	    if (ret <= 0) {                             \
+		if (ret < 0 && errno == EINTR) {        \
+		    __HANDLE_INTERRUPTS__;              \
+		    /* refetch */                       \
+		    buf = (char *)(obj);                \
+		    continue;                           \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    __offs += (ret);                            \
+	}                                               \
+	if (__offs > 0)                                 \
+	    (ret) = __offs;                             \
     }                                                   \
   }
 # else /* use STDIO */
@@ -1281,48 +1281,48 @@
     int __ooffs = obj_offs;                             \
     int __offs = 0;                                     \
     char *buf = (char *)(obj);                          \
-                                                        \
+							\
     (ret) = 0;                                          \
     if (isBuffered) {                                   \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f);  \
-            if ((ret) <= 0) {                           \
-                if (ferror(f)) {                        \
-                    if (errno == EINTR) {               \
-                        __HANDLE_INTERRUPTS__;          \
-                        /* refetch */                   \
-                        buf = (char *)(obj);            \
-                        clearerr(f);                    \
-                        continue;                       \
-                    }                                   \
-                    break;                              \
-                } else {                                \
-                    (ret) = 0;                          \
-                }                                       \
-            }                                           \
-            __offs += (ret);                            \
-        }                                               \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    (ret) = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f);  \
+	    if ((ret) <= 0) {                           \
+		if (ferror(f)) {                        \
+		    if (errno == EINTR) {               \
+			__HANDLE_INTERRUPTS__;          \
+			/* refetch */                   \
+			buf = (char *)(obj);            \
+			clearerr(f);                    \
+			continue;                       \
+		    }                                   \
+		    break;                              \
+		} else {                                \
+		    (ret) = 0;                          \
+		}                                       \
+	    }                                           \
+	    __offs += (ret);                            \
+	}                                               \
     } else {                                            \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs); \
-            if ((ret) <= 0) {                           \
-                if ((ret) < 0) {                        \
-                    if (errno == EINTR){                \
-                        __HANDLE_INTERRUPTS__;          \
-                        /* refetch */                   \
-                        buf = (char *)(obj);            \
-                        continue;                       \
-                    }                                   \
-                }                                       \
-                break;                                  \
-            }                                           \
-            __offs += (ret);                            \
-        }                                               \
+	while (__offs < (cnt)) {                        \
+	    CLEAR_ERRNO;                                \
+	    (ret) = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs); \
+	    if ((ret) <= 0) {                           \
+		if ((ret) < 0) {                        \
+		    if (errno == EINTR){                \
+			__HANDLE_INTERRUPTS__;          \
+			/* refetch */                   \
+			buf = (char *)(obj);            \
+			continue;                       \
+		    }                                   \
+		}                                       \
+		break;                                  \
+	    }                                           \
+	    __offs += (ret);                            \
+	}                                               \
     }                                                   \
     if (__offs > 0)                                     \
-        (ret) = __offs;                                 \
+	(ret) = __offs;                                 \
   }
 # endif /* use STDIO */
 #endif /* unix */
@@ -2031,13 +2031,13 @@
 eolMode
     "return how end-of-line (EOL) is to be marked.
      Returns one one of:
-        #crlf         -> add a CR-NL, as in MSDOS
-        #cr           -> add a CR, as in VMS
-        #nl           -> add a NL, as in Unix
-        nil           -> transparent
+	#crlf         -> add a CR-NL, as in MSDOS
+	#cr           -> add a CR, as in VMS
+	#nl           -> add a NL, as in Unix
+	nil           -> transparent
     "
 
-    ^ eolMode 
+    ^ eolMode
 !
 
 eolMode:aSymbolOrNil
@@ -2499,7 +2499,7 @@
 
     "/ with timeout to avoid blocking in a bad pty/socket
     [
-        self closeFile
+	self closeFile
     ] valueWithTimeout:30 seconds.
 ! !
 
@@ -2542,129 +2542,129 @@
      || (__INST(handleType) == @symbol(socketFilePointer))
      || (__INST(handleType) == @symbol(socketHandle))
      || (__INST(handleType) == @symbol(pipeFilePointer))) {
-        if (((fp = __INST(handle)) != nil)
-            && (__INST(mode) != @symbol(writeonly))
-            && (__INST(binary) != true)
-        ) {
-            f = __FILEVal(fp);
-            buffer[0] = '\0';
-
-            _buffered = (__INST(buffered) == true);
-            if (_buffered) {
-                __READING__(f);
-            }
-
-            rslt = nextPtr = buffer;
-            limit = buffer + sizeof(buffer) - 2;
-
-            for (;;) {
-                __READBYTE__(ret, f, nextPtr, _buffered, __INST(handleType));
-                if (ret <= 0) {
-                    if (nextPtr == buffer)
-                        rslt = NULL;
-                    if (ret == 0) {
-                        __INST(hitEOF) = true;
-                        break;
-                    } else {
-                        error = __mkSmallInteger(__threadErrno);
-                        goto err;
-                    }
-                }
-
-                if (*nextPtr == '\n') {
-                    cutOff = 1;
-                    *nextPtr = '\0';
-                    break;
-                }
-                if (*nextPtr == '\r') {
-                    char peekChar;
-
-                    /*
-                     * peek ahead for a newLine ...
-                     */
-                    __READBYTE__(ret, f, &peekChar, _buffered, __INST(handleType));
-                    if (ret <= 0) {
-                        cutOff = 1;
-                        *nextPtr = '\0';
-                        if (ret == 0) {
-                            __INST(hitEOF) = true;
-                            break;
-                        }
-                        error = __mkSmallInteger(__threadErrno);
-                        goto err;
-                    }
-
-                    if (peekChar == '\n') {
-                        cutOff = 2;
-                        *nextPtr = '\0';
-                        break;
-                    }
-
-                    __UNGETC__(peekChar, f, _buffered);
-
-                    cutOff = 1;
-                    *nextPtr = '\0';
-                    break;
-                }
-
-                nextPtr++;
-                if (nextPtr >= limit) {
-                    *nextPtr = '\0';
-                    lineTooLong = 1;
-                    if (@global(InfoPrinting) == true) {
-                        fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n");
-                    }
-                    break;
-                }
-            }
-
-            if (rslt != NULL) {
-                len = nextPtr-buffer;
-
-                if (__isSmallInteger(__INST(position))) {
-                    INT np = __intVal(__INST(position)) + len + cutOff;
-                    OBJ t;
-
-                    t = __MKINT(np); __INST(position) = t; __STORE(self, t);
-                } else {
-                    __INST(position) = nil; /* i.e. do not know */
-                }
-                /* remove any EOL character */
-                if (len != 0) {
-                    if (buffer[len-1] == '\n') {
-                        buffer[--len] = '\0';
-                    }
-                    if ((len != 0) && (buffer[len-1] == '\r')) {
-                        buffer[--len] = '\0';
-                    }
-                }
-                line = __MKSTRING_L(buffer, len);
-                if (! lineTooLong) {
-                    RETURN ( line );
-                }
-            }
-        }
+	if (((fp = __INST(handle)) != nil)
+	    && (__INST(mode) != @symbol(writeonly))
+	    && (__INST(binary) != true)
+	) {
+	    f = __FILEVal(fp);
+	    buffer[0] = '\0';
+
+	    _buffered = (__INST(buffered) == true);
+	    if (_buffered) {
+		__READING__(f);
+	    }
+
+	    rslt = nextPtr = buffer;
+	    limit = buffer + sizeof(buffer) - 2;
+
+	    for (;;) {
+		__READBYTE__(ret, f, nextPtr, _buffered, __INST(handleType));
+		if (ret <= 0) {
+		    if (nextPtr == buffer)
+			rslt = NULL;
+		    if (ret == 0) {
+			__INST(hitEOF) = true;
+			break;
+		    } else {
+			error = __mkSmallInteger(__threadErrno);
+			goto err;
+		    }
+		}
+
+		if (*nextPtr == '\n') {
+		    cutOff = 1;
+		    *nextPtr = '\0';
+		    break;
+		}
+		if (*nextPtr == '\r') {
+		    char peekChar;
+
+		    /*
+		     * peek ahead for a newLine ...
+		     */
+		    __READBYTE__(ret, f, &peekChar, _buffered, __INST(handleType));
+		    if (ret <= 0) {
+			cutOff = 1;
+			*nextPtr = '\0';
+			if (ret == 0) {
+			    __INST(hitEOF) = true;
+			    break;
+			}
+			error = __mkSmallInteger(__threadErrno);
+			goto err;
+		    }
+
+		    if (peekChar == '\n') {
+			cutOff = 2;
+			*nextPtr = '\0';
+			break;
+		    }
+
+		    __UNGETC__(peekChar, f, _buffered);
+
+		    cutOff = 1;
+		    *nextPtr = '\0';
+		    break;
+		}
+
+		nextPtr++;
+		if (nextPtr >= limit) {
+		    *nextPtr = '\0';
+		    lineTooLong = 1;
+		    if (@global(InfoPrinting) == true) {
+			fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n");
+		    }
+		    break;
+		}
+	    }
+
+	    if (rslt != NULL) {
+		len = nextPtr-buffer;
+
+		if (__isSmallInteger(__INST(position))) {
+		    INT np = __intVal(__INST(position)) + len + cutOff;
+		    OBJ t;
+
+		    t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+		} else {
+		    __INST(position) = nil; /* i.e. do not know */
+		}
+		/* remove any EOL character */
+		if (len != 0) {
+		    if (buffer[len-1] == '\n') {
+			buffer[--len] = '\0';
+		    }
+		    if ((len != 0) && (buffer[len-1] == '\r')) {
+			buffer[--len] = '\0';
+		    }
+		}
+		line = __MKSTRING_L(buffer, len);
+		if (! lineTooLong) {
+		    RETURN ( line );
+		}
+	    }
+	}
     }
 err: ;
 %}.
     line notNil ifTrue:[
-        "/ the line as read is longer than 32k characters (boy - what a line)
-        "/ The exception could be handled by reading more and returning the
-        "/ concatenation in your exception handler (the receiver and the partial
-        "/ line are passed as parameter)
-
-        LineTooLongErrorSignal isHandled ifTrue:[
-            ^ LineTooLongErrorSignal
-                raiseRequestWith:(Array with:self with:line)
-                     errorString:('line too long read error')
-        ].
-        ^ line , self nextLine
+	"/ the line as read is longer than 32k characters (boy - what a line)
+	"/ The exception could be handled by reading more and returning the
+	"/ concatenation in your exception handler (the receiver and the partial
+	"/ line are passed as parameter)
+
+	LineTooLongErrorSignal isHandled ifTrue:[
+	    ^ LineTooLongErrorSignal
+		raiseRequestWith:(Array with:self with:line)
+		     errorString:('line too long read error')
+	].
+	^ line , self nextLine
     ].
 
     (hitEOF == true) ifTrue:[^ self pastEndRead].
     error notNil ifTrue:[
-        lastErrorNumber := error.
-        ^ self readError:error
+	lastErrorNumber := error.
+	^ self readError:error
     ].
     handle isNil ifTrue:[^ self errorNotOpen].
     (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
@@ -4575,9 +4575,18 @@
 	    rslt = __STX_C_NOINT_CALL1("fclose", fclose, f);
 	} while((rslt < 0) && (__threadErrno == EINTR));
 #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 ableto do it without being interruptable.
+	// Must watch this - if it leads to blockings, change and think about it.
+	if (__INST(mode) != @symbol(readonly)) {
+	    __BEGIN_INTERRUPTABLE__
+	    rslt = fclose(f);
+	    __END_INTERRUPTABLE__
+	} else {
+	    rslt = fclose(f);
+	}
 #endif
     } else {
 	error = @symbol(badHandleType);
@@ -4599,7 +4608,11 @@
 	].
 	error isInteger ifTrue:[
 	    lastErrorNumber := error.
-	    self writeError:error.
+	    mode == #readonly ifTrue:[
+		self ioError:error.
+	    ] ifFalse:[
+		self writeError:error.
+	    ].
 	    ^ self.
 	].
 	self primitiveFailed:error.
@@ -4992,60 +5005,60 @@
      || (__INST(handleType) == @symbol(socketFilePointer))
      || (__INST(handleType) == @symbol(socketHandle))
      || (__INST(handleType) == @symbol(pipeFilePointer))) {
-        if (((fp = __INST(handle)) != nil)
-            && (__INST(mode) != @symbol(writeonly))
-        ) {
-            f = __FILEVal(fp);
-
-            _buffered = (__INST(buffered) == true);
-            if (_buffered) {
-                __READING__(f)
-            }
-            __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
-
-            if (ret > 0) {
-                pos = __INST(position);
-                if (__isSmallInteger(pos)) {
-                    OBJ t;
-
-                    t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
-                } else {
-                    __INST(position) = nil; /* i.e. do not know */
-                }
-                if (__INST(binary) == true) {
-                    RETURN ( __mkSmallInteger(ch) );
-                }
-                RETURN ( __MKCHARACTER(ch) );
-            }
-
-            __INST(position) = nil;
-            if (ret < 0) {
-                error = __mkSmallInteger(__threadErrno);
-            } else /* ret == 0 */ {
-                __INST(hitEOF) = true;
-            }
-        }
+	if (((fp = __INST(handle)) != nil)
+	    && (__INST(mode) != @symbol(writeonly))
+	) {
+	    f = __FILEVal(fp);
+
+	    _buffered = (__INST(buffered) == true);
+	    if (_buffered) {
+		__READING__(f)
+	    }
+	    __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
+
+	    if (ret > 0) {
+		pos = __INST(position);
+		if (__isSmallInteger(pos)) {
+		    OBJ t;
+
+		    t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
+		} else {
+		    __INST(position) = nil; /* i.e. do not know */
+		}
+		if (__INST(binary) == true) {
+		    RETURN ( __mkSmallInteger(ch) );
+		}
+		RETURN ( __MKCHARACTER(ch) );
+	    }
+
+	    __INST(position) = nil;
+	    if (ret < 0) {
+		error = __mkSmallInteger(__threadErrno);
+	    } else /* ret == 0 */ {
+		__INST(hitEOF) = true;
+	    }
+	}
     }
 %}.
     hitEOF == true ifTrue:[^ self pastEndRead].
     error notNil ifTrue:[
-        lastErrorNumber := error.
-        ^ self readError:error
+	lastErrorNumber := error.
+	^ self readError:error
     ].
     handle isNil ifTrue:[^ self errorNotOpen].
     (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
 
     readAhead notNil ifTrue:[
-        c := readAhead.
-        readAhead := nil.
-        ^ c.
+	c := readAhead.
+	readAhead := nil.
+	^ c.
     ].
     c := self nextByteFromFile:handle.
     c isNil ifTrue:[
-        ^ self pastEndRead.
+	^ self pastEndRead.
     ].
     binary == true ifTrue:[
-        ^ c
+	^ c
     ].
     ^ Character value:c
 !
@@ -5057,9 +5070,9 @@
     |coll nRead|
 
     binary ifTrue:[
-        coll := ByteArray uninitializedNew:count
+	coll := ByteArray uninitializedNew:count
     ] ifFalse:[
-        coll := String new:count
+	coll := String new:count
     ].
     nRead := self nextBytes:count into:coll startingAt:1.
 
@@ -5067,7 +5080,7 @@
     "/ we must raise an exception here.
 
     nRead < count ifTrue:[
-        ^ self pastEndRead
+	^ self pastEndRead
     ].
     ^ coll
 
@@ -5093,60 +5106,60 @@
      || (__INST(handleType) == @symbol(socketFilePointer))
      || (__INST(handleType) == @symbol(socketHandle))
      || (__INST(handleType) == @symbol(pipeFilePointer))) {
-        if (((fp = __INST(handle)) != nil)
-            && (__INST(mode) != @symbol(writeonly))
-        ) {
-            f = __FILEVal(fp);
-
-            _buffered = (__INST(buffered) == true);
-            if (_buffered) {
-                __READING__(f)
-            }
-            __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
-
-            if (ret > 0) {
-                pos = __INST(position);
-                if (__isSmallInteger(pos)) {
-                    OBJ t;
-
-                    t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
-                } else {
-                    __INST(position) = nil; /* i.e. do not know */
-                }
-                if (__INST(binary) == true) {
-                    RETURN ( __mkSmallInteger(ch) );
-                }
-                RETURN ( __MKCHARACTER(ch) );
-            }
-
-            __INST(position) = nil;
-            if (ret < 0) {
-                error = __mkSmallInteger(__threadErrno);
-            } else /* ret == 0 */ {
-                __INST(hitEOF) = true;
-            }
-        }
+	if (((fp = __INST(handle)) != nil)
+	    && (__INST(mode) != @symbol(writeonly))
+	) {
+	    f = __FILEVal(fp);
+
+	    _buffered = (__INST(buffered) == true);
+	    if (_buffered) {
+		__READING__(f)
+	    }
+	    __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
+
+	    if (ret > 0) {
+		pos = __INST(position);
+		if (__isSmallInteger(pos)) {
+		    OBJ t;
+
+		    t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
+		} else {
+		    __INST(position) = nil; /* i.e. do not know */
+		}
+		if (__INST(binary) == true) {
+		    RETURN ( __mkSmallInteger(ch) );
+		}
+		RETURN ( __MKCHARACTER(ch) );
+	    }
+
+	    __INST(position) = nil;
+	    if (ret < 0) {
+		error = __mkSmallInteger(__threadErrno);
+	    } else /* ret == 0 */ {
+		__INST(hitEOF) = true;
+	    }
+	}
     }
 %}.
     hitEOF == true ifTrue:[^ nil].
     error notNil ifTrue:[
-        lastErrorNumber := error.
-        ^ self readError:error.
+	lastErrorNumber := error.
+	^ self readError:error.
     ].
     handle isNil ifTrue:[^ self errorNotOpen].
     (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
 
     readAhead notNil ifTrue:[
-        c := readAhead.
-        readAhead := nil.
-        ^ c.
+	c := readAhead.
+	readAhead := nil.
+	^ c.
     ].
     c := self nextByteFromFile:handle.
     c isNil ifTrue:[
-        ^ nil.
+	^ nil.
     ].
     binary == true ifTrue:[
-        ^ c
+	^ c
     ].
     ^ Character value:c
 !
@@ -5166,11 +5179,11 @@
     OBJ ra;
 
     if ((ra = __INST(readAhead)) != nil) {
-        if (__INST(binary) == true) {
-            RETURN ( ra );
-        }
-        c = __intVal(ra);
-        RETURN ( __MKCHARACTER(c) );
+	if (__INST(binary) == true) {
+	    RETURN ( ra );
+	}
+	c = __intVal(ra);
+	RETURN ( __MKCHARACTER(c) );
     }
 
     __INST(lastErrorNumber) = nil;
@@ -5180,45 +5193,45 @@
      || (__INST(handleType) == @symbol(socketFilePointer))
      || (__INST(handleType) == @symbol(socketHandle))
      || (__INST(handleType) == @symbol(pipeFilePointer))) {
-        if (((fp = __INST(handle)) != nil)
-            && (__INST(mode) != @symbol(writeonly))
-        ) {
-            f = __FILEVal(fp);
-            _buffered = (__INST(buffered) == true);
-            if (_buffered) {
-                __READING__(f)
-            }
-            __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
-
-            if (ret > 0) {
-                __UNGETC__(c, f, _buffered);
-
-                if (__INST(binary) == true) {
-                    RETURN ( __mkSmallInteger(c) );
-                }
-                RETURN ( __MKCHARACTER(c) );
-            }
-            if (ret < 0) {
-                error = __mkSmallInteger(__threadErrno);
-            } else /* ret == 0 */ {
-                __INST(hitEOF) = true;
-            }
-        }
+	if (((fp = __INST(handle)) != nil)
+	    && (__INST(mode) != @symbol(writeonly))
+	) {
+	    f = __FILEVal(fp);
+	    _buffered = (__INST(buffered) == true);
+	    if (_buffered) {
+		__READING__(f)
+	    }
+	    __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+
+	    if (ret > 0) {
+		__UNGETC__(c, f, _buffered);
+
+		if (__INST(binary) == true) {
+		    RETURN ( __mkSmallInteger(c) );
+		}
+		RETURN ( __MKCHARACTER(c) );
+	    }
+	    if (ret < 0) {
+		error = __mkSmallInteger(__threadErrno);
+	    } else /* ret == 0 */ {
+		__INST(hitEOF) = true;
+	    }
+	}
     }
 %}.
     hitEOF == true ifTrue:[^ self pastEndRead].
     error notNil ifTrue:[
-        lastErrorNumber := error.
-        ^ self readError:error.
+	lastErrorNumber := error.
+	^ self readError:error.
     ].
     handle isNil ifTrue:[^ self errorNotOpen].
     (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
 
     readAhead isNil ifTrue:[
-        readAhead := self nextOrNil.
-        readAhead isNil ifTrue:[
-            ^ self pastEndRead.
-        ].
+	readAhead := self nextOrNil.
+	readAhead isNil ifTrue:[
+	    ^ self pastEndRead.
+	].
     ].
     ^ readAhead
 !
@@ -5238,11 +5251,11 @@
     OBJ ra;
 
     if ((ra = __INST(readAhead)) != nil) {
-        if (__INST(binary) == true) {
-            RETURN ( ra );
-        }
-        c = __intVal(ra);
-        RETURN ( __MKCHARACTER(c) );
+	if (__INST(binary) == true) {
+	    RETURN ( ra );
+	}
+	c = __intVal(ra);
+	RETURN ( __MKCHARACTER(c) );
     }
 
     __INST(lastErrorNumber) = nil;
@@ -5252,42 +5265,42 @@
      || (__INST(handleType) == @symbol(socketFilePointer))
      || (__INST(handleType) == @symbol(socketHandle))
      || (__INST(handleType) == @symbol(pipeFilePointer))) {
-        if (((fp = __INST(handle)) != nil)
-            && (__INST(mode) != @symbol(writeonly))
-        ) {
-            f = __FILEVal(fp);
-            _buffered = (__INST(buffered) == true);
-            if (_buffered) {
-                __READING__(f)
-            }
-            __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
-
-            if (ret > 0) {
-                __UNGETC__(c, f, _buffered);
-
-                if (__INST(binary) == true) {
-                    RETURN ( __mkSmallInteger(c) );
-                }
-                RETURN ( __MKCHARACTER(c) );
-            }
-            if (ret < 0) {
-                error = __mkSmallInteger(__threadErrno);
-            } else /* ret == 0 */ {
-                __INST(hitEOF) = true;
-            }
-        }
+	if (((fp = __INST(handle)) != nil)
+	    && (__INST(mode) != @symbol(writeonly))
+	) {
+	    f = __FILEVal(fp);
+	    _buffered = (__INST(buffered) == true);
+	    if (_buffered) {
+		__READING__(f)
+	    }
+	    __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+
+	    if (ret > 0) {
+		__UNGETC__(c, f, _buffered);
+
+		if (__INST(binary) == true) {
+		    RETURN ( __mkSmallInteger(c) );
+		}
+		RETURN ( __MKCHARACTER(c) );
+	    }
+	    if (ret < 0) {
+		error = __mkSmallInteger(__threadErrno);
+	    } else /* ret == 0 */ {
+		__INST(hitEOF) = true;
+	    }
+	}
     }
 %}.
     hitEOF == true ifTrue:[^ nil].
     error notNil ifTrue:[
-        lastErrorNumber := error.
-        ^ self readError:error.
+	lastErrorNumber := error.
+	^ self readError:error.
     ].
     handle isNil ifTrue:[^ self errorNotOpen].
     (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
 
     readAhead isNil ifTrue:[
-        readAhead := self nextOrNil.
+	readAhead := self nextOrNil.
     ].
     ^ readAhead
 !
@@ -5353,19 +5366,19 @@
     int ret, _buffered;
 
     if (__INST(hitEOF) == true) {
-        RETURN (true);
+	RETURN (true);
     }
     pos = __INST(position);
     lim = __INST(readLimit);
     if (lim != nil) {
-        off_t _pos, _readLimit;
-
-        _pos = __signedLongIntVal(pos);
-        _pos = _pos - __intVal( @global(PositionableStream:ZeroPosition)) + 1;
-        _readLimit = __signedLongIntVal(lim);
-        if (_pos > _readLimit) {
-            RETURN (true);
-        }
+	off_t _pos, _readLimit;
+
+	_pos = __signedLongIntVal(pos);
+	_pos = _pos - __intVal( @global(PositionableStream:ZeroPosition)) + 1;
+	_readLimit = __signedLongIntVal(lim);
+	if (_pos > _readLimit) {
+	    RETURN (true);
+	}
     }
 
     __INST(lastErrorNumber) = nil;
@@ -5375,48 +5388,48 @@
      || (__INST(handleType) == @symbol(socketFilePointer))
      || (__INST(handleType) == @symbol(socketHandle))
      || (__INST(handleType) == @symbol(pipeFilePointer))) {
-        if ((fp = __INST(handle)) != nil) {
-            f = __FILEVal(fp);
-            if (_buffered = (__INST(buffered) == true)) {
-                __READING__(f);
-            } else {
-                if (__INST(readAhead) != nil) {
-                    RETURN (false);
-                }
-            }
-
-            /*
-             * read ahead ...
-             */
-            do {
+	if ((fp = __INST(handle)) != nil) {
+	    f = __FILEVal(fp);
+	    if (_buffered = (__INST(buffered) == true)) {
+		__READING__(f);
+	    } else {
+		if (__INST(readAhead) != nil) {
+		    RETURN (false);
+		}
+	    }
+
+	    /*
+	     * read ahead ...
+	     */
+	    do {
 #ifdef WIN32
 # if 1
-                __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+		__READBYTE__(ret, f, &c, _buffered, __INST(handleType));
 
 # else
-                __BEGIN_INTERRUPTABLE__
-                __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
-                __END_INTERRUPTABLE__
+		__BEGIN_INTERRUPTABLE__
+		__READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+		__END_INTERRUPTABLE__
 # endif
 #else /* not WIN32 */
-                __BEGIN_INTERRUPTABLE__
-                __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
-                __END_INTERRUPTABLE__
+		__BEGIN_INTERRUPTABLE__
+		__READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+		__END_INTERRUPTABLE__
 #endif
-            } while ((ret < 0) && (__threadErrno == EINTR));
-
-            if (ret > 0) {
-                __UNGETC__(c&0xff, f, _buffered);
-                RETURN (false);
-            }
-            if (ret == 0) {
-                __INST(hitEOF) = true;
-                RETURN (true);
-            }
-
-            /* ret < 0 */
-            __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
-        }
+	    } while ((ret < 0) && (__threadErrno == EINTR));
+
+	    if (ret > 0) {
+		__UNGETC__(c&0xff, f, _buffered);
+		RETURN (false);
+	    }
+	    if (ret == 0) {
+		__INST(hitEOF) = true;
+		RETURN (true);
+	    }
+
+	    /* ret < 0 */
+	    __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
+	}
     }
 %}.
     lastErrorNumber notNil ifTrue:[^ self readError].
@@ -5426,7 +5439,7 @@
 
     "/ migration support
     ^ self
-        atEndFile:handle
+	atEndFile:handle
 
     "Modified: / 30.10.1998 / 20:16:06 / cg"
 !
@@ -6095,11 +6108,11 @@
 !ExternalStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.397 2014-11-18 20:17:17 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.398 2014-11-24 14:37:58 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.397 2014-11-18 20:17:17 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.398 2014-11-24 14:37:58 cg Exp $'
 ! !