class: ExternalStream
authorStefan Vogel <sv@exept.de>
Fri, 31 May 2013 14:50:39 +0200
changeset 15342 d89884677c76
parent 15341 4503c19ab8f9
child 15343 d46cfae69fd4
class: ExternalStream class definition changed: #nextAvailableBytes:into:startingAt: linux: __READAVAILBYTES_OBJ__ didn't set O_NONBLOCK flag
ExternalStream.st
--- a/ExternalStream.st	Wed May 29 13:31:27 2013 +0200
+++ b/ExternalStream.st	Fri May 31 14:50:39 2013 +0200
@@ -199,7 +199,7 @@
 # define DEBUGBUFFER(buf)  \
     if (((char *)(buf) >= __survStartPtr) \
      && ((char *)(buf) < __survEndPtr)) { \
-	__fatal0("read into survivor\n"); \
+        __fatal0("read into survivor\n"); \
     }
 
 #else
@@ -226,69 +226,69 @@
 
 #  define READ(ret,f, cp, n, handleType) \
       { int __res;\
-	HANDLE h; \
-	h = _get_osfhandle(fileno(f)); \
-	if ((handleType == @symbol(socketFilePointer)) \
-	|| ((handleType == nil) && (ioctlsocket((SOCKET)h,FIONREAD,&__res)==0))) { \
-	  (ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\
-	} else { \
-	  (ret) = __STX_C_NOINT_CALL3("_rtl_read", _rtl_read, fileno(f), (cp), (n));\
-	} \
+        HANDLE h; \
+        h = _get_osfhandle(fileno(f)); \
+        if ((handleType == @symbol(socketFilePointer)) \
+        || ((handleType == nil) && (ioctlsocket((SOCKET)h,FIONREAD,&__res)==0))) { \
+          (ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\
+        } else { \
+          (ret) = __STX_C_NOINT_CALL3("_rtl_read", _rtl_read, fileno(f), (cp), (n));\
+        } \
       }
 
 #  define WRITE(ret,f, cp, n, handleType) \
       { int __res;\
-	HANDLE h; \
-	h = _get_osfhandle(fileno(f)); \
-	if ((handleType == @symbol(socketFilePointer)) \
-	|| ((handleType == nil) && (ioctlsocket((SOCKET)h,FIONREAD,&__res)==0))) { \
-	  (ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\
-	} else { \
-	  (ret) = __STX_C_NOINT_CALL3("_rtl_write", _rtl_write, fileno(f), (cp), (n));\
-	} \
+        HANDLE h; \
+        h = _get_osfhandle(fileno(f)); \
+        if ((handleType == @symbol(socketFilePointer)) \
+        || ((handleType == nil) && (ioctlsocket((SOCKET)h,FIONREAD,&__res)==0))) { \
+          (ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\
+        } else { \
+          (ret) = __STX_C_NOINT_CALL3("_rtl_write", _rtl_write, fileno(f), (cp), (n));\
+        } \
       }
 
 # else /* MSC */
 
 #  define READ(ret,f, cp, n, handleType) \
       { int __res;\
-	int fd; \
-	HANDLE h; \
-	fd = fileno(f); \
-	if ((handleType == @symbol(socketFileDescriptor)) \
-	 || ((handleType == nil) && (ioctlsocket((SOCKET)fd,FIONREAD,&__res)==0))) { \
-	  (ret) = __STX_WSA_NOINT_CALL4("recv", recv, fd, (cp), (n), 0);\
-	} else { \
-	  h = _get_osfhandle(fd); \
-	  if ((handleType == @symbol(socketFilePointer)) \
-	  || ((handleType == nil) && (ioctlsocket((SOCKET)h,FIONREAD,&__res)==0))) { \
-	    (ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\
-	  } else { \
-	    (ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\
-	    if (ret) \
-	      ret = __res; \
-	  } \
-	} \
+        int fd; \
+        HANDLE h; \
+        fd = fileno(f); \
+        if ((handleType == @symbol(socketFileDescriptor)) \
+         || ((handleType == nil) && (ioctlsocket((SOCKET)fd,FIONREAD,&__res)==0))) { \
+          (ret) = __STX_WSA_NOINT_CALL4("recv", recv, fd, (cp), (n), 0);\
+        } else { \
+          h = _get_osfhandle(fd); \
+          if ((handleType == @symbol(socketFilePointer)) \
+          || ((handleType == nil) && (ioctlsocket((SOCKET)h,FIONREAD,&__res)==0))) { \
+            (ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\
+          } else { \
+            (ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\
+            if (ret) \
+              ret = __res; \
+          } \
+        } \
       }
 #  define WRITE(ret,f, cp, n, handleType) \
       { int __res;\
-	int fd; \
-	HANDLE h; \
-	fd = fileno(f); \
-	if ((handleType == @symbol(socketFileDescriptor)) \
-	 || ((handleType == nil) && (ioctlsocket((SOCKET)fd,FIONREAD,&__res)==0))) { \
-	  (ret) = __STX_WSA_NOINT_CALL4("send", send, fd, (cp), (n), 0);\
-	} else {\
-	  h = _get_osfhandle(fd); \
-	  if ((handleType == @symbol(socketFilePointer)) \
-	  || ((handleType == nil) && (ioctlsocket((SOCKET)h,FIONREAD,&__res)==0))) { \
-	    (ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\
-	  } else {\
-	    (ret) = __STX_API_NOINT_CALL5("WriteFile", WriteFile, h, (cp), (n), &__res, 0);\
-	    if (ret) \
-	      ret = __res; \
-	  } \
-	} \
+        int fd; \
+        HANDLE h; \
+        fd = fileno(f); \
+        if ((handleType == @symbol(socketFileDescriptor)) \
+         || ((handleType == nil) && (ioctlsocket((SOCKET)fd,FIONREAD,&__res)==0))) { \
+          (ret) = __STX_WSA_NOINT_CALL4("send", send, fd, (cp), (n), 0);\
+        } else {\
+          h = _get_osfhandle(fd); \
+          if ((handleType == @symbol(socketFilePointer)) \
+          || ((handleType == nil) && (ioctlsocket((SOCKET)h,FIONREAD,&__res)==0))) { \
+            (ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\
+          } else {\
+            (ret) = __STX_API_NOINT_CALL5("WriteFile", WriteFile, h, (cp), (n), &__res, 0);\
+            if (ret) \
+              ret = __res; \
+          } \
+        } \
       }
 # endif /* MSC */
 
@@ -300,56 +300,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;                              \
+            }                                           \
+        }                                               \
     }
 
   /*
@@ -359,120 +359,120 @@
 # 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);                    \
-	}                                               \
-	if (__offs > 0)                                 \
-	    (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);                    \
+        }                                               \
+        if (__offs > 0)                                 \
+            (ret) = __offs;                             \
     } else {                                            \
-	while (__offs < (cnt)) {                        \
-	    OBJ rA = __INST(readAhead);                 \
-	    if (rA != nil) {                            \
-		(buf)[__offs] = __intVal(rA);           \
-		__INST(readAhead) = nil;                \
-		(ret) = 1;                              \
-		__offs += (ret);                        \
-		continue;                               \
-	    }                                           \
-	    CLEAR_ERRNO;                                \
-	    {                                           \
-	      int res;                                  \
-	      if ((handleType == @symbol(socketFilePointer)) \
-	       || ((handleType == nil) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res)==0))) { \
-		  if (res > 0) {                        \
-		      if (res > ((cnt)-__offs))         \
-			res = (cnt)-__offs;             \
-		      READ(ret,f, (buf)+__offs, res, handleType);   \
-		  } else {                              \
-		      (ret) = 0;                        \
-		  }                                     \
-	      } else if ((handleType == @symbol(pipeFilePointer)) \
-			 || ((handleType == nil) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)))) { \
-		  if (res > 0) {                        \
-		      if (res > ((cnt)-__offs))         \
-			res = (cnt)-__offs;             \
-		      READ(ret,f, (buf)+__offs, res, handleType);   \
-		  } else                                \
-		      ret = 0;                          \
-	      } else {                                  \
-		  READ(ret,f, (buf)+__offs, (cnt)-__offs, handleType); \
-	      }                                         \
-	    }                                           \
-	    if ((ret) < 0) {                            \
-		if (__threadErrno == EINTR) {                   \
-		    continue;                           \
-		}                                       \
-		break;                                  \
-	    }                                           \
-	    __offs += (ret);                            \
-	    break;                                      \
-	}                                               \
-	if (__offs > 0)                                 \
-	    (ret) = __offs;                             \
+        while (__offs < (cnt)) {                        \
+            OBJ rA = __INST(readAhead);                 \
+            if (rA != nil) {                            \
+                (buf)[__offs] = __intVal(rA);           \
+                __INST(readAhead) = nil;                \
+                (ret) = 1;                              \
+                __offs += (ret);                        \
+                continue;                               \
+            }                                           \
+            CLEAR_ERRNO;                                \
+            {                                           \
+              int res;                                  \
+              if ((handleType == @symbol(socketFilePointer)) \
+               || ((handleType == nil) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res)==0))) { \
+                  if (res > 0) {                        \
+                      if (res > ((cnt)-__offs))         \
+                        res = (cnt)-__offs;             \
+                      READ(ret,f, (buf)+__offs, res, handleType);   \
+                  } else {                              \
+                      (ret) = 0;                        \
+                  }                                     \
+              } else if ((handleType == @symbol(pipeFilePointer)) \
+                         || ((handleType == nil) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)))) { \
+                  if (res > 0) {                        \
+                      if (res > ((cnt)-__offs))         \
+                        res = (cnt)-__offs;             \
+                      READ(ret,f, (buf)+__offs, res, handleType);   \
+                  } else                                \
+                      ret = 0;                          \
+              } else {                                  \
+                  READ(ret,f, (buf)+__offs, (cnt)-__offs, handleType); \
+              }                                         \
+            }                                           \
+            if ((ret) < 0) {                            \
+                if (__threadErrno == EINTR) {                   \
+                    continue;                           \
+                }                                       \
+                break;                                  \
+            }                                           \
+            __offs += (ret);                            \
+            break;                                      \
+        }                                               \
+        if (__offs > 0)                                 \
+            (ret) = __offs;                             \
     }                                                   \
   }
 
@@ -483,63 +483,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;                             \
     }                                                   \
   }
 
@@ -548,147 +548,147 @@
     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 += (ret);                     \
-		continue;                            \
-	    }                                        \
-	    {                                        \
-		int l;                               \
-		int res;                             \
-		CLEAR_ERRNO;                         \
-		l = (cnt)-__offs;                    \
-		if ( l > IO_BUFFER_SIZE)             \
-		    l = IO_BUFFER_SIZE;              \
-		if (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res)==0) { \
-		    if (res > 0) {                   \
-			if (res > l)                 \
-			    res = l;                 \
-			READ(ret,f, __buf, res, handleType);     \
-		    } else {                         \
-			(ret) = 0;                   \
-		    }                                \
-		} else if (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)) { \
-		    if (res > 0) {                   \
-			if (res > l)                 \
-			    res = l;                 \
-			READ(ret,f, __buf, res, handleType);     \
-		    } else                           \
-			(ret) = 0;                   \
-		} else {                             \
-		    READ(ret,f, __buf, l, handleType);           \
-		}                                    \
-		if ((ret) < 0 && __threadErrno == EINTR) {   \
-		    continue;                        \
-		}                                    \
-	    }                                        \
-	    if( (ret) > 0 ) {                               \
-		/* refetch */                               \
-		buf = (char *)(obj);               \
-		memcpy((buf)+__ooffs+__offs,__buf,(ret));   \
-		__offs += (ret);                            \
-	    } else {                                        \
-		(ret) = 0;                                  \
-	    }                                               \
-	    break;                                      \
-	}                                               \
-	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 += (ret);                     \
+                continue;                            \
+            }                                        \
+            {                                        \
+                int l;                               \
+                int res;                             \
+                CLEAR_ERRNO;                         \
+                l = (cnt)-__offs;                    \
+                if ( l > IO_BUFFER_SIZE)             \
+                    l = IO_BUFFER_SIZE;              \
+                if (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res)==0) { \
+                    if (res > 0) {                   \
+                        if (res > l)                 \
+                            res = l;                 \
+                        READ(ret,f, __buf, res, handleType);     \
+                    } else {                         \
+                        (ret) = 0;                   \
+                    }                                \
+                } else if (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)) { \
+                    if (res > 0) {                   \
+                        if (res > l)                 \
+                            res = l;                 \
+                        READ(ret,f, __buf, res, handleType);     \
+                    } else                           \
+                        (ret) = 0;                   \
+                } else {                             \
+                    READ(ret,f, __buf, l, handleType);           \
+                }                                    \
+                if ((ret) < 0 && __threadErrno == EINTR) {   \
+                    continue;                        \
+                }                                    \
+            }                                        \
+            if( (ret) > 0 ) {                               \
+                /* refetch */                               \
+                buf = (char *)(obj);               \
+                memcpy((buf)+__ooffs+__offs,__buf,(ret));   \
+                __offs += (ret);                            \
+            } else {                                        \
+                (ret) = 0;                                  \
+            }                                               \
+            break;                                      \
+        }                                               \
+        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) \
@@ -696,51 +696,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;                             \
     }                                                   \
   }
 
