--- a/ExternalStream.st Fri Nov 18 20:48:57 2016 +0000
+++ b/ExternalStream.st Tue Nov 22 14:52:52 2016 +0000
@@ -211,7 +211,7 @@
# define DEBUGBUFFER(buf) \
if (((char *)(buf) >= __survStartPtr) \
&& ((char *)(buf) < __survEndPtr)) { \
- __fatal0("read into survivor\n"); \
+ __fatal0("read into survivor\n"); \
}
#else
@@ -234,33 +234,33 @@
// Win returns from ReadFile() with false and _threadErrno == 0 on end of pipe.
// We don't know why
# define READ(ret, f, cp, n, handleType) { \
- if (handleType == @symbol(socketHandle)) { \
- (ret) = __STX_WSA_NOINT_CALL4("recv", recv, (f), (cp), (n), 0); \
- } else { \
- HANDLE h = _get_osfhandle(fileno(f)); \
- if (handleType == @symbol(socketFilePointer)) { \
- (ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\
- } else { \
- int __res; \
- (ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\
- (ret) = (ret) ? __res : ((__threadErrno == EPIPE || __threadErrno == 0) ? 0 : -1); \
- } \
- } \
+ if (handleType == @symbol(socketHandle)) { \
+ (ret) = __STX_WSA_NOINT_CALL4("recv", recv, (f), (cp), (n), 0); \
+ } else { \
+ HANDLE h = _get_osfhandle(fileno(f)); \
+ if (handleType == @symbol(socketFilePointer)) { \
+ (ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\
+ } else { \
+ int __res; \
+ (ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\
+ (ret) = (ret) ? __res : ((__threadErrno == EPIPE || __threadErrno == 0) ? 0 : -1); \
+ } \
+ } \
}
# define WRITE(ret, f, cp, n, handleType) { \
- if (handleType == @symbol(socketHandle)) { \
- (ret) = __STX_WSA_NOINT_CALL4("send", send, (f), (cp), (n), 0); \
- } else {\
- HANDLE h = _get_osfhandle(fileno(f)); \
- if (handleType == @symbol(socketFilePointer)) { \
- (ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\
- } else {\
- int __res; \
- (ret) = __STX_API_NOINT_CALL5("WriteFile", WriteFile, h, (cp), (n), &__res, 0);\
- (ret) = (ret) ? __res : -1; \
- } \
- } \
+ if (handleType == @symbol(socketHandle)) { \
+ (ret) = __STX_WSA_NOINT_CALL4("send", send, (f), (cp), (n), 0); \
+ } else {\
+ HANDLE h = _get_osfhandle(fileno(f)); \
+ if (handleType == @symbol(socketFilePointer)) { \
+ (ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\
+ } else {\
+ int __res; \
+ (ret) = __STX_API_NOINT_CALL5("WriteFile", WriteFile, h, (cp), (n), &__res, 0);\
+ (ret) = (ret) ? __res : -1; \
+ } \
+ } \
}
# define FFLUSH(fp) fflush(fp)
@@ -271,56 +271,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; \
+ } \
+ } \
}
/*
@@ -330,110 +330,112 @@
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \
(ret) = 0; \
if (isBuffered) { \
- int __offs = 0; \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = getc(f); \
- if ((ret) < 0) { \
- if (ferror(f)) { \
- if (__threadErrno == EINTR) { \
- clearerr(f); \
- continue; \
- } \
- } else { \
- (ret) = 0; \
- } \
- break; \
- } \
- (buf)[__offs++] = (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = getc(f); \
+ if ((ret) < 0) { \
+ if (ferror(f)) { \
+ if (__threadErrno == EINTR) { \
+ clearerr(f); \
+ continue; \
+ } \
+ } else { \
+ (ret) = 0; \
+ } \
+ break; \
+ } \
+ (buf)[__offs++] = (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} else { \
- int __offs = 0; \
- \
- while (__offs < (cnt)) { \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- (buf)[__offs] = __intVal(rA); \
- __INST(readAhead) = nil; \
- (ret) = 1; \
- } else { \
- CLEAR_ERRNO; \
- READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \
- if ((ret) <= 0) { \
- if ((ret) < 0 && __threadErrno == EINTR) { \
- continue; \
- } \
- break; \
- } \
- } \
- __offs += (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0; \
+ \
+ while (__offs < (cnt)) { \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ (buf)[__offs] = __intVal(rA); \
+ __INST(readAhead) = nil; \
+ (ret) = 1; \
+ } else { \
+ CLEAR_ERRNO; \
+ READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \
+ if ((ret) <= 0) { \
+ if ((ret) < 0 && __threadErrno == EINTR) { \
+ continue; \
+ } \
+ break; \
+ } \
+ } \
+ __offs += (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
}
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \
{ \
int __offs = 0; \
int oldFlags; \
- \
+ \
(ret) = 0; \
if (isBuffered) { \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = getc(f); \
- if ((ret) < 0) { \
- if (ferror(f)) { \
- if (__threadErrno == EINTR) { \
- clearerr(f); \
- continue; \
- } \
- } else { \
- (ret) = 0; \
- } \
- break; \
- } \
- (buf)[__offs++] = (ret); \
- } \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = getc(f); \
+ if ((ret) < 0) { \
+ if (ferror(f)) { \
+ if (__threadErrno == EINTR) { \
+ clearerr(f); \
+ continue; \
+ } \
+ } else { \
+ (ret) = 0; \
+ } \
+ break; \
+ } \
+ (buf)[__offs++] = (ret); \
+ } \
+ 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 ++; \
- continue; \
- } \
- CLEAR_ERRNO; \
- { \
- int res = 0; \
- if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res), 1)) \
- || (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \
- || (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0), 1))) { \
- if (res > 0) { \
- if (res > ((cnt)-__offs)) \
- res = (cnt)-__offs; \
- READ((ret), f, (buf)+__offs, res, handleType); \
- } else { \
- (ret) = 0; \
- break; \
- } \
- } else { \
- READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \
- } \
- } \
- if ((ret) <= 0) { \
- if (ret < 0 && __threadErrno == EINTR) \
- continue; \
- break; \
- } \
- __offs += (ret); \
- } \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ (buf)[__offs] = __intVal(rA); \
+ __INST(readAhead) = nil; \
+ (ret) = 1; \
+ __offs ++; \
+ continue; \
+ } \
+ CLEAR_ERRNO; \
+ { \
+ int res = 0; \
+ if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res), 1)) \
+ || (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \
+ || (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0), 1))) { \
+ if (res > 0) { \
+ if (res > ((cnt)-__offs)) \
+ res = (cnt)-__offs; \
+ READ((ret), f, (buf)+__offs, res, handleType); \
+ } else { \
+ (ret) = 0; \
+ break; \
+ } \
+ } else { \
+ READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \
+ } \
+ } \
+ if ((ret) <= 0) { \
+ if (ret < 0 && __threadErrno == EINTR) \
+ continue; \
+ break; \
+ } \
+ __offs += (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} \
}
@@ -444,63 +446,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; \
} \
}
@@ -509,141 +511,141 @@
int __ooffs = obj_offs; \
int __offs = 0; \
char *buf = (char *)(obj); \
- \
+ \
(ret) = 0; \
if (isBuffered) { \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = getc(f); \
- if ((ret) < 0) { \
- if (ferror(f)) { \
- if (__threadErrno == EINTR) { \
- clearerr(f); \
- /* refetch */ \
- buf = (char *)(obj);\
- continue; \
- } \
- } else { \
- (ret) = 0; \
- } \
- break; \
- } \
- (buf)[__ooffs+__offs] = (ret); \
- __offs++; \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = getc(f); \
+ if ((ret) < 0) { \
+ if (ferror(f)) { \
+ if (__threadErrno == EINTR) { \
+ clearerr(f); \
+ /* refetch */ \
+ buf = (char *)(obj);\
+ continue; \
+ } \
+ } else { \
+ (ret) = 0; \
+ } \
+ break; \
+ } \
+ (buf)[__ooffs+__offs] = (ret); \
+ __offs++; \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} else { \
- while (__offs < (cnt)) { \
- char __buf[IO_BUFFER_SIZE]; \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- (buf)[__ooffs+__offs] = __intVal(rA);\
- __INST(readAhead) = nil; \
- (ret) = 1; \
- __offs++; \
- continue; \
- } \
- { \
- int res = 0; \
- int l = (cnt)-__offs; \
- CLEAR_ERRNO; \
- if (l > IO_BUFFER_SIZE) \
- l = IO_BUFFER_SIZE; \
- if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)), FIONREAD, &res), 1)) \
- || (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \
- || (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0,0,0,&res,0), 1))) { \
- if (res > 0) { \
- if (res > l) res = l; \
- READ((ret), f, __buf, res, handleType); \
- } else { \
- (ret) = 0; \
- break; \
- } \
- } else { \
- READ((ret), f, __buf, l, handleType); \
- } \
- if ((ret) <= 0) { \
- if (ret < 0 && __threadErrno == EINTR) \
- continue; \
- break; \
- } \
- } \
- if ((ret) > 0) { \
- buf = (char *)(obj); \
- memcpy((buf)+__ooffs+__offs, __buf, (ret)); \
- __offs += (ret); \
- } else { \
- (ret) = 0; \
- } \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ char __buf[IO_BUFFER_SIZE]; \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ (buf)[__ooffs+__offs] = __intVal(rA);\
+ __INST(readAhead) = nil; \
+ (ret) = 1; \
+ __offs++; \
+ continue; \
+ } \
+ { \
+ int res = 0; \
+ int l = (cnt)-__offs; \
+ CLEAR_ERRNO; \
+ if (l > IO_BUFFER_SIZE) \
+ l = IO_BUFFER_SIZE; \
+ if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)), FIONREAD, &res), 1)) \
+ || (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \
+ || (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0,0,0,&res,0), 1))) { \
+ if (res > 0) { \
+ if (res > l) res = l; \
+ READ((ret), f, __buf, res, handleType); \
+ } else { \
+ (ret) = 0; \
+ break; \
+ } \
+ } else { \
+ READ((ret), f, __buf, l, handleType); \
+ } \
+ if ((ret) <= 0) { \
+ if (ret < 0 && __threadErrno == EINTR) \
+ continue; \
+ break; \
+ } \
+ } \
+ if ((ret) > 0) { \
+ buf = (char *)(obj); \
+ memcpy((buf)+__ooffs+__offs, __buf, (ret)); \
+ __offs += (ret); \
+ } else { \
+ (ret) = 0; \
+ } \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} \
}
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \
if (isBuffered) { \
- for (;;) { \
- CLEAR_ERRNO; \
- ret = putc(*(buf), f); \
- if ((ret) >= 0) { \
- (ret) = 1; \
- } else if (ferror(f)) { \
- if (__threadErrno == EINTR) { \
- clearerr(f); \
- continue; \
- } \
- } else \
- (ret) = 0; \
- break; \
- } \
+ for (;;) { \
+ CLEAR_ERRNO; \
+ ret = putc(*(buf), f); \
+ if ((ret) >= 0) { \
+ (ret) = 1; \
+ } else if (ferror(f)) { \
+ if (__threadErrno == EINTR) { \
+ clearerr(f); \
+ continue; \
+ } \
+ } else \
+ (ret) = 0; \
+ break; \
+ } \
} else { \
- for (;;) { \
- CLEAR_ERRNO; \
- WRITE(ret,f, buf, 1, handleType); \
- if ((ret) >= 0 || __threadErrno != EINTR) \
- break; \
- } \
+ for (;;) { \
+ CLEAR_ERRNO; \
+ WRITE(ret,f, buf, 1, handleType); \
+ if ((ret) >= 0 || __threadErrno != EINTR) \
+ break; \
+ } \
}
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \
(ret) = 0; \
if (isBuffered) { \
- int __offs = 0; \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
- if ((ret) <= 0) { \
- if (ferror(f)) { \
- if (__threadErrno == EINTR) { \
- clearerr(f); \
- continue; \
- } \
- break; \
- } else { \
- (ret) = 0; \
- } \
- } \
- __offs += (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
+ if ((ret) <= 0) { \
+ if (ferror(f)) { \
+ if (__threadErrno == EINTR) { \
+ clearerr(f); \
+ continue; \
+ } \
+ break; \
+ } else { \
+ (ret) = 0; \
+ } \
+ } \
+ __offs += (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} else { \
- int __offs = 0; \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- WRITE(ret,f, (buf)+__offs, (cnt)-__offs, handleType); \
- if (ret <= 0) { \
- if (ret < 0 && __threadErrno == EINTR) { \
- continue; \
- } \
- break; \
- } \
- __offs += (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ WRITE(ret,f, (buf)+__offs, (cnt)-__offs, handleType); \
+ if (ret <= 0) { \
+ if (ret < 0 && __threadErrno == EINTR) { \
+ continue; \
+ } \
+ break; \
+ } \
+ __offs += (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
}
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \
@@ -651,51 +653,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; \
} \
}
@@ -706,15 +708,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 */ \
}
@@ -724,73 +726,73 @@
# else /* use STDIO */
# define __UNGETC__(c, f, isBuffered) \
if (isBuffered) { \
- ungetc((c), (f)); \
+ ungetc((c), (f)); \
} else { \
- __INST(readAhead) = __mkSmallInteger((c)); \
+ __INST(readAhead) = __mkSmallInteger((c)); \
}
# endif /* use STDIO */
# ifdef NO_STDIO
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \
{ \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- *(buf) = __intVal(rA); \
- DEBUGBUFFER(buf); \
- __INST(readAhead) = nil; \
- (ret) = 1; \
- } else { \
- for (;;) { \
- CLEAR_ERRNO; \
- (ret) = READ(f, buf, 1, handleType); \
- DEBUGBUFFER(buf); \
- if ((ret) >= 0) break; \
- if (errno != EINTR) { \
- break; \
- } \
- __HANDLE_INTERRUPTS__; \
- } \
- } \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ *(buf) = __intVal(rA); \
+ DEBUGBUFFER(buf); \
+ __INST(readAhead) = nil; \
+ (ret) = 1; \
+ } else { \
+ for (;;) { \
+ CLEAR_ERRNO; \
+ (ret) = READ(f, buf, 1, handleType); \
+ DEBUGBUFFER(buf); \
+ if ((ret) >= 0) break; \
+ if (errno != EINTR) { \
+ break; \
+ } \
+ __HANDLE_INTERRUPTS__; \
+ } \
+ } \
}
# else /* use STDIO */
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \
if (isBuffered) { \
- for (;;) { \
- CLEAR_ERRNO; \
- (ret) = getc(f); \
- if ((ret) >= 0) { \
- DEBUGBUFFER(buf); \
- *(buf) = (ret); \
- (ret) = 1; \
- } else if (ferror(f)) { \
- if (errno == EINTR) { \
- __HANDLE_INTERRUPTS__; \
- clearerr(f); \
- continue; \
- } \
- } else \
- (ret) = 0; \
- break; \
- } \
+ for (;;) { \
+ CLEAR_ERRNO; \
+ (ret) = getc(f); \
+ if ((ret) >= 0) { \
+ DEBUGBUFFER(buf); \
+ *(buf) = (ret); \
+ (ret) = 1; \
+ } else if (ferror(f)) { \
+ if (errno == EINTR) { \
+ __HANDLE_INTERRUPTS__; \
+ clearerr(f); \
+ continue; \
+ } \
+ } else \
+ (ret) = 0; \
+ break; \
+ } \
} else { \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- *(buf) = __intVal(rA); \
- DEBUGBUFFER(buf); \
- __INST(readAhead) = nil; \
- (ret) = 1; \
- } else { \
- for (;;) { \
- CLEAR_ERRNO; \
- (ret) = read(fileno(f), buf, 1); \
- DEBUGBUFFER(buf); \
- if ((ret) >= 0) break; \
- if (errno != EINTR) { \
- break; \
- } \
- __HANDLE_INTERRUPTS__; \
- } \
- } \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ *(buf) = __intVal(rA); \
+ DEBUGBUFFER(buf); \
+ __INST(readAhead) = nil; \
+ (ret) = 1; \
+ } else { \
+ for (;;) { \
+ CLEAR_ERRNO; \
+ (ret) = read(fileno(f), buf, 1); \
+ DEBUGBUFFER(buf); \
+ if ((ret) >= 0) break; \
+ if (errno != EINTR) { \
+ break; \
+ } \
+ __HANDLE_INTERRUPTS__; \
+ } \
+ } \
}
# endif /* use STDIO */
@@ -801,84 +803,84 @@
# ifdef NO_STDIO
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \
{ \
- int __offs = 0, __cnt; \
- \
- while (__offs < (cnt)) { \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- (buf)[__offs] = __intVal(rA); \
- DEBUGBUFFER(buf); \
- __INST(readAhead) = nil; \
- __offs++; \
- } else { \
- CLEAR_ERRNO; \
- __cnt = READ(f, (buf)+__offs, (cnt)-__offs, handleType); \
- DEBUGBUFFER(buf); \
- if (__cnt <= 0) { \
- if (__cnt < 0 && errno == EINTR) { \
- __HANDLE_INTERRUPTS__; \
- continue; \
- } \
- break; \
- } \
- __offs += __cnt; \
- } \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0, __cnt; \
+ \
+ while (__offs < (cnt)) { \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ (buf)[__offs] = __intVal(rA); \
+ DEBUGBUFFER(buf); \
+ __INST(readAhead) = nil; \
+ __offs++; \
+ } else { \
+ CLEAR_ERRNO; \
+ __cnt = READ(f, (buf)+__offs, (cnt)-__offs, handleType); \
+ DEBUGBUFFER(buf); \
+ if (__cnt <= 0) { \
+ if (__cnt < 0 && errno == EINTR) { \
+ __HANDLE_INTERRUPTS__; \
+ continue; \
+ } \
+ break; \
+ } \
+ __offs += __cnt; \
+ } \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
}
# else /* use STDIO */
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \
(ret) = 0; \
if (isBuffered) { \
- int __offs = 0; \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = getc(f); \
- if ((ret) < 0) { \
- if (ferror(f)) { \
- if (errno == EINTR) { \
- __HANDLE_INTERRUPTS__; \
- clearerr(f); \
- continue; \
- } \
- } else { \
- (ret) = 0; \
- } \
- break; \
- } \
- DEBUGBUFFER(buf); \
- (buf)[__offs++] = (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = getc(f); \
+ if ((ret) < 0) { \
+ if (ferror(f)) { \
+ if (errno == EINTR) { \
+ __HANDLE_INTERRUPTS__; \
+ clearerr(f); \
+ continue; \
+ } \
+ } else { \
+ (ret) = 0; \
+ } \
+ break; \
+ } \
+ DEBUGBUFFER(buf); \
+ (buf)[__offs++] = (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} else { \
- int __offs = 0, __cnt; \
- int fd = fileno(f); \
- \
- while (__offs < (cnt)) { \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- DEBUGBUFFER(buf); \
- (buf)[__offs] = __intVal(rA); \
- __INST(readAhead) = nil; \
- __offs++; \
- } else { \
- CLEAR_ERRNO; \
- __cnt = read(fd, (buf)+__offs, (cnt)-__offs); \
- DEBUGBUFFER(buf); \
- if (__cnt <= 0) { \
- if (__cnt < 0 && errno == EINTR) { \
- __HANDLE_INTERRUPTS__; \
- continue; \
- } \
- break; \
- } \
- __offs += __cnt; \
- } \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0, __cnt; \
+ int fd = fileno(f); \
+ \
+ while (__offs < (cnt)) { \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ DEBUGBUFFER(buf); \
+ (buf)[__offs] = __intVal(rA); \
+ __INST(readAhead) = nil; \
+ __offs++; \
+ } else { \
+ CLEAR_ERRNO; \
+ __cnt = read(fd, (buf)+__offs, (cnt)-__offs); \
+ DEBUGBUFFER(buf); \
+ if (__cnt <= 0) { \
+ if (__cnt < 0 && errno == EINTR) { \
+ __HANDLE_INTERRUPTS__; \
+ continue; \
+ } \
+ break; \
+ } \
+ __offs += __cnt; \
+ } \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
}
@@ -888,7 +890,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
@@ -901,13 +903,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 */
@@ -917,52 +919,52 @@
{ \
int __offs = 0, __cnt; \
int oldFlags; \
- \
+ \
(ret) = 0; \
SETNONBLOCKING(fileno(f), oldFlags); \
if (isBuffered) { \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = getc(f); \
- if ((ret) < 0) { \
- if (ferror(f)) { \
- if (errno == EINTR) { \
- (ret) = 0; \
- clearerr(f); \
- break; \
- } \
- } else { \
- (ret) = 0; \
- } \
- break; \
- } \
- (buf)[__offs++] = (ret); \
- DEBUGBUFFER(buf); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = getc(f); \
+ if ((ret) < 0) { \
+ if (ferror(f)) { \
+ if (errno == EINTR) { \
+ (ret) = 0; \
+ clearerr(f); \
+ break; \
+ } \
+ } else { \
+ (ret) = 0; \
+ } \
+ break; \
+ } \
+ (buf)[__offs++] = (ret); \
+ DEBUGBUFFER(buf); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} else { \
- int fd = fileno(f); \
- \
- while (__offs < (cnt)) { \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- (buf)[__offs] = __intVal(rA); \
- DEBUGBUFFER(buf); \
- __INST(readAhead) = nil; \
- __offs++; \
- continue; \
- } \
- CLEAR_ERRNO; \
- __cnt = read(fd, (buf)+__offs, (cnt)-__offs); \
- DEBUGBUFFER(buf); \
- if (__cnt > 0) { \
- __offs += __cnt; \
- } \
- break; \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int fd = fileno(f); \
+ \
+ while (__offs < (cnt)) { \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ (buf)[__offs] = __intVal(rA); \
+ DEBUGBUFFER(buf); \
+ __INST(readAhead) = nil; \
+ __offs++; \
+ continue; \
+ } \
+ CLEAR_ERRNO; \
+ __cnt = read(fd, (buf)+__offs, (cnt)-__offs); \
+ DEBUGBUFFER(buf); \
+ if (__cnt > 0) { \
+ __offs += __cnt; \
+ } \
+ break; \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} \
SETFLAGS(fileno(f), oldFlags); \
}
@@ -980,34 +982,34 @@
int __offs = 0; \
int __cnt; \
char *buf = (char *)(obj); \
- \
+ \
(ret) = 0; \
{ \
- while (__offs < (cnt)) { \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- (buf)[__ooffs+__offs] = __intVal(rA); \
- DEBUGBUFFER(buf); \
- __INST(readAhead) = nil; \
- __offs++; \
- } else { \
- CLEAR_ERRNO; \
- __cnt = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \
- DEBUGBUFFER(buf); \
- if (__cnt <= 0) { \
- if (__cnt < 0 && errno == EINTR) { \
- __HANDLE_INTERRUPTS__; \
- /* refetch */ \
- buf = (char *)(obj); \
- continue; \
- } \
- break; \
- } \
- __offs += __cnt; \
- } \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ (buf)[__ooffs+__offs] = __intVal(rA); \
+ DEBUGBUFFER(buf); \
+ __INST(readAhead) = nil; \
+ __offs++; \
+ } else { \
+ CLEAR_ERRNO; \
+ __cnt = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \
+ DEBUGBUFFER(buf); \
+ if (__cnt <= 0) { \
+ if (__cnt < 0 && errno == EINTR) { \
+ __HANDLE_INTERRUPTS__; \
+ /* refetch */ \
+ buf = (char *)(obj); \
+ continue; \
+ } \
+ break; \
+ } \
+ __offs += __cnt; \
+ } \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} \
}
@@ -1019,61 +1021,61 @@
int __offs = 0; \
int __cnt; \
char *buf = (char *)(obj); \
- \
+ \
(ret) = 0; \
if (isBuffered) { \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = getc(f); \
- if ((ret) < 0) { \
- if (ferror(f)) { \
- if (errno == EINTR) { \
- __HANDLE_INTERRUPTS__; \
- clearerr(f); \
- /* refetch */ \
- buf = (char *)(obj); \
- DEBUGBUFFER(buf); \
- continue; \
- } \
- } else { \
- (ret) = 0; \
- } \
- break; \
- } \
- (buf)[__ooffs+__offs] = (ret); \
- DEBUGBUFFER(buf); \
- __offs++; \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = getc(f); \
+ if ((ret) < 0) { \
+ if (ferror(f)) { \
+ if (errno == EINTR) { \
+ __HANDLE_INTERRUPTS__; \
+ clearerr(f); \
+ /* refetch */ \
+ buf = (char *)(obj); \
+ DEBUGBUFFER(buf); \
+ continue; \
+ } \
+ } else { \
+ (ret) = 0; \
+ } \
+ break; \
+ } \
+ (buf)[__ooffs+__offs] = (ret); \
+ DEBUGBUFFER(buf); \
+ __offs++; \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} else { \
- int fd = fileno(f); \
- \
- while (__offs < (cnt)) { \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- (buf)[__ooffs+__offs] = __intVal(rA); \
- DEBUGBUFFER(buf); \
- __INST(readAhead) = nil; \
- __offs++; \
- } else { \
- CLEAR_ERRNO; \
- __cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
- DEBUGBUFFER(buf); \
- if (__cnt <= 0) { \
- if (__cnt < 0 && errno == EINTR) { \
- __HANDLE_INTERRUPTS__; \
- /* refetch */ \
- buf = (char *)(obj); \
- continue; \
- } \
- break; \
- } \
- __offs += __cnt; \
- } \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int fd = fileno(f); \
+ \
+ while (__offs < (cnt)) { \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ (buf)[__ooffs+__offs] = __intVal(rA); \
+ DEBUGBUFFER(buf); \
+ __INST(readAhead) = nil; \
+ __offs++; \
+ } else { \
+ CLEAR_ERRNO; \
+ __cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
+ DEBUGBUFFER(buf); \
+ if (__cnt <= 0) { \
+ if (__cnt < 0 && errno == EINTR) { \
+ __HANDLE_INTERRUPTS__; \
+ /* refetch */ \
+ buf = (char *)(obj); \
+ continue; \
+ } \
+ break; \
+ } \
+ __offs += __cnt; \
+ } \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} \
}
@@ -1084,56 +1086,56 @@
int __cnt; \
char *buf = (char *)(obj); \
int oldFlags; \
- \
+ \
(ret) = 0; \
SETNONBLOCKING(fileno(f), oldFlags); \
- \
+ \
if (isBuffered) { \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = getc(f); \
- if ((ret) < 0) { \
- if (ferror(f)) { \
- if (errno == EINTR) { \
- clearerr(f); \
- /* refetch */ \
- buf = (char *)(obj); \
- (ret) = 0; \
- break; \
- } \
- } else { \
- (ret) = 0; \
- } \
- break; \
- } \
- (buf)[__ooffs+__offs] = (ret); \
- DEBUGBUFFER(buf); \
- __offs++; \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = getc(f); \
+ if ((ret) < 0) { \
+ if (ferror(f)) { \
+ if (errno == EINTR) { \
+ clearerr(f); \
+ /* refetch */ \
+ buf = (char *)(obj); \
+ (ret) = 0; \
+ break; \
+ } \
+ } else { \
+ (ret) = 0; \
+ } \
+ break; \
+ } \
+ (buf)[__ooffs+__offs] = (ret); \
+ DEBUGBUFFER(buf); \
+ __offs++; \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} else { \
- int fd = fileno(f); \
- \
- while (__offs < (cnt)) { \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- (buf)[__ooffs+__offs] = __intVal(rA); \
- DEBUGBUFFER(buf); \
- __INST(readAhead) = nil; \
- __offs++; \
- continue; \
- } \
- CLEAR_ERRNO; \
- __cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
- DEBUGBUFFER(buf); \
- if (__cnt > 0) { \
- __offs += __cnt; \
- } \
- break; \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int fd = fileno(f); \
+ \
+ while (__offs < (cnt)) { \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ (buf)[__ooffs+__offs] = __intVal(rA); \
+ DEBUGBUFFER(buf); \
+ __INST(readAhead) = nil; \
+ __offs++; \
+ continue; \
+ } \
+ CLEAR_ERRNO; \
+ __cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
+ DEBUGBUFFER(buf); \
+ if (__cnt > 0) { \
+ __offs += __cnt; \
+ } \
+ break; \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} \
SETFLAGS(fileno(f), oldFlags); \
}
@@ -1143,44 +1145,44 @@
# ifdef NO_STDIO
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \
- for (;;) { \
- CLEAR_ERRNO; \
- (ret) = WRITE(f, buf, 1, handleType); \
- if ((ret) >= 0) break; \
- if (errno != EINTR) { \
- break; \
- } \
- __HANDLE_INTERRUPTS__; \
- }
+ for (;;) { \
+ CLEAR_ERRNO; \
+ (ret) = WRITE(f, buf, 1, handleType); \
+ if ((ret) >= 0) break; \
+ if (errno != EINTR) { \
+ break; \
+ } \
+ __HANDLE_INTERRUPTS__; \
+ }
# else /* use STDIO */
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \
if (isBuffered) { \
- for (;;) { \
- CLEAR_ERRNO; \
- ret = putc(*(buf), f); \
- if ((ret) >= 0) { \
- (ret) = 1; \
- } else if (ferror(f)) { \
- /* SOLARIS/SPARC (2.6) generates spurious errors with errno = 0 */ \
- if (errno == EINTR || errno == 0) { \
- __HANDLE_INTERRUPTS__; \
- clearerr(f); \
- continue; \
- } \
- } else \
- (ret) = 0; \
- break; \
- } \
+ for (;;) { \
+ CLEAR_ERRNO; \
+ ret = putc(*(buf), f); \
+ if ((ret) >= 0) { \
+ (ret) = 1; \
+ } else if (ferror(f)) { \
+ /* SOLARIS/SPARC (2.6) generates spurious errors with errno = 0 */ \
+ if (errno == EINTR || errno == 0) { \
+ __HANDLE_INTERRUPTS__; \
+ clearerr(f); \
+ continue; \
+ } \
+ } else \
+ (ret) = 0; \
+ break; \
+ } \
} else { \
- for (;;) { \
- CLEAR_ERRNO; \
- (ret) = write(fileno(f), buf, 1); \
- if ((ret) >= 0) break; \
- if (errno != EINTR) { \
- break; \
- } \
- __HANDLE_INTERRUPTS__; \
- } \
+ for (;;) { \
+ CLEAR_ERRNO; \
+ (ret) = write(fileno(f), buf, 1); \
+ if ((ret) >= 0) break; \
+ if (errno != EINTR) { \
+ break; \
+ } \
+ __HANDLE_INTERRUPTS__; \
+ } \
}
# endif /* use STDIO */
@@ -1192,64 +1194,64 @@
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \
(ret) = 0; \
{ \
- int __offs = 0; \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- ret = WRITE(f, (buf)+__offs, (cnt)-__offs, handleType); \
- if (ret <= 0) { \
- if (ret < 0 && errno == EINTR) { \
- __HANDLE_INTERRUPTS__; \
- continue; \
- } \
- break; \
- } \
- __offs += (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ ret = WRITE(f, (buf)+__offs, (cnt)-__offs, handleType); \
+ if (ret <= 0) { \
+ if (ret < 0 && errno == EINTR) { \
+ __HANDLE_INTERRUPTS__; \
+ continue; \
+ } \
+ break; \
+ } \
+ __offs += (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
}
# else /* use STDIO */
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \
(ret) = 0; \
if (isBuffered) { \
- int __offs = 0; \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
- if ((ret) <= 0) { \
- if (ferror(f)) { \
- if (errno == EINTR) { \
- __HANDLE_INTERRUPTS__; \
- clearerr(f); \
- continue; \
- } \
- } else { \
- (ret) = 0; \
- } \
- break; \
- } \
- __offs += (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
+ if ((ret) <= 0) { \
+ if (ferror(f)) { \
+ if (errno == EINTR) { \
+ __HANDLE_INTERRUPTS__; \
+ clearerr(f); \
+ continue; \
+ } \
+ } else { \
+ (ret) = 0; \
+ } \
+ break; \
+ } \
+ __offs += (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} else { \
- int __offs = 0; \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = write(fileno(f), (buf)+__offs, (cnt)-__offs);\
- if ((ret) <= 0) { \
- if ((ret) < 0) { \
- if (errno == EINTR) { \
- __HANDLE_INTERRUPTS__; \
- continue; \
- } \
- } \
- break; \
- } \
- __offs += (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = write(fileno(f), (buf)+__offs, (cnt)-__offs);\
+ if ((ret) <= 0) { \
+ if ((ret) < 0) { \
+ if (errno == EINTR) { \
+ __HANDLE_INTERRUPTS__; \
+ continue; \
+ } \
+ } \
+ break; \
+ } \
+ __offs += (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
}
# endif /* use STDIO */
@@ -1263,25 +1265,25 @@
int __ooffs = obj_offs; \
int __offs = 0; \
char *buf = (char *)(obj); \
- \
+ \
(ret) = 0; \
{ \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \
- if (ret <= 0) { \
- if (ret < 0 && errno == EINTR) { \
- __HANDLE_INTERRUPTS__; \
- /* refetch */ \
- buf = (char *)(obj); \
- continue; \
- } \
- break; \
- } \
- __offs += (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \
+ if (ret <= 0) { \
+ if (ret < 0 && errno == EINTR) { \
+ __HANDLE_INTERRUPTS__; \
+ /* refetch */ \
+ buf = (char *)(obj); \
+ continue; \
+ } \
+ break; \
+ } \
+ __offs += (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} \
}
# else /* use STDIO */
@@ -1290,48 +1292,48 @@
int __ooffs = obj_offs; \
int __offs = 0; \
char *buf = (char *)(obj); \
- \
+ \
(ret) = 0; \
if (isBuffered) { \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \
- if ((ret) <= 0) { \
- if (ferror(f)) { \
- if (errno == EINTR) { \
- __HANDLE_INTERRUPTS__; \
- /* refetch */ \
- buf = (char *)(obj); \
- clearerr(f); \
- continue; \
- } \
- break; \
- } else { \
- (ret) = 0; \
- } \
- } \
- __offs += (ret); \
- } \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \
+ if ((ret) <= 0) { \
+ if (ferror(f)) { \
+ if (errno == EINTR) { \
+ __HANDLE_INTERRUPTS__; \
+ /* refetch */ \
+ buf = (char *)(obj); \
+ clearerr(f); \
+ continue; \
+ } \
+ break; \
+ } else { \
+ (ret) = 0; \
+ } \
+ } \
+ __offs += (ret); \
+ } \
} else { \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs); \
- if ((ret) <= 0) { \
- if ((ret) < 0) { \
- if (errno == EINTR){ \
- __HANDLE_INTERRUPTS__; \
- /* refetch */ \
- buf = (char *)(obj); \
- continue; \
- } \
- } \
- break; \
- } \
- __offs += (ret); \
- } \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs); \
+ if ((ret) <= 0) { \
+ if ((ret) < 0) { \
+ if (errno == EINTR){ \
+ __HANDLE_INTERRUPTS__; \
+ /* refetch */ \
+ buf = (char *)(obj); \
+ continue; \
+ } \
+ } \
+ break; \
+ } \
+ __offs += (ret); \
+ } \
} \
if (__offs > 0) \
- (ret) = __offs; \
+ (ret) = __offs; \
}
# endif /* use STDIO */
#endif /* unix */
@@ -1897,6 +1899,15 @@
^ false
! !
+!ExternalStream class methodsFor:'finalization'!
+
+finalizationLobby
+ "answer the registry used for finalization.
+ ExternalStreams have their own Registry"
+
+ ^ Lobby
+! !
+
!ExternalStream class methodsFor:'obsolete'!
makePTYPair
@@ -2519,13 +2530,6 @@
^ self class basicNew setAccessor:handleType to:handle
!
-finalizationLobby
- "answer the registry used for finalization.
- ExternalStreams have their own Registry"
-
- ^ Lobby
-!
-
finalize
"some Stream has been collected - close the file if not already done"
@@ -4675,9 +4679,7 @@
clearEOF
hitEOF := false
-! !
-
-!ExternalStream protectedMethodsFor:'private'!
+!
closeFile
"low level close - may be redefined in subclasses
@@ -4740,14 +4742,14 @@
// cg: the pre Nov2014 code always did the fclose interruptable;
// I am not sure, if fclose is actually prepared to do this;
// at least when only reading, this should not block, and we
- // should be ableto do it without being interruptable.
+ // should be able to do it without being interruptable.
// Must watch this - if it leads to blockings, change and think about it.
- if (__INST(mode) != @symbol(readonly)) {
+ if (__INST(mode) == @symbol(readonly)) {
+ rslt = fclose(f);
+ } else {
__BEGIN_INTERRUPTABLE__
rslt = fclose(f);
__END_INTERRUPTABLE__
- } else {
- rslt = fclose(f);
}
#endif
} else {
@@ -4785,9 +4787,7 @@
handle := nil.
self closeFile:fp
]
-! !
-
-!ExternalStream methodsFor:'private'!
+!
closeFile:handle
"for rel5 only"