ExternalStream.st
changeset 15435 fc902ce16af0
parent 15361 ff526d39bb07
child 15452 e2a3b2dc064b
child 18070 d262e3aecaca
--- a/ExternalStream.st	Wed Jun 26 10:00:12 2013 +0200
+++ b/ExternalStream.st	Wed Jun 26 13:04:06 2013 +0200
@@ -127,7 +127,7 @@
 # define WIN32_LEAN_AND_MEAN
 
 # include <windows.h>
-# include <winsock2.h> 
+# include <winsock2.h>
 
 # ifdef __DEF_Array
 #  define Array __DEF_Array
@@ -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;                             \
    }
 
 
@@ -927,7 +927,7 @@
 
 #  if defined(F_GETFL) && defined(F_SETFL) && (defined(O_NONBLOCK) || defined(O_NDELAY) || defined(FNDELAY))
 #   define SETFLAGS(fd, flags) \
-        fcntl(fd, F_SETFL, flags)
+	fcntl(fd, F_SETFL, flags)
 
 #   if defined(O_NONBLOCK)
 #    define __STX_NONBLOCK_FLAG O_NONBLOCK
@@ -940,13 +940,13 @@
 #   endif
 
 #   define SETNONBLOCKING(fd, oldFlags) \
-        { \
-            int flags = fcntl(fd, F_GETFL, 0); \
-            if (flags >= 0) { \
-                fcntl(fd, F_SETFL, flags | __STX_NONBLOCK_FLAG); \
-            } \
-            oldFlags = flags; \
-        }
+	{ \
+	    int flags = fcntl(fd, F_GETFL, 0); \
+	    if (flags >= 0) { \
+		fcntl(fd, F_SETFL, flags | __STX_NONBLOCK_FLAG); \
+	    } \
+	    oldFlags = flags; \
+	}
 #  else
 #   define SETFLAGS(fd, flags) /* nothing */
 #   define SETNONBLOCKING(fd, oldFlags) /* nothing */
@@ -956,52 +956,52 @@
   {                                                     \
     int __offs = 0, __cnt;                              \
     int oldFlags;                                       \
-                                                        \
+							\
     (ret) = 0;                                          \
     SETNONBLOCKING(fileno(f), oldFlags);                \
     if (isBuffered) {                                   \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = getc(f);                            \
-            if ((ret) < 0) {                            \
-                if (ferror(f)) {                        \
-                    if (__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);                      \
   }
@@ -1019,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;                             \
     }                                                   \
   }
 
@@ -1058,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;                             \
     }                                                   \
   }
 
@@ -1123,56 +1123,56 @@
     int __cnt;                                          \
     char *buf = (char *)(obj);                          \
     int oldFlags;                                       \
-                                                        \
+							\
     (ret) = 0;                                          \
     SETNONBLOCKING(fileno(f), oldFlags);                \
-                                                        \
+							\
     if (isBuffered) {                                   \
-        while (__offs < (cnt)) {                        \
-            CLEAR_ERRNO;                                \
-            (ret) = getc(f);                            \
-            if ((ret) < 0) {                            \
-                if (ferror(f)) {                        \
-                    if (__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);                      \
   }
@@ -1182,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 */
 
@@ -1227,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 */
 
@@ -1296,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 */
@@ -1323,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 */
@@ -3029,29 +3029,29 @@
      || (__INST(handleType) == @symbol(filePointer))
      || (__INST(handleType) == @symbol(socketFilePointer))
      || (__INST(handleType) == @symbol(pipeFilePointer))) {
-        if ((fp = __INST(handle)) != nil) {
-            f = __FILEVal(fp);
+	if ((fp = __INST(handle)) != nil) {
+	    f = __FILEVal(fp);
 #ifdef WIN32
-            __threadErrno = 0;
-            ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fileno(f)));
-            if (ret) {
-                RETURN (self);
-            }
+	    __threadErrno = 0;
+	    ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fileno(f)));
+	    if (ret) {
+		RETURN (self);
+	    }
 #else
 
-            __BEGIN_INTERRUPTABLE__
-            do {
-                __threadErrno = 0;
-                ret = fsync(fileno(f));
-            } while ((ret < 0) && (__threadErrno == EINTR));
-            __END_INTERRUPTABLE__
-
-            if (ret >= 0) {
-                RETURN (self);
-            }
+	    __BEGIN_INTERRUPTABLE__
+	    do {
+		__threadErrno = 0;
+		ret = fsync(fileno(f));
+	    } while ((ret < 0) && (__threadErrno == EINTR));
+	    __END_INTERRUPTABLE__
+
+	    if (ret >= 0) {
+		RETURN (self);
+	    }
 #endif /* ! WIN32 */
-            __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
-        }
+	    __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
+	}
     }
 #endif /* ! __openVMS__ */
 %}.