@@ -749,15 +749,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 */  \
     }
 
 
@@ -767,69 +767,69 @@
 # 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 || __threadErrno != 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 || __threadErrno != 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 (__threadErrno == 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 (__threadErrno == 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 || __threadErrno != 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 || __threadErrno != EINTR)       \
+                    break;                              \
+                __HANDLE_INTERRUPTS__;                  \
+            }                                           \
+        }                                               \
    }
 # endif /* use STDIO */
 
@@ -840,84 +840,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 && __threadErrno == 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 && __threadErrno == 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 (__threadErrno == 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 (__threadErrno == 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 && __threadErrno == 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 && __threadErrno == EINTR) {  \
+                        __HANDLE_INTERRUPTS__;          \
+                        continue;                       \
+                    }                                   \
+                    break;                              \
+                }                                       \
+                __offs += __cnt;                        \
+            }                                           \
+        }                                               \
+        if (__offs > 0)                                 \
+            (ret) = __offs;                             \
    }
 
 
@@ -926,11 +926,8 @@
  */
 
 #  if defined(F_GETFL) && defined(F_SETFL) && (defined(O_NONBLOCK) || defined(O_NDELAY) || defined(FNDELAY))
-#   define GETFLAGS(fd) \
-	fcntl(fd, F_GETFL, 0);
-
 #   define SETFLAGS(fd, flags) \
