--- a/ExternalStream.st Mon May 28 16:20:20 2018 +0200
+++ b/ExternalStream.st Tue May 29 10:54:19 2018 +0200
@@ -2,7 +2,7 @@
"
COPYRIGHT (c) 1988 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -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 */
@@ -1357,7 +1357,7 @@
copyright
"
COPYRIGHT (c) 1988 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -1407,37 +1407,37 @@
[Instance variables:]
- handleType <Symbol> desribes what handle is:
- win32: #fileHandle, #socketHandle,
- #filePointer, #socketFilePointer, #pipeFilePointer
- unix: #filePointer, #socketFilePointer, #pipeFilePointer
- needed for win32, which uses different APIs for the different handles (sigh)
- handle <Integer> used to be always a filePointer somehow mapped to an integer (FILE* - not the fd);
- now, either a filePointer or a handle (win32)
- mode <Symbol> #readwrite, #readonly or #writeonly
- buffered <Boolean> true, if buffered (i.e. collects characters - does
- not output immediately)
- binary <Boolean> true if in binary mode (reads bytes instead of chars)
- eolMode <Symbol> one of nil, #nl, #cr or #crlf.
- determines how lines should be terminated.
- nil -> newLine (as in Unix);
- #crlf -> with cr-lf (as in MSDOS)
- #cr -> with cr (as in VMS)
- hitEOF <Boolean> true, if EOF was reached
-
- lastErrorNumber <Integer> the value of errno (only valid right after the error -
- updated with next i/o operation)
+ handleType <Symbol> desribes what handle is:
+ win32: #fileHandle, #socketHandle,
+ #filePointer, #socketFilePointer, #pipeFilePointer
+ unix: #filePointer, #socketFilePointer, #pipeFilePointer
+ needed for win32, which uses different APIs for the different handles (sigh)
+ handle <Integer> used to be always a filePointer somehow mapped to an integer (FILE* - not the fd);
+ now, either a filePointer or a handle (win32)
+ mode <Symbol> #readwrite, #readonly or #writeonly
+ buffered <Boolean> true, if buffered (i.e. collects characters - does
+ not output immediately)
+ binary <Boolean> true if in binary mode (reads bytes instead of chars)
+ eolMode <Symbol> one of nil, #nl, #cr or #crlf.
+ determines how lines should be terminated.
+ nil -> newLine (as in Unix);
+ #crlf -> with cr-lf (as in MSDOS)
+ #cr -> with cr (as in VMS)
+ hitEOF <Boolean> true, if EOF was reached
+
+ lastErrorNumber <Integer> the value of errno (only valid right after the error -
+ updated with next i/o operation)
[Class variables:]
- Lobby <Registry> keeps track of used ext-streams (to free up FILE*'s)
-
- StreamErrorSignal <Signal> parent of all stream errors (see Stream class)
- InvalidReadSignal <Signal> raised on read from writeonly stream
- InvalidWriteSignal <Signal> raised on write to readonly stream
- InvalidModeSignal <Signal> raised on text I/O with binary-stream
- or binary I/O with text-stream
- OpenErrorSignal <Signal> raised if open fails
- StreamNotOpenSignal <Signal> raised on I/O with non-open stream
+ Lobby <Registry> keeps track of used ext-streams (to free up FILE*'s)
+
+ StreamErrorSignal <Signal> parent of all stream errors (see Stream class)
+ InvalidReadSignal <Signal> raised on read from writeonly stream
+ InvalidWriteSignal <Signal> raised on write to readonly stream
+ InvalidModeSignal <Signal> raised on text I/O with binary-stream
+ or binary I/O with text-stream
+ OpenErrorSignal <Signal> raised if open fails
+ StreamNotOpenSignal <Signal> raised on I/O with non-open stream
Additional notes:
This class is implemented using the underlying stdio-c library package, which
@@ -1471,44 +1471,44 @@
fread/fgetc and fwrite/putc respectively.
[author:]
- Claus Gittinger
- Stefan Vogel (many, many fixes ...)
+ Claus Gittinger
+ Stefan Vogel (many, many fixes ...)
[see also:]
- FileStream Socket PipeStream
- Filename OperatingSystem
+ FileStream Socket PipeStream
+ Filename OperatingSystem
"
!
examples
"
open a file, read the contents and display it in a textView:
- [exBegin]
- |topView scrollPane textView fileStream text|
-
- topView := StandardSystemView new.
- topView label:'contents of Makefile'.
-
- scrollPane := HVScrollableView in:topView.
- scrollPane origin:0.0@0.0 corner:1.0@1.0.
-
- textView := EditTextView new.
- scrollPane scrolledView:textView.
-
- fileStream := 'Makefile' asFilename readStream.
- text := fileStream upToEnd.
- fileStream close.
-
- textView contents:text.
-
- topView open.
- [exEnd]
+ [exBegin]
+ |topView scrollPane textView fileStream text|
+
+ topView := StandardSystemView new.
+ topView label:'contents of Makefile'.
+
+ scrollPane := HVScrollableView in:topView.
+ scrollPane origin:0.0@0.0 corner:1.0@1.0.
+
+ textView := EditTextView new.
+ scrollPane scrolledView:textView.
+
+ fileStream := 'Makefile' asFilename readStream.
+ text := fileStream upToEnd.
+ fileStream close.
+
+ textView contents:text.
+
+ topView open.
+ [exEnd]
Notice, all of the above can also be done (simply) as:
- [exBegin]
- EditTextView openOn:'Makefile'
- [exEnd]
+ [exBegin]
+ EditTextView openOn:'Makefile'
+ [exEnd]
"
! !
@@ -1519,11 +1519,11 @@
To be called on exit of Smalltalk."
Lobby do:[:eachFileStream |
- (eachFileStream ~~ Stdin
- and:[eachFileStream ~~ Stdout
- and:[eachFileStream ~~ Stderr]]) ifTrue:[
- eachFileStream close
- ].
+ (eachFileStream ~~ Stdin
+ and:[eachFileStream ~~ Stdout
+ and:[eachFileStream ~~ Stderr]]) ifTrue:[
+ eachFileStream close
+ ].
].
"Modified: / 25-04-2018 / 15:23:41 / stefan"
@@ -1531,24 +1531,24 @@
initDefaultEOLMode
OperatingSystem isUNIXlike ifTrue:[
- "/ unix EOL conventions
- DefaultEOLMode := #nl
+ "/ unix EOL conventions
+ DefaultEOLMode := #nl
] ifFalse:[
- OperatingSystem isVMSlike ifTrue:[
- "/ vms EOL conventions
- DefaultEOLMode := #cr
- ] ifFalse:[
- "/ msdos EOL conventions
- "/ msdos uses #crlf.
- "/ the following breaks all programs, which do not explicitly
- "/ change th eolMode when writing/reading binary files (zip reader)
- "/ MUST change all classes before doing the following.
- "/ Anyway: for backward compatibility (swisscom), it is left in this
- "/ mode (for a while, I hope).
- DefaultEOLMode := #crlf.
-
- "/ DefaultEOLMode := #nl
- ]
+ OperatingSystem isVMSlike ifTrue:[
+ "/ vms EOL conventions
+ DefaultEOLMode := #cr
+ ] ifFalse:[
+ "/ msdos EOL conventions
+ "/ msdos uses #crlf.
+ "/ the following breaks all programs, which do not explicitly
+ "/ change th eolMode when writing/reading binary files (zip reader)
+ "/ MUST change all classes before doing the following.
+ "/ Anyway: for backward compatibility (swisscom), it is left in this
+ "/ mode (for a while, I hope).
+ DefaultEOLMode := #crlf.
+
+ "/ DefaultEOLMode := #nl
+ ]
]
!
@@ -1557,57 +1557,57 @@
fopen/fdopen functions."
OperatingSystem isMSDOSlike ifTrue:[
- ReadMode := 'rb'.
- ReadWriteMode := 'rb+'.
- WriteMode := 'wb'.
- AppendMode := 'ab+'.
- CreateReadWriteMode := 'wb+'.
+ ReadMode := 'rb'.
+ ReadWriteMode := 'rb+'.
+ WriteMode := 'wb'.
+ AppendMode := 'ab+'.
+ CreateReadWriteMode := 'wb+'.
] ifFalse:[
- ReadMode := 'r'.
- ReadWriteMode := 'r+'.
- WriteMode := 'w'.
- AppendMode := 'a+'.
- CreateReadWriteMode := 'w+'.
+ ReadMode := 'r'.
+ ReadWriteMode := 'r+'.
+ WriteMode := 'w'.
+ AppendMode := 'a+'.
+ CreateReadWriteMode := 'w+'.
]
!
initialize
OpenErrorSignal isNil ifTrue:[
- OpenErrorSignal := OpenError.
- OpenErrorSignal notifierString:'open error'.
-
- InvalidReadSignal := InvalidReadError.
- InvalidReadSignal notifierString:'stream does not support reading'.
-
- InvalidWriteSignal := InvalidWriteError.
- InvalidWriteSignal notifierString:'stream does not support writing'.
-
- InvalidModeSignal := InvalidModeError.
- InvalidModeSignal notifierString:'binary/text mode mismatch'.
-
- InvalidOperationSignal := InvalidOperationError.
- InvalidOperationSignal notifierString:'unsupported file operation'.
-
- StreamNotOpenSignal := StreamNotOpenError.
- StreamNotOpenSignal notifierString:'stream is not open'.
-
- StreamIOErrorSignal := StreamIOError.
- StreamIOErrorSignal notifierString:'I/O error'.
-
- "/ self patchByteOrderOptimizedMethods
+ OpenErrorSignal := OpenError.
+ OpenErrorSignal notifierString:'open error'.
+
+ InvalidReadSignal := InvalidReadError.
+ InvalidReadSignal notifierString:'stream does not support reading'.
+
+ InvalidWriteSignal := InvalidWriteError.
+ InvalidWriteSignal notifierString:'stream does not support writing'.
+
+ InvalidModeSignal := InvalidModeError.
+ InvalidModeSignal notifierString:'binary/text mode mismatch'.
+
+ InvalidOperationSignal := InvalidOperationError.
+ InvalidOperationSignal notifierString:'unsupported file operation'.
+
+ StreamNotOpenSignal := StreamNotOpenError.
+ StreamNotOpenSignal notifierString:'stream is not open'.
+
+ StreamIOErrorSignal := StreamIOError.
+ StreamIOErrorSignal notifierString:'I/O error'.
+
+ "/ self patchByteOrderOptimizedMethods
].
Lobby isNil ifTrue:[
- Lobby := Registry new.
-
- "want to get informed when returning from snapshot"
- ObjectMemory addDependent:self
+ Lobby := Registry new.
+
+ "want to get informed when returning from snapshot"
+ ObjectMemory addDependent:self
].
DefaultEOLMode isNil ifTrue:[
- self initDefaultEOLMode.
+ self initDefaultEOLMode.
].
ReadMode isNil ifTrue:[
- self initModeStrings.
+ self initModeStrings.
].
"limit the amount of newspace to be used for non-tenurable executors to 5%"
@@ -1622,8 +1622,8 @@
patchByteOrderOptimizedMethods
"EXPERIMENTAL (not yet done by default):
change the underlying implementation of
- nextPutInt16MSB / nextPutInt16LSB
- nextPutInt32MSB / nextPutInt32LSB
+ nextPutInt16MSB / nextPutInt16LSB
+ nextPutInt32MSB / nextPutInt32LSB
to the corresponding NATIVE methods."
|native16 native32|
@@ -1632,11 +1632,11 @@
native32 := self compiledMethodAt:#nextPutInt32NATIVE:.
UninterpretedBytes isBigEndian ifTrue:[
- (self compiledMethodAt:#nextPutInt16MSB:) code:(native16 code).
- (self compiledMethodAt:#nextPutInt32MSB:) code:(native32 code).
+ (self compiledMethodAt:#nextPutInt16MSB:) code:(native16 code).
+ (self compiledMethodAt:#nextPutInt32MSB:) code:(native32 code).
] ifFalse:[
- (self compiledMethodAt:#nextPutInt16LSB:) code:(native16 code).
- (self compiledMethodAt:#nextPutInt32LSB:) code:(native32 code).
+ (self compiledMethodAt:#nextPutInt16LSB:) code:(native16 code).
+ (self compiledMethodAt:#nextPutInt32LSB:) code:(native32 code).
].
!
@@ -1645,7 +1645,7 @@
This is invoked via the #earlyRestart change notification."
Lobby do:[:eachFileStream |
- eachFileStream reOpen
+ eachFileStream reOpen
].
!
@@ -1653,8 +1653,8 @@
"have to reopen files when returning from snapshot"
something == #earlyRestart ifTrue:[
- self reOpenFiles.
- self initDefaultEOLMode
+ self reOpenFiles.
+ self initDefaultEOLMode
]
"Created: 15.6.1996 / 15:19:59 / cg"
@@ -1692,8 +1692,8 @@
primitive code, or to wrap pipe-fds into externalStreams."
^ self new
- buffered:buffered;
- connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol.
+ buffered:buffered;
+ connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol.
"
the example below will probably fail (15 is a random FD):
@@ -1762,18 +1762,18 @@
'read ...'.
[
- 1 to:10 do:[:i |
- Transcript showCR:rs nextLine
- ].
- rs close.
+ 1 to:10 do:[:i |
+ Transcript showCR:rs nextLine
+ ].
+ rs close.
] forkAt:7.
'write ...'.
[
- 1 to:10 do:[:i |
- ws nextPutAll:'hello world '; nextPutAll:i printString; cr
- ].
- ws close.
+ 1 to:10 do:[:i |
+ ws nextPutAll:'hello world '; nextPutAll:i printString; cr
+ ].
+ ws close.
] fork.
"
@@ -1876,18 +1876,18 @@
|openStreams|
openStreams := OrderedCollection new.
- Lobby keysDo:[:eachStream|
- (eachStream isKindOf:self) ifTrue:[
- openStreams add:eachStream
- ]
- ].
+ Lobby keysDo:[:eachStream|
+ (eachStream isKindOf:self) ifTrue:[
+ openStreams add:eachStream
+ ]
+ ].
^ openStreams
"
- self openStreams
- Socket openStreams
- NonPositionableExternalStream openStreams
+ self openStreams
+ Socket openStreams
+ NonPositionableExternalStream openStreams
"
"Created: / 24-04-2018 / 09:23:33 / stefan"
@@ -1909,12 +1909,12 @@
DefaultCopyBufferSize notNil ifTrue:[^ DefaultCopyBufferSize].
OperatingSystem isMSDOSlike ifTrue:[
- OperatingSystem isWin7Like ifTrue:[
- ^ 64*1024
- ] ifFalse:[
- "/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ?
- ^ 1 * 1024.
- ].
+ OperatingSystem isWin7Like ifTrue:[
+ ^ 64*1024
+ ] ifFalse:[
+ "/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ?
+ ^ 1 * 1024.
+ ].
].
^ 32 * 1024.
!
@@ -1967,16 +1967,16 @@
Report it via an Exception"
anErrorSymbolOrNumber isInteger ifTrue:[
- StreamError
- raiseRequestWith:anErrorSymbolOrNumber
- errorString:(' - os error:' , (OperatingSystem errorTextForNumber:anErrorSymbolOrNumber))
+ StreamError
+ raiseRequestWith:anErrorSymbolOrNumber
+ errorString:(' - os error:' , (OperatingSystem errorTextForNumber:anErrorSymbolOrNumber))
].
(self respondsTo:anErrorSymbolOrNumber) ifTrue:[
- self perform:anErrorSymbolOrNumber
+ self perform:anErrorSymbolOrNumber
] ifFalse:[
- StreamError
- raiseRequestWith:anErrorSymbolOrNumber
- errorString:(' - ' , anErrorSymbolOrNumber printString)
+ StreamError
+ raiseRequestWith:anErrorSymbolOrNumber
+ errorString:(' - ' , anErrorSymbolOrNumber printString)
].
^ false
! !
@@ -2099,19 +2099,19 @@
|text|
binary ifTrue:[
- ^ self upToEnd.
+ ^ self upToEnd.
].
"/ text mode
text := StringCollection new.
[self atEnd] whileFalse:[
- |line|
-
- line := self nextLine.
- line isNil ifTrue:[
- ^ text
- ].
- text add:line
+ |line|
+
+ line := self nextLine.
+ line isNil ifTrue:[
+ ^ text
+ ].
+ text add:line
].
^ text
!
@@ -2121,12 +2121,12 @@
See also #contents, which returns the lines as stringCollection for textFiles."
binary ifTrue:[
- ^ [
- binary := false.
- self contentsOfEntireFile.
- ] ensure:[
- binary := true.
- ].
+ ^ [
+ binary := false.
+ self contentsOfEntireFile.
+ ] ensure:[
+ binary := true.
+ ].
].
^ self contentsOfEntireFile.
@@ -2149,7 +2149,7 @@
(such as upTo)"
binary ifTrue:[
- ^ ByteArray
+ ^ ByteArray
].
^ String
!
@@ -2157,13 +2157,13 @@
eolMode
"return how end-of-line (EOL) is to be marked.
Returns one one of:
- #crlf -> add a CR-NL, as in MSDOS
- #cr -> add a CR, as in VMS
- #nl -> add a NL, as in Unix
- #eot -> add an EOT (= 0x04, as used in some modems/protocols)
- #etx -> add an ETX (= 0x03, as used in some modems/protocols)
- #nl -> add a NL, as in Unix
- nil -> transparent
+ #crlf -> add a CR-NL, as in MSDOS
+ #cr -> add a CR, as in VMS
+ #nl -> add a NL, as in Unix
+ #eot -> add an EOT (= 0x04, as used in some modems/protocols)
+ #etx -> add an ETX (= 0x03, as used in some modems/protocols)
+ #nl -> add a NL, as in Unix
+ nil -> transparent
"
^ eolMode
@@ -2174,22 +2174,22 @@
eolMode:aSymbolOrNil
"specify how end-of-line (EOL) is to be marked.
The argument may be one of:
- #crlf -> add a CR-NL, as in MSDOS
- #cr -> add a CR, as in VMS
- #nl -> add a NL, as in Unix
- #eot -> add an EOT (= 0x04, as used in some modems/protocols)
- #etx -> add an ETX (= 0x03, as used in some modems/protocols)
- anyOther -> like #nl
+ #crlf -> add a CR-NL, as in MSDOS
+ #cr -> add a CR, as in VMS
+ #nl -> add a NL, as in Unix
+ #eot -> add an EOT (= 0x04, as used in some modems/protocols)
+ #etx -> add an ETX (= 0x03, as used in some modems/protocols)
+ anyOther -> like #nl
"
aSymbolOrNil == #crnl ifTrue:[
- eolMode := #crlf
+ eolMode := #crlf
] ifFalse:[
- aSymbolOrNil == #lf ifTrue:[
- eolMode := #nl
- ] ifFalse:[
- eolMode := aSymbolOrNil
- ]
+ aSymbolOrNil == #lf ifTrue:[
+ eolMode := #nl
+ ] ifFalse:[
+ eolMode := aSymbolOrNil
+ ]
].
"Modified (comment): / 06-12-2016 / 14:26:37 / cg"
@@ -2207,25 +2207,25 @@
fileClosed = false;
if (_handle != nil) {
- if ((__INST(handleType) == @symbol(fileHandle))
- || (__INST(handleType) == @symbol(socketHandle))) {
- RETURN (_handle);
- }
-
- if ((__INST(handleType) == nil)
- || (__INST(handleType) == @symbol(filePointer))
- || (__INST(handleType) == @symbol(socketFilePointer))
- || (__INST(handleType) == @symbol(pipeFilePointer))) {
- FILE *file = __FILEVal(_handle);
- if (file != NULL) {
- int fileNo = fileno(file);
-
- if (fileNo >= 0) {
- RETURN ( __MKINT(fileNo));
- }
- fileClosed = true;
- }
- }
+ if ((__INST(handleType) == @symbol(fileHandle))
+ || (__INST(handleType) == @symbol(socketHandle))) {
+ RETURN (_handle);
+ }
+
+ if ((__INST(handleType) == nil)
+ || (__INST(handleType) == @symbol(filePointer))
+ || (__INST(handleType) == @symbol(socketFilePointer))
+ || (__INST(handleType) == @symbol(pipeFilePointer))) {
+ FILE *file = __FILEVal(_handle);
+ if (file != NULL) {
+ int fileNo = fileno(file);
+
+ if (fileNo >= 0) {
+ RETURN ( __MKINT(fileNo));
+ }
+ fileClosed = true;
+ }
+ }
}
%}.
handle isNil ifTrue:[^ self errorNotOpen].
@@ -2259,29 +2259,29 @@
OBJ _handle = __INST(handle);
if (_handle != nil) {
- if ((__INST(handleType) == @symbol(fileHandle))
- || (__INST(handleType) == @symbol(socketHandle))) {
- RETURN (_handle);
- }
- if (__INST(handleType) == @symbol(pipeFilePointer)) {
- RETURN (__MKINT(fileno(__FILEVal(_handle))));
- }
- if ((__INST(handleType) == nil)
- || (__INST(handleType) == @symbol(filePointer))
- || (__INST(handleType) == @symbol(socketFilePointer))
- || (__INST(handleType) == @symbol(pipeFilePointer))) {
+ if ((__INST(handleType) == @symbol(fileHandle))
+ || (__INST(handleType) == @symbol(socketHandle))) {
+ RETURN (_handle);
+ }
+ if (__INST(handleType) == @symbol(pipeFilePointer)) {
+ RETURN (__MKINT(fileno(__FILEVal(_handle))));
+ }
+ if ((__INST(handleType) == nil)
+ || (__INST(handleType) == @symbol(filePointer))
+ || (__INST(handleType) == @symbol(socketFilePointer))
+ || (__INST(handleType) == @symbol(pipeFilePointer))) {
#ifdef __win32__
- RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileno(__FILEVal(_handle)))));
+ RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileno(__FILEVal(_handle)))));
#else
- FILE *file = __FILEVal(_handle);
- if (file != NULL) {
- int fileNo = fileno(file);
- if (fileNo >= 0) {
- RETURN (__MKINT(fileNo));
- }
- }
+ FILE *file = __FILEVal(_handle);
+ if (file != NULL) {
+ int fileNo = fileno(file);
+ if (fileNo >= 0) {
+ RETURN (__MKINT(fileNo));
+ }
+ }
#endif
- }
+ }
}
%}.
^ handle
@@ -2298,7 +2298,7 @@
- except passing it to a primitive, for example."
(handleType isNil or:[handleType == #filePointer]) ifTrue:[
- ^ handle
+ ^ handle
].
^ self error:'not a FILE*'
!
@@ -2355,9 +2355,9 @@
which offers another choice."
aBoolean ifTrue:[
- eolMode := #crlf
+ eolMode := #crlf
] ifFalse:[
- eolMode := #nl
+ eolMode := #nl
].
!
@@ -2383,10 +2383,10 @@
No error if the stream is not open."
self isOpen ifTrue:[
- self unregisterForFinalization.
- self isOpen ifTrue:[
- self closeFile.
- ].
+ self unregisterForFinalization.
+ self isOpen ifTrue:[
+ self closeFile.
+ ].
].
!
@@ -2410,7 +2410,7 @@
copy := super copy.
copy dupFd.
self isPositionable ifTrue:[
- copy position:position.
+ copy position:position.
].
copy registerForFinalization.
^ copy
@@ -2458,8 +2458,8 @@
"report an error, that the stream is already opened"
^ OpenError
- raiseRequestWith:self
- errorString:' - stream is already open'
+ raiseRequestWith:self
+ errorString:' - stream is already open'
"
self new errorAlreadyOpen
@@ -2474,9 +2474,9 @@
"report an error, that the stream is in binary mode"
^ InvalidModeError
- raiseRequestWith:self
- errorString:(self class name , ' is in binary mode')
- "/ in:thisContext sender
+ raiseRequestWith:self
+ errorString:(self class name , ' is in binary mode')
+ "/ in:thisContext sender
"Modified: / 8.5.1999 / 20:12:43 / cg"
!
@@ -2487,9 +2487,9 @@
"report an error, that the stream is not in binary mode"
^ InvalidModeError
- raiseRequestWith:self
- errorString:(self class name , ' is not in binary mode')
- "/ in:thisContext sender
+ raiseRequestWith:self
+ errorString:(self class name , ' is not in binary mode')
+ "/ in:thisContext sender
"Modified: / 8.5.1999 / 20:12:40 / cg"
!
@@ -2500,9 +2500,9 @@
"report an error, that the stream is not in buffered mode"
^ StreamError
- raiseRequestWith:self
- errorString:(self class name , ' is unbuffered - operation not allowed')
- "/ in:thisContext sender
+ raiseRequestWith:self
+ errorString:(self class name , ' is unbuffered - operation not allowed')
+ "/ in:thisContext sender
"Modified: / 8.5.1999 / 20:12:36 / cg"
!
@@ -2563,10 +2563,10 @@
"{ Pragma: +optSpace }"
^ StreamIOError newException
- errorCode:errorNumber;
- osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber);
- parameter:self;
- raiseRequest
+ errorCode:errorNumber;
+ osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber);
+ parameter:self;
+ raiseRequest
"Modified: / 8.5.1999 / 20:12:16 / cg"
!
@@ -2581,7 +2581,7 @@
"return a message string describing the last error"
(lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[
- ^ 'I/O error'
+ ^ 'I/O error'
].
^ OperatingSystem errorTextForNumber:lastErrorNumber
!
@@ -2610,17 +2610,17 @@
errorHolder := OperatingSystem errorHolderForNumber:errorNumber.
exClass := (errorHolder errorCategory == #nonexistentSignal)
- ifTrue:[ FileDoesNotExistException ]
- ifFalse:[ OpenError ].
+ ifTrue:[ FileDoesNotExistException ]
+ ifFalse:[ OpenError ].
^ exClass newException
- errorCode:errorNumber;
- osErrorHolder:errorHolder;
- "/ cg: initialized lazily - see OpenError>>#description
- "/ errorString:(' : ' , errorHolder errorString);
- parameter:self;
- raiseRequest
- "/ in:thisContext sender
+ errorCode:errorNumber;
+ osErrorHolder:errorHolder;
+ "/ cg: initialized lazily - see OpenError>>#description
+ "/ errorString:(' : ' , errorHolder errorString);
+ parameter:self;
+ raiseRequest
+ "/ in:thisContext sender
"Modified: / 09-09-2011 / 07:22:49 / cg"
!
@@ -2639,10 +2639,10 @@
"{ Pragma: +optSpace }"
^ ReadError newException
- errorCode:errorNumber;
- osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber);
- parameter:self;
- raiseRequest
+ errorCode:errorNumber;
+ osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber);
+ parameter:self;
+ raiseRequest
!
writeError
@@ -2659,10 +2659,10 @@
"{ Pragma: +optSpace }"
^ WriteError newException
- errorCode:errorNumber;
- osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber);
- parameter:self;
- raiseRequest
+ errorCode:errorNumber;
+ osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber);
+ parameter:self;
+ raiseRequest
! !
!ExternalStream methodsFor:'finalization'!
@@ -2682,9 +2682,9 @@
a cheaper copy is possible."
^ self class basicNew
- beExecutor;
- setAccessor:handleType to:handle;
- yourself.
+ beExecutor;
+ setAccessor:handleType to:handle;
+ yourself.
"Modified: / 23-04-2018 / 18:34:38 / stefan"
!
@@ -2703,7 +2703,7 @@
"keep myself in newSpace, so it will be finalized early"
Lobby size < MaxNonTenurableExecutors ifTrue:[
- ObjectMemory preventTenureOf:self.
+ ObjectMemory preventTenureOf:self.
].
Lobby register:self.
!
@@ -2757,133 +2757,129 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- && (__INST(binary) != true)
- ) {
- f = __FILEVal(fp);
- buffer[0] = '\0';
-
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f);
- }
-
- rslt = nextPtr = buffer;
- limit = buffer + sizeof(buffer) - 2;
-
- for (;;) {
- __READBYTE__(ret, f, nextPtr, _buffered, __INST(handleType));
- if (ret <= 0) {
- if (nextPtr == buffer)
- rslt = NULL;
- if (ret == 0) {
- __INST(hitEOF) = true;
- break;
- } else {
- error = __mkSmallInteger(__threadErrno);
- goto err;
- }
- }
-
- if (*nextPtr == '\n') {
- cutOff = 1;
- *nextPtr = '\0';
- break;
- }
- if (*nextPtr == '\r') {
- char peekChar;
-
- /*
- * peek ahead for a newLine ...
- */
- __READBYTE__(ret, f, &peekChar, _buffered, __INST(handleType));
- if (ret <= 0) {
- cutOff = 1;
- *nextPtr = '\0';
- if (ret == 0) {
- __INST(hitEOF) = true;
- break;
- }
- error = __mkSmallInteger(__threadErrno);
- goto err;
- }
-
- if (peekChar == '\n') {
- cutOff = 2;
- *nextPtr = '\0';
- break;
- }
-
- __UNGETC__(peekChar, f, _buffered);
-
- cutOff = 1;
- *nextPtr = '\0';
- break;
- }
-
- nextPtr++;
- if (nextPtr >= limit) {
- *nextPtr = '\0';
- lineTooLong = 1;
- // signalled below anyway; so no need to print on stderr
-#if 0
- if (@global(InfoPrinting) == true) {
- fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n");
- }
-#endif
- break;
- }
- }
-
- if (rslt != NULL) {
- len = nextPtr-buffer;
-
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + len + cutOff;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- /* remove any EOL character */
- if (len != 0) {
- if (buffer[len-1] == '\n') {
- buffer[--len] = '\0';
- }
- if ((len != 0) && (buffer[len-1] == '\r')) {
- buffer[--len] = '\0';
- }
- }
- line = __MKSTRING_L(buffer, len);
- if (! lineTooLong) {
- RETURN ( line );
- }
- }
- }
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ && (__INST(binary) != true)
+ ) {
+ f = __FILEVal(fp);
+ buffer[0] = '\0';
+
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f);
+ }
+
+ rslt = nextPtr = buffer;
+ limit = buffer + sizeof(buffer) - 2;
+
+ for (;;) {
+ __READBYTE__(ret, f, nextPtr, _buffered, __INST(handleType));
+ if (ret <= 0) {
+ if (nextPtr == buffer)
+ rslt = NULL;
+ if (ret == 0) {
+ __INST(hitEOF) = true;
+ break;
+ } else {
+ error = __mkSmallInteger(__threadErrno);
+ goto err;
+ }
+ }
+
+ if (*nextPtr == '\n') {
+ cutOff = 1;
+ *nextPtr = '\0';
+ break;
+ }
+ if (*nextPtr == '\r') {
+ char peekChar;
+
+ /*
+ * peek ahead for a newLine ...
+ */
+ __READBYTE__(ret, f, &peekChar, _buffered, __INST(handleType));
+ if (ret <= 0) {
+ cutOff = 1;
+ *nextPtr = '\0';
+ if (ret == 0) {
+ __INST(hitEOF) = true;
+ break;
+ }
+ error = __mkSmallInteger(__threadErrno);
+ goto err;
+ }
+
+ if (peekChar == '\n') {
+ cutOff = 2;
+ *nextPtr = '\0';
+ break;
+ }
+
+ __UNGETC__(peekChar, f, _buffered);
+
+ cutOff = 1;
+ *nextPtr = '\0';
+ break;
+ }
+
+ nextPtr++;
+ if (nextPtr >= limit) {
+ *nextPtr = '\0';
+ lineTooLong = 1;
+ break;
+ }
+ }
+
+ if (rslt != NULL) {
+ len = nextPtr-buffer;
+
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + len + cutOff;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ /* remove any EOL character */
+ if (len != 0) {
+ if (buffer[len-1] == '\n') {
+ buffer[--len] = '\0';
+ }
+ if ((len != 0) && (buffer[len-1] == '\r')) {
+ buffer[--len] = '\0';
+ }
+ }
+ line = __MKSTRING_L(buffer, len);
+ if (! lineTooLong) {
+ RETURN ( line );
+ }
+ }
+ }
}
err: ;
%}.
line notNil ifTrue:[
- "/ the line as read is longer than 32k characters (boy - what a line)
- "/ The exception could be handled by reading more and returning the
- "/ concatenation in your exception handler (the receiver and the partial
- "/ line are passed as parameter)
-
- LineTooLongErrorSignal isHandled ifTrue:[
- ^ LineTooLongErrorSignal
- raiseRequestWith:(Array with:self with:line)
- errorString:('line too long read error')
- ].
- 'ExternalStream [warning]: line truncated in nextLine' infoPrintCR.
- ^ line , self nextLine
+ "/ 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 , self nextLine
].
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].
@@ -2905,74 +2901,74 @@
|| (__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 );
- }
- }
- error = __mkSmallInteger(__threadErrno);
- }
+ {
+ __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 );
+ }
+ }
+ error = __mkSmallInteger(__threadErrno);
+ }
}
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self writeError:error.
- ^ self
+ lastErrorNumber := error.
+ self writeError:error.
+ ^ self
].
super nextPutLine:aString.
!
@@ -2987,14 +2983,14 @@
|line|
[aStream atEnd] whileFalse:[
- line := aStream nextLine.
- line isNil ifTrue:[
- ^ self.
- ].
- self nextPutLine:line.
- (aStringOrNil notNil and:[line startsWith:aStringOrNil]) ifTrue:[
- ^ self
- ]
+ line := aStream nextLine.
+ line isNil ifTrue:[
+ ^ self.
+ ].
+ self nextPutLine:line.
+ (aStringOrNil notNil and:[line startsWith:aStringOrNil]) ifTrue:[
+ ^ self
+ ]
].
!
@@ -3014,16 +3010,16 @@
firstPos := self position.
[self atEnd] whileFalse:[
- lastPos := self position.
- line := self nextLine.
- line isNil ifTrue:[
- self position:firstPos.
- ^ nil
- ].
- (line startsWith:aString) ifTrue:[
- self position:lastPos.
- ^ line
- ]
+ lastPos := self position.
+ line := self nextLine.
+ line isNil ifTrue:[
+ self position:firstPos.
+ ^ nil
+ ].
+ (line startsWith:aString) ifTrue:[
+ self position:lastPos.
+ ^ line
+ ]
].
self position:firstPos.
^ nil
@@ -3043,18 +3039,18 @@
startPos := self position.
[self atEnd] whileFalse:[
- linePos := self position.
- line := self nextLine.
- line notNil ifTrue:[
- index := 1.
- aCollectionOfStrings do:[:prefix |
- (line startsWith:prefix) ifTrue:[
- self position:linePos.
- ^ index
- ].
- index := index + 1
- ]
- ]
+ linePos := self position.
+ line := self nextLine.
+ line notNil ifTrue:[
+ index := 1.
+ aCollectionOfStrings do:[:prefix |
+ (line startsWith:prefix) ifTrue:[
+ self position:linePos.
+ ^ index
+ ].
+ index := index + 1
+ ]
+ ]
].
self position:startPos.
^ nil
@@ -3067,13 +3063,13 @@
the receiver will trigger an ioInterrupt.
If cleared (which is the default) no special notification is made.
Notice:
- not every OS supports this
- - check with OS>>supportsIOInterrupts before using"
+ not every OS supports this
+ - check with OS>>supportsIOInterrupts before using"
|fd|
OperatingSystem supportsIOInterrupts ifFalse:[
- ^ self errorUnsupportedOperation
+ ^ self errorUnsupportedOperation
].
fd := self fileDescriptor.
@@ -3081,7 +3077,7 @@
handle isNil ifTrue:[^ self errorNotOpen].
aBoolean ifTrue:[
- ^ OperatingSystem enableIOInterruptsOn:fd
+ ^ OperatingSystem enableIOInterruptsOn:fd
].
^ OperatingSystem disableIOInterruptsOn:fd
@@ -3177,55 +3173,55 @@
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) );
}
error = __mkSmallInteger(__threadErrno);
#endif
@@ -3233,8 +3229,8 @@
out:;
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- ^ self ioError:error.
+ lastErrorNumber := error.
+ ^ self ioError:error.
].
handle isNil ifTrue:[^ self errorNotOpen].
@@ -3268,39 +3264,39 @@
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);
}
#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);
@@ -3308,16 +3304,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
"
!
@@ -3337,39 +3333,39 @@
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);
}
#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);
@@ -3378,9 +3374,9 @@
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self ioError:error.
- ^ self.
+ lastErrorNumber := error.
+ self ioError:error.
+ ^ self.
].
handle isNil ifTrue:[^ self errorNotOpen].
@@ -3388,9 +3384,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
"
!
@@ -3423,33 +3419,33 @@
int sz;
if (fp == nil)
- goto out;
+ goto out;
if (__INST(handleType) == @symbol(socketHandle)) {
- // cg: termina attributes of a socket?
- error = @symbol(badHandleType);
- goto out;
- // fd = __FILEVal(fp);
+ // cg: termina attributes of a socket?
+ 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;
}
__BEGIN_INTERRUPTABLE__
do {
- __threadErrno = 0;
- _ret = tcgetattr(fd, &t);
+ __threadErrno = 0;
+ _ret = tcgetattr(fd, &t);
} while (_ret < 0 && __threadErrno == EINTR);
__END_INTERRUPTABLE__
if (_ret < 0) {
- error = __mkSmallInteger(__threadErrno);
+ error = __mkSmallInteger(__threadErrno);
}
ignbrk = t.c_iflag & IGNBRK ? true : false;
brkint = t.c_iflag & BRKINT ? true : false;
@@ -3485,18 +3481,18 @@
sz = t.c_cflag & CSIZE;
switch (sz) {
- case CS5:
- csize = @symbol(cs5);
- break;
- case CS6:
- csize = @symbol(cs6);
- break;
- case CS7:
- csize = @symbol(cs7);
- break;
- case CS8:
- csize = @symbol(cs8);
- break;
+ case CS5:
+ csize = @symbol(cs5);
+ break;
+ case CS6:
+ csize = @symbol(cs6);
+ break;
+ case CS7:
+ csize = @symbol(cs7);
+ break;
+ case CS8:
+ csize = @symbol(cs8);
+ break;
}
cstopb = t.c_cflag & CSTOPB ? true : false;
cread = t.c_cflag & CREAD ? true : false;
@@ -3532,12 +3528,12 @@
out:;
%}.
error notNil ifTrue:[
- error == #unsupportedOperation ifTrue:[
- "/ the system does not support tcgetattr
- ^ self errorUnsupportedOperation
- ].
- lastErrorNumber := error.
- ^ self ioError:error.
+ error == #unsupportedOperation ifTrue:[
+ "/ the system does not support tcgetattr
+ ^ self errorUnsupportedOperation
+ ].
+ lastErrorNumber := error.
+ ^ self ioError:error.
].
handle isNil ifTrue:[^ self errorNotOpen].
@@ -3601,7 +3597,7 @@
readCount := self nextBytes:count into:aCollection startingAt:start.
readCount = count ifTrue:[
- ^ aCollection.
+ ^ aCollection.
].
^ aCollection copyFrom:1 to:start+readCount-1.
!
@@ -3617,14 +3613,14 @@
buffer := self contentsSpecies uninitializedNew:count.
n := self nextAvailableBytes:count into:buffer startingAt:1.
n == 0 ifTrue:[
- binary ifTrue:[
- ^ #[]
- ].
- ^ ''
+ binary ifTrue:[
+ ^ #[]
+ ].
+ ^ ''
].
n ~~ count ifTrue:[
- ^ buffer copyTo:n
+ ^ buffer copyTo:n
].
^ buffer.
@@ -3682,99 +3678,99 @@
|| (__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;
- error = __mkSmallInteger(__threadErrno);
- }
- }
+ 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;
+ 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].
@@ -3795,14 +3791,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;
@@ -3816,41 +3812,41 @@
|| (__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;
- error = __mkSmallInteger(__threadErrno);
- }
- }
+ 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;
+ 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
@@ -3895,98 +3891,98 @@
|| (__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;
- error = __mkSmallInteger(__threadErrno);
- }
- }
- }
+ 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;
+ 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].
@@ -4013,56 +4009,56 @@
|| (__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 */
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ }
+ RETURN (__mkSmallInteger(value));
+ }
+
+ if (ret < 0) {
+ __INST(position) = nil; /* i.e. do not know */
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF ifTrue:[^ self pastEndRead].
@@ -4090,66 +4086,66 @@
|| (__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;
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ }
+
+ if (ret < 0) {
+ __INST(position) = nil;
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF ifTrue:[^ self pastEndRead].
@@ -4176,56 +4172,56 @@
|| (__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 */
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ }
+ RETURN (__mkSmallInteger(value));
+ }
+
+ if (ret < 0) {
+ __INST(position) = nil; /* i.e. do not know */
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF ifTrue:[^ self pastEndRead].
@@ -4253,70 +4249,70 @@
|| (__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 */
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ }
+
+ if (ret < 0) {
+ __INST(position) = nil; /* i.e. do not know */
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF ifTrue:[^ self pastEndRead].
@@ -4329,15 +4325,15 @@
nextWord
<resource: #obsolete>
"in text-mode:
- read the alphaNumeric next word (i.e. up to non letter-or-digit).
- return a string containing those characters.
+ read the alphaNumeric next word (i.e. up to non letter-or-digit).
+ return a string containing those characters.
in binary-mode:
- read two bytes (msb-first) and return the value as a 16-bit
- unsigned Integer (for compatibility with other smalltalks)"
+ read two bytes (msb-first) and return the value as a 16-bit
+ unsigned Integer (for compatibility with other smalltalks)"
binary ifTrue:[
- self obsoleteMethodWarning:'use #nextUnsignedInt16MSB:true'.
- ^ self nextUnsignedInt16MSB:true
+ self obsoleteMethodWarning:'use #nextUnsignedInt16MSB:true'.
+ ^ self nextUnsignedInt16MSB:true
].
self obsoleteMethodWarning:'use #nextAlphaNumericWord'.
^ self nextAlphaNumericWord
@@ -4360,43 +4356,43 @@
|| (__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 */
- }
- error = __mkSmallInteger(__threadErrno);
- }
+ {
+ __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 */
+ }
+ error = __mkSmallInteger(__threadErrno);
+ }
}
%}.
handle isNil ifTrue:[self errorNotOpen. ^ self].
@@ -4417,8 +4413,8 @@
%{
int num;
union {
- char bytes[2];
- short shortVal;
+ char bytes[2];
+ short shortVal;
} u;
OBJ fp;
@@ -4428,62 +4424,62 @@
|| (__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 */
- error = __mkSmallInteger(__threadErrno);
- }
+ }
+
+ 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 */
+ 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].
@@ -4517,8 +4513,8 @@
%{
int num;
union {
- char bytes[2];
- short shortVal;
+ char bytes[2];
+ short shortVal;
} u;
OBJ fp;
@@ -4528,41 +4524,41 @@
|| (__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 */
- error = __mkSmallInteger(__threadErrno);
- }
+ 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 */
+ error = __mkSmallInteger(__threadErrno);
+ }
}
out:;
%}.
@@ -4584,29 +4580,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
}
@@ -4615,65 +4611,65 @@
|| (__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 */
- error = __mkSmallInteger(__threadErrno);
- }
+ }
+
+ 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 */
+ 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
@@ -4701,37 +4697,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
}
@@ -4740,33 +4736,33 @@
|| (__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 */
- error = __mkSmallInteger(__threadErrno);
- }
+ 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 */
+ error = __mkSmallInteger(__threadErrno);
+ }
}
badArg: ;
%}.
@@ -4782,13 +4778,13 @@
self nextPutUtf16Bytes:aCharacter MSB:true
"
- (FileStream newTemporary
- nextPutUtf16:$B;
- nextPutUtf16:$Ă„;
- nextPutUtf16:(Character codePoint:16r10CCCC);
- reset;
- binary;
- contents)
+ (FileStream newTemporary
+ nextPutUtf16:$B;
+ nextPutUtf16:$Ă„;
+ nextPutUtf16:(Character codePoint:16r10CCCC);
+ reset;
+ binary;
+ contents)
"
!
@@ -4813,8 +4809,8 @@
printOn:aStream
aStream
- nextPutAll:self className;
- nextPut:$(.
+ nextPutAll:self className;
+ nextPut:$(.
handleType printOn:aStream.
aStream nextPutAll:':('.
handle printOn:aStream.
@@ -4834,7 +4830,7 @@
|fp error|
handle isNil ifTrue:[
- ^ self.
+ ^ self.
].
fp := handle.
"/ (didWrite==true and:[binary ~~ true and:[eolMode = #crlf]]) ifTrue: [ self breakPoint:#sr ].
@@ -4843,76 +4839,76 @@
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
- rslt = close(sock);
+ rslt = close(sock);
#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);
- }
- // whether the close() will be successful or not - the handle is invalid now!
- __INST(handle) = nil;
+ FILEPOINTER f = __FILEVal(fp);
+
+ if (@global(FileOpenTrace) == true) {
+ fprintf(stderr, "fclose [ExternalStream] %"_lx_"\n", (INT)f);
+ }
+ // whether the close() will be successful or not - the handle is invalid now!
+ __INST(handle) = nil;
#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));
- }
- 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));
+ }
+ 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));
- }
- do {
- __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));
+ }
+ do {
+ __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) {
- error = __mkSmallInteger(__threadErrno);
- goto out;
+ error = __mkSmallInteger(__threadErrno);
+ goto out;
}
RETURN (self);
@@ -4920,25 +4916,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"
@@ -4971,54 +4967,54 @@
if (__isStringLike(openmode)) {
#ifdef __win32__
- __stxWrapApiEnterCritical();
+ __stxWrapApiEnterCritical();
#endif
- if (__isSmallInteger(aFileDescriptor)) {
- fd = __intVal(aFileDescriptor);
- }
+ if (__isSmallInteger(aFileDescriptor)) {
+ fd = __intVal(aFileDescriptor);
+ }
#ifdef __win32__
- else if (__isExternalAddressLike(aFileDescriptor)) {
- fd = _open_osfhandle((long)__externalAddressVal(aFileDescriptor), O_BINARY);
- if (fd < 0) {
- if (__threadErrno == 0) {
- // no more file descriptors
- __threadErrno = EMFILE;
- }
- error = __mkSmallInteger(__threadErrno);
- __stxWrapApiLeaveCritical();
- goto out;
- }
- }
+ else if (__isExternalAddressLike(aFileDescriptor)) {
+ fd = _open_osfhandle((long)__externalAddressVal(aFileDescriptor), O_BINARY);
+ if (fd < 0) {
+ if (__threadErrno == 0) {
+ // no more file descriptors
+ __threadErrno = EMFILE;
+ }
+ error = __mkSmallInteger(__threadErrno);
+ __stxWrapApiLeaveCritical();
+ goto out;
+ }
+ }
#endif
- f = (FILEPOINTER) fdopen(fd, (char *)__stringVal(openmode));
+ f = (FILEPOINTER) fdopen(fd, (char *)__stringVal(openmode));
#ifdef __win32__
- __stxWrapApiLeaveCritical();
+ __stxWrapApiLeaveCritical();
#endif
- if (f == NULL) {
- error =__mkSmallInteger(__threadErrno);
- } else {
- if (@global(FileOpenTrace) == true) {
- fprintf(stderr, "fdopen [ExternalStream] %"_ld_" (%"_lx_") -> %"_lx_"\n", (INT)fd, (INT)fd, (INT)f);
- }
-
- fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
- }
+ if (f == NULL) {
+ 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.
@@ -5031,7 +5027,7 @@
fd := self fileHandle.
fd isNil ifTrue:[
- ^ self errorNotOpen.
+ ^ self errorNotOpen.
].
dupFd := OperatingSystem dup:fd.
self setFileHandle:dupFd mode:self fopenMode.
@@ -5042,16 +5038,16 @@
Only used internally"
mode == #readonly ifTrue:[
- ^ ReadMode
+ ^ ReadMode
].
mode == #writeonly ifTrue:[
- ^ WriteMode
+ ^ WriteMode
].
mode == #readWrite ifTrue:[
- ^ ReadWriteMode
+ ^ ReadWriteMode
].
mode == #append ifTrue:[
- ^ AppendMode
+ ^ AppendMode
].
^ ReadWriteMode
!
@@ -5072,42 +5068,42 @@
# 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) {
- 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;
- }
+ if (f == NULL) {
+ 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.
!
@@ -5154,39 +5150,39 @@
int fd;
if (!__isStringLike(openMode))
- goto err;
+ goto err;
#ifdef __win32__
__stxWrapApiEnterCritical();
if (__isExternalAddressLike(anIntegerOrExternalAddress) ) {
- HANDLE __fileHandle = (HANDLE)__externalAddressVal(anIntegerOrExternalAddress);
- fd = _open_osfhandle((long)__fileHandle, O_BINARY); /* should we handle readonly, append or text mode? */
- if (fd < 0) {
- __stxWrapApiLeaveCritical();
- CloseHandle(__fileHandle);
- goto err;
- }
+ HANDLE __fileHandle = (HANDLE)__externalAddressVal(anIntegerOrExternalAddress);
+ fd = _open_osfhandle((long)__fileHandle, O_BINARY); /* should we handle readonly, append or text mode? */
+ if (fd < 0) {
+ __stxWrapApiLeaveCritical();
+ CloseHandle(__fileHandle);
+ goto err;
+ }
} else
#endif
if (__isSmallInteger(anIntegerOrExternalAddress)) {
- fd = __smallIntegerVal(anIntegerOrExternalAddress);
+ fd = __smallIntegerVal(anIntegerOrExternalAddress);
} else {
#ifdef __win32__
- __stxWrapApiLeaveCritical();
+ __stxWrapApiLeaveCritical();
#endif
- goto err;
+ goto err;
}
f = fdopen(fd, __stringVal(openMode));
#ifdef __win32__
__stxWrapApiLeaveCritical();
#endif
if (f != NULL) {
- if (@global(FileOpenTrace) == true) {
- fprintf(stderr, "fdopen [ExternalStream] %d -> %"_lx_"\n", fd, (INT)f);
- }
- fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
- __INST(handleType) = @symbol(filePointer);
- RETURN (self);
+ if (@global(FileOpenTrace) == true) {
+ fprintf(stderr, "fdopen [ExternalStream] %d -> %"_lx_"\n", fd, (INT)f);
+ }
+ fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp);
+ __INST(handleType) = @symbol(filePointer);
+ RETURN (self);
}
err:;
%}.
@@ -5232,26 +5228,26 @@
|| (__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) {
- RETURN(__mkSmallInteger(__threadErrno));
- } else /* ret == 0 */ {
- RETURN(__mkSmallInteger(0)); /* EOF */
- }
- }
+ 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) {
+ RETURN(__mkSmallInteger(__threadErrno));
+ } else /* ret == 0 */ {
+ RETURN(__mkSmallInteger(0)); /* EOF */
+ }
+ }
}
%}.
!
@@ -5275,18 +5271,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;
@@ -5300,63 +5296,63 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
-
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
-
- if (ret > 0) {
- pos = __INST(position);
- if (__isSmallInteger(pos)) {
- OBJ t;
-
- t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- if (__INST(binary) == true) {
- RETURN ( __mkSmallInteger(ch) );
- }
- RETURN ( __MKCHARACTER(ch) );
- }
-
- __INST(position) = nil;
- if (ret < 0) {
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ pos = __INST(position);
+ if (__isSmallInteger(pos)) {
+ OBJ t;
+
+ t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ if (__INST(binary) == true) {
+ RETURN ( __mkSmallInteger(ch) );
+ }
+ RETURN ( __MKCHARACTER(ch) );
+ }
+
+ __INST(position) = nil;
+ if (ret < 0) {
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
#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
!
@@ -5371,9 +5367,9 @@
nRead := self nextBytes:count into:coll startingAt:1.
nRead ~~ count ifTrue:[
- "/ for readStream protocol compatibility,
- "/ we must raise an exception here.
- ^ self pastEndRead
+ "/ for readStream protocol compatibility,
+ "/ we must raise an exception here.
+ ^ self pastEndRead
].
^ coll
@@ -5399,62 +5395,62 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
-
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
-
- if (ret > 0) {
- pos = __INST(position);
- if (__isSmallInteger(pos)) {
- OBJ t;
-
- t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- if (__INST(binary) == true) {
- RETURN ( __mkSmallInteger(ch) );
- }
- RETURN ( __MKCHARACTER(ch) );
- }
-
- __INST(position) = nil;
- if (ret < 0) {
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ pos = __INST(position);
+ if (__isSmallInteger(pos)) {
+ OBJ t;
+
+ t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ if (__INST(binary) == true) {
+ RETURN ( __mkSmallInteger(ch) );
+ }
+ RETURN ( __MKCHARACTER(ch) );
+ }
+
+ __INST(position) = nil;
+ if (ret < 0) {
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF 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
!
@@ -5474,11 +5470,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;
@@ -5488,45 +5484,45 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
-
- if (ret > 0) {
- __UNGETC__(c, f, _buffered);
-
- if (__INST(binary) == true) {
- RETURN ( __mkSmallInteger(c) );
- }
- RETURN ( __MKCHARACTER(c) );
- }
- if (ret < 0) {
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ __UNGETC__(c, f, _buffered);
+
+ if (__INST(binary) == true) {
+ RETURN ( __mkSmallInteger(c) );
+ }
+ RETURN ( __MKCHARACTER(c) );
+ }
+ if (ret < 0) {
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF 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
!
@@ -5546,11 +5542,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;
@@ -5560,42 +5556,42 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
-
- if (ret > 0) {
- __UNGETC__(c, f, _buffered);
-
- if (__INST(binary) == true) {
- RETURN ( __mkSmallInteger(c) );
- }
- RETURN ( __MKCHARACTER(c) );
- }
- if (ret < 0) {
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ __UNGETC__(c, f, _buffered);
+
+ if (__INST(binary) == true) {
+ RETURN ( __mkSmallInteger(c) );
+ }
+ RETURN ( __MKCHARACTER(c) );
+ }
+ if (ret < 0) {
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF 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
!
@@ -5615,33 +5611,33 @@
contentsSpecies := self contentsSpecies.
[self atEnd] whileFalse:[
- |chunk cnt|
-
- chunk := contentsSpecies uninitializedNew:chunkSize.
- cnt := self nextBytes:chunkSize into:chunk startingAt:1.
- cnt ~~ 0 ifTrue:[
- chunksAndCounts isNil ifTrue:[
- (cnt < chunkSize and:[self atEnd]) ifTrue:[
- "all data is in a single chunk, so we are done"
- ^ chunk copyFrom:1 to:cnt.
- ].
- chunksAndCounts := OrderedCollection new.
- ].
- chunksAndCounts add:chunk; add:cnt.
- byteCount := byteCount + cnt.
- ]
+ |chunk cnt|
+
+ chunk := contentsSpecies uninitializedNew:chunkSize.
+ cnt := self nextBytes:chunkSize into:chunk startingAt:1.
+ cnt ~~ 0 ifTrue:[
+ chunksAndCounts isNil ifTrue:[
+ (cnt < chunkSize and:[self atEnd]) ifTrue:[
+ "all data is in a single chunk, so we are done"
+ ^ chunk copyFrom:1 to:cnt.
+ ].
+ chunksAndCounts := OrderedCollection new.
+ ].
+ chunksAndCounts add:chunk; add:cnt.
+ byteCount := byteCount + cnt.
+ ]
].
"now, create one big array"
data := contentsSpecies uninitializedNew:byteCount.
offset := 1.
1 to:chunksAndCounts size by:2 do:[:index |
- |chunk cnt|
-
- chunk := chunksAndCounts at:index.
- cnt := chunksAndCounts at:index+1.
- data replaceFrom:offset to:(offset + cnt - 1) with:chunk startingAt:1.
- offset := offset + cnt
+ |chunk cnt|
+
+ chunk := chunksAndCounts at:index.
+ cnt := chunksAndCounts at:index+1.
+ data replaceFrom:offset to:(offset + cnt - 1) with:chunk startingAt:1.
+ offset := offset + cnt
].
^ data
@@ -5652,7 +5648,7 @@
'librun.so' asFilename readStream binary upToEnd
self assert:('smalltalk.rc' asFilename readStream upToEnd size)
- = ('smalltalk.rc' asFilename readStream size)
+ = ('smalltalk.rc' asFilename readStream size)
"
"Modified (format): / 09-05-2018 / 20:09:31 / stefan"
@@ -5692,11 +5688,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;
@@ -5706,42 +5702,42 @@
|| (__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 */
- __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
- }
- // we do not raise an error here - the next read operation will raise the error.
- RETURN(false);
+ } 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 */
+ __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
+ }
+ // we do not raise an error here - the next read operation will raise the error.
+ RETURN(false);
}
%}.
@@ -5839,19 +5835,19 @@
|available|
handle isNil ifTrue:[
- ^ self errorNotOpen
+ ^ self errorNotOpen
].
mode == #writeonly ifTrue:[
- ^ self errorWriteOnly
+ ^ self errorWriteOnly
].
available := OperatingSystem numAvailableForReadOn:self fileHandle.
readAhead notNil ifTrue:[
- available := available + 1
+ available := available + 1
].
^ available.
"
- '/etc/hosts' asFilename readStream numAvailableForRead
+ '/etc/hosts' asFilename readStream numAvailableForRead
"
!
@@ -5884,14 +5880,14 @@
wasBlocked := OperatingSystem blockInterrupts.
inputSema := Semaphore name:'readWait'.
[
- Processor signal:inputSema onInput:fd.
- hasTimedout := (inputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
+ Processor signal:inputSema onInput:fd.
+ hasTimedout := (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
@@ -5910,7 +5906,7 @@
readAhead notNil ifTrue:[^ false].
handle isNil ifTrue:[
- ^ self errorNotOpen
+ ^ self errorNotOpen
].
fd := self fileHandle.
@@ -5919,16 +5915,16 @@
wasBlocked := OperatingSystem blockInterrupts.
sema := Semaphore name:'readWriteWait'.
[
- Processor
- signal:sema onOutput:fd;
- signal:sema onInput:fd.
- hasTimedout := (sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
+ Processor
+ signal:sema onOutput:fd;
+ signal:sema onInput:fd.
+ hasTimedout := (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
@@ -5946,7 +5942,7 @@
|fd sema hasTimedout wasBlocked|
handle isNil ifTrue:[
- ^ self errorNotOpen
+ ^ self errorNotOpen
].
fd := self fileHandle.
@@ -5955,16 +5951,16 @@
wasBlocked := OperatingSystem blockInterrupts.
sema := Semaphore name:'writeExceptionWait'.
[
- Processor
- signal:sema onOutput:fd;
- signal:sema onException:fd.
- hasTimedout := (sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
+ Processor
+ signal:sema onOutput:fd;
+ signal:sema onException:fd.
+ hasTimedout := (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
@@ -5982,10 +5978,10 @@
|fd outputSema hasTimedout wasBlocked|
handle isNil ifTrue:[
- ^ self errorNotOpen
+ ^ self errorNotOpen
].
mode == #readonly ifTrue:[
- ^ self errorReadOnly
+ ^ self errorReadOnly
].
fd := self fileHandle.
@@ -5994,14 +5990,14 @@
wasBlocked := OperatingSystem blockInterrupts.
outputSema := Semaphore name:'writeWait'.
[
- Processor signal:outputSema onOutput:fd.
- hasTimedout := (outputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
+ Processor signal:outputSema onOutput:fd.
+ hasTimedout := (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
@@ -6021,57 +6017,57 @@
|| (__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 );
- }
- __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
- }
+ {
+ __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 );
+ }
+ __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
+ }
}
%}.
lastErrorNumber notNil ifTrue:[self writeError. ^ self].
@@ -6080,11 +6076,11 @@
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
@@ -6099,32 +6095,32 @@
|| (__INST(handleType) == @symbol(filePointer))
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- OBJ fp;
- int _buffered = (__INST(buffered) == true);
-
- if ((fp = __INST(handle)) != nil) {
- if (__INST(mode) != @symbol(readonly)) {
- if (_buffered) {
- FILEPOINTER f = __FILEVal(fp);
+ OBJ fp;
+ int _buffered = (__INST(buffered) == true);
+
+ if ((fp = __INST(handle)) != nil) {
+ if (__INST(mode) != @symbol(readonly)) {
+ if (_buffered) {
+ FILEPOINTER f = __FILEVal(fp);
#ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- __win32_fflush(f);
- } else {
- int rslt;
-
- do {
- __threadErrno = 0;
- rslt = __STX_C_CALL1("fflush", fflush, f);
- } while((rslt < 0) && (__threadErrno == EINTR));
- }
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ __win32_fflush(f);
+ } else {
+ int rslt;
+
+ do {
+ __threadErrno = 0;
+ rslt = __STX_C_CALL1("fflush", fflush, f);
+ } while((rslt < 0) && (__threadErrno == EINTR));
+ }
#else /* ! __win32__ */
- __BEGIN_INTERRUPTABLE__
- FFLUSH(f);
- __END_INTERRUPTABLE__
+ __BEGIN_INTERRUPTABLE__
+ FFLUSH(f);
+ __END_INTERRUPTABLE__
#endif /* ! __win32__ */
- }
- }
- }
+ }
+ }
+ }
}
%}
!
@@ -6140,9 +6136,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;
@@ -6151,109 +6147,109 @@
|| (__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 );
- }
- error = __mkSmallInteger(__threadErrno);
- }
- }
- } else {
- if (__isSmallInteger(aCharacter)) {
- unsigned char c = __intVal(aCharacter);
- buff[0] = c; nBytes = 1;
- goto doWrite;
- }
- }
- }
+ {
+ __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 );
+ }
+ 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
!
nextPutAll:aCollection
@@ -6268,9 +6264,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
@@ -6281,164 +6277,164 @@
|| (__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);
- }
- fprintf(stderr, "cnt=%"_ld_" len=%"_ld_"\n", (INT)cnt, (INT)len);
- error = __mkSmallInteger(__threadErrno);
- }
+ {
+ 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);
+ }
+ fprintf(stderr, "cnt=%"_ld_" len=%"_ld_"\n", (INT)cnt, (INT)len);
+ error = __mkSmallInteger(__threadErrno);
+ }
}
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].
@@ -6455,7 +6451,7 @@
I don't know how to write non-bytes to an external stream, but let superclass handle this."
buffer isSingleByteCollection ifTrue:[
- ^ self nextPutBytes:initialWriteCount from:buffer startingAt:initialOffset.
+ ^ self nextPutBytes:initialWriteCount from:buffer startingAt:initialOffset.
].
^ super nextPutAll:initialWriteCount from:buffer startingAt:initialOffset
@@ -6475,176 +6471,176 @@
|| (__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);
- }
- error = __mkSmallInteger(__threadErrno);
- }
+ {
+ 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);
+ }
+ 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
!
@@ -6654,11 +6650,11 @@
This is needed, so that you can do ('something' asUnicode16String errorPrintCR)"
aString do:[:eachCharacter|
- self nextPutUtf8:eachCharacter.
+ self nextPutUtf8:eachCharacter.
].
"
- 'Bönnigheim' asUnicode16String errorPrintCR
+ 'Bönnigheim' asUnicode16String errorPrintCR
"
!
@@ -6671,9 +6667,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|
@@ -6683,16 +6679,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;
@@ -6706,121 +6702,121 @@
|| (__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 */
- error = __mkSmallInteger(__threadErrno);
- }
- }
- }
+ (__threadErrno == EAGAIN)
+ ) {
+ RETURN ( __mkSmallInteger(0) );
+ }
+ __INST(position) = nil; /* i.e. do not know */
+ 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].