@@ -3059,9 +3059,9 @@
     handle isNil ifTrue:[^ self errorNotOpen].
 
     "
-        |f|
-        f := 'x' asFilename writeStream.
-        f nextPutAll:'hallo'; sync; syncData; close
+	|f|
+	f := 'x' asFilename writeStream.
+	f nextPutAll:'hallo'; sync; syncData; close
     "
 !
 
@@ -3082,32 +3082,32 @@
      || (__INST(handleType) == @symbol(filePointer))
      || (__INST(handleType) == @symbol(socketFilePointer))
      || (__INST(handleType) == @symbol(pipeFilePointer))) {
-        OBJ fp;
-        FILEPOINTER f;
-
-        if ((fp = __INST(handle)) != nil) {
-            f = __FILEVal(fp);
+	OBJ fp;
+	FILEPOINTER f;
+
+	if ((fp = __INST(handle)) != nil) {
+	    f = __FILEVal(fp);
 #ifdef WIN32
-            __threadErrno = 0;
-            ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fileno(f)));
-            if (ret) {
-                RETURN (self);
-            }
+	    __threadErrno = 0;
+	    ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fileno(f)));
+	    if (ret) {
+		RETURN (self);
+	    }
 #else
 
-            __BEGIN_INTERRUPTABLE__
-            do {
-                __threadErrno = 0;
-                ret = fdatasync(fileno(f));
-            } while ((ret < 0) && (__threadErrno == EINTR));
-            __END_INTERRUPTABLE__
-
-            if (ret >= 0) {
-                RETURN (self);
-            }
+	    __BEGIN_INTERRUPTABLE__
+	    do {
+		__threadErrno = 0;
+		ret = fdatasync(fileno(f));
+	    } while ((ret < 0) && (__threadErrno == EINTR));
+	    __END_INTERRUPTABLE__
+
+	    if (ret >= 0) {
+		RETURN (self);
+	    }
 #endif /* ! WIN32 */
-            __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
-        }
+	    __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
+	}
     }
 #endif /* ! __openVMS__ */
 %}.
@@ -3118,9 +3118,9 @@
     self sync.
 
     "
-        |f|
-        f := 'x' asFilename writeStream.
-        f nextPutAll:'hallo'; sync; syncData; close
+	|f|
+	f := 'x' asFilename writeStream.
+	f nextPutAll:'hallo'; sync; syncData; close
     "
 !
 
@@ -3302,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: ;
 %}.
@@ -4309,7 +4309,7 @@
 
 	    f = __FILEVal(fp);
 	    if (@global(FileOpenTrace) == true) {
-		fprintf(stderr, "fclose [ExternalStream] %x\n", f);
+		fprintf(stderr, "fclose [ExternalStream] %"_lx_"\n", (INT)f);
 	    }
 #ifdef WIN32
 	    if (__INST(mode) != @symbol(readonly)) {
@@ -4381,59 +4381,59 @@
 
     if (__isStringLike(openmode)) {
 #ifdef WIN32
-        __stxWrapApiEnterCritical();
+	__stxWrapApiEnterCritical();
 #endif
-        if (__isSmallInteger(aFileDescriptor)) {
-            fd = __intVal(aFileDescriptor);
-        }
+	if (__isSmallInteger(aFileDescriptor)) {
+	    fd = __intVal(aFileDescriptor);
+	}
 #ifdef WIN32
-        else if (__isExternalAddressLike(aFileDescriptor)) {
-            fd = _open_osfhandle((long)__externalAddressVal(aFileDescriptor), O_BINARY);
-            if (fd < 0) {
-                if (__threadErrno == 0) {
-                    // no more file descriptors
-                    __threadErrno = EMFILE;
-                }
-                error = __mkSmallInteger(__threadErrno);
-                __stxWrapApiLeaveCritical();
-                goto out;
-            }
-        }
+	else if (__isExternalAddressLike(aFileDescriptor)) {
+	    fd = _open_osfhandle((long)__externalAddressVal(aFileDescriptor), O_BINARY);
+	    if (fd < 0) {
+		if (__threadErrno == 0) {
+		    // no more file descriptors
+		    __threadErrno = EMFILE;
+		}
+		error = __mkSmallInteger(__threadErrno);
+		__stxWrapApiLeaveCritical();
+		goto out;
+	    }
+	}
 #endif
-        f = (FILEPOINTER) fdopen(fd, (char *)__stringVal(openmode));
+	f = (FILEPOINTER) fdopen(fd, (char *)__stringVal(openmode));
 #ifdef WIN32
-        __stxWrapApiLeaveCritical();
+	__stxWrapApiLeaveCritical();
 #endif
-        if (f == NULL) {
-            error =__mkSmallInteger(__threadErrno);
-        } else {
-            if (@global(FileOpenTrace) == true) {
-                fprintf(stderr, "fdopen [ExternalStream] %d (%x) -> %x\n", fd, fd, f);
-            }
-
-            fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
-            retVal = self;
-        }
+	if (f == NULL) {
+	    error =__mkSmallInteger(__threadErrno);
+	} else {
+	    if (@global(FileOpenTrace) == true) {
+		fprintf(stderr, "fdopen [ExternalStream] %d (%"_lx_") -> %x\n", fd, fd, (INT)f);
+	    }
+
+	    fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
+	    retVal = self;
+	}
     }
 out:;
 %}.
     retVal notNil ifTrue:[
-        position := 0.
-        buffered isNil ifTrue:[
-            buffered := true.       "default is buffered"
-        ].
-        handleType := handleTypeSymbol.
-        Lobby register:self.
-        ^ retVal
+	position := 0.
+	buffered isNil ifTrue:[
+	    buffered := true.       "default is buffered"
+	].
+	handleType := handleTypeSymbol.
+	Lobby register:self.
+	^ retVal
     ].
     error notNil ifTrue:[
-        OperatingSystem closeFd:aFileDescriptor.
-        lastErrorNumber := error.
-        position := nil.
-        "
-         the open failed for some reason ...
-        "
-        ^ self openError:error
+	OperatingSystem closeFd:aFileDescriptor.
+	lastErrorNumber := error.
+	position := nil.
+	"
+	 the open failed for some reason ...
+	"
+	^ self openError:error
     ].
 !
 