-	fcntl(fd, F_SETFL, flags)
+        fcntl(fd, F_SETFL, flags)
 
 #   if defined(O_NONBLOCK)
 #    define __STX_NONBLOCK_FLAG O_NONBLOCK
@@ -942,71 +939,69 @@
 #    endif
 #   endif
 
-#   define SETNONBLOCKING(fd) \
-	{ \
-	    int flags; \
-	    flags = fcntl(fd, F_GETFL, 0); \
-	    if (flags >= 0) { \
-		fcntl(fd, F_SETFL, flags | __STX_NONBLOCK_FLAG); \
-	    } \
-	}
+#   define SETNONBLOCKING(fd, oldFlags) \
+        { \
+            int flags = fcntl(fd, F_GETFL, 0); \
+            if (flags >= 0) { \
+                fcntl(fd, F_SETFL, flags | __STX_NONBLOCK_FLAG); \
+            } \
+            oldFlags = flags; \
+        }
 #  else
-#   define GETFLAGS(fd) 0
 #   define SETFLAGS(fd, flags) /* nothing */
-#   define SETNONBLOCKING(fd) /* nothing */
+#   define SETNONBLOCKING(fd, oldFlags) /* nothing */
 #  endif
 
 #  define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \
   {                                                     \
-    int __offs = 0, __cnt;                                     \
+    int __offs = 0, __cnt;                              \
     int oldFlags;                                       \
-							\
+                                                        \
     (ret) = 0;                                          \
-    oldFlags = GETFLAGS(fileno(f));                     \
-    SETNONBLOCKING(fileno(f));                          \
+    SETNONBLOCKING(fileno(f), oldFlags);                \
     if (isBuffered) {                                   \
-	while (__offs < (cnt)) {                        \
-	    CLEAR_ERRNO;                                \
-	    (ret) = getc(f);                            \
-	    if ((ret) < 0) {                            \
-		if (ferror(f)) {                        \
-		    if (__threadErrno == 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 (__threadErrno == 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);                      \
   }
@@ -1024,34 +1019,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 && __threadErrno == 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 && __threadErrno == EINTR) {  \
+                        __HANDLE_INTERRUPTS__;          \
+                        /* refetch */                   \
+                        buf = (char *)(obj);   \
+                        continue;                       \
+                    }                                   \
+                    break;                              \
+                }                                       \
+                __offs += __cnt;                        \
+            }                                           \
+        }                                               \
+        if (__offs > 0)                                 \
+            (ret) = __offs;                             \
     }                                                   \
   }
 
