--- a/ExternalStream.st Thu Oct 01 06:52:24 2015 +0200
+++ b/ExternalStream.st Fri Oct 02 06:42:49 2015 +0100
@@ -1,6 +1,8 @@
+"{ Encoding: utf8 }"
+
"
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
@@ -14,15 +16,15 @@
"{ NameSpace: Smalltalk }"
ReadWriteStream subclass:#ExternalStream
- instanceVariableNames:'handleType handle mode buffered binary eolMode hitEOF didWrite
- lastErrorNumber readAhead'
- classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal
- InvalidModeSignal OpenErrorSignal StreamNotOpenSignal
- InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode
- WriteMode AppendMode CreateReadWriteMode StreamIOErrorSignal
- FileOpenTrace'
- poolDictionaries:''
- category:'Streams-External'
+ instanceVariableNames:'handleType handle mode buffered binary eolMode hitEOF didWrite
+ lastErrorNumber readAhead'
+ classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal
+ InvalidModeSignal OpenErrorSignal StreamNotOpenSignal
+ InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode
+ WriteMode AppendMode CreateReadWriteMode StreamIOErrorSignal
+ FileOpenTrace MaxNonTenurableExecutors'
+ poolDictionaries:''
+ category:'Streams-External'
!
!ExternalStream primitiveDefinitions!
@@ -204,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 +229,33 @@
// Win returns from ReadFile() with false and _threadErrno == 0 on end of pipe.
// We don't know why
# define READ(ret, f, cp, n, handleType) { \
- if (handleType == @symbol(socketHandle)) { \
- (ret) = __STX_WSA_NOINT_CALL4("recv", recv, (f), (cp), (n), 0); \
- } else { \
- HANDLE h = _get_osfhandle(fileno(f)); \
- if (handleType == @symbol(socketFilePointer)) { \
- (ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\
- } else { \
- int __res; \
- (ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\
- (ret) = (ret) ? __res : ((__threadErrno == EPIPE || __threadErrno == 0) ? 0 : -1); \
- } \
- } \
+ if (handleType == @symbol(socketHandle)) { \
+ (ret) = __STX_WSA_NOINT_CALL4("recv", recv, (f), (cp), (n), 0); \
+ } else { \
+ HANDLE h = _get_osfhandle(fileno(f)); \
+ if (handleType == @symbol(socketFilePointer)) { \
+ (ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\
+ } else { \
+ int __res; \
+ (ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\
+ (ret) = (ret) ? __res : ((__threadErrno == EPIPE || __threadErrno == 0) ? 0 : -1); \
+ } \
+ } \
}
# define WRITE(ret, f, cp, n, handleType) { \
- if (handleType == @symbol(socketHandle)) { \
- (ret) = __STX_WSA_NOINT_CALL4("send", send, (f), (cp), (n), 0); \
- } else {\
- HANDLE h = _get_osfhandle(fileno(f)); \
- if (handleType == @symbol(socketFilePointer)) { \
- (ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\
- } else {\
- int __res; \
- (ret) = __STX_API_NOINT_CALL5("WriteFile", WriteFile, h, (cp), (n), &__res, 0);\
- (ret) = (ret) ? __res : -1; \
- } \
- } \
+ if (handleType == @symbol(socketHandle)) { \
+ (ret) = __STX_WSA_NOINT_CALL4("send", send, (f), (cp), (n), 0); \
+ } else {\
+ HANDLE h = _get_osfhandle(fileno(f)); \
+ if (handleType == @symbol(socketFilePointer)) { \
+ (ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\
+ } else {\
+ int __res; \
+ (ret) = __STX_API_NOINT_CALL5("WriteFile", WriteFile, h, (cp), (n), &__res, 0);\
+ (ret) = (ret) ? __res : -1; \
+ } \
+ } \
}
# define FFLUSH(fp) fflush(fp)
@@ -264,56 +266,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,110 +325,110 @@
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \
(ret) = 0; \
if (isBuffered) { \
- int __offs = 0; \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = getc(f); \
- if ((ret) < 0) { \
- if (ferror(f)) { \
- if (__threadErrno == EINTR) { \
- clearerr(f); \
- continue; \
- } \
- } else { \
- (ret) = 0; \
- } \
- break; \
- } \
- (buf)[__offs++] = (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = getc(f); \
+ if ((ret) < 0) { \
+ if (ferror(f)) { \
+ if (__threadErrno == EINTR) { \
+ clearerr(f); \
+ continue; \
+ } \
+ } else { \
+ (ret) = 0; \
+ } \
+ break; \
+ } \
+ (buf)[__offs++] = (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} else { \
- int __offs = 0; \
- \
- while (__offs < (cnt)) { \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- (buf)[__offs] = __intVal(rA); \
- __INST(readAhead) = nil; \
- (ret) = 1; \
- } else { \
- CLEAR_ERRNO; \
- READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \
- if ((ret) <= 0) { \
- if ((ret) < 0 && __threadErrno == EINTR) { \
- continue; \
- } \
- break; \
- } \
- } \
- __offs += (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0; \
+ \
+ while (__offs < (cnt)) { \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ (buf)[__offs] = __intVal(rA); \
+ __INST(readAhead) = nil; \
+ (ret) = 1; \
+ } else { \
+ CLEAR_ERRNO; \
+ READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \
+ if ((ret) <= 0) { \
+ if ((ret) < 0 && __threadErrno == EINTR) { \
+ continue; \
+ } \
+ break; \
+ } \
+ } \
+ __offs += (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
}
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \
{ \
int __offs = 0; \
int oldFlags; \
- \
+ \
(ret) = 0; \
if (isBuffered) { \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = getc(f); \
- if ((ret) < 0) { \
- if (ferror(f)) { \
- if (__threadErrno == EINTR) { \
- clearerr(f); \
- continue; \
- } \
- } else { \
- (ret) = 0; \
- } \
- break; \
- } \
- (buf)[__offs++] = (ret); \
- } \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = getc(f); \
+ if ((ret) < 0) { \
+ if (ferror(f)) { \
+ if (__threadErrno == EINTR) { \
+ clearerr(f); \
+ continue; \
+ } \
+ } else { \
+ (ret) = 0; \
+ } \
+ break; \
+ } \
+ (buf)[__offs++] = (ret); \
+ } \
+ (ret) = __offs; \
} else { \
- while (__offs < (cnt)) { \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- (buf)[__offs] = __intVal(rA); \
- __INST(readAhead) = nil; \
- (ret) = 1; \
- __offs ++; \
- continue; \
- } \
- CLEAR_ERRNO; \
- { \
- int res = 0; \
- if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res), 1)) \
- || (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \
- || (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0), 1))) { \
- if (res > 0) { \
- if (res > ((cnt)-__offs)) \
- res = (cnt)-__offs; \
- READ((ret), f, (buf)+__offs, res, handleType); \
- } else { \
- (ret) = 0; \
- break; \
- } \
- } else { \
- READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \
- } \
- } \
- if ((ret) <= 0) { \
- if (ret < 0 && __threadErrno == EINTR) \
- continue; \
- break; \
- } \
- __offs += (ret); \
- } \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ (buf)[__offs] = __intVal(rA); \
+ __INST(readAhead) = nil; \
+ (ret) = 1; \
+ __offs ++; \
+ continue; \
+ } \
+ CLEAR_ERRNO; \
+ { \
+ int res = 0; \
+ if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res), 1)) \
+ || (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \
+ || (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0), 1))) { \
+ if (res > 0) { \
+ if (res > ((cnt)-__offs)) \
+ res = (cnt)-__offs; \
+ READ((ret), f, (buf)+__offs, res, handleType); \
+ } else { \
+ (ret) = 0; \
+ break; \
+ } \
+ } else { \
+ READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \
+ } \
+ } \
+ if ((ret) <= 0) { \
+ if (ret < 0 && __threadErrno == EINTR) \
+ continue; \
+ break; \
+ } \
+ __offs += (ret); \
+ } \
+ (ret) = __offs; \
} \
}
@@ -437,63 +439,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; \
} \
}
@@ -502,141 +504,141 @@
int __ooffs = obj_offs; \
int __offs = 0; \
char *buf = (char *)(obj); \
- \
+ \
(ret) = 0; \
if (isBuffered) { \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = getc(f); \
- if ((ret) < 0) { \
- if (ferror(f)) { \
- if (__threadErrno == EINTR) { \
- clearerr(f); \
- /* refetch */ \
- buf = (char *)(obj);\
- continue; \
- } \
- } else { \
- (ret) = 0; \
- } \
- break; \
- } \
- (buf)[__ooffs+__offs] = (ret); \
- __offs++; \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = getc(f); \
+ if ((ret) < 0) { \
+ if (ferror(f)) { \
+ if (__threadErrno == EINTR) { \
+ clearerr(f); \
+ /* refetch */ \
+ buf = (char *)(obj);\
+ continue; \
+ } \
+ } else { \
+ (ret) = 0; \
+ } \
+ break; \
+ } \
+ (buf)[__ooffs+__offs] = (ret); \
+ __offs++; \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} else { \
- while (__offs < (cnt)) { \
- char __buf[IO_BUFFER_SIZE]; \
- OBJ rA = __INST(readAhead); \
- if (rA != nil) { \
- (buf)[__ooffs+__offs] = __intVal(rA);\
- __INST(readAhead) = nil; \
- (ret) = 1; \
- __offs++; \
- continue; \
- } \
- { \
- int res = 0; \
- int l = (cnt)-__offs; \
- CLEAR_ERRNO; \
- if (l > IO_BUFFER_SIZE) \
- l = IO_BUFFER_SIZE; \
- if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)), FIONREAD, &res), 1)) \
- || (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \
- || (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0,0,0,&res,0), 1))) { \
- if (res > 0) { \
- if (res > l) res = l; \
- READ((ret), f, __buf, res, handleType); \
- } else { \
- (ret) = 0; \
- break; \
- } \
- } else { \
- READ((ret), f, __buf, l, handleType); \
- } \
- if ((ret) <= 0) { \
- if (ret < 0 && __threadErrno == EINTR) \
- continue; \
- break; \
- } \
- } \
- if ((ret) > 0) { \
- buf = (char *)(obj); \
- memcpy((buf)+__ooffs+__offs, __buf, (ret)); \
- __offs += (ret); \
- } else { \
- (ret) = 0; \
- } \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ while (__offs < (cnt)) { \
+ char __buf[IO_BUFFER_SIZE]; \
+ OBJ rA = __INST(readAhead); \
+ if (rA != nil) { \
+ (buf)[__ooffs+__offs] = __intVal(rA);\
+ __INST(readAhead) = nil; \
+ (ret) = 1; \
+ __offs++; \
+ continue; \
+ } \
+ { \
+ int res = 0; \
+ int l = (cnt)-__offs; \
+ CLEAR_ERRNO; \
+ if (l > IO_BUFFER_SIZE) \
+ l = IO_BUFFER_SIZE; \
+ if ((handleType == @symbol(socketFilePointer) && (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)), FIONREAD, &res), 1)) \
+ || (handleType == @symbol(socketHandle) && (ioctlsocket((SOCKET)(f), FIONREAD, &res), 1)) \
+ || (handleType == @symbol(pipeFilePointer) && (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0,0,0,&res,0), 1))) { \
+ if (res > 0) { \
+ if (res > l) res = l; \
+ READ((ret), f, __buf, res, handleType); \
+ } else { \
+ (ret) = 0; \
+ break; \
+ } \
+ } else { \
+ READ((ret), f, __buf, l, handleType); \
+ } \
+ if ((ret) <= 0) { \
+ if (ret < 0 && __threadErrno == EINTR) \
+ continue; \
+ break; \
+ } \
+ } \
+ if ((ret) > 0) { \
+ buf = (char *)(obj); \
+ memcpy((buf)+__ooffs+__offs, __buf, (ret)); \
+ __offs += (ret); \
+ } else { \
+ (ret) = 0; \
+ } \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} \
}
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \
if (isBuffered) { \
- for (;;) { \
- CLEAR_ERRNO; \
- ret = putc(*(buf), f); \
- if ((ret) >= 0) { \
- (ret) = 1; \
- } else if (ferror(f)) { \
- if (__threadErrno == EINTR) { \
- clearerr(f); \
- continue; \
- } \
- } else \
- (ret) = 0; \
- break; \
- } \
+ for (;;) { \
+ CLEAR_ERRNO; \
+ ret = putc(*(buf), f); \
+ if ((ret) >= 0) { \
+ (ret) = 1; \
+ } else if (ferror(f)) { \
+ if (__threadErrno == EINTR) { \
+ clearerr(f); \
+ continue; \
+ } \
+ } else \
+ (ret) = 0; \
+ break; \
+ } \
} else { \
- for (;;) { \
- CLEAR_ERRNO; \
- WRITE(ret,f, buf, 1, handleType); \
- if ((ret) >= 0 || __threadErrno != EINTR) \
- break; \
- } \
+ for (;;) { \
+ CLEAR_ERRNO; \
+ WRITE(ret,f, buf, 1, handleType); \
+ if ((ret) >= 0 || __threadErrno != EINTR) \
+ break; \
+ } \
}
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \
(ret) = 0; \
if (isBuffered) { \
- int __offs = 0; \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- (ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
- if ((ret) <= 0) { \
- if (ferror(f)) { \
- if (__threadErrno == EINTR) { \
- clearerr(f); \
- continue; \
- } \
- break; \
- } else { \
- (ret) = 0; \
- } \
- } \
- __offs += (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ (ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
+ if ((ret) <= 0) { \
+ if (ferror(f)) { \
+ if (__threadErrno == EINTR) { \
+ clearerr(f); \
+ continue; \
+ } \
+ break; \
+ } else { \
+ (ret) = 0; \
+ } \
+ } \
+ __offs += (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
} else { \
- int __offs = 0; \
- while (__offs < (cnt)) { \
- CLEAR_ERRNO; \
- WRITE(ret,f, (buf)+__offs, (cnt)-__offs, handleType); \
- if (ret <= 0) { \
- if (ret < 0 && __threadErrno == EINTR) { \
- continue; \
- } \
- break; \
- } \
- __offs += (ret); \
- } \
- if (__offs > 0) \
- (ret) = __offs; \
+ int __offs = 0; \
+ while (__offs < (cnt)) { \
+ CLEAR_ERRNO; \
+ WRITE(ret,f, (buf)+__offs, (cnt)-__offs, handleType); \
+ if (ret <= 0) { \
+ if (ret < 0 && __threadErrno == EINTR) { \
+ continue; \
+ } \
+ break; \
+ } \
+ __offs += (ret); \
+ } \
+ if (__offs > 0) \
+ (ret) = __offs; \
}
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \
@@ -644,51 +646,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; \
} \
}
@@ -699,15 +701,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 */ \
}
@@ -717,73 +719,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 */
@@ -794,84 +796,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; \
}
@@ -881,7 +883,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
@@ -894,13 +896,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 */
@@ -910,52 +912,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); \
}
@@ -973,34 +975,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; \
} \
}
@@ -1012,61 +1014,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; \
} \
}
@@ -1077,56 +1079,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); \
}
@@ -1136,44 +1138,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 */
@@ -1185,64 +1187,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 */
@@ -1256,25 +1258,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 */
@@ -1283,48 +1285,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 */
@@ -1336,7 +1338,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
@@ -1386,37 +1388,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
@@ -1450,44 +1452,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]
"
! !
@@ -1498,25 +1500,25 @@
To be called on exit of Smalltalk."
Lobby do:[:eachFileStream |
- eachFileStream close
+ eachFileStream close
].
!
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. but we keep #nl here,
- "/ otherwise sending HTTP request over sockets fails
+ OperatingSystem isVMSlike ifTrue:[
+ "/ vms EOL conventions
+ DefaultEOLMode := #cr
+ ] ifFalse:[
+ "/ msdos EOL conventions
+ "/ msdos uses #crlf. but we keep #nl here,
+ "/ otherwise sending HTTP request over sockets fails
"/ DefaultEOLMode := #crlf
- DefaultEOLMode := #nl
- ]
+ DefaultEOLMode := #nl
+ ]
]
!
@@ -1525,56 +1527,60 @@
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'.
+ 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'.
].
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%"
+ MaxNonTenurableExecutors := ObjectMemory newSpaceSize // (Socket sizeOfInst:0) // 20.
+
"Modified: / 21.5.1998 / 16:33:53 / cg"
!
@@ -1583,7 +1589,7 @@
This is invoked via the #earlyRestart change notification."
Lobby do:[:eachFileStream |
- eachFileStream reOpen
+ eachFileStream reOpen
].
!
@@ -1591,8 +1597,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"
@@ -1702,18 +1708,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.
"
@@ -1841,16 +1847,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
! !
@@ -1958,42 +1964,42 @@
|text l chunks sizes chunk byteCount cnt bytes offset|
binary ifTrue:[
- "adding to a ByteArray produces quadratic time-space
- behavior - therefore we allocate chunks, and concatenate them
- at the end."
-
- chunks := OrderedCollection new.
- sizes := OrderedCollection new.
- byteCount := 0.
- [self atEnd] whileFalse:[
- chunk := ByteArray uninitializedNew:4096.
- cnt := self nextBytes:(chunk size) into:chunk.
- cnt notNil ifTrue:[
- chunks add:chunk.
- sizes add:cnt.
- byteCount := byteCount + cnt
- ]
- ].
-
- "now, create one big ByteArray"
- bytes := ByteArray uninitializedNew:byteCount.
- offset := 1.
- 1 to:chunks size do:[:index |
- chunk := chunks at:index.
- cnt := sizes at:index.
- bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk.
- offset := offset + cnt
- ].
- ^ bytes
+ "adding to a ByteArray produces quadratic time-space
+ behavior - therefore we allocate chunks, and concatenate them
+ at the end."
+
+ chunks := OrderedCollection new.
+ sizes := OrderedCollection new.
+ byteCount := 0.
+ [self atEnd] whileFalse:[
+ chunk := ByteArray uninitializedNew:4096.
+ cnt := self nextBytes:(chunk size) into:chunk.
+ cnt notNil ifTrue:[
+ chunks add:chunk.
+ sizes add:cnt.
+ byteCount := byteCount + cnt
+ ]
+ ].
+
+ "now, create one big ByteArray"
+ bytes := ByteArray uninitializedNew:byteCount.
+ offset := 1.
+ 1 to:chunks size do:[:index |
+ chunk := chunks at:index.
+ cnt := sizes at:index.
+ bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk.
+ offset := offset + cnt
+ ].
+ ^ bytes
].
text := StringCollection new.
[self atEnd] whileFalse:[
- l := self nextLine.
- l isNil ifTrue:[
- ^ text
- ].
- text add:l
+ l := self nextLine.
+ l isNil ifTrue:[
+ ^ text
+ ].
+ text add:l
].
^ text
!
@@ -2010,7 +2016,7 @@
See also #contents, which returns the lines as stringCollection for text files."
binary ifTrue:[
- ^ self contents.
+ ^ self contents.
].
^ self upToEnd
@@ -2023,7 +2029,7 @@
(such as upTo)"
binary == true ifTrue:[
- ^ ByteArray
+ ^ ByteArray
].
^ String
!
@@ -2031,10 +2037,10 @@
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
- nil -> transparent
+ #crlf -> add a CR-NL, as in MSDOS
+ #cr -> add a CR, as in VMS
+ #nl -> add a NL, as in Unix
+ nil -> transparent
"
^ eolMode
@@ -2043,20 +2049,20 @@
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
- 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
+ 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
+ ]
].
!
@@ -2069,14 +2075,14 @@
OBJ _handle = __INST(handle);
if (_handle != nil) {
- if (__INST(handleType) == @symbol(socketHandle)) {
- RETURN (_handle);
- } else if ((__INST(handleType) == nil)
- || (__INST(handleType) == @symbol(filePointer))
- || (__INST(handleType) == @symbol(socketFilePointer))
- || (__INST(handleType) == @symbol(pipeFilePointer))) {
- RETURN ( __MKINT(fileno(__FILEVal(_handle))));
- }
+ if (__INST(handleType) == @symbol(socketHandle)) {
+ RETURN (_handle);
+ } else if ((__INST(handleType) == nil)
+ || (__INST(handleType) == @symbol(filePointer))
+ || (__INST(handleType) == @symbol(socketFilePointer))
+ || (__INST(handleType) == @symbol(pipeFilePointer))) {
+ RETURN ( __MKINT(fileno(__FILEVal(_handle))));
+ }
}
%}.
handle isNil ifTrue:[^ self errorNotOpen].
@@ -2105,20 +2111,20 @@
OBJ _handle = __INST(handle);
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))) {
+ 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))) {
#ifdef WIN32
- RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileno(__FILEVal(_handle)))));
+ RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileno(__FILEVal(_handle)))));
#else
- RETURN (__MKINT(fileno(__FILEVal(_handle))));
+ RETURN (__MKINT(fileno(__FILEVal(_handle))));
#endif
- }
+ }
}
%}.
handle isNil ifTrue:[^ self errorNotOpen].
@@ -2134,7 +2140,7 @@
- except passing it to a primitive, for example."
(handleType isNil or:[handleType == #filePointer]) ifTrue:[
- ^ handle
+ ^ handle
].
^ self error:'not a FILE*'
!
@@ -2186,9 +2192,9 @@
which offers another choice."
aBoolean ifTrue:[
- eolMode := #crlf
+ eolMode := #crlf
] ifFalse:[
- eolMode := #nl
+ eolMode := #nl
].
!
@@ -2278,8 +2284,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
@@ -2294,9 +2300,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"
!
@@ -2307,9 +2313,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"
!
@@ -2320,9 +2326,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"
!
@@ -2393,10 +2399,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"
!
@@ -2411,7 +2417,7 @@
"return a message string describing the last error"
(lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[
- ^ 'I/O error'
+ ^ 'I/O error'
].
^ OperatingSystem errorTextForNumber:lastErrorNumber
!
@@ -2440,17 +2446,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 lazyly - see OpenError>>#description
- "/ errorString:(' : ' , errorHolder errorString);
- parameter:self;
- raiseRequest
- "/ in:thisContext sender
+ errorCode:errorNumber;
+ osErrorHolder:errorHolder;
+ "/ cg: initialized lazyly - see OpenError>>#description
+ "/ errorString:(' : ' , errorHolder errorString);
+ parameter:self;
+ raiseRequest
+ "/ in:thisContext sender
"Modified: / 09-09-2011 / 07:22:49 / cg"
!
@@ -2469,10 +2475,10 @@
"{ Pragma: +optSpace }"
^ ReadError newException
- errorCode:errorNumber;
- osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber);
- parameter:self;
- raiseRequest
+ errorCode:errorNumber;
+ osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber);
+ parameter:self;
+ raiseRequest
!
writeError
@@ -2489,10 +2495,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'!
@@ -2517,7 +2523,7 @@
"/ with timeout to avoid blocking in a bad pty/socket
[
- self closeFile
+ self closeFile
] valueWithTimeout:30 seconds.
!
@@ -2528,14 +2534,16 @@
registerForFinalization
"keep myself in newSpace, so it will be finalized early"
- ObjectMemory preventTenureOf:self.
+ Lobby size < MaxNonTenurableExecutors ifTrue:[
+ ObjectMemory preventTenureOf:self.
+ ].
Lobby register:self.
!
unregisterForFinalization
Lobby unregister:self.
"probably the object will be collected soon..."
- ObjectMemory setAgeOf:self to:0.
+ ObjectMemory allowTenureOf:self
! !
!ExternalStream methodsFor:'initialization'!
@@ -2577,129 +2585,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;
- if (@global(InfoPrinting) == true) {
- fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n");
- }
- 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;
+ if (@global(InfoPrinting) == true) {
+ fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n");
+ }
+ 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')
- ].
- ^ line , self nextLine
+ "/ 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')
+ ].
+ ^ line , self nextLine
].
(hitEOF == true) 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].
@@ -2721,74 +2729,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)
+ }
#if defined(WIN32) && !defined(__MINGW__)
- 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;
+ }
#if defined(WIN32) && !defined(__MINGW__)
- 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)) + 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)) + 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.
!
@@ -2803,14 +2811,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
+ ]
].
!
@@ -2830,16 +2838,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
@@ -2859,18 +2867,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
@@ -2883,20 +2891,20 @@
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|
handle isNil ifTrue:[^ self errorNotOpen].
OperatingSystem supportsIOInterrupts ifFalse:[
- ^ self errorUnsupportedOperation
+ ^ self errorUnsupportedOperation
].
fd := self fileDescriptor.
aBoolean ifTrue:[
- ^ OperatingSystem enableIOInterruptsOn:fd
+ ^ OperatingSystem enableIOInterruptsOn:fd
].
^ OperatingSystem disableIOInterruptsOn:fd
@@ -2929,10 +2937,10 @@
|bufferSize|
OperatingSystem isMSDOSlike ifTrue:[
- "/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ?
- bufferSize := 1 * 1024.
+ "/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ?
+ bufferSize := 1 * 1024.
] ifFalse:[
- bufferSize := 8 * 1024.
+ bufferSize := 8 * 1024.
].
^ inStream copyToEndInto:self bufferSize:bufferSize
@@ -2953,10 +2961,10 @@
|bufferSize|
OperatingSystem isMSDOSlike ifTrue:[
- "/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ?
- bufferSize := 1 * 1024.
+ "/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ?
+ bufferSize := 1 * 1024.
] ifFalse:[
- bufferSize := 8 * 1024.
+ bufferSize := 8 * 1024.
].
^ self copyToEndInto:outStream bufferSize:bufferSize
@@ -3013,55 +3021,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 = __FILEVal(fp);
+ 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;
}
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
@@ -3069,8 +3077,8 @@
out:;
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- ^ self ioError:error.
+ lastErrorNumber := error.
+ ^ self ioError:error.
].
handle isNil ifTrue:[^ self errorNotOpen].
@@ -3104,39 +3112,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);
@@ -3144,16 +3152,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
"
!
@@ -3173,39 +3181,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);
@@ -3214,9 +3222,9 @@
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self ioError:error.
- ^ self.
+ lastErrorNumber := error.
+ self ioError:error.
+ ^ self.
].
handle isNil ifTrue:[^ self errorNotOpen].
@@ -3224,9 +3232,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
"
!
@@ -3259,33 +3267,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;
@@ -3321,18 +3329,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;
@@ -3368,12 +3376,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].
@@ -3435,7 +3443,7 @@
readCount := self nextBytes:count into:aCollection startingAt:start.
readCount = count ifTrue:[
- ^ aCollection.
+ ^ aCollection.
].
^ aCollection copyFrom:1 to:start+readCount-1.
!
@@ -3449,20 +3457,20 @@
|buffer n|
binary ifTrue:[
- buffer := ByteArray uninitializedNew:count
+ buffer := ByteArray uninitializedNew:count
] ifFalse:[
- buffer := String uninitializedNew:count
+ buffer := String 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.
@@ -3520,99 +3528,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 and:[self pastEndRead isNil]) 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].
@@ -3633,14 +3641,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;
@@ -3654,41 +3662,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
@@ -3733,98 +3741,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 and:[self pastEndRead isNil]) 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].
@@ -3860,69 +3868,69 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- FILEPOINTER f;
- int ret, _buffered;
- int value;
- union {
- unsigned char buffer[4];
- int intVal;
- } u;
-
- f = __FILEVal(fp);
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType));
-
- if (ret == 4) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 4;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- if (msbFlag == true) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ FILEPOINTER f;
+ int ret, _buffered;
+ int value;
+ union {
+ unsigned char buffer[4];
+ int intVal;
+ } u;
+
+ f = __FILEVal(fp);
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType));
+
+ if (ret == 4) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 4;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ if (msbFlag == true) {
#if defined(__MSBFIRST__)
- value = u.intVal;
+ value = u.intVal;
#else
- value = (u.buffer[0] & 0xFF);
- value = (value << 8) | (u.buffer[1] & 0xFF);
- value = (value << 8) | (u.buffer[2] & 0xFF);
- value = (value << 8) | (u.buffer[3] & 0xFF);
+ value = (u.buffer[0] & 0xFF);
+ value = (value << 8) | (u.buffer[1] & 0xFF);
+ value = (value << 8) | (u.buffer[2] & 0xFF);
+ value = (value << 8) | (u.buffer[3] & 0xFF);
#endif
- } else {
+ } else {
#if defined(__LSBFIRST__)
- value = u.intVal;
+ value = u.intVal;
#else
- value = (u.buffer[3] & 0xFF);
- value = (value << 8) | (u.buffer[2] & 0xFF);
- value = (value << 8) | (u.buffer[1] & 0xFF);
- value = (value << 8) | (u.buffer[0] & 0xFF);
+ value = (u.buffer[3] & 0xFF);
+ value = (value << 8) | (u.buffer[2] & 0xFF);
+ value = (value << 8) | (u.buffer[1] & 0xFF);
+ value = (value << 8) | (u.buffer[0] & 0xFF);
#endif
- }
+ }
#if __POINTER_SIZE__ == 8
- RETURN ( __mkSmallInteger(value));
+ RETURN ( __mkSmallInteger(value));
#else
- if ((value >= _MIN_INT) && (value <= _MAX_INT)) {
- RETURN ( __mkSmallInteger(value));
- }
- RETURN ( __MKLARGEINT(value) );
+ if ((value >= _MIN_INT) && (value <= _MAX_INT)) {
+ RETURN ( __mkSmallInteger(value));
+ }
+ RETURN ( __MKLARGEINT(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].
@@ -3949,56 +3957,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].
@@ -4026,70 +4034,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].
@@ -4116,56 +4124,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].
@@ -4178,14 +4186,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 nextUnsignedShortMSB:true
+ self obsoleteMethodWarning:'use #nextUnsignedShortMSB:true'.
+ ^ self nextUnsignedShortMSB:true
].
self obsoleteMethodWarning:'use #nextAlphaNumericWord'.
^ self nextAlphaNumericWord
@@ -4208,43 +4217,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)
+ }
#if defined(WIN32) && !defined(__MINGW__)
- 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].
@@ -4264,29 +4273,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
}
@@ -4295,65 +4304,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 nextPutLong:aNumber MSB:msbFlag
+ ^ super nextPutLong:aNumber MSB:msbFlag
].
self argumentMustBeInteger
!
@@ -4368,8 +4377,8 @@
%{
int num;
union {
- char bytes[2];
- short shortVal;
+ char bytes[2];
+ short shortVal;
} u;
OBJ fp;
@@ -4379,62 +4388,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].
@@ -4455,8 +4464,8 @@
printOn:aStream
aStream
- nextPutAll:self className;
- nextPutAll:'(handle:('.
+ nextPutAll:self className;
+ nextPutAll:'(handle:('.
handle printOn:aStream.
aStream nextPutAll:'))'
! !
@@ -4481,74 +4490,74 @@
int rslt;
if (fp == nil) {
- error = @symbol(errorNotOpen);
- goto out;
+ error = @symbol(errorNotOpen);
+ goto out;
}
if (__INST(handleType) == @symbol(socketHandle)) {
- SOCKET sock = __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 = __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: the pre Nov2014 code always did the fclose interruptable;
- // I am not sure, if fclose is actually prepared to do this;
- // at least when only reading, this should not block, and we
- // should be ableto do it without being interruptable.
- // Must watch this - if it leads to blockings, change and think about it.
- if (__INST(mode) != @symbol(readonly)) {
- __BEGIN_INTERRUPTABLE__
- rslt = fclose(f);
- __END_INTERRUPTABLE__
- } else {
- rslt = fclose(f);
- }
+ // cg: the pre Nov2014 code always did the fclose interruptable;
+ // I am not sure, if fclose is actually prepared to do this;
+ // at least when only reading, this should not block, and we
+ // should be ableto do it without being interruptable.
+ // Must watch this - if it leads to blockings, change and think about it.
+ if (__INST(mode) != @symbol(readonly)) {
+ __BEGIN_INTERRUPTABLE__
+ rslt = fclose(f);
+ __END_INTERRUPTABLE__
+ } else {
+ rslt = fclose(f);
+ }
#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);
@@ -4556,28 +4565,28 @@
%}.
error notNil ifTrue:[
- error == #errorNotOpen ifTrue:[
- self errorNotOpen.
- ].
- error isInteger ifTrue:[
- lastErrorNumber := error.
- mode == #readonly ifTrue:[
- self ioError:error.
- ] ifFalse:[
- self writeError:error.
- ].
- ^ self.
- ].
- self primitiveFailed:error.
- ^ self.
+ error == #errorNotOpen ifTrue:[
+ self errorNotOpen.
+ ].
+ 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
]
! !
@@ -4681,16 +4690,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
!
@@ -4801,39 +4810,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:;
%}.
@@ -4879,26 +4888,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 */
+ }
+ }
}
%}.
!
@@ -4918,15 +4927,15 @@
int success = 0;
if (__INST(handleType) == @symbol(socketHandle)) {
- success = ioctlsocket((SOCKET)__externalAddressVal(fd), FIONREAD, &res) == 0;
+ success = ioctlsocket((SOCKET)__externalAddressVal(fd), FIONREAD, &res) == 0;
} else if (__INST(handleType) == @symbol(socketFilePointer)) {
- success = ioctlsocket((SOCKET)_get_osfhandle(__intVal(fd)), FIONREAD, &res) == 0;
+ success = ioctlsocket((SOCKET)_get_osfhandle(__intVal(fd)), FIONREAD, &res) == 0;
} else if (__INST(handleType) == @symbol(pipeFilePointer)) {
- success = PeekNamedPipe((HANDLE)_get_osfhandle(__intVal(fd)),0,0,0,&res,0);
+ success = PeekNamedPipe((HANDLE)_get_osfhandle(__intVal(fd)),0,0,0,&res,0);
}
if (success) {
- if (__INST(readAhead) != nil) res++;
- RETURN(__mkSmallInteger(res));
+ if (__INST(readAhead) != nil) res++;
+ RETURN(__mkSmallInteger(res));
}
#endif
%}.
@@ -4951,18 +4960,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;
@@ -4976,65 +4985,65 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
-
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
-
- if (ret > 0) {
- pos = __INST(position);
- if (__isSmallInteger(pos)) {
- OBJ t;
-
- t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- if (__INST(binary) == true) {
- RETURN ( __mkSmallInteger(ch) );
- }
- RETURN ( __MKCHARACTER(ch) );
- }
-
- __INST(position) = nil;
- if ((ret < 0)
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ pos = __INST(position);
+ if (__isSmallInteger(pos)) {
+ OBJ t;
+
+ t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ if (__INST(binary) == true) {
+ RETURN ( __mkSmallInteger(ch) );
+ }
+ RETURN ( __MKCHARACTER(ch) );
+ }
+
+ __INST(position) = nil;
+ if ((ret < 0)
# ifdef ECONNRESET
- && (__threadErrno != ECONNRESET)
+ && (__threadErrno != ECONNRESET)
# endif
- ){
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ ){
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
#endif /* not SCHTEAM */
%}.
hitEOF == true 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.
].
c := self nextByteFromFile:handle.
c isNil ifTrue:[
- ^ self pastEndRead.
+ ^ self pastEndRead.
].
binary == true ifTrue:[
- ^ c
+ ^ c
].
^ Character value:c
!
@@ -5046,9 +5055,9 @@
|coll nRead|
binary ifTrue:[
- coll := ByteArray uninitializedNew:count
+ coll := ByteArray uninitializedNew:count
] ifFalse:[
- coll := String new:count
+ coll := String new:count
].
nRead := self nextBytes:count into:coll startingAt:1.
@@ -5056,7 +5065,7 @@
"/ we must raise an exception here.
nRead < count ifTrue:[
- ^ self pastEndRead
+ ^ self pastEndRead
].
^ coll
@@ -5082,64 +5091,64 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
-
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
-
- if (ret > 0) {
- pos = __INST(position);
- if (__isSmallInteger(pos)) {
- OBJ t;
-
- t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- if (__INST(binary) == true) {
- RETURN ( __mkSmallInteger(ch) );
- }
- RETURN ( __MKCHARACTER(ch) );
- }
-
- __INST(position) = nil;
- if ((ret < 0)
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &ch, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ pos = __INST(position);
+ if (__isSmallInteger(pos)) {
+ OBJ t;
+
+ t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ if (__INST(binary) == true) {
+ RETURN ( __mkSmallInteger(ch) );
+ }
+ RETURN ( __MKCHARACTER(ch) );
+ }
+
+ __INST(position) = nil;
+ if ((ret < 0)
#ifdef ECONNRESET
- && (__threadErrno != ECONNRESET)
+ && (__threadErrno != ECONNRESET)
#endif
- ){
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ ){
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF == true 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.
].
c := self nextByteFromFile:handle.
c isNil ifTrue:[
- ^ nil.
+ ^ nil.
].
binary == true ifTrue:[
- ^ c
+ ^ c
].
^ Character value:c
!
@@ -5159,11 +5168,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;
@@ -5173,49 +5182,49 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
-
- if (ret > 0) {
- __UNGETC__(c, f, _buffered);
-
- if (__INST(binary) == true) {
- RETURN ( __mkSmallInteger(c) );
- }
- RETURN ( __MKCHARACTER(c) );
- }
- if ((ret < 0)
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ __UNGETC__(c, f, _buffered);
+
+ if (__INST(binary) == true) {
+ RETURN ( __mkSmallInteger(c) );
+ }
+ RETURN ( __MKCHARACTER(c) );
+ }
+ if ((ret < 0)
#ifdef ECONNRESET
- && (__threadErrno != ECONNRESET)
+ && (__threadErrno != ECONNRESET)
#endif
- ){
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ ){
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF == true 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
!
@@ -5235,11 +5244,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;
@@ -5249,46 +5258,46 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- f = __FILEVal(fp);
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
-
- if (ret > 0) {
- __UNGETC__(c, f, _buffered);
-
- if (__INST(binary) == true) {
- RETURN ( __mkSmallInteger(c) );
- }
- RETURN ( __MKCHARACTER(c) );
- }
- if ((ret < 0)
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ f = __FILEVal(fp);
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+
+ if (ret > 0) {
+ __UNGETC__(c, f, _buffered);
+
+ if (__INST(binary) == true) {
+ RETURN ( __mkSmallInteger(c) );
+ }
+ RETURN ( __MKCHARACTER(c) );
+ }
+ if ((ret < 0)
#ifdef ECONNRESET
- && (__threadErrno != ECONNRESET)
+ && (__threadErrno != ECONNRESET)
#endif
- ){
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ ){
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF == true 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
!
@@ -5301,16 +5310,16 @@
buffer := self contentsSpecies new:4096.
[self atEnd] whileFalse:[
- count := self nextAvailableBytes:4096 into:buffer startingAt:1.
- count ~~ 0 ifTrue:[
- answerStream isNil ifTrue:[
- answerStream := WriteStream with:buffer.
- answerStream position:count.
- buffer := self contentsSpecies new:4096.
- ] ifFalse:[
- answerStream nextPutAll:buffer startingAt:1 to:count.
- ].
- ].
+ count := self nextAvailableBytes:4096 into:buffer startingAt:1.
+ count ~~ 0 ifTrue:[
+ answerStream isNil ifTrue:[
+ answerStream := WriteStream with:buffer.
+ answerStream position:count.
+ buffer := self contentsSpecies new:4096.
+ ] ifFalse:[
+ answerStream nextPutAll:buffer startingAt:1 to:count.
+ ].
+ ].
].
answerStream isNil ifTrue:[^ self contentsSpecies new].
^ answerStream contents
@@ -5352,19 +5361,19 @@
char c;
if (__INST(hitEOF) == true) {
- RETURN (true);
+ RETURN (true);
}
pos = __INST(position);
lim = __INST(readLimit);
if (lim != nil) {
- off_t _pos, _readLimit;
-
- _pos = __signedLongIntVal(pos);
- _pos = _pos - __intVal( @global(PositionableStream:ZeroPosition)) + 1;
- _readLimit = __signedLongIntVal(lim);
- if (_pos > _readLimit) {
- RETURN (true);
- }
+ off_t _pos, _readLimit;
+
+ _pos = __signedLongIntVal(pos);
+ _pos = _pos - __intVal( @global(PositionableStream:ZeroPosition)) + 1;
+ _readLimit = __signedLongIntVal(lim);
+ if (_pos > _readLimit) {
+ RETURN (true);
+ }
}
__INST(lastErrorNumber) = nil;
@@ -5374,57 +5383,57 @@
|| (__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
# if 1
- __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+ __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
# else
- __BEGIN_INTERRUPTABLE__
- __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
- __END_INTERRUPTABLE__
+ __BEGIN_INTERRUPTABLE__
+ __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
+ __END_INTERRUPTABLE__
# endif
#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
- } while ((ret < 0) && (__threadErrno == EINTR));
-
- if (ret > 0) {
- __UNGETC__(c&0xff, f, _buffered);
- RETURN (false);
- }
- if (ret == 0) {
- __INST(hitEOF) = true;
- RETURN (true);
- }
+ } while ((ret < 0) && (__threadErrno == EINTR));
+
+ if (ret > 0) {
+ __UNGETC__(c&0xff, f, _buffered);
+ RETURN (false);
+ }
+ if (ret == 0) {
+ __INST(hitEOF) = true;
+ RETURN (true);
+ }
#ifdef ECONNRESET
- // connection reset by peer is also an EOF
- if (__threadErrno == ECONNRESET) {
- __INST(hitEOF) = true;
- RETURN (true);
- }
+ // connection reset by peer is also an EOF
+ if (__threadErrno == ECONNRESET) {
+ __INST(hitEOF) = true;
+ RETURN (true);
+ }
#endif
- /* ret < 0 */
- __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
- }
+ /* ret < 0 */
+ __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
+ }
}
%}.
lastErrorNumber notNil ifTrue:[^ self readError].
@@ -5434,7 +5443,7 @@
"/ migration support
^ self
- atEndFile:handle
+ atEndFile:handle
"Modified: / 30.10.1998 / 20:16:06 / cg"
!
@@ -5445,18 +5454,18 @@
We know, that error conditions do not block, so return true for errors."
^ readAhead notNil
- or:[handle isNil]
- or:[mode == #writeonly
- or:[OperatingSystem readCheck:self fileDescriptor]]
+ or:[handle isNil]
+ or:[mode == #writeonly
+ or:[OperatingSystem readCheck:self fileDescriptor]]
"
|pipe|
pipe := PipeStream readingFrom:'(sleep 10; echo hello)'.
pipe canReadWithoutBlocking ifTrue:[
- Transcript showCR:'data available'
+ Transcript showCR:'data available'
] ifFalse:[
- Transcript showCR:'no data available'
+ Transcript showCR:'no data available'
].
pipe close
"
@@ -5470,8 +5479,8 @@
We know, that error conditions do not block, so return true for errors."
^ handle isNil
- or:[mode == #readonly
- or:[OperatingSystem writeCheck:self fileDescriptor]]
+ or:[mode == #readonly
+ or:[OperatingSystem writeCheck:self fileDescriptor]]
!
gotErrorOrEOF
@@ -5547,19 +5556,19 @@
wasBlocked := OperatingSystem blockInterrupts.
inputSema := Semaphore new name:'readWait'.
[
- timeoutOrNil notNil ifTrue:[
- Processor signal:inputSema afterMilliseconds:timeoutOrNil.
- ].
- Processor signal:inputSema onInput:fd.
- Processor activeProcess state:#ioWait.
- inputSema wait.
- hasTimedout := timeoutOrNil notNil and:[(OperatingSystem readCheck:fd) not].
+ timeoutOrNil notNil ifTrue:[
+ Processor signal:inputSema afterMilliseconds:timeoutOrNil.
+ ].
+ Processor signal:inputSema onInput:fd.
+ Processor activeProcess state:#ioWait.
+ inputSema wait.
+ hasTimedout := timeoutOrNil notNil and:[(OperatingSystem readCheck:fd) not].
] ifCurtailed:[
- Processor disableSemaphore:inputSema.
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ Processor disableSemaphore:inputSema.
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
].
timeoutOrNil notNil ifTrue:[
- Processor disableSemaphore:inputSema.
+ Processor disableSemaphore:inputSema.
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
^ hasTimedout
@@ -5575,7 +5584,7 @@
|fd sema hasTimedout wasBlocked|
handle isNil ifTrue:[
- ^ self errorNotOpen
+ ^ self errorNotOpen
].
fd := self fileDescriptor.
@@ -5584,20 +5593,20 @@
wasBlocked := OperatingSystem blockInterrupts.
sema := Semaphore new name:'readWriteWait'.
[
- timeout notNil ifTrue:[
- Processor signal:sema afterMilliseconds:timeout
- ].
- Processor signal:sema onOutput:fd.
- Processor signal:sema onInput:fd.
- Processor activeProcess state:#ioWait.
- sema wait.
- hasTimedout := timeout notNil and:[(OperatingSystem readWriteCheck:fd) not].
+ timeout notNil ifTrue:[
+ Processor signal:sema afterMilliseconds:timeout
+ ].
+ Processor signal:sema onOutput:fd.
+ Processor signal:sema onInput:fd.
+ Processor activeProcess state:#ioWait.
+ sema wait.
+ hasTimedout := timeout notNil and:[(OperatingSystem readWriteCheck:fd) not].
] ifCurtailed:[
- Processor disableSemaphore:sema.
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ Processor disableSemaphore:sema.
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
].
timeout notNil ifTrue:[
- Processor disableSemaphore:sema.
+ Processor disableSemaphore:sema.
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
^ hasTimedout
@@ -5613,10 +5622,10 @@
|fd outputSema hasTimedout wasBlocked|
handle isNil ifTrue:[
- ^ self errorNotOpen
+ ^ self errorNotOpen
].
mode == #readonly ifTrue:[
- ^ self errorReadOnly
+ ^ self errorReadOnly
].
fd := self fileDescriptor.
@@ -5625,19 +5634,19 @@
wasBlocked := OperatingSystem blockInterrupts.
outputSema := Semaphore new name:'writeWait'.
[
- timeout notNil ifTrue:[
- Processor signal:outputSema afterMilliseconds:timeout
- ].
- Processor signal:outputSema onOutput:fd.
- Processor activeProcess state:#ioWait.
- outputSema wait.
- hasTimedout := timeout notNil and:[(OperatingSystem writeCheck:fd) not].
+ timeout notNil ifTrue:[
+ Processor signal:outputSema afterMilliseconds:timeout
+ ].
+ Processor signal:outputSema onOutput:fd.
+ Processor activeProcess state:#ioWait.
+ outputSema wait.
+ hasTimedout := timeout notNil and:[(OperatingSystem writeCheck:fd) not].
] ifCurtailed:[
- Processor disableSemaphore:outputSema.
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ Processor disableSemaphore:outputSema.
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
].
timeout notNil ifTrue:[
- Processor disableSemaphore:outputSema.
+ Processor disableSemaphore:outputSema.
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
^ hasTimedout
@@ -5655,57 +5664,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;
+ }
+ }
#if defined(WIN32) && !defined(__MINGW__)
- 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: dont 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: dont know */
+ }
+ RETURN ( self );
+ }
+ __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
+ }
}
%}.
lastErrorNumber notNil ifTrue:[self writeError. ^ self].
@@ -5714,11 +5723,11 @@
(binary==true) 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
@@ -5733,32 +5742,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);
#if defined(WIN32) && !defined(__MINGW__)
- 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 */
- }
- }
- }
+ }
+ }
+ }
}
%}
!
@@ -5774,9 +5783,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;
@@ -5785,112 +5794,112 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- OBJ fp;
-
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- ) {
- FILEPOINTER f = __FILEVal(fp);
- int _buffered = (__INST(buffered) == true);
- unsigned codePoint;
- unsigned char c;
- int cnt;
- char buff[2];
- int nBytes = 1;
-
- if (__INST(binary) != true) {
- if (__isCharacter(aCharacter)) {
-
- codePoint = __intVal(__characterVal(aCharacter));
- if (codePoint <= 0xFF) {
- 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);
+ unsigned codePoint;
+ unsigned char c;
+ int cnt;
+ char buff[2];
+ int nBytes = 1;
+
+ if (__INST(binary) != true) {
+ if (__isCharacter(aCharacter)) {
+
+ codePoint = __intVal(__characterVal(aCharacter));
+ if (codePoint <= 0xFF) {
+ 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)
+ }
#if defined(WIN32) && !defined(__MINGW__)
- 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)) {
- 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)) {
+ 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 ifFalse:[
- (aCharacter isCharacter not
- or:[aCharacter codePoint > 16rFF]) ifTrue:[
- self argumentMustBeCharacter.
- ^ self.
- ].
+ (aCharacter isCharacter not
+ or:[aCharacter codePoint > 16rFF]) ifTrue:[
+ self argumentMustBeCharacter.
+ ^ self.
+ ].
] ifTrue:[
- aCharacter isInteger ifFalse:[
- self argumentMustBeInteger.
- ^ self.
- ].
+ aCharacter isInteger ifFalse:[
+ self argumentMustBeInteger.
+ ^ self.
+ ].
].
"/ migration support
self
- nextPutByte:aCharacter asInteger
- toFile:handle
+ nextPutByte:aCharacter asInteger
+ toFile:handle
!
nextPutAll:aCollection
@@ -5905,9 +5914,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
@@ -5918,164 +5927,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;
#if defined(WIN32) && !defined(__MINGW__)
- 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
#if defined(WIN32) && !defined(__MINGW__)
- 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;
#if defined(WIN32) && !defined(__MINGW__)
- 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=%d len=%d\n", cnt, 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=%d len=%d\n", cnt, 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].
@@ -6088,7 +6097,7 @@
I don't know how to write non-bytes to a external stream, but let superclass handle this."
buffer isByteCollection ifTrue:[
- ^ self nextPutBytes:initialWriteCount from:buffer startingAt:initialOffset.
+ ^ self nextPutBytes:initialWriteCount from:buffer startingAt:initialOffset.
].
^ super nextPutAll:initialWriteCount from:buffer startingAt:initialOffset
@@ -6108,176 +6117,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;
#if defined(WIN32) && !defined(__MINGW__)
- 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
#if defined(WIN32) && !defined(__MINGW__)
- 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;
#if defined(WIN32) && !defined(__MINGW__)
- 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
!
@@ -6287,11 +6296,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
"
!
@@ -6304,9 +6313,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|
@@ -6316,16 +6325,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;
@@ -6339,121 +6348,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) {
#if defined(WIN32) && !defined(__MINGW__)
- 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;
#if defined(WIN32) && !defined(__MINGW__)
- 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].
@@ -6476,27 +6485,27 @@
codePoint := aCharacter codePoint.
(codePoint <= 16rD7FF
or:[codePoint >= 16rE000 and:[codePoint <= 16rFFFF]]) ifTrue:[
- self nextPutShort:codePoint MSB:true.
+ self nextPutShort:codePoint MSB:true.
] ifFalse:[codePoint <= 16r10FFFF ifTrue:[
- |highBits lowBits|
-
- codePoint := codePoint - 16r100000.
- highBits := codePoint bitShift:-10.
- lowBits := codePoint bitAnd:16r3FF.
- self nextPutShort:highBits+16rD800 MSB:true.
- self nextPutShort:lowBits+16rDC00 MSB:true.
+ |highBits lowBits|
+
+ codePoint := codePoint - 16r100000.
+ highBits := codePoint bitShift:-10.
+ lowBits := codePoint bitAnd:16r3FF.
+ self nextPutShort:highBits+16rD800 MSB:true.
+ self nextPutShort:lowBits+16rDC00 MSB:true.
] ifFalse:[
- EncodingError raiseWith:aCharacter errorString:'Character cannot be encoded as UTF-16'.
+ EncodingError raiseWith:aCharacter errorString:'Character cannot be encoded as UTF-16'.
]].
"
- (FileStream newTemporary
- nextPutUtf16:$B;
- nextPutUtf16:$Ä;
- nextPutUtf16:(Character codePoint:16r10CCCC);
- reset;
- binary;
- contents)
+ (FileStream newTemporary
+ nextPutUtf16:$B;
+ nextPutUtf16:$Ä;
+ nextPutUtf16:(Character codePoint:16r10CCCC);
+ reset;
+ binary;
+ contents)
"
!
@@ -6514,84 +6523,84 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- ) {
- unsigned char c;
- int _buffered = (__INST(buffered) == true);
- FILEPOINTER f = __FILEVal(fp);
-
- if (__INST(binary) != true) {
- if (__isCharacter(aCharacter)) {
- unsigned codePoint = __intVal(__characterVal(aCharacter));
-
- if (codePoint <= 0xFF) {
- int cnt;
-
- c = codePoint;
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ ) {
+ unsigned char c;
+ int _buffered = (__INST(buffered) == true);
+ FILEPOINTER f = __FILEVal(fp);
+
+ if (__INST(binary) != true) {
+ if (__isCharacter(aCharacter)) {
+ unsigned codePoint = __intVal(__characterVal(aCharacter));
+
+ if (codePoint <= 0xFF) {
+ int cnt;
+
+ c = codePoint;
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)
+ }
#if defined(WIN32) && !defined(__MINGW__)
- 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 );
- }
- error = __mkSmallInteger(__threadErrno);
- }
- }
- } else {
- if (__isSmallInteger(aCharacter)) {
- c = __intVal(aCharacter);
- goto doWrite;
- }
- }
- }
+ __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 );
+ }
+ error = __mkSmallInteger(__threadErrno);
+ }
+ }
+ } else {
+ if (__isSmallInteger(aCharacter)) {
+ c = __intVal(aCharacter);
+ goto doWrite;
+ }
+ }
+ }
}
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].
binary == true ifFalse:[
- (aCharacter isCharacter not
- or:[aCharacter codePoint > 16rFF]) ifTrue:[
- self argumentMustBeCharacter.
- ^ self.
- ].
+ (aCharacter isCharacter not
+ or:[aCharacter codePoint > 16rFF]) ifTrue:[
+ self argumentMustBeCharacter.
+ ^ self.
+ ].
] ifTrue:[
- aCharacter isInteger ifFalse:[
- self argumentMustBeInteger.
- ^ self.
- ].
+ aCharacter isInteger ifFalse:[
+ self argumentMustBeInteger.
+ ^ self.
+ ].
].
"/ migration support
self
- nextPutByte:aCharacter asInteger
- toFile:handle
+ nextPutByte:aCharacter asInteger
+ toFile:handle
! !
!ExternalStream class methodsFor:'documentation'!