@@ -4482,36 +4482,36 @@
 # if 1
        f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString));
 # else
-        __BEGIN_INTERRUPTABLE__
-        do {
-            f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString));
-        } while ((f == NULL) && (__threadErrno == EINTR));
-        __END_INTERRUPTABLE__
+	__BEGIN_INTERRUPTABLE__
+	do {
+	    f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString));
+	} while ((f == NULL) && (__threadErrno == EINTR));
+	__END_INTERRUPTABLE__
 # endif
 #else /* UNIX */
-        __BEGIN_INTERRUPTABLE__
-        do {
-            f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString));
-        } while ((f == NULL) && (__threadErrno == EINTR));
-        __END_INTERRUPTABLE__
+	__BEGIN_INTERRUPTABLE__
+	do {
+	    f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString));
+	} while ((f == NULL) && (__threadErrno == EINTR));
+	__END_INTERRUPTABLE__
 #endif /* UNIX */
-        if (f == NULL) {
-            __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
-        } else {
-            if (@global(FileOpenTrace) == true) {
-                fprintf(stderr, "fopen %s [ExternalStream] -> %x\n", __stringVal(aPath), f);
-            }
-            fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
-            __INST(handleType) = @symbol(filePointer);
-            ok = true;
-        }
+	if (f == NULL) {
+	    __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
+	} else {
+	    if (@global(FileOpenTrace) == true) {
+		fprintf(stderr, "fopen %s [ExternalStream] -> %"_lx_"\n", __stringVal(aPath), (INT)f);
+	    }
+	    fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
+	    __INST(handleType) = @symbol(filePointer);
+	    ok = true;
+	}
     }
 %}.
     ok ifFalse:[
-        "
-         the open failed for some reason ...
-        "
-        ^ self openError:lastErrorNumber.
+	"
+	 the open failed for some reason ...
+	"
+	^ self openError:lastErrorNumber.
     ].
     position := 0.
     Lobby register:self.
@@ -4595,7 +4595,7 @@
 #endif
     if (f != NULL) {
 	if (@global(FileOpenTrace) == true) {
-	    fprintf(stderr, "fdopen [ExternalStream] %d -> %x\n", fd, f);
+	    fprintf(stderr, "fdopen [ExternalStream] %d -> %"_lx_"\n", fd, (INT)f);
 	}
 	fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
 	__INST(handleType) = @symbol(filePointer);
@@ -5745,11 +5745,11 @@
      This is needed, so that you can do ('something' asUnicode16String errorPrintCR)"
 
     aString do:[:eachCharacter|
-        self nextPutUtf8:eachCharacter.
+	self nextPutUtf8:eachCharacter.
     ].
 
     "
-        'Bönnigheim' asUnicode16String errorPrintCR
+	'Bönnigheim' asUnicode16String errorPrintCR
     "
 !
 
@@ -5762,11 +5762,11 @@
 !ExternalStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.364 2013-06-03 18:41:42 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.365 2013-06-26 11:04:06 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.364 2013-06-03 18:41:42 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.365 2013-06-26 11:04:06 cg Exp $'
 ! !