@@ -1063,61 +1058,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 (__threadErrno == 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 (__threadErrno == 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 && __threadErrno == 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 && __threadErrno == EINTR) {  \
+                        __HANDLE_INTERRUPTS__;          \
+                        /* refetch */                   \
+                        buf = (char *)(obj);   \
+                        continue;                       \
+                    }                                   \
+                    break;                              \
+                }                                       \
+                __offs += __cnt;                        \
+            }                                           \
+        }                                               \
+        if (__offs > 0)                                 \
+            (ret) = __offs;                             \
     }                                                   \
   }
 
@@ -1127,55 +1122,59 @@
     int __offs = 0;                                     \
     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 (__threadErrno == 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 (__threadErrno == 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);                      \
   }
 
 
@@ -1183,40 +1182,40 @@
 
 # ifdef NO_STDIO
 #  define __WRITEBYTE__(ret, f, buf, isBuffered, handleType)          \
-	for (;;) {                                      \
-	    CLEAR_ERRNO;                                \
-	    (ret) = WRITE(f, buf, 1, handleType);                   \
-	    if ((ret) >= 0 || __threadErrno != EINTR)           \
-		break;                                  \
-	    __HANDLE_INTERRUPTS__;                      \
-	}
+        for (;;) {                                      \
+            CLEAR_ERRNO;                                \
+            (ret) = WRITE(f, buf, 1, handleType);                   \
+            if ((ret) >= 0 || __threadErrno != 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 (__threadErrno == EINTR || __threadErrno == 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 (__threadErrno == EINTR || __threadErrno == 0) {     \
+                    __HANDLE_INTERRUPTS__;              \
+                    clearerr(f);                        \
+                    continue;                           \
+                }                                       \
+            } else                                      \
+                (ret) = 0;                              \
+            break;                                      \
+        }                                               \
     } else {                                            \
-	for (;;) {                                      \
-	    CLEAR_ERRNO;                                \
-	    (ret) = write(fileno(f), buf, 1);           \
-	    if ((ret) >= 0 || __threadErrno != EINTR)           \
-		break;                                  \
-	    __HANDLE_INTERRUPTS__;                      \
-	}                                               \
+        for (;;) {                                      \
+            CLEAR_ERRNO;                                \
+            (ret) = write(fileno(f), buf, 1);           \
+            if ((ret) >= 0 || __threadErrno != EINTR)           \
+                break;                                  \
+            __HANDLE_INTERRUPTS__;                      \
+        }                                               \
    }
 # endif /* use STDIO */
 
