--- a/ExtStream.st Tue Mar 05 22:10:57 1996 +0100
+++ b/ExtStream.st Tue Mar 05 23:26:38 1996 +0100
@@ -563,8 +563,7 @@
_INST(filePointer) = fp = __MKOBJ((int)f); __STORE(self, fp);
RETURN (self);
}
-%}
-.
+%}.
^ self primitiveFailed
!
@@ -810,7 +809,7 @@
char buffer[16*1024];
char *rslt, *nextPtr, *limit;
int fd, ch;
- int _buffered, _isReadWrite;
+ int _buffered;
OBJ fp;
OBJ __MKSTRING_L();
@@ -819,12 +818,10 @@
&& (_INST(mode) != @symbol(writeonly))) {
if (_INST(binary) != true) {
f = __FILEVal(fp);
- _buffered = (_INST(buffered) == true);
- _isReadWrite = (_INST(mode) == @symbol(readwrite));
-
__BEGIN_INTERRUPTABLE__
buffer[0] = 0;
+ _buffered = (_INST(buffered) == true);
if (_buffered) {
__READING__(f);
} else {
@@ -836,7 +833,7 @@
* but seems not to work for sockets
*/
#ifdef DOES_NOT_WORK
- if (_isReadWrite)
+ if (_INST(mode) == _readwrite)
fseek(f, 0L, SEEK_CUR); /* needed in stdio */
do {
rslt = fgets(buffer, sizeof(buffer), f);
@@ -945,7 +942,6 @@
int len, cnt, len1;
OBJ pos, fp;
char *cp;
- int _buffered, _useCRLF;
_INST(lastErrorNumber) = nil;
if (((fp = _INST(filePointer)) != nil)
@@ -953,30 +949,29 @@
if (_INST(binary) != true) {
if (__isString(aString)) {
f = __FILEVal(fp);
+ cp = (char *) _stringVal(aString);
len = _stringSize(aString);
- _buffered = (_INST(buffered) == true);
- _useCRLF = (_INST(useCRLF) == true);
__BEGIN_INTERRUPTABLE__
- if (_buffered) {
+ if (_INST(buffered) == true) {
__WRITING__(f)
- cnt = fwrite(_stringVal(aString), 1, len, f);
+ cnt = fwrite(cp, 1, len, f);
} else {
do {
- cnt = write(fileno(f), _stringVal(aString), len);
+ cnt = write(fileno(f), cp, len);
} while ((cnt < 0) && (errno == EINTR));
}
if (cnt == len) {
len1 = len;
- if (_useCRLF) {
+ if (_INST(useCRLF) == true) {
cp = "\r\n"; len = 2;
} else {
cp = "\n"; len = 1;
}
- if (_buffered) {
+ if (_INST(buffered) == true) {
cnt = fwrite(cp, 1, len, f);
} else {
do {
@@ -984,13 +979,12 @@
} while ((cnt < 0) && (errno == EINTR));
}
- __END_INTERRUPTABLE__
-
if (cnt > 0) {
pos = _INST(position);
if (pos != nil) {
_INST(position) = __MKSMALLINT(__intVal(pos)+len1+cnt);
}
+ __END_INTERRUPTABLE__
RETURN ( self );
}
@@ -1043,7 +1037,6 @@
}
dst = __FILEVal(_INST(filePointer));
src = __FILEVal(srcFilePointer);
-
__BEGIN_INTERRUPTABLE__
errno = 0;
@@ -1077,7 +1070,6 @@
}
}
__END_INTERRUPTABLE__
-
_INST(position) = nil;
RETURN (self);
}
@@ -1368,8 +1360,7 @@
"truncate the underlying OS file to newSize.
Warning: this may not be implemented on all platforms."
-%{ /* NOCONTEXT */
-
+%{
#ifdef HAS_FTRUNCATE
FILE *f;
OBJ fp;
@@ -1417,7 +1408,7 @@
FILE *f;
unsigned char byte;
- int cnt, _buffered;
+ int cnt;
OBJ fp;
_INST(lastErrorNumber) = nil;
@@ -1425,14 +1416,13 @@
&& (_INST(mode) != @symbol(writeonly))) {
f = __FILEVal(fp);
- _buffered = (_INST(buffered) == true);
- if (_buffered) {
+ if (_INST(buffered) == true) {
__READING__(f)
}
__BEGIN_INTERRUPTABLE__
do {
- if (! _buffered) {
+ if (_INST(buffered) == false) {
cnt = read(fileno(f), &byte, 1);
} else {
cnt = fread(&byte, 1, 1, f);
@@ -1500,7 +1490,7 @@
%{
FILE *f;
- int cnt, offs, ret, _buffered;
+ int cnt, offs, ret;
int objSize, nInstVars, nInstBytes;
char *cp;
OBJ pos, fp, oClass;
@@ -1528,13 +1518,11 @@
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
objSize = __Size(anObject) - nInstBytes;
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
- _buffered = (_INST(buffered) == true);
-
/*
* mhmh - since we are interruptable, anObject may move.
* therefore, fetch the cp-pointer within the loop
*/
- if (_buffered) {
+ if (_INST(buffered) == true) {
__READING__(f)
}
@@ -1545,7 +1533,7 @@
* because we are interruptable, refetch pointer
*/
cp = (char *)__InstPtr(anObject) + nInstBytes + offs;
- if (! _buffered) {
+ if (_INST(buffered) == false) {
ret = read(fileno(f), cp, cnt);
} else {
if (feof(f)) {
@@ -1567,7 +1555,6 @@
}
__END_INTERRUPTABLE__
-
cnt = __intVal(count) - cnt;
if (cnt > 0) {
@@ -1664,7 +1651,6 @@
int value;
f = __FILEVal(fp);
-
__BEGIN_INTERRUPTABLE__
__READING__(f)
@@ -1742,7 +1728,6 @@
short value;
f = __FILEVal(fp);
-
__BEGIN_INTERRUPTABLE__
__READING__(f)
@@ -1756,7 +1741,6 @@
} while ((second < 0) && (errno == EINTR));
__END_INTERRUPTABLE__
-
if (second != EOF) {
if (_INST(position) != nil) {
_INST(position) = __MKSMALLINT(__intVal(_INST(position)) + 2);
@@ -1804,7 +1788,6 @@
unsigned int value;
f = __FILEVal(fp);
-
__BEGIN_INTERRUPTABLE__
__READING__(f)
@@ -1882,7 +1865,6 @@
unsigned value;
f = __FILEVal(fp);
-
__BEGIN_INTERRUPTABLE__
__READING__(f)
@@ -1896,7 +1878,6 @@
} while ((second < 0) && (errno == EINTR));
__END_INTERRUPTABLE__
-
if (second != EOF) {
if (_INST(position) != nil) {
_INST(position) = __MKSMALLINT(__intVal(_INST(position)) + 2);
@@ -1951,7 +1932,6 @@
char c;
OBJ pos, fp;
int cnt;
- int _buffered;
_INST(lastErrorNumber) = nil;
if (((fp = _INST(filePointer)) != nil)
@@ -1959,12 +1939,10 @@
if (__isSmallInteger(aByteValue)) {
c = __intVal(aByteValue);
f = __FILEVal(fp);
- _buffered = (_INST(buffered) == true);
-
__BEGIN_INTERRUPTABLE__
/*
*#ifdef OLD
- * if (_buffered) {
+ * if (_INST(buffered) == false) {
* cnt = write(fileno(f), &c, 1);
* } else
*#endif
@@ -1972,13 +1950,13 @@
* __WRITING__(f)
* cnt = fwrite(&c, 1, 1, f);
*#ifndef OLD
- * if (_buffered) {
+ * if (_INST(buffered) == false) {
* fflush(f);
* }
*#endif
* }
*/
- if (_buffered) {
+ if (_INST(buffered) == true) {
__WRITING__(f)
cnt = fwrite(&c, 1, 1, f);
} else {
@@ -2028,7 +2006,7 @@
%{
FILE *f;
- int cnt, offs, _buffered;
+ int cnt, offs;
int objSize, nInstVars, nInstBytes;
char *cp;
OBJ oClass, pos, fp;
@@ -2057,21 +2035,19 @@
objSize = __Size(anObject) - nInstBytes;
if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
cp = (char *)__InstPtr(anObject) + nInstBytes + offs;
-
- _buffered = (_INST(buffered) == true);
-
- if (_buffered) {
+ __BEGIN_INTERRUPTABLE__
+
+ if (_INST(buffered) == true) {
__WRITING__(f)
cnt = fwrite(cp, 1, cnt, f);
} else {
- __BEGIN_INTERRUPTABLE__
do {
cp = (char *)__InstPtr(anObject) + nInstBytes + offs;
cnt = write(fileno(f), cp, cnt);
} while ((cnt < 0) && (errno == EINTR));
- __END_INTERRUPTABLE__
}
+ __END_INTERRUPTABLE__
if (cnt >= 0) {
pos = _INST(position);
@@ -2115,7 +2091,7 @@
int num;
char bytes[4];
FILE *f;
- int cnt, _buffered;
+ int cnt;
OBJ fp;
_INST(lastErrorNumber) = nil;
@@ -2136,11 +2112,9 @@
}
f = __FILEVal(fp);
- _buffered = (_INST(buffered) == true);
-
__BEGIN_INTERRUPTABLE__
- if (_buffered) {
+ if (_INST(buffered) == true) {
__WRITING__(f)
cnt = fwrite(bytes, 1, 4, f);
} else {
@@ -2188,7 +2162,7 @@
int num;
char bytes[2];
FILE *f;
- int cnt, _buffered;
+ int cnt;
OBJ fp;
_INST(lastErrorNumber) = nil;
@@ -2205,11 +2179,9 @@
}
f = __FILEVal(fp);
- _buffered = (_INST(buffered) == true);
-
__BEGIN_INTERRUPTABLE__
- if (_buffered) {
+ if (_INST(buffered) == true) {
__WRITING__(f)
cnt = fwrite(bytes, 1, 2, f);
} else {
@@ -2333,7 +2305,7 @@
%{
FILE *f;
- int c, _buffered;
+ int c;
OBJ pos, fp;
unsigned char ch;
@@ -2341,18 +2313,15 @@
if (((fp = _INST(filePointer)) != nil)
&& (_INST(mode) != @symbol(writeonly))) {
f = __FILEVal(fp);
-
- _buffered = (_INST(buffered) == false);
-
__BEGIN_INTERRUPTABLE__
- if (_buffered) {
+ if (_INST(buffered) == true) {
__READING__(f)
}
do {
errno = 0;
- if (! _buffered) {
+ if (_INST(buffered) == false) {
if (read(fileno(f), &ch, 1) != 1)
c = EOF;
else
@@ -2794,7 +2763,6 @@
if (peekValue >= 0) {
_INST(position) = nil;
f = __FILEVal(fp);
-
__BEGIN_INTERRUPTABLE__
__READING__(f)
@@ -2805,7 +2773,6 @@
if (c == EOF) {
__END_INTERRUPTABLE__
-
if (ferror(f) && (errno != 0)) {
_INST(lastErrorNumber) = __MKSMALLINT(errno);
break;
@@ -3447,7 +3414,7 @@
%{
FILE *f;
- int len, cnt, _buffered;
+ int len, cnt;
OBJ fp;
char *cp;
@@ -3462,12 +3429,9 @@
} else {
cp = "\n"; len = 1;
}
-
- _buffered = (_INST(buffered) == true);
-
__BEGIN_INTERRUPTABLE__
- if (_buffered) {
+ if (_INST(buffered) == true) {
__WRITING__(f)
cnt = fwrite(cp, 1, len, f);
} else {
@@ -3502,7 +3466,7 @@
FILE *f;
char c;
- int cnt, _buffered;
+ int cnt;
OBJ pos, fp;
_INST(lastErrorNumber) = nil;
@@ -3513,11 +3477,10 @@
c = __intVal(__characterVal(aCharacter)) & 0xFF;
doWrite:
f = __FILEVal(fp);
- _buffered = (_INST(buffered) == true);
__BEGIN_INTERRUPTABLE__
- if (_buffered) {
+ if (_INST(buffered) == true) {
__WRITING__(f)
do {
@@ -3566,7 +3529,7 @@
unsigned char *cp;
int len, cnt;
OBJ pos, fp;
- int offs, _buffered;
+ int offs;
_INST(lastErrorNumber) = nil;
@@ -3598,11 +3561,10 @@
}
if (cp != NULL) {
f = __FILEVal(fp);
- _buffered = (_INST(buffered) == false);
__BEGIN_INTERRUPTABLE__
- if (! _buffered) {
+ if (_INST(buffered) == false) {
int cc, rest;
cnt = 0;
@@ -3674,7 +3636,6 @@
FILE *f;
unsigned char *cp;
int offs, len, cnt, index1, index2;
- int _buffered;
OBJ fp;
_INST(lastErrorNumber) = nil;
@@ -3719,11 +3680,9 @@
len = index2 - index1 + 1;
- _buffered = (_INST(buffered) == true);
-
__BEGIN_INTERRUPTABLE__
- if (_buffered) {
+ if (_INST(buffered) == true) {
__WRITING__(f)
cnt = fwrite(cp+index1-1, 1, len, f);
} else {
@@ -3772,6 +3731,6 @@
!ExternalStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Attic/ExtStream.st,v 1.91 1996-03-05 21:10:57 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Attic/ExtStream.st,v 1.92 1996-03-05 22:26:38 cg Exp $'
! !
ExternalStream initialize!