--- a/ExternalStream.st Tue Feb 19 15:30:53 2019 +0100
+++ b/ExternalStream.st Tue Feb 19 16:00:56 2019 +0100
@@ -15,7 +15,7 @@
ReadWriteStream subclass:#ExternalStream
instanceVariableNames:'handleType handle mode buffered binary eolMode hitEOF didWrite
- lastErrorNumber readAhead'
+ lastErrorNumber readAhead eventHandlers'
classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal
InvalidModeSignal OpenErrorSignal StreamNotOpenSignal
InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode
@@ -206,7 +206,7 @@
# define DEBUGBUFFER(buf) \
if (((char *)(buf) >= __survStartPtr) \
&& ((char *)(buf) < __survEndPtr)) { \
- __fatal0("read into survivor\n"); \
+ __fatal0("read into survivor\n"); \
}
#else
@@ -227,33 +227,33 @@
#ifdef __win32__
# 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) > 0 ? __res : (__threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 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) > 0 ? __res : (__threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 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)
@@ -264,56 +264,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; \
+ } \
+ } \
}
/*
@@ -323,122 +323,122 @@
# 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 ++; \
- continue; \
- } \
- CLEAR_ERRNO; \
- { \
- int res = -1, ok = 0; \
- SOCKET sock = 0; \
- if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \
- || (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \
- || (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \
- if (!ok) { \
- __threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \
- (ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \
- break; \
- } \
- if (res > 0) { \
- if (res > ((cnt)-__offs)) \
- res = (cnt)-__offs; \
- READ((ret), f, (buf)+__offs, res, handleType); \
- } else { \
- if (sock && send(sock, NULL, 0, 0) == SOCKET_ERROR) { \
- (ret) = -1; __threadErrno = WSAGetLastError(); \
- } 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; \
+ 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 = -1, ok = 0; \
+ SOCKET sock = 0; \
+ if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \
+ || (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \
+ || (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \
+ if (!ok) { \
+ __threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \
+ (ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \
+ break; \
+ } \
+ if (res > 0) { \
+ if (res > ((cnt)-__offs)) \
+ res = (cnt)-__offs; \
+ READ((ret), f, (buf)+__offs, res, handleType); \
+ } else { \
+ if (sock && send(sock, NULL, 0, 0) == SOCKET_ERROR) { \
+ (ret) = -1; __threadErrno = WSAGetLastError(); \
+ } 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; \
} \
}
@@ -449,63 +449,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; \
} \
}
@@ -514,150 +514,150 @@
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 = -1, ok = 0; \
- SOCKET sock = 0; \
- int l = (cnt)-__offs; \
- CLEAR_ERRNO; \
- if (l > IO_BUFFER_SIZE) l = IO_BUFFER_SIZE; \
- if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \
- || (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \
- || (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \
- if (!ok) { \
- __threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \
- (ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \
- break; \
- } \
- if (res > 0) { \
- if (res > l) res = l; \
- READ((ret), f, __buf, res, handleType); \
- } else { \
- if (sock && send(sock, NULL, 0, 0) == SOCKET_ERROR) { \
- (ret) = -1; __threadErrno = WSAGetLastError(); \
- } 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 = -1, ok = 0; \
+ SOCKET sock = 0; \
+ int l = (cnt)-__offs; \
+ CLEAR_ERRNO; \
+ if (l > IO_BUFFER_SIZE) l = IO_BUFFER_SIZE; \
+ if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \
+ || (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \
+ || (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \
+ if (!ok) { \
+ __threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \
+ (ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \
+ break; \
+ } \
+ if (res > 0) { \
+ if (res > l) res = l; \
+ READ((ret), f, __buf, res, handleType); \
+ } else { \
+ if (sock && send(sock, NULL, 0, 0) == SOCKET_ERROR) { \
+ (ret) = -1; __threadErrno = WSAGetLastError(); \
+ } 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) \
@@ -665,51 +665,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; \
} \
}
@@ -720,15 +720,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 */ \
}
@@ -738,73 +738,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 */
@@ -815,84 +815,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; \
}
@@ -902,7 +902,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
@@ -915,13 +915,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 */
@@ -931,52 +931,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); \
}
@@ -994,34 +994,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; \
} \
}
@@ -1033,61 +1033,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; \
} \
}
@@ -1098,56 +1098,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); \
}
@@ -1157,44 +1157,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 */
@@ -1206,64 +1206,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 */
@@ -1277,25 +1277,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 */
@@ -1304,48 +1304,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 */
@@ -2757,135 +2757,135 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- && (__INST(binary) != true)
- ) {
- f = __FILEVal(fp);
- buffer[0] = '\0';
-
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f);
- }
-
- rslt = nextPtr = buffer;
- limit = buffer + sizeof(buffer) - 2;
-
- for (;;) {
- __READBYTE__(ret, f, nextPtr, _buffered, __INST(handleType));
- if (ret <= 0) {
- if (nextPtr == buffer)
- rslt = NULL;
- if (ret == 0) {
- __INST(hitEOF) = true;
- break;
- } else {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ && (__INST(binary) != true)
+ ) {
+ f = __FILEVal(fp);
+ buffer[0] = '\0';
+
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f);
+ }
+
+ rslt = nextPtr = buffer;
+ limit = buffer + sizeof(buffer) - 2;
+
+ for (;;) {
+ __READBYTE__(ret, f, nextPtr, _buffered, __INST(handleType));
+ if (ret <= 0) {
+ if (nextPtr == buffer)
+ rslt = NULL;
+ if (ret == 0) {
+ __INST(hitEOF) = true;
+ break;
+ } else {
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- goto err;
- }
- }
-
- if (*nextPtr == '\n') {
- cutOff = 1;
- *nextPtr = '\0';
- break;
- }
- if (*nextPtr == '\r') {
- char peekChar;
-
- /*
- * peek ahead for a newLine ...
- */
- __READBYTE__(ret, f, &peekChar, _buffered, __INST(handleType));
- if (ret <= 0) {
- cutOff = 1;
- *nextPtr = '\0';
- if (ret == 0) {
- __INST(hitEOF) = true;
- break;
- }
+ error = __mkSmallInteger(__threadErrno);
+ goto err;
+ }
+ }
+
+ if (*nextPtr == '\n') {
+ cutOff = 1;
+ *nextPtr = '\0';
+ break;
+ }
+ if (*nextPtr == '\r') {
+ char peekChar;
+
+ /*
+ * peek ahead for a newLine ...
+ */
+ __READBYTE__(ret, f, &peekChar, _buffered, __INST(handleType));
+ if (ret <= 0) {
+ cutOff = 1;
+ *nextPtr = '\0';
+ if (ret == 0) {
+ __INST(hitEOF) = true;
+ break;
+ }
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- goto err;
- }
-
- if (peekChar == '\n') {
- cutOff = 2;
- *nextPtr = '\0';
- break;
- }
-
- __UNGETC__(peekChar, f, _buffered);
-
- cutOff = 1;
- *nextPtr = '\0';
- break;
- }
-
- nextPtr++;
- if (nextPtr >= limit) {
- *nextPtr = '\0';
- lineTooLong = 1;
- break;
- }
- }
-
- if (rslt != NULL) {
- len = nextPtr-buffer;
-
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + len + cutOff;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- /* remove any EOL character */
- if (len != 0) {
- if (buffer[len-1] == '\n') {
- buffer[--len] = '\0';
- }
- if ((len != 0) && (buffer[len-1] == '\r')) {
- buffer[--len] = '\0';
- }
- }
- line = __MKSTRING_L(buffer, len);
- if (! lineTooLong) {
- RETURN ( line );
- }
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ goto err;
+ }
+
+ if (peekChar == '\n') {
+ cutOff = 2;
+ *nextPtr = '\0';
+ break;
+ }
+
+ __UNGETC__(peekChar, f, _buffered);
+
+ cutOff = 1;
+ *nextPtr = '\0';
+ break;
+ }
+
+ nextPtr++;
+ if (nextPtr >= limit) {
+ *nextPtr = '\0';
+ lineTooLong = 1;
+ break;
+ }
+ }
+
+ if (rslt != NULL) {
+ len = nextPtr-buffer;
+
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + len + cutOff;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ /* remove any EOL character */
+ if (len != 0) {
+ if (buffer[len-1] == '\n') {
+ buffer[--len] = '\0';
+ }
+ if ((len != 0) && (buffer[len-1] == '\r')) {
+ buffer[--len] = '\0';
+ }
+ }
+ line = __MKSTRING_L(buffer, len);
+ if (! lineTooLong) {
+ RETURN ( line );
+ }
+ }
+ }
}
err: ;
%}.
line notNil ifTrue:[
- "/ the line as read is longer than 32k characters (boy - what a line)
- "/ The exception raised below can be handled to ask the user
- "/ and to read more and return the concatenation from the exception handler
- "/ (the receiver and the partial line are passed as parameter)
- "/ If unhandled, we do exactly that: read the rest and return the concatenation
- "/ i.e. the full line - whatever its size is.
-
- LineTooLongErrorSignal isHandled ifTrue:[
- ^ LineTooLongErrorSignal
- raiseRequestWith:(Array with:self with:line)
- errorString:('line too long read error')
- ].
- 'ExternalStream [info]: very long line in nextLine' infoPrintCR.
- ^ line , super nextLine "use super to avoid recursion"
+ "/ the line as read is longer than 32k characters (boy - what a line)
+ "/ The exception raised below can be handled to ask the user
+ "/ and to read more and return the concatenation from the exception handler
+ "/ (the receiver and the partial line are passed as parameter)
+ "/ If unhandled, we do exactly that: read the rest and return the concatenation
+ "/ i.e. the full line - whatever its size is.
+
+ LineTooLongErrorSignal isHandled ifTrue:[
+ ^ LineTooLongErrorSignal
+ raiseRequestWith:(Array with:self with:line)
+ errorString:('line too long read error')
+ ].
+ 'ExternalStream [info]: very long line in nextLine' infoPrintCR.
+ ^ line , super nextLine "use super to avoid recursion"
].
hitEOF ifTrue:[^ self pastEndRead].
error notNil ifTrue:[
- lastErrorNumber := error.
- ^ self readError:error
+ lastErrorNumber := error.
+ ^ self readError:error
].
handle isNil ifTrue:[^ self errorNotOpen].
(mode == #writeonly) ifTrue:[^ self errorWriteOnly].
@@ -2909,77 +2909,77 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- && (__INST(binary) != true)
- && __isStringLike(aString)
- ) {
- int _buffered = (__INST(buffered) == true);
- int len = __stringSize(aString);
- int cnt, len1;
- FILEPOINTER f = __FILEVal(fp);
- char *cp;
- int o_offs;
-
- if (_buffered) {
- __WRITING__(f)
- }
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ && (__INST(binary) != true)
+ && __isStringLike(aString)
+ ) {
+ int _buffered = (__INST(buffered) == true);
+ int len = __stringSize(aString);
+ int cnt, len1;
+ FILEPOINTER f = __FILEVal(fp);
+ char *cp;
+ int o_offs;
+
+ if (_buffered) {
+ __WRITING__(f)
+ }
#ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(__stringVal(aString), 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(__stringVal(aString), 1, len, f);
+ } else
#endif
- {
- o_offs = (char *)__stringVal(aString)-(char *)aString;
- __WRITEBYTES_OBJ__(cnt, f, aString, o_offs, len, _buffered, __INST(handleType));
- }
- if (cnt == len) {
- OBJ mode = __INST(eolMode);
-
- len1 = len;
-
- if (mode == @symbol(cr)) {
- cp = "\r"; len = 1;
- } else if (mode == @symbol(crlf)) {
- cp = "\r\n"; len = 2;
- } else if (mode == @symbol(eot)) {
- cp = "\004"; len = 1;
- } else if (mode == @symbol(etx)) {
- cp = "\003"; len = 1;
- } else {
- cp = "\n"; len = 1;
- }
+ {
+ o_offs = (char *)__stringVal(aString)-(char *)aString;
+ __WRITEBYTES_OBJ__(cnt, f, aString, o_offs, len, _buffered, __INST(handleType));
+ }
+ if (cnt == len) {
+ OBJ mode = __INST(eolMode);
+
+ len1 = len;
+
+ if (mode == @symbol(cr)) {
+ cp = "\r"; len = 1;
+ } else if (mode == @symbol(crlf)) {
+ cp = "\r\n"; len = 2;
+ } else if (mode == @symbol(eot)) {
+ cp = "\004"; len = 1;
+ } else if (mode == @symbol(etx)) {
+ cp = "\003"; len = 1;
+ } else {
+ cp = "\n"; len = 1;
+ }
#ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(cp, 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(cp, 1, len, f);
+ } else
#endif
- {
- __WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType));
- }
- if (cnt > 0) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + len1 + cnt;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN ( self );
- }
- }
+ {
+ __WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType));
+ }
+ if (cnt > 0) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + len1 + cnt;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN ( self );
+ }
+ }
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
}
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self writeError:error.
- ^ self
+ lastErrorNumber := error.
+ self writeError:error.
+ ^ self
].
super nextPutLine:aString.
@@ -3186,58 +3186,58 @@
OBJ fp = __INST(handle);
if (fp == nil)
- goto out;
+ goto out;
if (!__isInteger(ioctlNumber)
- || (!__isInteger(arg)
- && (arg != nil)
- && !__isBytes(arg)
- && !__isExternalBytesLike(arg)
- && !__isExternalAddress(arg))) {
- error = @symbol(badArgument);
- goto out;
+ || (!__isInteger(arg)
+ && (arg != nil)
+ && !__isBytes(arg)
+ && !__isExternalBytesLike(arg)
+ && !__isExternalAddress(arg))) {
+ error = @symbol(badArgument);
+ goto out;
}
if (__INST(handleType) == @symbol(socketHandle)) {
- fd = (int)((SOCKET)(__FILEVal(fp)));
+ fd = (int)((SOCKET)(__FILEVal(fp)));
} else
- if ((__INST(handleType) == nil)
- || (__INST(handleType) == @symbol(filePointer))
- || (__INST(handleType) == @symbol(socketFilePointer))
- || (__INST(handleType) == @symbol(pipeFilePointer))) {
- fd = fileno(__FILEVal(fp));
+ if ((__INST(handleType) == nil)
+ || (__INST(handleType) == @symbol(filePointer))
+ || (__INST(handleType) == @symbol(socketFilePointer))
+ || (__INST(handleType) == @symbol(pipeFilePointer))) {
+ fd = fileno(__FILEVal(fp));
} else {
- error = @symbol(badHandleType);
- goto out;
+ error = @symbol(badHandleType);
+ goto out;
}
ioNum = __unsignedLongIntVal(ioctlNumber);
__BEGIN_INTERRUPTABLE__
do {
- __threadErrno = 0;
- if (arg == nil) {
- ioArg = 0;
- } else if (__isSmallInteger(arg)) {
- ioArg = __intVal(arg);
- } else if (__isInteger(arg)) {
- ioArg = __unsignedLongIntVal(arg);
- } else if (__isExternalBytesLike(arg)) {
- ioArg = (INT)(__externalBytesAddress(arg));
- } else if (__isExternalAddress(arg)) {
- ioArg = (INT)(__externalAddressVal(arg));
- } else {
- ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element);
- }
- ret = ioctl(fd, ioNum, ioArg);
+ __threadErrno = 0;
+ if (arg == nil) {
+ ioArg = 0;
+ } else if (__isSmallInteger(arg)) {
+ ioArg = __intVal(arg);
+ } else if (__isInteger(arg)) {
+ ioArg = __unsignedLongIntVal(arg);
+ } else if (__isExternalBytesLike(arg)) {
+ ioArg = (INT)(__externalBytesAddress(arg));
+ } else if (__isExternalAddress(arg)) {
+ ioArg = (INT)(__externalAddressVal(arg));
+ } else {
+ ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element);
+ }
+ ret = ioctl(fd, ioNum, ioArg);
} while (ret < 0 && __threadErrno == EINTR);
__END_INTERRUPTABLE__
if (ret >= 0) {
- RETURN ( __mkSmallInteger(ret) );
+ RETURN ( __mkSmallInteger(ret) );
}
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
error = __mkSmallInteger(__threadErrno);
#endif
@@ -3245,8 +3245,8 @@
out:;
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- ^ self ioError:error.
+ lastErrorNumber := error.
+ ^ self ioError:error.
].
handle isNil ifTrue:[^ self errorNotOpen].
@@ -3282,40 +3282,40 @@
OBJ fp = __INST(handle);
if (fp == nil)
- goto out;
+ goto out;
if (__INST(handleType) == @symbol(socketHandle)) {
- // syncing a socket to disk ?
- error = @symbol(badHandleType);
- goto out;
- // fd = __FILEVal(fp);
+ // syncing a socket to disk ?
+ error = @symbol(badHandleType);
+ goto out;
+ // fd = __FILEVal(fp);
} else
- if ((__INST(handleType) == nil)
- || (__INST(handleType) == @symbol(filePointer))
- || (__INST(handleType) == @symbol(socketFilePointer))
- || (__INST(handleType) == @symbol(pipeFilePointer))) {
- fd = fileno(__FILEVal(fp));
+ if ((__INST(handleType) == nil)
+ || (__INST(handleType) == @symbol(filePointer))
+ || (__INST(handleType) == @symbol(socketFilePointer))
+ || (__INST(handleType) == @symbol(pipeFilePointer))) {
+ fd = fileno(__FILEVal(fp));
} else {
- error = @symbol(badHandleType);
- goto out;
+ error = @symbol(badHandleType);
+ goto out;
}
#ifdef __win32__
__threadErrno = 0;
ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd));
if (ret) {
- RETURN (self);
+ RETURN (self);
}
__threadErrno = __WIN32_ERR(GetLastError());
#else
__BEGIN_INTERRUPTABLE__
do {
- ret = fsync(fd);
+ ret = fsync(fd);
} while ((ret < 0) && (__threadErrno == EINTR));
__END_INTERRUPTABLE__
if (ret >= 0) {
- RETURN (self);
+ RETURN (self);
}
#endif /* ! __win32__ */
error = __mkSmallInteger(__threadErrno);
@@ -3323,16 +3323,16 @@
out:;
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self ioError:error.
- ^ self.
+ lastErrorNumber := error.
+ self ioError:error.
+ ^ self.
].
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
"
"Modified: / 22-11-2018 / 14:51:43 / Stefan Vogel"
@@ -3354,40 +3354,40 @@
OBJ fp = __INST(handle);
if (fp == nil)
- goto out;
+ goto out;
if (__INST(handleType) == @symbol(socketHandle)) {
- // syncing a socket to disk ?
- error = @symbol(badHandleType);
- goto out;
- // fd = __FILEVal(fp);
+ // syncing a socket to disk ?
+ error = @symbol(badHandleType);
+ goto out;
+ // fd = __FILEVal(fp);
} else
- if ((__INST(handleType) == nil)
- || (__INST(handleType) == @symbol(filePointer))
- || (__INST(handleType) == @symbol(socketFilePointer))
- || (__INST(handleType) == @symbol(pipeFilePointer))) {
- fd = fileno(__FILEVal(fp));
+ if ((__INST(handleType) == nil)
+ || (__INST(handleType) == @symbol(filePointer))
+ || (__INST(handleType) == @symbol(socketFilePointer))
+ || (__INST(handleType) == @symbol(pipeFilePointer))) {
+ fd = fileno(__FILEVal(fp));
} else {
- error = @symbol(badHandleType);
- goto out;
+ error = @symbol(badHandleType);
+ goto out;
}
#ifdef __win32__
__threadErrno = 0;
ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd));
if (ret) {
- RETURN (self);
+ RETURN (self);
}
__threadErrno = __WIN32_ERR(GetLastError());
#else
__BEGIN_INTERRUPTABLE__
do {
- ret = fdatasync(fd);
+ ret = fdatasync(fd);
} while ((ret < 0) && (__threadErrno == EINTR));
__END_INTERRUPTABLE__
if (ret >= 0) {
- RETURN (self);
+ RETURN (self);
}
#endif /* ! __win32__ */
error = __mkSmallInteger(__threadErrno);
@@ -3396,9 +3396,9 @@
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self ioError:error.
- ^ self.
+ lastErrorNumber := error.
+ self ioError:error.
+ ^ self.
].
handle isNil ifTrue:[^ self errorNotOpen].
@@ -3406,9 +3406,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
"
"Modified: / 22-11-2018 / 14:51:31 / Stefan Vogel"
@@ -3702,102 +3702,102 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__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 = __Class(anObject);
- int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
-
- nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
-
- switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
- case BYTEARRAY:
- case WORDARRAY:
- case LONGARRAY:
- case SWORDARRAY:
- case SLONGARRAY:
- case FLOATARRAY:
- break;
- case DOUBLEARRAY:
+ 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 = __Class(anObject);
+ int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+
+ nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
+
+ switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+ case BYTEARRAY:
+ case WORDARRAY:
+ case LONGARRAY:
+ case SWORDARRAY:
+ case SLONGARRAY:
+ case FLOATARRAY:
+ break;
+ case DOUBLEARRAY:
#ifdef __NEED_DOUBLE_ALIGN
- nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
+ nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
#endif
- break;
- case LONGLONGARRAY:
- case SLONGLONGARRAY:
+ break;
+ case LONGLONGARRAY:
+ case SLONGLONGARRAY:
#ifdef __NEED_LONGLONG_ALIGN
- nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
+ nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
#endif
- break;
- default:
- goto bad;
- }
- extPtr = (char *)0;
- 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));
- }
- /* 0 is NOT an EOF condition here ... */
- if (ret >= 0) {
- 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));
- }
- __INST(position) = nil;
+ break;
+ default:
+ goto bad;
+ }
+ extPtr = (char *)0;
+ 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));
+ }
+ /* 0 is NOT an EOF condition here ... */
+ if (ret >= 0) {
+ 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));
+ }
+ __INST(position) = nil;
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
+ }
}
bad: ;
%}.
hitEOF ifTrue:[^ 0].
error notNil ifTrue:[
- lastErrorNumber := error.
- ^ self readError:error
+ lastErrorNumber := error.
+ ^ self readError:error
].
handle isNil ifTrue:[^ self errorNotOpen].
(mode == #writeonly) ifTrue:[^ self errorWriteOnly].
@@ -3820,14 +3820,14 @@
STObject handle = self.instVarAt(I_handle);
if (handle != STObject.Nil) {
- STObject next;
-
- next = handle.nextByte();
- if (next != STObject.EOF) {
- self.instVarAt_put(I_position, STObject.Nil);
- return __c__._RETURN( next );
- }
- self.instVarAt_put(I_hitEOF, STObject.True);
+ STObject next;
+
+ next = handle.nextByte();
+ if (next != STObject.EOF) {
+ self.instVarAt_put(I_position, STObject.Nil);
+ return __c__._RETURN( next );
+ }
+ self.instVarAt_put(I_hitEOF, STObject.True);
}
#else
FILEPOINTER f;
@@ -3841,44 +3841,44 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))) {
- f = __FILEVal(fp);
-
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &byte, _buffered, __INST(handleType));
- if (ret > 0) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 1;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN (__mkSmallInteger(byte));
- }
-
- if (ret == 0) {
- __INST(hitEOF) = true;
- } else /* ret < 0 */ {
- __INST(position) = nil;
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))) {
+ f = __FILEVal(fp);
+
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &byte, _buffered, __INST(handleType));
+ if (ret > 0) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 1;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN (__mkSmallInteger(byte));
+ }
+
+ if (ret == 0) {
+ __INST(hitEOF) = true;
+ } else /* ret < 0 */ {
+ __INST(position) = nil;
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
+ }
}
#endif /* not SCHTEAM */
%}.
hitEOF ifTrue:[^ self pastEndRead].
error notNil ifTrue:[
- lastErrorNumber := error.
- ^ self readError:error
+ lastErrorNumber := error.
+ ^ self readError:error
].
handle isNil ifTrue:[^ self errorNotOpen].
^ self errorWriteOnly
@@ -3925,101 +3925,101 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__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 = __Class(anObject);
- int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
-
- nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
- switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
- case BYTEARRAY:
- case WORDARRAY:
- case LONGARRAY:
- case SWORDARRAY:
- case SLONGARRAY:
- case FLOATARRAY:
- break;
- case DOUBLEARRAY:
+ 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 = __Class(anObject);
+ int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+
+ nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
+ switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+ case BYTEARRAY:
+ case WORDARRAY:
+ case LONGARRAY:
+ case SWORDARRAY:
+ case SLONGARRAY:
+ case FLOATARRAY:
+ break;
+ case DOUBLEARRAY:
#ifdef __NEED_DOUBLE_ALIGN
- nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
+ nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
#endif
- break;
- case LONGLONGARRAY:
- case SLONGLONGARRAY:
+ break;
+ case LONGLONGARRAY:
+ case SLONGLONGARRAY:
#ifdef __NEED_LONGLONG_ALIGN
- nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
+ nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
#endif
- break;
- default:
- goto bad;
- }
- extPtr = (char *)0;
- objSize = __Size(anObject) - nInstBytes;
- }
- if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f);
- }
-
- if (extPtr) {
- __READBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType));
- } else {
- /*
- * on interrupt, anObject may be moved to another location.
- * So we pass anObject, and the offset to the __READBYTES_OBJ__ macro.
- */
- offs += nInstBytes;
- __READBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType));
- }
-
- if (ret > 0) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + ret;
- OBJ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN (__mkSmallInteger(ret));
- }
- if (ret == 0) {
- __INST(hitEOF) = true;
- } else /* ret < 0 */ {
- __INST(position) = nil;
+ break;
+ default:
+ goto bad;
+ }
+ extPtr = (char *)0;
+ objSize = __Size(anObject) - nInstBytes;
+ }
+ if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f);
+ }
+
+ if (extPtr) {
+ __READBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType));
+ } else {
+ /*
+ * on interrupt, anObject may be moved to another location.
+ * So we pass anObject, and the offset to the __READBYTES_OBJ__ macro.
+ */
+ offs += nInstBytes;
+ __READBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType));
+ }
+
+ if (ret > 0) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + ret;
+ OBJ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN (__mkSmallInteger(ret));
+ }
+ if (ret == 0) {
+ __INST(hitEOF) = true;
+ } else /* ret < 0 */ {
+ __INST(position) = nil;
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
+ }
+ }
}
bad: ;
%}.
hitEOF ifTrue:[^ 0].
error notNil ifTrue:[
- lastErrorNumber := error.
- ^ self readError:error
+ lastErrorNumber := error.
+ ^ self readError:error
].
handle isNil ifTrue:[^ self errorNotOpen].
(mode == #writeonly) ifTrue:[^ self errorWriteOnly].
@@ -4048,59 +4048,59 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- FILEPOINTER f;
- int ret, _buffered;
- short value;
- union {
- unsigned char buffer[2];
- short shortVal;
- } u;
-
- f = __FILEVal(fp);
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType));
-
- if (ret == 2) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 2;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- if (msbFlag == true) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ FILEPOINTER f;
+ int ret, _buffered;
+ short value;
+ union {
+ unsigned char buffer[2];
+ short shortVal;
+ } u;
+
+ f = __FILEVal(fp);
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType));
+
+ if (ret == 2) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 2;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ if (msbFlag == true) {
#if defined(__MSBFIRST__)
- value = u.shortVal;
+ value = u.shortVal;
#else
- value = ((u.buffer[0] & 0xFF) << 8) | (u.buffer[1] & 0xFF);
+ value = ((u.buffer[0] & 0xFF) << 8) | (u.buffer[1] & 0xFF);
#endif
- } else {
+ } else {
#if defined(__LSBFIRST__)
- value = u.shortVal;
+ value = u.shortVal;
#else
- value = ((u.buffer[1] & 0xFF) << 8) | (u.buffer[0] & 0xFF);
+ value = ((u.buffer[1] & 0xFF) << 8) | (u.buffer[0] & 0xFF);
#endif
- }
- RETURN (__mkSmallInteger(value));
- }
-
- if (ret < 0) {
- __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN (__mkSmallInteger(value));
+ }
+
+ if (ret < 0) {
+ __INST(position) = nil; /* i.e. do not know */
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF ifTrue:[^ self pastEndRead].
@@ -4130,69 +4130,69 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- FILEPOINTER f;
- int ret, _buffered;
- int value;
- union {
- unsigned char buffer[4];
- int intVal;
- } u;
-
- f = __FILEVal(fp);
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType));
-
- if (ret == 4) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 4;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- if (msbFlag == true) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ FILEPOINTER f;
+ int ret, _buffered;
+ int value;
+ union {
+ unsigned char buffer[4];
+ int intVal;
+ } u;
+
+ f = __FILEVal(fp);
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType));
+
+ if (ret == 4) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 4;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ if (msbFlag == true) {
#if defined(__MSBFIRST__)
- value = u.intVal;
+ value = u.intVal;
#else
- value = (u.buffer[0] & 0xFF);
- value = (value << 8) | (u.buffer[1] & 0xFF);
- value = (value << 8) | (u.buffer[2] & 0xFF);
- value = (value << 8) | (u.buffer[3] & 0xFF);
+ value = (u.buffer[0] & 0xFF);
+ value = (value << 8) | (u.buffer[1] & 0xFF);
+ value = (value << 8) | (u.buffer[2] & 0xFF);
+ value = (value << 8) | (u.buffer[3] & 0xFF);
#endif
- } else {
+ } else {
#if defined(__LSBFIRST__)
- value = u.intVal;
+ value = u.intVal;
#else
- value = (u.buffer[3] & 0xFF);
- value = (value << 8) | (u.buffer[2] & 0xFF);
- value = (value << 8) | (u.buffer[1] & 0xFF);
- value = (value << 8) | (u.buffer[0] & 0xFF);
+ value = (u.buffer[3] & 0xFF);
+ value = (value << 8) | (u.buffer[2] & 0xFF);
+ value = (value << 8) | (u.buffer[1] & 0xFF);
+ value = (value << 8) | (u.buffer[0] & 0xFF);
#endif
- }
+ }
#if __POINTER_SIZE__ == 8
- RETURN ( __mkSmallInteger(value));
+ RETURN ( __mkSmallInteger(value));
#else
- RETURN ( __MKINT(value) );
+ RETURN ( __MKINT(value) );
#endif
- }
-
- if (ret < 0) {
- __INST(position) = nil;
+ }
+
+ if (ret < 0) {
+ __INST(position) = nil;
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF ifTrue:[^ self pastEndRead].
@@ -4221,59 +4221,59 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- FILEPOINTER f;
- int ret, _buffered;
- unsigned int value;
- union {
- unsigned char buffer[2];
- unsigned short shortVal;
- } u;
-
- f = __FILEVal(fp);
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType));
-
- if (ret == 2) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 2;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- if (msbFlag == true) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ FILEPOINTER f;
+ int ret, _buffered;
+ unsigned int value;
+ union {
+ unsigned char buffer[2];
+ unsigned short shortVal;
+ } u;
+
+ f = __FILEVal(fp);
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType));
+
+ if (ret == 2) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 2;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ if (msbFlag == true) {
#if defined(__MSBFIRST__)
- value = u.shortVal;
+ value = u.shortVal;
#else
- value = (u.buffer[0] << 8) | u.buffer[1];
+ value = (u.buffer[0] << 8) | u.buffer[1];
#endif
- } else {
+ } else {
#if defined(__LSBFIRST__)
- value = u.shortVal;
+ value = u.shortVal;
#else
- value = (u.buffer[1] << 8) | u.buffer[0];
+ value = (u.buffer[1] << 8) | u.buffer[0];
#endif
- }
- RETURN (__mkSmallInteger(value));
- }
-
- if (ret < 0) {
- __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN (__mkSmallInteger(value));
+ }
+
+ if (ret < 0) {
+ __INST(position) = nil; /* i.e. do not know */
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF ifTrue:[^ self pastEndRead].
@@ -4303,73 +4303,73 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- FILEPOINTER f;
- int ret, _buffered;
- unsigned INT value;
- union {
- unsigned char buffer[4];
- unsigned int intVal;
- } u;
-
- f = __FILEVal(fp);
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType));
-
- if (ret == 4) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 4;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- if (msbFlag == true) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ FILEPOINTER f;
+ int ret, _buffered;
+ unsigned INT value;
+ union {
+ unsigned char buffer[4];
+ unsigned int intVal;
+ } u;
+
+ f = __FILEVal(fp);
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType));
+
+ if (ret == 4) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 4;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ if (msbFlag == true) {
#if defined(__MSBFIRST__)
- value = u.intVal;
+ value = u.intVal;
#else
- value = u.buffer[0];
- value = (value << 8) | u.buffer[1];
- value = (value << 8) | u.buffer[2];
- value = (value << 8) | u.buffer[3];
+ value = u.buffer[0];
+ value = (value << 8) | u.buffer[1];
+ value = (value << 8) | u.buffer[2];
+ value = (value << 8) | u.buffer[3];
#endif
- } else {
+ } else {
#if defined(__LSBFIRST__)
- value = u.intVal;
+ value = u.intVal;
#else
- value = u.buffer[3];
- value = (value << 8) | u.buffer[2];
- value = (value << 8) | u.buffer[1];
- value = (value << 8) | u.buffer[0];
+ value = u.buffer[3];
+ value = (value << 8) | u.buffer[2];
+ value = (value << 8) | u.buffer[1];
+ value = (value << 8) | u.buffer[0];
#endif
- }
+ }
#if __POINTER_SIZE__ == 8
- value &= 0xFFFFFFFF;
- RETURN (__mkSmallInteger(value));
+ value &= 0xFFFFFFFF;
+ RETURN (__mkSmallInteger(value));
#else
- if (value <= _MAX_INT) {
- RETURN (__mkSmallInteger(value));
- }
- RETURN (__MKULARGEINT(value) );
+ if (value <= _MAX_INT) {
+ RETURN (__mkSmallInteger(value));
+ }
+ RETURN (__MKULARGEINT(value) );
#endif
- }
-
- if (ret < 0) {
- __INST(position) = nil; /* i.e. do not know */
+ }
+
+ if (ret < 0) {
+ __INST(position) = nil; /* i.e. do not know */
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF ifTrue:[^ self pastEndRead].
@@ -4415,46 +4415,46 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- && __isSmallInteger(aByteValue)
-
- ) {
- int _buffered = (__INST(buffered) == true);
- FILEPOINTER f = __FILEVal(fp);
- char c = __intVal(aByteValue);
- int cnt;
-
- if (_buffered) {
- __WRITING__(f)
- }
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ && __isSmallInteger(aByteValue)
+
+ ) {
+ int _buffered = (__INST(buffered) == true);
+ FILEPOINTER f = __FILEVal(fp);
+ char c = __intVal(aByteValue);
+ int cnt;
+
+ if (_buffered) {
+ __WRITING__(f)
+ }
#ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(&c, 1, 1, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(&c, 1, 1, f);
+ } else
#endif
- {
- __WRITEBYTE__(cnt, f, &c, _buffered, __INST(handleType));
- }
- if (cnt == 1) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 1;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN (self);
- }
- if (cnt < 0) {
- __INST(position) = nil; /* i.e. do not know */
- }
+ {
+ __WRITEBYTE__(cnt, f, &c, _buffered, __INST(handleType));
+ }
+ if (cnt == 1) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 1;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN (self);
+ }
+ if (cnt < 0) {
+ __INST(position) = nil; /* i.e. do not know */
+ }
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
}
%}.
handle isNil ifTrue:[self errorNotOpen. ^ self].
@@ -4477,8 +4477,8 @@
%{
int num;
union {
- char bytes[2];
- short shortVal;
+ char bytes[2];
+ short shortVal;
} u;
OBJ fp;
@@ -4488,65 +4488,65 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- ) {
- FILEPOINTER f = __FILEVal(fp);
- int _buffered = (__INST(buffered) == true);
- int cnt;
-
- if (__isSmallInteger(anIntegerOrCharacter)) {
- num = __intVal(anIntegerOrCharacter);
- } else if (__isCharacter(anIntegerOrCharacter)) {
- num = __smallIntegerVal(__characterVal(anIntegerOrCharacter));
- } else
- goto out;
-
- if (msbFlag == true) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ ) {
+ FILEPOINTER f = __FILEVal(fp);
+ int _buffered = (__INST(buffered) == true);
+ int cnt;
+
+ if (__isSmallInteger(anIntegerOrCharacter)) {
+ num = __intVal(anIntegerOrCharacter);
+ } else if (__isCharacter(anIntegerOrCharacter)) {
+ num = __smallIntegerVal(__characterVal(anIntegerOrCharacter));
+ } else
+ goto out;
+
+ if (msbFlag == true) {
#if defined(__MSBFIRST__)
- u.shortVal = num;
+ u.shortVal = num;
#else
- u.bytes[0] = (num >> 8) & 0xFF;
- u.bytes[1] = num & 0xFF;
+ u.bytes[0] = (num >> 8) & 0xFF;
+ u.bytes[1] = num & 0xFF;
#endif
- } else {
+ } else {
#if defined(__LSBFIRST__)
- u.shortVal = num;
+ u.shortVal = num;
#else
- u.bytes[1] = (num >> 8) & 0xFF;
- u.bytes[0] = num & 0xFF;
+ u.bytes[1] = (num >> 8) & 0xFF;
+ u.bytes[0] = num & 0xFF;
#endif
- }
-
- if (_buffered) {
- __WRITING__(f)
- }
- __WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType));
-
- if (cnt == 2) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 2;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN ( self );
- }
- __INST(position) = nil; /* i.e. do not know */
+ }
+
+ if (_buffered) {
+ __WRITING__(f)
+ }
+ __WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType));
+
+ if (cnt == 2) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 2;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN ( self );
+ }
+ __INST(position) = nil; /* i.e. do not know */
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
}
out:;
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self writeError:error.
- ^ self
+ lastErrorNumber := error.
+ self writeError:error.
+ ^ self
].
handle isNil ifTrue:[self errorNotOpen. ^ self].
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
@@ -4581,8 +4581,8 @@
%{
int num;
union {
- char bytes[2];
- short shortVal;
+ char bytes[2];
+ short shortVal;
} u;
OBJ fp;
@@ -4592,44 +4592,44 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- ) {
- FILEPOINTER f = __FILEVal(fp);
- int _buffered = (__INST(buffered) == true);
- int cnt;
-
- if (__isSmallInteger(anIntegerOrCharacter)) {
- num = __intVal(anIntegerOrCharacter);
- } else if (__isCharacter(anIntegerOrCharacter)) {
- num = __smallIntegerVal(__characterVal(anIntegerOrCharacter));
- } else
- goto out;
-
- u.shortVal = num;
-
- if (_buffered) {
- __WRITING__(f)
- }
- __WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType));
-
- if (cnt == 2) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 2;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN ( self );
- }
- __INST(position) = nil; /* i.e. do not know */
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ ) {
+ FILEPOINTER f = __FILEVal(fp);
+ int _buffered = (__INST(buffered) == true);
+ int cnt;
+
+ if (__isSmallInteger(anIntegerOrCharacter)) {
+ num = __intVal(anIntegerOrCharacter);
+ } else if (__isCharacter(anIntegerOrCharacter)) {
+ num = __smallIntegerVal(__characterVal(anIntegerOrCharacter));
+ } else
+ goto out;
+
+ u.shortVal = num;
+
+ if (_buffered) {
+ __WRITING__(f)
+ }
+ __WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType));
+
+ if (cnt == 2) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 2;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN ( self );
+ }
+ __INST(position) = nil; /* i.e. do not know */
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
}
out:;
%}.
@@ -4652,29 +4652,29 @@
%{
int num;
union {
- char bytes[4];
- int intVal;
+ char bytes[4];
+ int intVal;
} u;
OBJ fp;
__INST(lastErrorNumber) = nil;
if (__isSmallInteger(aNumber)) {
- num = __intVal(aNumber);
+ num = __intVal(aNumber);
} else {
#if __POINTER_SIZE__ == 8
- // always more than 4-bytes
- goto badArg;
+ // always more than 4-bytes
+ goto badArg;
#else
- num = __longIntVal(aNumber);
- if (num == 0) {
- num = __signedLongIntVal(aNumber);
- if (num == 0) {
- /* bad arg or out-of-range integer
- * (handled by the fallBack code)
- */
- goto badArg;
- }
- }
+ num = __longIntVal(aNumber);
+ if (num == 0) {
+ num = __signedLongIntVal(aNumber);
+ if (num == 0) {
+ /* bad arg or out-of-range integer
+ * (handled by the fallBack code)
+ */
+ goto badArg;
+ }
+ }
#endif
}
@@ -4683,68 +4683,68 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- ) {
- int _buffered = (__INST(buffered) == true);
- FILEPOINTER f = __FILEVal(fp);
- int cnt;
-
- if (msbFlag == true) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ ) {
+ int _buffered = (__INST(buffered) == true);
+ FILEPOINTER f = __FILEVal(fp);
+ int cnt;
+
+ if (msbFlag == true) {
#if defined(__MSBFIRST__)
- u.intVal = num;
+ u.intVal = num;
#else
- u.bytes[0] = (num >> 24) & 0xFF;
- u.bytes[1] = (num >> 16) & 0xFF;
- u.bytes[2] = (num >> 8) & 0xFF;
- u.bytes[3] = num & 0xFF;
+ u.bytes[0] = (num >> 24) & 0xFF;
+ u.bytes[1] = (num >> 16) & 0xFF;
+ u.bytes[2] = (num >> 8) & 0xFF;
+ u.bytes[3] = num & 0xFF;
#endif
- } else {
+ } else {
#if defined(__LSBFIRST__)
- u.intVal = num;
+ u.intVal = num;
#else
- u.bytes[3] = (num >> 24) & 0xFF;
- u.bytes[2] = (num >> 16) & 0xFF;
- u.bytes[1] = (num >> 8) & 0xFF;
- u.bytes[0] = num & 0xFF;
+ u.bytes[3] = (num >> 24) & 0xFF;
+ u.bytes[2] = (num >> 16) & 0xFF;
+ u.bytes[1] = (num >> 8) & 0xFF;
+ u.bytes[0] = num & 0xFF;
#endif
- }
-
- if (_buffered) {
- __WRITING__(f)
- }
- __WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType));
-
- if (cnt == 4) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 4;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN ( self );
- }
- __INST(position) = nil; /* i.e. do not know */
+ }
+
+ if (_buffered) {
+ __WRITING__(f)
+ }
+ __WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType));
+
+ if (cnt == 4) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 4;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN ( self );
+ }
+ __INST(position) = nil; /* i.e. do not know */
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
}
badArg: ;
%}.
handle isNil ifTrue:[self errorNotOpen. ^ self].
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
error notNil ifTrue:[
- lastErrorNumber := error.
- self writeError:error.
- ^ self
+ lastErrorNumber := error.
+ self writeError:error.
+ ^ self
].
aNumber isInteger ifTrue:[
- ^ super nextPutInt32:aNumber MSB:msbFlag
+ ^ super nextPutInt32:aNumber MSB:msbFlag
].
self argumentMustBeInteger
@@ -4773,37 +4773,37 @@
(i.e. both signed and unsigned int32 values can be written.
Works in both binary and text modes.
Notice: this message should not be sent explicitly by ANY program.
- the following implementation replaces the code of either nextPutInt32MSB or LSB
- dynamically (see #initialize on the class side)"
+ the following implementation replaces the code of either nextPutInt32MSB or LSB
+ dynamically (see #initialize on the class side)"
|error|
%{
int num;
union {
- char bytes[4];
- int intVal;
+ char bytes[4];
+ int intVal;
} u;
OBJ fp;
__INST(lastErrorNumber) = nil;
if (__isSmallInteger(anInteger)) {
- num = __intVal(anInteger);
+ num = __intVal(anInteger);
} else {
#if __POINTER_SIZE__ == 8
- // always more than 4-bytes
- goto badArg;
+ // always more than 4-bytes
+ goto badArg;
#else
- num = __longIntVal(anInteger);
- if (num == 0) {
- num = __signedLongIntVal(anInteger);
- if (num == 0) {
- /* bad arg or out-of-range integer
- * (handled by the fallBack code)
- */
- goto badArg;
- }
- }
+ num = __longIntVal(anInteger);
+ if (num == 0) {
+ num = __signedLongIntVal(anInteger);
+ if (num == 0) {
+ /* bad arg or out-of-range integer
+ * (handled by the fallBack code)
+ */
+ goto badArg;
+ }
+ }
#endif
}
@@ -4812,36 +4812,36 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- ) {
- int _buffered = (__INST(buffered) == true);
- FILEPOINTER f = __FILEVal(fp);
- int cnt;
-
- u.intVal = num;
- if (_buffered) {
- __WRITING__(f)
- }
- __WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType));
-
- if (cnt == 4) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 4;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN ( self );
- }
- __INST(position) = nil; /* i.e. do not know */
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ ) {
+ int _buffered = (__INST(buffered) == true);
+ FILEPOINTER f = __FILEVal(fp);
+ int cnt;
+
+ u.intVal = num;
+ if (_buffered) {
+ __WRITING__(f)
+ }
+ __WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType));
+
+ if (cnt == 4) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 4;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN ( self );
+ }
+ __INST(position) = nil; /* i.e. do not know */
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
}
badArg: ;
%}.
@@ -4910,7 +4910,7 @@
|fp error|
handle isNil ifTrue:[
- ^ self.
+ ^ self.
].
fp := handle.
"/ (didWrite==true and:[binary ~~ true and:[eolMode = #crlf]]) ifTrue: [ self breakPoint:#sr ].
@@ -4919,90 +4919,90 @@
int rslt;
if (__INST(handleType) == @symbol(socketHandle)) {
- SOCKET sock = (SOCKET)(__FILEVal(fp));
-
- if (@global(FileOpenTrace) == true) {
- fprintf(stderr, "close socket [ExternalStream] %"_lx_"\n", (INT)sock);
- }
-
- // whether the close() will be successful or not - the handle is invalid now!
- __INST(handle) = nil;
- do {
+ SOCKET sock = (SOCKET)(__FILEVal(fp));
+
+ if (@global(FileOpenTrace) == true) {
+ fprintf(stderr, "close socket [ExternalStream] %"_lx_"\n", (INT)sock);
+ }
+
+ // whether the close() will be successful or not - the handle is invalid now!
+ __INST(handle) = nil;
+ do {
#ifdef __win32__
- rslt = __STX_WSA_NOINT_CALL1("closesocket", closesocket, sock);
+ rslt = __STX_WSA_NOINT_CALL1("closesocket", closesocket, sock);
#else
- __threadErrno = 0;
- __BEGIN_INTERRUPTABLE__
- rslt = close(sock);
- __END_INTERRUPTABLE__
+ __threadErrno = 0;
+ __BEGIN_INTERRUPTABLE__
+ rslt = close(sock);
+ __END_INTERRUPTABLE__
#endif
- } while((rslt < 0) && (__threadErrno == EINTR));
+ } while((rslt < 0) && (__threadErrno == EINTR));
} else if ((__INST(handleType) == nil)
- || (__INST(handleType) == @symbol(filePointer))
- || (__INST(handleType) == @symbol(socketFilePointer))
- || (__INST(handleType) == @symbol(pipeFilePointer)))
+ || (__INST(handleType) == @symbol(filePointer))
+ || (__INST(handleType) == @symbol(socketFilePointer))
+ || (__INST(handleType) == @symbol(pipeFilePointer)))
{
- FILEPOINTER f = __FILEVal(fp);
-
- if (@global(FileOpenTrace) == true) {
- fprintf(stderr, "fclose [ExternalStream] %"_lx_"\n", (INT)f);
- }
+ FILEPOINTER f = __FILEVal(fp);
+
+ if (@global(FileOpenTrace) == true) {
+ fprintf(stderr, "fclose [ExternalStream] %"_lx_"\n", (INT)f);
+ }
#ifdef __win32__
- if (__INST(mode) != @symbol(readonly) && __INST(buffered) != false) {
- // do a fflush() first, so that fclose() doesn't block
- // we suspect, that EINTR causes problems in fclose()
- do {
- __threadErrno = 0;
- rslt = __STX_C_CALL1("fflush", fflush, f);
- } while((rslt < 0) && (__threadErrno == EINTR));
- if (rslt < 0)
- goto err;
- }
- // whether the close() will be successful or not - the handle is invalid now!
- __INST(handle) = nil;
- do {
- __threadErrno = 0;
- rslt = __STX_C_NOINT_CALL1("fclose", fclose, f);
- } while((rslt < 0) && (__threadErrno == EINTR));
+ if (__INST(mode) != @symbol(readonly) && __INST(buffered) != false) {
+ // do a fflush() first, so that fclose() doesn't block
+ // we suspect, that EINTR causes problems in fclose()
+ do {
+ __threadErrno = 0;
+ rslt = __STX_C_CALL1("fflush", fflush, f);
+ } while((rslt < 0) && (__threadErrno == EINTR));
+ if (rslt < 0)
+ goto err;
+ }
+ // whether the close() will be successful or not - the handle is invalid now!
+ __INST(handle) = nil;
+ do {
+ __threadErrno = 0;
+ rslt = __STX_C_NOINT_CALL1("fclose", fclose, f);
+ } while((rslt < 0) && (__threadErrno == EINTR));
#else
- // cg: not sure why, but on osx, I get blocked occasionally in fclose
- // lets try this:
- if ((__INST(mode) != @symbol(readonly)) && (__INST(buffered) != false)) {
- // do a fflush() first, so that fclose() doesn't block
- // we suspect, that EINTR causes problems in fclose()
- do {
- clearerr(f);
- __threadErrno = 0;
- __BEGIN_INTERRUPTABLE__
- rslt = fflush(f);
- __END_INTERRUPTABLE__
- } while((rslt < 0) && (__threadErrno == EINTR));
- if (rslt < 0)
- goto err;
- }
- // whether the close() will be successful or not - the handle is invalid now!
- __INST(handle) = nil;
- do {
- clearerr(f);
- __threadErrno = 0;
- __BEGIN_INTERRUPTABLE__
- rslt = fclose(f);
- __END_INTERRUPTABLE__
- } while((rslt < 0) && (__threadErrno == EINTR));
+ // cg: not sure why, but on osx, I get blocked occasionally in fclose
+ // lets try this:
+ if ((__INST(mode) != @symbol(readonly)) && (__INST(buffered) != false)) {
+ // do a fflush() first, so that fclose() doesn't block
+ // we suspect, that EINTR causes problems in fclose()
+ do {
+ clearerr(f);
+ __threadErrno = 0;
+ __BEGIN_INTERRUPTABLE__
+ rslt = fflush(f);
+ __END_INTERRUPTABLE__
+ } while((rslt < 0) && (__threadErrno == EINTR));
+ if (rslt < 0)
+ goto err;
+ }
+ // whether the close() will be successful or not - the handle is invalid now!
+ __INST(handle) = nil;
+ do {
+ clearerr(f);
+ __threadErrno = 0;
+ __BEGIN_INTERRUPTABLE__
+ rslt = fclose(f);
+ __END_INTERRUPTABLE__
+ } while((rslt < 0) && (__threadErrno == EINTR));
#endif
} else {
- error = @symbol(badHandleType);
- goto out;
+ error = @symbol(badHandleType);
+ goto out;
}
if (rslt < 0) {
err:
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- goto out;
+ error = __mkSmallInteger(__threadErrno);
+ goto out;
}
RETURN (self);
@@ -5010,25 +5010,25 @@
%}.
error notNil ifTrue:[
- error isInteger ifTrue:[
- lastErrorNumber := error.
- mode == #readonly ifTrue:[
- self ioError:error.
- ] ifFalse:[
- self writeError:error.
- ].
- ^ self.
- ].
- self primitiveFailed:error.
- ^ self.
+ error isInteger ifTrue:[
+ lastErrorNumber := error.
+ mode == #readonly ifTrue:[
+ self ioError:error.
+ ] ifFalse:[
+ self writeError:error.
+ ].
+ ^ self.
+ ].
+ self primitiveFailed:error.
+ ^ self.
].
"/ fallback for rel5
fp := handle.
fp notNil ifTrue:[
- handle := nil.
- self closeFile:fp
+ handle := nil.
+ self closeFile:fp
]
"Modified: / 19-04-2018 / 10:57:54 / stefan"
@@ -5063,57 +5063,57 @@
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(__WIN32_ERR(GetLastError()));
- __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(__WIN32_ERR(GetLastError()));
+ __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) {
+ if (f == NULL) {
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error =__mkSmallInteger(__threadErrno);
- } else {
- if (@global(FileOpenTrace) == true) {
- fprintf(stderr, "fdopen [ExternalStream] %"_ld_" (%"_lx_") -> %"_lx_"\n", (INT)fd, (INT)fd, (INT)f);
- }
-
- fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
- }
+ error =__mkSmallInteger(__threadErrno);
+ } else {
+ if (@global(FileOpenTrace) == true) {
+ fprintf(stderr, "fdopen [ExternalStream] %"_ld_" (%"_lx_") -> %"_lx_"\n", (INT)fd, (INT)fd, (INT)f);
+ }
+
+ fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
+ }
}
out:;
%}.
error notNil ifTrue:[
- "
- the open failed for some reason ...
- "
- OperatingSystem closeFd:aFileDescriptor.
- lastErrorNumber := error.
- position := nil.
- ^ self openError:error
+ "
+ the open failed for some reason ...
+ "
+ OperatingSystem closeFd:aFileDescriptor.
+ lastErrorNumber := error.
+ position := nil.
+ ^ self openError:error
].
position := 0.
buffered isNil ifTrue:[
- buffered := true. "default is buffered"
+ buffered := true. "default is buffered"
].
handleType := handleTypeSymbol.
self registerForFinalization.
@@ -5169,45 +5169,45 @@
# 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) {
+ if (f == NULL) {
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __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;
- }
+ error = __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 ifTrue:[
- position := 0.
- self registerForFinalization.
- ^ self.
+ position := 0.
+ self registerForFinalization.
+ ^ self.
].
error notNil ifTrue:[
- "
- the open failed for some reason ...
- "
- lastErrorNumber := error.
- self openError:error.
+ "
+ the open failed for some reason ...
+ "
+ lastErrorNumber := error.
+ self openError:error.
].
self primitiveFailed.
@@ -5334,29 +5334,29 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
-
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
-
- if (ret > 0) {
- RETURN(nil)
- }
- if (ret < 0) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ RETURN(nil)
+ }
+ if (ret < 0) {
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- RETURN(__mkSmallInteger(__threadErrno));
- } else /* ret == 0 */ {
- RETURN(__mkSmallInteger(0)); /* EOF */
- }
- }
+ RETURN(__mkSmallInteger(__threadErrno));
+ } else /* ret == 0 */ {
+ RETURN(__mkSmallInteger(0)); /* EOF */
+ }
+ }
}
%}.
@@ -5382,18 +5382,18 @@
STObject handle = self.instVarAt(I_handle);
if (handle != STObject.Nil) {
- STObject next;
-
- if (self.instVarAt(I_binary) == STObject.True) {
- next = handle.nextByte();
- } else {
- next = handle.nextChar();
- }
- if (next != STObject.EOF) {
- self.instVarAt_put(I_position, STObject.Nil);
- return __c__._RETURN( next );
- }
- self.instVarAt_put(I_hitEOF, STObject.True);
+ STObject next;
+
+ if (self.instVarAt(I_binary) == STObject.True) {
+ next = handle.nextByte();
+ } else {
+ next = handle.nextChar();
+ }
+ if (next != STObject.EOF) {
+ self.instVarAt_put(I_position, STObject.Nil);
+ return __c__._RETURN( next );
+ }
+ self.instVarAt_put(I_hitEOF, STObject.True);
}
#else
FILEPOINTER f;
@@ -5407,66 +5407,66 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
-
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
-
- if (ret > 0) {
- pos = __INST(position);
- if (__isSmallInteger(pos)) {
- OBJ t;
-
- t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- if (__INST(binary) == true) {
- RETURN ( __mkSmallInteger(ch) );
- }
- RETURN ( __MKCHARACTER(ch) );
- }
-
- __INST(position) = nil;
- if (ret < 0) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ pos = __INST(position);
+ if (__isSmallInteger(pos)) {
+ OBJ t;
+
+ t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ if (__INST(binary) == true) {
+ RETURN ( __mkSmallInteger(ch) );
+ }
+ RETURN ( __MKCHARACTER(ch) );
+ }
+
+ __INST(position) = nil;
+ if (ret < 0) {
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
#endif /* not SCHTEAM */
%}.
hitEOF ifTrue:[^ self pastEndRead].
error notNil ifTrue:[
- lastErrorNumber := error.
- ^ self readError:error
+ lastErrorNumber := error.
+ ^ self readError:error
].
handle isNil ifTrue:[^ self errorNotOpen].
(mode == #writeonly) ifTrue:[^ self errorWriteOnly].
readAhead notNil ifTrue:[
- c := readAhead.
- readAhead := nil.
- ^ c.
+ c := readAhead.
+ readAhead := nil.
+ ^ c.
].
"unknown handleType - future"
c := self nextByteFromFile:handle.
c isNil ifTrue:[
- ^ self pastEndRead.
+ ^ self pastEndRead.
].
binary ifTrue:[
- ^ c
+ ^ c
].
^ Character value:c
@@ -5511,65 +5511,65 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
-
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
-
- if (ret > 0) {
- pos = __INST(position);
- if (__isSmallInteger(pos)) {
- OBJ t;
-
- t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- if (__INST(binary) == true) {
- RETURN ( __mkSmallInteger(ch) );
- }
- RETURN ( __MKCHARACTER(ch) );
- }
-
- __INST(position) = nil;
- if (ret < 0) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ pos = __INST(position);
+ if (__isSmallInteger(pos)) {
+ OBJ t;
+
+ t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ if (__INST(binary) == true) {
+ RETURN ( __mkSmallInteger(ch) );
+ }
+ RETURN ( __MKCHARACTER(ch) );
+ }
+
+ __INST(position) = nil;
+ if (ret < 0) {
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF ifTrue:[^ nil].
error notNil ifTrue:[
- lastErrorNumber := error.
- ^ self readError:error.
+ lastErrorNumber := error.
+ ^ self readError:error.
].
handle isNil ifTrue:[^ self errorNotOpen].
(mode == #writeonly) ifTrue:[^ self errorWriteOnly].
readAhead notNil ifTrue:[
- c := readAhead.
- readAhead := nil.
- ^ c.
+ c := readAhead.
+ readAhead := nil.
+ ^ c.
].
"unknown handleType - future"
c := self nextByteFromFile:handle.
c isNil ifTrue:[
- ^ nil.
+ ^ nil.
].
binary == true ifTrue:[
- ^ c
+ ^ c
].
^ Character value:c
@@ -5591,11 +5591,11 @@
OBJ ra;
if ((ra = __INST(readAhead)) != nil) {
- if (__INST(binary) == true) {
- RETURN ( ra );
- }
- c = __intVal(ra);
- RETURN ( __MKCHARACTER(c) );
+ if (__INST(binary) == true) {
+ RETURN ( ra );
+ }
+ c = __intVal(ra);
+ RETURN ( __MKCHARACTER(c) );
}
__INST(lastErrorNumber) = nil;
@@ -5605,48 +5605,48 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
-
- if (ret > 0) {
- __UNGETC__(c, f, _buffered);
-
- if (__INST(binary) == true) {
- RETURN ( __mkSmallInteger(c) );
- }
- RETURN ( __MKCHARACTER(c) );
- }
- if (ret < 0) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ __UNGETC__(c, f, _buffered);
+
+ if (__INST(binary) == true) {
+ RETURN ( __mkSmallInteger(c) );
+ }
+ RETURN ( __MKCHARACTER(c) );
+ }
+ if (ret < 0) {
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF ifTrue:[^ self pastEndRead].
error notNil ifTrue:[
- lastErrorNumber := error.
- ^ self readError:error.
+ lastErrorNumber := error.
+ ^ self readError:error.
].
handle isNil ifTrue:[^ self errorNotOpen].
(mode == #writeonly) ifTrue:[^ self errorWriteOnly].
readAhead isNil ifTrue:[
- readAhead := self nextOrNil.
- readAhead isNil ifTrue:[
- ^ self pastEndRead.
- ].
+ readAhead := self nextOrNil.
+ readAhead isNil ifTrue:[
+ ^ self pastEndRead.
+ ].
].
^ readAhead
@@ -5668,11 +5668,11 @@
OBJ ra;
if ((ra = __INST(readAhead)) != nil) {
- if (__INST(binary) == true) {
- RETURN ( ra );
- }
- c = __intVal(ra);
- RETURN ( __MKCHARACTER(c) );
+ if (__INST(binary) == true) {
+ RETURN ( ra );
+ }
+ c = __intVal(ra);
+ RETURN ( __MKCHARACTER(c) );
}
__INST(lastErrorNumber) = nil;
@@ -5682,45 +5682,45 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
-
- if (ret > 0) {
- __UNGETC__(c, f, _buffered);
-
- if (__INST(binary) == true) {
- RETURN ( __mkSmallInteger(c) );
- }
- RETURN ( __MKCHARACTER(c) );
- }
- if (ret < 0) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ __UNGETC__(c, f, _buffered);
+
+ if (__INST(binary) == true) {
+ RETURN ( __mkSmallInteger(c) );
+ }
+ RETURN ( __MKCHARACTER(c) );
+ }
+ if (ret < 0) {
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF ifTrue:[^ nil].
error notNil ifTrue:[
- lastErrorNumber := error.
- ^ self readError:error.
+ lastErrorNumber := error.
+ ^ self readError:error.
].
handle isNil ifTrue:[^ self errorNotOpen].
(mode == #writeonly) ifTrue:[^ self errorWriteOnly].
readAhead isNil ifTrue:[
- readAhead := self nextOrNil.
+ readAhead := self nextOrNil.
].
^ readAhead
@@ -5819,11 +5819,11 @@
char c;
if (__INST(hitEOF) == true) {
- RETURN (true);
+ RETURN (true);
}
lim = __INST(readLimit);
if (lim != nil && __signedLongIntVal(__INST(position)) >= __signedLongIntVal(lim)) {
- RETURN (true);
+ RETURN (true);
}
__INST(lastErrorNumber) = nil;
@@ -5833,45 +5833,45 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if ((fp = __INST(handle)) != nil) {
- int _buffered = (__INST(buffered) == true);
- int ret;
- FILEPOINTER f = __FILEVal(fp);
-
- if (_buffered) {
- __READING__(f);
- } else if (__INST(readAhead) != nil) {
- RETURN (false);
- }
-
- /*
- * read ahead ...
- */
- do {
+ if ((fp = __INST(handle)) != nil) {
+ int _buffered = (__INST(buffered) == true);
+ int ret;
+ FILEPOINTER f = __FILEVal(fp);
+
+ if (_buffered) {
+ __READING__(f);
+ } else if (__INST(readAhead) != nil) {
+ RETURN (false);
+ }
+
+ /*
+ * read ahead ...
+ */
+ do {
#ifdef __win32__
- __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+ __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
#else /* not __win32__ */
- __BEGIN_INTERRUPTABLE__
- __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
- __END_INTERRUPTABLE__
+ __BEGIN_INTERRUPTABLE__
+ __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+ __END_INTERRUPTABLE__
#endif /* not __win32__ */
- } while ((ret < 0) && (__threadErrno == EINTR));
- if (ret > 0) {
- __UNGETC__(c&0xff, f, _buffered);
- RETURN (false);
- }
- if (ret == 0) {
- __INST(hitEOF) = true;
- RETURN (true);
- }
- /* ret < 0 -> error */
+ } while ((ret < 0) && (__threadErrno == EINTR));
+ if (ret > 0) {
+ __UNGETC__(c&0xff, f, _buffered);
+ RETURN (false);
+ }
+ if (ret == 0) {
+ __INST(hitEOF) = true;
+ RETURN (true);
+ }
+ /* ret < 0 -> error */
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
- }
- // we do not raise an error here - the next read operation will raise the error.
- RETURN(false);
+ __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
+ }
+ // we do not raise an error here - the next read operation will raise the error.
+ RETURN(false);
}
%}.
@@ -6011,20 +6011,20 @@
In this case, all I/O operations here will be blocking."
Smalltalk isInitialized ifFalse:[
- ^ false
+ ^ false
].
wasBlocked := OperatingSystem blockInterrupts.
inputSema := Semaphore name:'readWait'.
hasTimedout := [
- Processor signal:inputSema onInput:fd.
- (inputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
+ Processor signal:inputSema onInput:fd.
+ (inputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
] ifCurtailed:[
- Processor disableSemaphore:inputSema.
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ Processor disableSemaphore:inputSema.
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
].
hasTimedout ifTrue:[
- Processor disableSemaphore:inputSema.
+ Processor disableSemaphore:inputSema.
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
^ hasTimedout
@@ -6044,7 +6044,7 @@
readAhead notNil ifTrue:[^ false].
handle isNil ifTrue:[
- ^ self errorNotOpen
+ ^ self errorNotOpen
].
fd := self fileHandle.
@@ -6053,16 +6053,16 @@
wasBlocked := OperatingSystem blockInterrupts.
sema := Semaphore name:'readWriteWait'.
hasTimedout := [
- Processor
- signal:sema onOutput:fd;
- signal:sema onInput:fd.
- (sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
+ Processor
+ signal:sema onOutput:fd;
+ signal:sema onInput:fd.
+ (sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
] ifCurtailed:[
- Processor disableSemaphore:sema.
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ Processor disableSemaphore:sema.
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
].
hasTimedout ifTrue:[
- Processor disableSemaphore:sema.
+ Processor disableSemaphore:sema.
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
^ hasTimedout
@@ -6081,7 +6081,7 @@
|fd sema hasTimedout wasBlocked|
handle isNil ifTrue:[
- ^ self errorNotOpen
+ ^ self errorNotOpen
].
fd := self fileHandle.
@@ -6090,16 +6090,16 @@
wasBlocked := OperatingSystem blockInterrupts.
sema := Semaphore name:'writeExceptionWait'.
hasTimedout := [
- Processor
- signal:sema onOutput:fd;
- signal:sema onException:fd.
- (sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
+ Processor
+ signal:sema onOutput:fd;
+ signal:sema onException:fd.
+ (sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
] ifCurtailed:[
- Processor disableSemaphore:sema.
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ Processor disableSemaphore:sema.
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
].
hasTimedout ifTrue:[
- Processor disableSemaphore:sema.
+ Processor disableSemaphore:sema.
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
^ hasTimedout
@@ -6118,10 +6118,10 @@
|fd outputSema hasTimedout wasBlocked|
handle isNil ifTrue:[
- ^ self errorNotOpen
+ ^ self errorNotOpen
].
mode == #readonly ifTrue:[
- ^ self errorReadOnly
+ ^ self errorReadOnly
].
fd := self fileHandle.
@@ -6130,14 +6130,14 @@
wasBlocked := OperatingSystem blockInterrupts.
outputSema := Semaphore name:'writeWait'.
hasTimedout := [
- Processor signal:outputSema onOutput:fd.
- (outputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
+ Processor signal:outputSema onOutput:fd.
+ (outputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
] ifCurtailed:[
- Processor disableSemaphore:outputSema.
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ Processor disableSemaphore:outputSema.
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
].
hasTimedout ifTrue:[
- Processor disableSemaphore:outputSema.
+ Processor disableSemaphore:outputSema.
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
^ hasTimedout
@@ -6160,77 +6160,77 @@
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- OBJ fp;
-
- __INST(lastErrorNumber) = nil;
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- && (__INST(binary) != true)
- ) {
- FILEPOINTER f = __FILEVal(fp);
- int _buffered = (__INST(buffered) == true);
- int len, cnt;
- char *cp;
-
- if (_buffered) {
- __WRITING__(f)
- }
- {
- OBJ mode = __INST(eolMode);
-
- if (mode == @symbol(cr)) {
- cp = "\r"; len = 1;
- } else if (mode == @symbol(crlf)) {
- cp = "\r\n"; len = 2;
- } else if (mode == @symbol(eot)) {
- cp = "\004"; len = 1;
- } else if (mode == @symbol(etx)) {
- cp = "\003"; len = 1;
- } else {
- cp = "\n"; len = 1;
- }
- }
+ OBJ fp;
+
+ __INST(lastErrorNumber) = nil;
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ && (__INST(binary) != true)
+ ) {
+ FILEPOINTER f = __FILEVal(fp);
+ int _buffered = (__INST(buffered) == true);
+ int len, cnt;
+ char *cp;
+
+ if (_buffered) {
+ __WRITING__(f)
+ }
+ {
+ OBJ mode = __INST(eolMode);
+
+ if (mode == @symbol(cr)) {
+ cp = "\r"; len = 1;
+ } else if (mode == @symbol(crlf)) {
+ cp = "\r\n"; len = 2;
+ } else if (mode == @symbol(eot)) {
+ cp = "\004"; len = 1;
+ } else if (mode == @symbol(etx)) {
+ cp = "\003"; len = 1;
+ } else {
+ cp = "\n"; len = 1;
+ }
+ }
#ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(cp, 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(cp, 1, len, f);
+ } else
#endif
- {
- __WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType));
- }
- if (cnt == len) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + len;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e: don't know */
- }
- RETURN ( self );
- }
+ {
+ __WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType));
+ }
+ if (cnt == len) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + len;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e: don't know */
+ }
+ RETURN ( self );
+ }
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
}
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self writeError:error.
- ^ self
+ lastErrorNumber := error.
+ self writeError:error.
+ ^ self
].
handle isNil ifTrue:[self errorNotOpen. ^ self].
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
binary ifTrue:[self errorBinary. ^ self].
(eolMode == #cr) ifTrue:[
- self nextPut:(Character return).
- ^ self
+ self nextPut:(Character return).
+ ^ self
].
(eolMode == #crlf) ifTrue:[
- self nextPut:(Character return).
+ self nextPut:(Character return).
].
self nextPut:(Character nl).
^ self
@@ -6288,9 +6288,9 @@
if ((handle != STObject.Nil)
&& (aCharacter.isSTCharacter())) {
- handle.writeChar( aCharacter );
- self.instVarAt_put(I_position, STObject.Nil);
- return __c__._RETURN_self();
+ handle.writeChar( aCharacter );
+ self.instVarAt_put(I_position, STObject.Nil);
+ return __c__._RETURN_self();
}
#else
__INST(lastErrorNumber) = nil;
@@ -6299,112 +6299,112 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- OBJ fp;
-
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- ) {
- FILEPOINTER f = __FILEVal(fp);
- int _buffered = (__INST(buffered) == true);
- int cnt;
- char buff[2];
- int nBytes = 1;
-
- if (__INST(binary) != true) {
- if (__isCharacter(aCharacter)) {
- unsigned int codePoint = __intVal(__characterVal(aCharacter));
- if (codePoint <= 0xFF) {
- unsigned char c = codePoint;
- buff[0] = c; nBytes = 1;
-
- if (c == '\n') {
- OBJ mode = __INST(eolMode);
- if (mode == @symbol(nl)) {
- // no EOL translation
- } else if (mode == nil) {
- // no EOL translation
- } else if (mode == @symbol(cr)) {
- buff[0] = '\r';
- } else if (mode == @symbol(eot)) {
- buff[0] = '\004';
- } else if (mode == @symbol(etx)) {
- buff[0] = '\003';
- } else if (mode == @symbol(crlf)) {
- buff[0] = '\r';
- buff[1] = '\n';
- nBytes = 2;
- }
- }
+ OBJ fp;
+
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ ) {
+ FILEPOINTER f = __FILEVal(fp);
+ int _buffered = (__INST(buffered) == true);
+ int cnt;
+ char buff[2];
+ int nBytes = 1;
+
+ if (__INST(binary) != true) {
+ if (__isCharacter(aCharacter)) {
+ unsigned int codePoint = __intVal(__characterVal(aCharacter));
+ if (codePoint <= 0xFF) {
+ unsigned char c = codePoint;
+ buff[0] = c; nBytes = 1;
+
+ if (c == '\n') {
+ OBJ mode = __INST(eolMode);
+ if (mode == @symbol(nl)) {
+ // no EOL translation
+ } else if (mode == nil) {
+ // no EOL translation
+ } else if (mode == @symbol(cr)) {
+ buff[0] = '\r';
+ } else if (mode == @symbol(eot)) {
+ buff[0] = '\004';
+ } else if (mode == @symbol(etx)) {
+ buff[0] = '\003';
+ } else if (mode == @symbol(crlf)) {
+ buff[0] = '\r';
+ buff[1] = '\n';
+ nBytes = 2;
+ }
+ }
doWrite:
- if (! f) {
- fprintf(stderr, "oops - fileHandle is NULL in nextPut:\n");
- __INST(handle) = nil;
- goto out;
- }
-
- if (_buffered) {
- __WRITING__(f)
- }
+ if (! f) {
+ fprintf(stderr, "oops - fileHandle is NULL in nextPut:\n");
+ __INST(handle) = nil;
+ goto out;
+ }
+
+ if (_buffered) {
+ __WRITING__(f)
+ }
# ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(buff, 1, nBytes, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(buff, 1, nBytes, f);
+ } else
# endif
- {
- __WRITEBYTES__(cnt, f, buff, nBytes, _buffered, __INST(handleType));
- }
- if (cnt == nBytes) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + nBytes;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN ( self );
- }
+ {
+ __WRITEBYTES__(cnt, f, buff, nBytes, _buffered, __INST(handleType));
+ }
+ if (cnt == nBytes) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + nBytes;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN ( self );
+ }
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
- }
- } else {
- if (__isSmallInteger(aCharacter)) {
- unsigned char c = __intVal(aCharacter);
- buff[0] = c; nBytes = 1;
- goto doWrite;
- }
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
+ }
+ } else {
+ if (__isSmallInteger(aCharacter)) {
+ unsigned char c = __intVal(aCharacter);
+ buff[0] = c; nBytes = 1;
+ goto doWrite;
+ }
+ }
+ }
}
out: ;
#endif /* not SCHTEAM */
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self writeError:error.
- ^ self
+ lastErrorNumber := error.
+ self writeError:error.
+ ^ self
].
handle isNil ifTrue:[self errorNotOpen. ^ self].
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
binary == true ifTrue:[
- aCharacter isInteger ifFalse:[
- self argumentMustBeInteger.
- ^ self.
- ].
+ aCharacter isInteger ifFalse:[
+ self argumentMustBeInteger.
+ ^ self.
+ ].
] ifFalse:[
- (aCharacter isCharacter not
- or:[aCharacter codePoint > 16rFF]) ifTrue:[
- self argumentMustBeCharacter.
- ^ self.
- ].
+ (aCharacter isCharacter not
+ or:[aCharacter codePoint > 16rFF]) ifTrue:[
+ self argumentMustBeCharacter.
+ ^ self.
+ ].
].
"/ migration support
self
- nextPutByte:aCharacter asInteger
- toFile:handle
+ nextPutByte:aCharacter asInteger
+ toFile:handle
"Modified: / 22-11-2018 / 14:47:13 / Stefan Vogel"
!
@@ -6421,9 +6421,9 @@
if ((handle != STObject.Nil)
&& (aCollection.isSTString())) {
- handle.writeCharacters( aCollection.asSTString().characters );
- self.instVarAt_put(I_position, STObject.Nil);
- return __c__._RETURN_self();
+ handle.writeCharacters( aCollection.asSTString().characters );
+ self.instVarAt_put(I_position, STObject.Nil);
+ return __c__._RETURN_self();
}
#else
@@ -6434,167 +6434,167 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- OBJ fp;
-
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- ) {
- INT len, cnt;
- INT o_offs;
- FILEPOINTER f = __FILEVal(fp);
- int _buffered = (__INST(buffered) == true);
-
- if (! f) {
- fprintf(stderr, "oops - fileHandle is NULL in nextPutAll:\n");
- __INST(handle) = nil;
- goto out;
- }
- if (_buffered) {
- __WRITING__(f)
- }
-
- if (__isStringLike(aCollection)) {
- OBJ mode = __INST(eolMode);
- char *stringP = __stringVal(aCollection);
- len = __stringSize(aCollection);
-
- if (__INST(binary) != true
- && ((mode == @symbol(cr))
- || (mode == @symbol(etx))
- || (mode == @symbol(eot))
- || (mode == @symbol(crlf)))
- && memchr(stringP, '\n', len) != NULL)
- {
- // there is a '\n' to be translated, replace it into a buffer
-
- char *end;
- char sep[2];
- int sepLen = 1;
- int bufLen;
- char *buf, *endBuf, *sp, *dp;
-
- sep[0] = '\n';
- if (mode == @symbol(crlf)) {
- sep[0] = '\r'; sep[1] = '\n'; sepLen = 2;
- } else if (mode == @symbol(cr)) {
- sep[0] = '\r';
- } else if (mode == @symbol(eot)) {
- sep[0] = '\004';
- } else if (mode == @symbol(etx)) {
- sep[0] = '\003';
- }
-
- // estimate size of buffer - assume every 4th char is a separator
- bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen);
- buf = (char *)malloc(bufLen);
- if (buf == NULL) {
- error = __mkSmallInteger(ENOMEM);
- goto out;
- }
-
- endBuf = buf + bufLen;
- end = stringP + len;
- for (sp = stringP, dp = buf; sp < end; sp++) {
- char c;
-
- if ((dp+sepLen) >= endBuf) {
- char *newBuf;
-
- bufLen = bufLen * 2;
- newBuf = (char *)realloc(buf, bufLen);
- if (newBuf == NULL) {
- free(buf);
- error = __mkSmallInteger(ENOMEM);
- goto out;
- }
- endBuf = newBuf + bufLen;
- dp = newBuf + (dp-buf);
- buf = newBuf;
- }
-
- if ((c = *sp) != '\n') {
- *dp++ = c;
- } else {
- *dp++ = sep[0];
- if (sepLen == 2) {
- *dp++ = sep[1];
- };
- }
- }
-
- len = dp - buf;
+ OBJ fp;
+
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ ) {
+ INT len, cnt;
+ INT o_offs;
+ FILEPOINTER f = __FILEVal(fp);
+ int _buffered = (__INST(buffered) == true);
+
+ if (! f) {
+ fprintf(stderr, "oops - fileHandle is NULL in nextPutAll:\n");
+ __INST(handle) = nil;
+ goto out;
+ }
+ if (_buffered) {
+ __WRITING__(f)
+ }
+
+ if (__isStringLike(aCollection)) {
+ OBJ mode = __INST(eolMode);
+ char *stringP = __stringVal(aCollection);
+ len = __stringSize(aCollection);
+
+ if (__INST(binary) != true
+ && ((mode == @symbol(cr))
+ || (mode == @symbol(etx))
+ || (mode == @symbol(eot))
+ || (mode == @symbol(crlf)))
+ && memchr(stringP, '\n', len) != NULL)
+ {
+ // there is a '\n' to be translated, replace it into a buffer
+
+ char *end;
+ char sep[2];
+ int sepLen = 1;
+ int bufLen;
+ char *buf, *endBuf, *sp, *dp;
+
+ sep[0] = '\n';
+ if (mode == @symbol(crlf)) {
+ sep[0] = '\r'; sep[1] = '\n'; sepLen = 2;
+ } else if (mode == @symbol(cr)) {
+ sep[0] = '\r';
+ } else if (mode == @symbol(eot)) {
+ sep[0] = '\004';
+ } else if (mode == @symbol(etx)) {
+ sep[0] = '\003';
+ }
+
+ // estimate size of buffer - assume every 4th char is a separator
+ bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen);
+ buf = (char *)malloc(bufLen);
+ if (buf == NULL) {
+ error = __mkSmallInteger(ENOMEM);
+ goto out;
+ }
+
+ endBuf = buf + bufLen;
+ end = stringP + len;
+ for (sp = stringP, dp = buf; sp < end; sp++) {
+ char c;
+
+ if ((dp+sepLen) >= endBuf) {
+ char *newBuf;
+
+ bufLen = bufLen * 2;
+ newBuf = (char *)realloc(buf, bufLen);
+ if (newBuf == NULL) {
+ free(buf);
+ error = __mkSmallInteger(ENOMEM);
+ goto out;
+ }
+ endBuf = newBuf + bufLen;
+ dp = newBuf + (dp-buf);
+ buf = newBuf;
+ }
+
+ if ((c = *sp) != '\n') {
+ *dp++ = c;
+ } else {
+ *dp++ = sep[0];
+ if (sepLen == 2) {
+ *dp++ = sep[1];
+ };
+ }
+ }
+
+ len = dp - buf;
# ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(buf, 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(buf, 1, len, f);
+ } else
# endif
- {
- __WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType));
- }
- free(buf);
- } else { // No EOL conversion needed
+ {
+ __WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType));
+ }
+ free(buf);
+ } else { // No EOL conversion needed
# ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(stringP, 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(stringP, 1, len, f);
+ } else
# endif
- {
- o_offs = stringP - (char *)__InstPtr(aCollection);
- __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType));
- }
- }
- } else { // Not a String
- if (__INST(binary) == true) {
- INT offs;
-
- if (__isByteArrayLike(aCollection)) {
- offs = 0;
- len = __byteArraySize(aCollection);
- } else if (__isBytes(aCollection)) {
- offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
- len = __byteArraySize(aCollection) - offs;
- } else
- goto out;
+ {
+ o_offs = stringP - (char *)__InstPtr(aCollection);
+ __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType));
+ }
+ }
+ } else { // Not a String
+ if (__INST(binary) == true) {
+ INT offs;
+
+ if (__isByteArrayLike(aCollection)) {
+ offs = 0;
+ len = __byteArraySize(aCollection);
+ } else if (__isBytes(aCollection)) {
+ offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
+ len = __byteArraySize(aCollection) - offs;
+ } else
+ goto out;
# ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(__stringVal(aCollection), 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(__stringVal(aCollection), 1, len, f);
+ } else
# endif
- {
- o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection);
- o_offs += offs;
- __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType));
- }
- } else // Not binary mode
- goto out;
- }
-
- // Now check for errors
- if (cnt == len) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + len;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN (self);
- }
+ {
+ o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection);
+ o_offs += offs;
+ __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType));
+ }
+ } else // Not binary mode
+ goto out;
+ }
+
+ // Now check for errors
+ if (cnt == len) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + len;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN (self);
+ }
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- fprintf(stderr, "cnt=%"_ld_" len=%"_ld_"\n", (INT)cnt, (INT)len);
- }
+ error = __mkSmallInteger(__threadErrno);
+ fprintf(stderr, "cnt=%"_ld_" len=%"_ld_"\n", (INT)cnt, (INT)len);
+ }
}
out: ;
#endif /* not SCHTEAM */
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self writeError:error.
- ^ self
+ lastErrorNumber := error.
+ self writeError:error.
+ ^ self
].
handle isNil ifTrue:[self errorNotOpen. ^ self].
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
@@ -6633,179 +6633,179 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- OBJ fp = __INST(handle);
-
- if ((fp != nil)
- && (__INST(mode) != @symbol(readonly))
- && __bothSmallInteger(start, stop)
- ) {
- int _buffered = (__INST(buffered) == true);
- FILEPOINTER f = __FILEVal(fp);
- int offs, len, cnt;
- int iStart = __intVal(start);
- int iStop = __intVal(stop);
- int o_offs;
-
- if (_buffered ) {
- __WRITING__(f)
- }
-
- if ((iStart < 1) || (iStop < iStart)) {
- RETURN(self);
- }
- if (__isStringLike(aCollection)) {
- char *stringP;
- OBJ mode = __INST(eolMode);
-
- len = __stringSize(aCollection);
- if (iStop > len) {
- RETURN(self);
- }
- if (iStop > len)
- iStop = len;
- len = iStop - iStart + 1;
- stringP = __stringVal(aCollection) + iStart - 1;
-
- if (__INST(binary) != true
- && ((mode == @symbol(cr))
- || (mode == @symbol(etx))
- || (mode == @symbol(eot))
- || (mode == @symbol(crlf)))
- && memchr(stringP, '\n', len) != NULL)
- {
- // see if there is a \n which needs to be translated, replace it
-
- char *end = stringP + len;
- char sep[2];
- int sepLen = 1;
- int bufLen;
- char *buf, *endBuf, *sp, *dp;
-
- sep[0] = '\n';
- if (mode == @symbol(crlf)) {
- sep[0] = '\r'; sep[1] = '\n'; sepLen = 2;
- } else if (mode == @symbol(cr)) {
- sep[0] = '\r';
- } else if (mode == @symbol(eot)) {
- sep[0] = '\004';
- } else if (mode == @symbol(etx)) {
- sep[0] = '\003';
- }
-
- // estimate size of buffer - assume every 4th char is a separator
- bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen);
- buf = (char *)malloc(bufLen);
- if (buf == NULL) {
- error = __mkSmallInteger(ENOMEM);
- goto out;
- }
-
- endBuf = buf + bufLen;
-
- for (sp = stringP, dp = buf; sp < end; sp++) {
- char c;
-
- if ((dp+sepLen) >= endBuf) {
- char *newBuf;
-
- bufLen = bufLen * 2;
- newBuf = (char *)realloc(buf, bufLen);
- if (newBuf == NULL) {
- free(buf);
- error = __mkSmallInteger(ENOMEM);
- goto out;
- }
- endBuf = newBuf + bufLen;
- dp = newBuf + (dp-buf);
- buf = newBuf;
- }
-
- if ((c = *sp) == '\n') {
- *dp++ = sep[0];
- if (sepLen == 2) {
- *dp++ = sep[1];
- };
- } else {
- *dp++ = c;
- }
- }
-
- len = dp - buf;
+ OBJ fp = __INST(handle);
+
+ if ((fp != nil)
+ && (__INST(mode) != @symbol(readonly))
+ && __bothSmallInteger(start, stop)
+ ) {
+ int _buffered = (__INST(buffered) == true);
+ FILEPOINTER f = __FILEVal(fp);
+ int offs, len, cnt;
+ int iStart = __intVal(start);
+ int iStop = __intVal(stop);
+ int o_offs;
+
+ if (_buffered ) {
+ __WRITING__(f)
+ }
+
+ if ((iStart < 1) || (iStop < iStart)) {
+ RETURN(self);
+ }
+ if (__isStringLike(aCollection)) {
+ char *stringP;
+ OBJ mode = __INST(eolMode);
+
+ len = __stringSize(aCollection);
+ if (iStop > len) {
+ RETURN(self);
+ }
+ if (iStop > len)
+ iStop = len;
+ len = iStop - iStart + 1;
+ stringP = __stringVal(aCollection) + iStart - 1;
+
+ if (__INST(binary) != true
+ && ((mode == @symbol(cr))
+ || (mode == @symbol(etx))
+ || (mode == @symbol(eot))
+ || (mode == @symbol(crlf)))
+ && memchr(stringP, '\n', len) != NULL)
+ {
+ // see if there is a \n which needs to be translated, replace it
+
+ char *end = stringP + len;
+ char sep[2];
+ int sepLen = 1;
+ int bufLen;
+ char *buf, *endBuf, *sp, *dp;
+
+ sep[0] = '\n';
+ if (mode == @symbol(crlf)) {
+ sep[0] = '\r'; sep[1] = '\n'; sepLen = 2;
+ } else if (mode == @symbol(cr)) {
+ sep[0] = '\r';
+ } else if (mode == @symbol(eot)) {
+ sep[0] = '\004';
+ } else if (mode == @symbol(etx)) {
+ sep[0] = '\003';
+ }
+
+ // estimate size of buffer - assume every 4th char is a separator
+ bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen);
+ buf = (char *)malloc(bufLen);
+ if (buf == NULL) {
+ error = __mkSmallInteger(ENOMEM);
+ goto out;
+ }
+
+ endBuf = buf + bufLen;
+
+ for (sp = stringP, dp = buf; sp < end; sp++) {
+ char c;
+
+ if ((dp+sepLen) >= endBuf) {
+ char *newBuf;
+
+ bufLen = bufLen * 2;
+ newBuf = (char *)realloc(buf, bufLen);
+ if (newBuf == NULL) {
+ free(buf);
+ error = __mkSmallInteger(ENOMEM);
+ goto out;
+ }
+ endBuf = newBuf + bufLen;
+ dp = newBuf + (dp-buf);
+ buf = newBuf;
+ }
+
+ if ((c = *sp) == '\n') {
+ *dp++ = sep[0];
+ if (sepLen == 2) {
+ *dp++ = sep[1];
+ };
+ } else {
+ *dp++ = c;
+ }
+ }
+
+ len = dp - buf;
#ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(buf, 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(buf, 1, len, f);
+ } else
#endif
- {
- __WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType));
- }
- free(buf);
- } else { // No EOL conversion needed
+ {
+ __WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType));
+ }
+ free(buf);
+ } else { // No EOL conversion needed
#ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(stringP, 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(stringP, 1, len, f);
+ } else
#endif
- {
- o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection);
- __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+iStart-1, len, _buffered, __INST(handleType));
- }
- }
- } else { // Not a string
- if (__INST(binary) == true) {
- int offs;
-
- if (__isByteArrayLike(aCollection)) {
- offs = 0;
- len = __byteArraySize(aCollection);
- } else if (__isBytes(aCollection)) {
- offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
- len = __byteArraySize(aCollection) - offs;
- } else
- goto out;
-
- if (iStop > len) {
- RETURN(self);
- }
- if (iStop > len)
- iStop = len;
- len = iStop - iStart + 1;
- offs += iStart - 1;
+ {
+ o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection);
+ __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+iStart-1, len, _buffered, __INST(handleType));
+ }
+ }
+ } else { // Not a string
+ if (__INST(binary) == true) {
+ int offs;
+
+ if (__isByteArrayLike(aCollection)) {
+ offs = 0;
+ len = __byteArraySize(aCollection);
+ } else if (__isBytes(aCollection)) {
+ offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
+ len = __byteArraySize(aCollection) - offs;
+ } else
+ goto out;
+
+ if (iStop > len) {
+ RETURN(self);
+ }
+ if (iStop > len)
+ iStop = len;
+ len = iStop - iStart + 1;
+ offs += iStart - 1;
#ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(__stringVal(aCollection)+iStart-1, 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(__stringVal(aCollection)+iStart-1, 1, len, f);
+ } else
#endif
- {
- o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element)-(char *)__InstPtr(aCollection);
- __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+offs, len, _buffered, __INST(handleType));
- }
- } else
- goto out;
- }
- if (cnt == len) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + len;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN (self);
- }
+ {
+ o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element)-(char *)__InstPtr(aCollection);
+ __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+offs, len, _buffered, __INST(handleType));
+ }
+ } else
+ goto out;
+ }
+ if (cnt == len) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + len;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN (self);
+ }
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
}
out: ;
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self writeError:error.
- ^ self
+ lastErrorNumber := error.
+ self writeError:error.
+ ^ self
].
super nextPutAll:aCollection startingAt:start to:stop
@@ -6834,9 +6834,9 @@
Use with care - non object oriented i/o.
Warning:
- in general, you cannot use this method to pass non-byte data to other
- architectures (unless you prepared the buffer with care),
- since it does not care for byte order or float representation."
+ in general, you cannot use this method to pass non-byte data to other
+ architectures (unless you prepared the buffer with care),
+ since it does not care for byte order or float representation."
|error|
@@ -6846,16 +6846,16 @@
STObject handle = self.instVarAt(I_handle);
if (anObject.isSTString()) {
- char[] chars = anObject.asSTString().characters;
- handle.writeCharacters(chars, start.intValue()-1, count.intValue());
- self.instVarAt_put(I_position, STObject.Nil);
- return context._RETURN(count);
+ char[] chars = anObject.asSTString().characters;
+ handle.writeCharacters(chars, start.intValue()-1, count.intValue());
+ self.instVarAt_put(I_position, STObject.Nil);
+ return context._RETURN(count);
}
if (anObject.isSymbol()) {
- java.lang.String chars = anObject.asSTSymbol().characters;
- handle.writeString(chars, start.intValue()-1, count.intValue());
- self.instVarAt_put(I_position, STObject.Nil);
- return context._RETURN(count);
+ java.lang.String chars = anObject.asSTSymbol().characters;
+ handle.writeString(chars, start.intValue()-1, count.intValue());
+ self.instVarAt_put(I_position, STObject.Nil);
+ return context._RETURN(count);
}
#else
int ret;
@@ -6869,124 +6869,124 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- && __bothSmallInteger(count, start)
- ) {
- int _buffered = (__INST(buffered) == true);
- FILEPOINTER f = __FILEVal(fp);
- int len = __intVal(count);
- int 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 = __Class(anObject);
- int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
-
- nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
- switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
- case BYTEARRAY:
- case WORDARRAY:
- case LONGARRAY:
- case SWORDARRAY:
- case SLONGARRAY:
- case FLOATARRAY:
- break;
- case DOUBLEARRAY:
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ && __bothSmallInteger(count, start)
+ ) {
+ int _buffered = (__INST(buffered) == true);
+ FILEPOINTER f = __FILEVal(fp);
+ int len = __intVal(count);
+ int 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 = __Class(anObject);
+ int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+
+ nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
+ switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+ case BYTEARRAY:
+ case WORDARRAY:
+ case LONGARRAY:
+ case SWORDARRAY:
+ case SLONGARRAY:
+ case FLOATARRAY:
+ break;
+ case DOUBLEARRAY:
# ifdef __NEED_DOUBLE_ALIGN
- nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
+ nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
# endif
- break;
- case LONGLONGARRAY:
- case SLONGLONGARRAY:
+ break;
+ case LONGLONGARRAY:
+ case SLONGLONGARRAY:
# ifdef __NEED_LONGLONG_ALIGN
- nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
+ nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
# endif
- break;
- default:
- goto bad;
- }
- extPtr = (char *)0;
- objSize = __Size(anObject) - nInstBytes;
- }
- if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) {
- int cnt;
-
- if (_buffered) {
- __WRITING__(f)
- }
-
- if (extPtr) {
+ break;
+ default:
+ goto bad;
+ }
+ extPtr = (char *)0;
+ objSize = __Size(anObject) - nInstBytes;
+ }
+ if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) {
+ int cnt;
+
+ if (_buffered) {
+ __WRITING__(f)
+ }
+
+ if (extPtr) {
# ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(extPtr+offs, 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(extPtr+offs, 1, len, f);
+ } else
# endif
- {
- __WRITEBYTES__(cnt, f, extPtr+offs, len, _buffered, __INST(handleType));
- }
- } else {
- /*
- * on interrupt, anObject may be moved to another location.
- * So we pass anObject, and the offset to the __WRITEBYTES_OBJ__ macro.
- */
- offs += nInstBytes;
+ {
+ __WRITEBYTES__(cnt, f, extPtr+offs, len, _buffered, __INST(handleType));
+ }
+ } else {
+ /*
+ * on interrupt, anObject may be moved to another location.
+ * So we pass anObject, and the offset to the __WRITEBYTES_OBJ__ macro.
+ */
+ offs += nInstBytes;
# ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite((char *)anObject+offs, 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite((char *)anObject+offs, 1, len, f);
+ } else
# endif
- {
- __WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered, __INST(handleType));
- }
- }
-
- if (cnt >= 0) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + cnt;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN ( __mkSmallInteger(cnt) );
- } else /* cnt < 0 */ {
- if (
+ {
+ __WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered, __INST(handleType));
+ }
+ }
+
+ if (cnt >= 0) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + cnt;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN ( __mkSmallInteger(cnt) );
+ } else /* cnt < 0 */ {
+ if (
# ifdef EWOULDBLOCK
- (__threadErrno == EWOULDBLOCK) ||
+ (__threadErrno == EWOULDBLOCK) ||
# endif
- (__threadErrno == EAGAIN)
- ) {
- RETURN ( __mkSmallInteger(0) );
- }
- __INST(position) = nil; /* i.e. do not know */
+ (__threadErrno == EAGAIN)
+ ) {
+ RETURN ( __mkSmallInteger(0) );
+ }
+ __INST(position) = nil; /* i.e. do not know */
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
+ }
+ }
}
bad: ;
#endif /* not SCHTEAM */
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self writeError:error.
- ^ 0
+ lastErrorNumber := error.
+ self writeError:error.
+ ^ 0
].
handle isNil ifTrue:[self errorNotOpen. ^ 0].
(mode == #readonly) ifTrue:[self errorReadOnly. ^ 0].