@@ -1228,62 +1227,62 @@
 #  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 && __threadErrno == 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 && __threadErrno == 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 (__threadErrno == EINTR) {               \
-			__HANDLE_INTERRUPTS__;          \
-			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) {               \
+                        __HANDLE_INTERRUPTS__;          \
+                        clearerr(f);                    \
+                        continue;                       \
+                    }                                   \
+                    break;                              \
+                } else {                                \
+                    (ret) = 0;                          \
+                }                                       \
+            }                                           \
+            __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 && __threadErrno == 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 && __threadErrno == EINTR) {        \
+                    __HANDLE_INTERRUPTS__;              \
+                    continue;                           \
+                }                                       \
+                break;                                  \
+            }                                           \
+            __offs += (ret);                            \
+        }                                               \
+        if (__offs > 0)                                 \
+            (ret) = __offs;                             \
    }
 # endif /* use STDIO */
 
@@ -1297,25 +1296,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 && __threadErrno == 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 && __threadErrno == EINTR) { \
+                    __HANDLE_INTERRUPTS__;              \
+                    /* refetch */                       \
+                    buf = (char *)(obj);       \
+                    continue;                           \
+                }                                       \
+                break;                                  \
+            }                                           \
+            __offs += (ret);                            \
+        }                                               \
+        if (__offs > 0)                                 \
+            (ret) = __offs;                             \
     }                                                   \
   }
 # else /* use STDIO */
@@ -1324,47 +1323,47 @@
     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) {       \
-			__HANDLE_INTERRUPTS__;          \
-			/* 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) {       \
+                        __HANDLE_INTERRUPTS__;          \
+                        /* refetch */                   \
+                        buf = (char *)(obj);   \
+                        clearerr(f);                    \
+                        continue;                       \
+                    }                                   \
+                    break;                              \
+                } else {                                \
+                    (ret) = 0;                          \
+                }                                       \
+            }                                           \
+            __offs += (ret);                            \
+        }                                               \
+        if (__offs > 0)                                 \
+            (ret) = __offs;                             \
     } else {                                            \
-	while (__offs < (cnt)) {                        \
-	    CLEAR_ERRNO;                                \
-	    ret = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs);       \
-	    if (ret <= 0) {                             \
-		if (ret < 0 && __threadErrno == EINTR){ \
-		    __HANDLE_INTERRUPTS__;              \
-		    /* refetch */                       \
-		    buf = (char *)(obj);       \
-		    continue;                           \
-		}                                       \
-		break;                                  \
-	    }                                           \
-	    __offs += (ret);                            \
-	}                                               \
-	if (__offs > 0)                                 \
-	    (ret) = __offs;                             \
+        while (__offs < (cnt)) {                        \
+            CLEAR_ERRNO;                                \
+            ret = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs);       \
+            if (ret <= 0) {                             \
+                if (ret < 0 && __threadErrno == EINTR){ \
+                    __HANDLE_INTERRUPTS__;              \
+                    /* refetch */                       \
+                    buf = (char *)(obj);       \
+                    continue;                           \
+                }                                       \
+                break;                                  \
+            }                                           \
+            __offs += (ret);                            \
+        }                                               \
+        if (__offs > 0)                                 \
+            (ret) = __offs;                             \
     }                                                   \
   }
 # endif /* use STDIO */
@@ -3303,94 +3302,94 @@
      || (__INST(handleType) == @symbol(filePointer))
      || (__INST(handleType) == @symbol(socketFilePointer))
      || (__INST(handleType) == @symbol(pipeFilePointer))) {
-	if (((fp = __INST(handle)) != nil)
-	    && (__INST(mode) != @symbol(writeonly))
-	    && __bothSmallInteger(count, start)
-	) {
-	    f = __FILEVal(fp);
-
-	    cnt = __intVal(count);
-	    offs = __intVal(start) - 1;
-
-	    if (__isExternalBytesLike(anObject)) {
-		OBJ sz;
-
-		nInstBytes = 0;
-		extPtr = (char *)(__externalBytesAddress(anObject));
-		if (extPtr == NULL) goto bad;
-		sz = __externalBytesSize(anObject);
-		if (__isSmallInteger(sz)) {
-		    objSize = __intVal(sz);
-		} else {
-		    objSize = 0; /* unknown */
-		}
-	    } else {
-		OBJ oClass;
-
-		oClass = __Class(anObject);
-		switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
-		    case BYTEARRAY:
-		    case WORDARRAY:
-		    case LONGARRAY:
-		    case SWORDARRAY:
-		    case SLONGARRAY:
-		    case FLOATARRAY:
-		    case DOUBLEARRAY:
-			break;
-		    default:
-			goto bad;
-		}
-		extPtr = (char *)0;
-		nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
-		nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
-		objSize = __Size(anObject) - nInstBytes;
-	    }
-
-	    if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
-		_buffered = (__INST(buffered) == true);
-		if (_buffered) {
-		    __READING__(f);
-		}
-
-		if (extPtr) {
-		    __READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType));
-		} else {
-		    /*
-		     * on interrupt, anObject may be moved to another location.
-		     * So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__,
-		     * to get a new address.
-		     */
-		    offs += nInstBytes;
-		    __READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType));
-		}
+        if (((fp = __INST(handle)) != nil)
+            && (__INST(mode) != @symbol(writeonly))
+            && __bothSmallInteger(count, start)
+        ) {
+            f = __FILEVal(fp);
+
+            cnt = __intVal(count);
+            offs = __intVal(start) - 1;
+
+            if (__isExternalBytesLike(anObject)) {
+                OBJ sz;
+
+                nInstBytes = 0;
+                extPtr = (char *)(__externalBytesAddress(anObject));
+                if (extPtr == NULL) goto bad;
+                sz = __externalBytesSize(anObject);
+                if (__isSmallInteger(sz)) {
+                    objSize = __intVal(sz);
+                } else {
+                    objSize = 0; /* unknown */
+                }
+            } else {
+                OBJ oClass;
+
+                oClass = __Class(anObject);
+                switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+                    case BYTEARRAY:
+                    case WORDARRAY:
+                    case LONGARRAY:
+                    case SWORDARRAY:
+                    case SLONGARRAY:
+                    case FLOATARRAY:
+                    case DOUBLEARRAY:
+                        break;
+                    default:
+                        goto bad;
+                }
+                extPtr = (char *)0;
+                nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+                nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
+                objSize = __Size(anObject) - nInstBytes;
+            }
+
+            if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
+                _buffered = (__INST(buffered) == true);
+                if (_buffered) {
+                    __READING__(f);
+                }
+
+                if (extPtr) {
+                    __READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType));
+                } else {
+                    /*
+                     * on interrupt, anObject may be moved to another location.
+                     * So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__,
+                     * to get a new address.
+                     */
+                    offs += nInstBytes;
+                    __READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType));
+                }
 #ifdef PRE_22_jan_2000
-		if (ret > 0)
+                if (ret > 0)
 #else
-		/* 0 is NOT an EOF condition here ... */
-		if (ret >= 0)
+                /* 0 is NOT an EOF condition here ... */
+                if (ret >= 0)
 #endif
-		{
-		    if (__isSmallInteger(__INST(position))) {
-			INT np = __intVal(__INST(position)) + ret;
-			OBJ t;
-
-			t = __MKINT(np); __INST(position) = t; __STORE(self, t);
-		    } else {
-			__INST(position) = nil; /* i.e. do not know */
-		    }
-		    RETURN (__mkSmallInteger(ret));
-		}
+                {
+                    if (__isSmallInteger(__INST(position))) {
+                        INT np = __intVal(__INST(position)) + ret;
+                        OBJ t;
+
+                        t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+                    } else {
+                        __INST(position) = nil; /* i.e. do not know */
+                    }
+                    RETURN (__mkSmallInteger(ret));
+                }
 #ifdef PRE_22_jan_2000
-		if (ret == 0) {
-		    __INST(hitEOF) = true;
-		} else /* ret < 0 */
+                if (ret == 0) {
+                    __INST(hitEOF) = true;
+                } else /* ret < 0 */
 #endif
-		{
-		    __INST(position) = nil;
-		    __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
-		}
-	    }
-	}
+                {
+                    __INST(position) = nil;
+                    __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
+                }
+            }
+        }
     }
 bad: ;
 %}.
@@ -5763,11 +5762,11 @@
 !ExternalStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.362 2013-05-15 21:49:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.363 2013-05-31 12:50:39 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.362 2013-05-15 21:49:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.363 2013-05-31 12:50:39 stefan Exp $'
 ! !