--- a/FileStream.st Fri Feb 06 11:41:15 2004 +0100
+++ b/FileStream.st Fri Feb 06 12:40:43 2004 +0100
@@ -695,11 +695,11 @@
# endif
} else {
OBJ rA = __INST(readAhead);
- long offs = 0L;
+ off_t offs = 0;
if (rA != nil) {
__INST(readAhead) = nil;
- offs = -1L;
+ offs = -1;
}
# if 0
currentPosition = STX_C_CALL3( "lseek", lseek, fileno(f), offs, SEEK_CUR);
@@ -709,9 +709,13 @@
}
#else
if (__INST(buffered) == true) {
+#ifdef _LFS_LARGEFILE
+ currentPosition = ftello(f);
+#else
currentPosition = ftell(f);
+#endif
} else {
- currentPosition = lseek(fileno(f), 0L, SEEK_CUR);
+ currentPosition = lseek(fileno(f), (off_t)0, SEEK_CUR);
}
#endif
} while ((currentPosition < 0) && (__threadErrno == EINTR));
@@ -744,12 +748,16 @@
long ret;
OBJ fp;
- if ((__INST(canPosition) != false)
- || (newPos == __MKSMALLINT(0))) {
+ if ((__INST(canPosition) != false) || (newPos == __MKSMALLINT(0))) {
if ((fp = __INST(filePointer)) != nil) {
+
+#if defined(_LFS_LARGE_FILE) && !defined(WIN32)
+# define FSEEK fseeko
+ off_t nP;
+#else
+#define FSEEK fseek
long nP;
- __int64__ nP64;
- int need64BitPosition = 0;
+#endif
if (__isSmallInteger(newPos)) {
nP = __intVal(newPos);
@@ -764,17 +772,15 @@
goto getOutOfHere;
}
if (nP == 0) {
- __int64__ nP64;
-
- if (__signedLong64IntVal(newPos, &nP64) == 0) {
+ if (sizeof(nP) == 8) {
+ if (__signedLong64IntVal(newPos, &nP) == 0 || nP < 0) {
+ __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
+ goto getOutOfHere;
+ }
+ } else {
__INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
goto getOutOfHere;
}
- if (nP64.hi < 0) {
- __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
- goto getOutOfHere;
- }
- need64BitPosition = 1;
}
}
@@ -784,36 +790,16 @@
#ifdef WIN32
__threadErrno = 0;
if (__INST(buffered) == true) {
- if (need64BitPosition) {
- __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
- goto getOutOfHere;
- } else {
- ret = STX_C_CALL3( "fseek", fseek, f, nP, SEEK_SET);
- }
+ ret = STX_C_CALL3( "fseek", fseek, f, nP, SEEK_SET);
} else {
__INST(readAhead) = nil;
- if (need64BitPosition) {
- __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
- goto getOutOfHere;
- } else {
- ret = STX_C_CALL3( "lseek", lseek, fileno(f), nP, SEEK_SET);
- }
+ ret = STX_C_CALL3( "lseek", lseek, fileno(f), nP, SEEK_SET);
}
#else
if (__INST(buffered) == true) {
- if (need64BitPosition) {
- __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
- goto getOutOfHere;
- } else {
- ret = fseek(f, nP, SEEK_SET);
- }
+ ret = FSEEK(f, nP, SEEK_SET);
} else {
- if (need64BitPosition) {
- __INST(lastErrorNumber) = __MKSMALLINT(EINVAL);
- goto getOutOfHere;
- } else {
- ret = lseek(fileno(f), nP, SEEK_SET);
- }
+ ret = lseek(fileno(f), nP, SEEK_SET);
}
#endif
} while ((ret < 0) && (__threadErrno == EINTR));
@@ -829,6 +815,7 @@
}
}
getOutOfHere: ;
+#undef FSEEK
%}.
canPosition == false ifTrue:[
"/ position by rewinding & re-reading everything up-to
@@ -858,32 +845,36 @@
%{
HFILE f;
- long ret;
+ off_t ret;
if (__INST(filePointer) != nil) {
- f = __FILEVal(__INST(filePointer));
- __INST(position) = nil; /* i.e. unknown */
- do {
+ f = __FILEVal(__INST(filePointer));
+ __INST(position) = nil; /* i.e. unknown */
+ do {
#ifdef WIN32
- __threadErrno = 0;
- if (__INST(buffered) == true) {
- ret = STX_C_CALL3( "fseek", fseek, f, 0L, SEEK_END);
- } else {
- __INST(readAhead) = nil;
- ret = STX_C_CALL3( "lseek", lseek, fileno(f), 0L, SEEK_END);
- }
+ __threadErrno = 0;
+ if (__INST(buffered) == true) {
+ ret = STX_C_CALL3( "fseek", fseek, f, 0L, SEEK_END);
+ } else {
+ __INST(readAhead) = nil;
+ ret = STX_C_CALL3( "lseek", lseek, fileno(f), 0L, SEEK_END);
+ }
#else
- if (__INST(buffered) == true) {
- ret = fseek(f, 0L, SEEK_END);
- } else {
- ret = lseek(fileno(f), 0L, SEEK_END);
- }
+ if (__INST(buffered) == true) {
+#ifdef _LFS_LARGE_FILE
+ ret = fseeko(f, (off_t)0, SEEK_END);
+#else
+ ret = fseek(f, 0L, SEEK_END);
#endif
- } while ((ret < 0) && (__threadErrno == EINTR));
- if (ret >= 0) {
- RETURN ( self );
- }
- __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
+ } else {
+ ret = lseek(fileno(f), (off_t)0, SEEK_END);
+ }
+#endif
+ } while ((ret < 0) && (__threadErrno == EINTR));
+ if (ret >= 0) {
+ RETURN ( self );
+ }
+ __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
}
%}.
lastErrorNumber notNil ifTrue:[^ self ioError].
@@ -1022,213 +1013,213 @@
retry:
if (__isNonNilObject(pathName) && (__qClass(pathName)==String)) {
#ifdef __VMS__
- do {
- /*
- * allow passing additional RMS arguments.
- * stupid: DEC does not seem to offer an interface for passing a char **.
- */
- __threadErrno = 0;
+ do {
+ /*
+ * allow passing additional RMS arguments.
+ * stupid: DEC does not seem to offer an interface for passing a char **.
+ */
+ __threadErrno = 0;
- {
- if (__isArray(attributeSpec)) {
- OBJ *ap = __ArrayInstPtr(attributeSpec)->a_element;
- int numAttrib = 0;
- int i;
+ {
+ if (__isArray(attributeSpec)) {
+ OBJ *ap = __ArrayInstPtr(attributeSpec)->a_element;
+ int numAttrib = 0;
+ int i;
- numAttrib = __arraySize(attributeSpec);
- for (i=0; i<numAttrib;i++) {
- if (! __isString(ap[i])) {
- f = NULL;
- __threadErrno = EINVAL; /* invalid argument */
- goto getOutOfHere;
- }
- }
- switch (numAttrib) {
- case 0:
- __BEGIN_INTERRUPTABLE__
- f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode));
- __END_INTERRUPTABLE__
- break;
- case 1:
- __BEGIN_INTERRUPTABLE__
- f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
- __stringVal(ap[0]));
- __END_INTERRUPTABLE__
- break;
- case 2:
- __BEGIN_INTERRUPTABLE__
- f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
- __stringVal(ap[0]), __stringVal(ap[1]));
- __END_INTERRUPTABLE__
- break;
- case 3:
- __BEGIN_INTERRUPTABLE__
- f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
- __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]));
- __END_INTERRUPTABLE__
- break;
- case 4:
- __BEGIN_INTERRUPTABLE__
- f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
- __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
- __stringVal(ap[3]));
- __END_INTERRUPTABLE__
- break;
- case 5:
- __BEGIN_INTERRUPTABLE__
- f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
- __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
- __stringVal(ap[3]), __stringVal(ap[4]));
- __END_INTERRUPTABLE__
- break;
- case 6:
- __BEGIN_INTERRUPTABLE__
- f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
- __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
- __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]));
- __END_INTERRUPTABLE__
- break;
- case 7:
- __BEGIN_INTERRUPTABLE__
- f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
- __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
- __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
- __stringVal(ap[6]));
- __END_INTERRUPTABLE__
- break;
- case 8:
- __BEGIN_INTERRUPTABLE__
- f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
- __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
- __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
- __stringVal(ap[6]), __stringVal(ap[7]));
- __END_INTERRUPTABLE__
- break;
- case 9:
- __BEGIN_INTERRUPTABLE__
- f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
- __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
- __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
- __stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]));
- __END_INTERRUPTABLE__
- break;
- case 10:
- __BEGIN_INTERRUPTABLE__
- f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
- __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
- __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
- __stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]),
- __stringVal(ap[9]));
- __END_INTERRUPTABLE__
- break;
- default:
- f = NULL;
- __threadErrno = E2BIG; /* too many args */
- goto getOutOfHere;
- }
- } else if (attributeSpec != nil) {
- f = NULL;
- __threadErrno = EINVAL; /* invalid argument */
- goto getOutOfHere;
- } else {
- /*
- * create file as sequential streamLF by default.
- */
- __BEGIN_INTERRUPTABLE__
- f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), "rfm=stmlf");
- __END_INTERRUPTABLE__
- }
- }
- } while ((f == NULL) && (__threadErrno == EINTR));
+ numAttrib = __arraySize(attributeSpec);
+ for (i=0; i<numAttrib;i++) {
+ if (! __isString(ap[i])) {
+ f = NULL;
+ __threadErrno = EINVAL; /* invalid argument */
+ goto getOutOfHere;
+ }
+ }
+ switch (numAttrib) {
+ case 0:
+ __BEGIN_INTERRUPTABLE__
+ f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode));
+ __END_INTERRUPTABLE__
+ break;
+ case 1:
+ __BEGIN_INTERRUPTABLE__
+ f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+ __stringVal(ap[0]));
+ __END_INTERRUPTABLE__
+ break;
+ case 2:
+ __BEGIN_INTERRUPTABLE__
+ f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+ __stringVal(ap[0]), __stringVal(ap[1]));
+ __END_INTERRUPTABLE__
+ break;
+ case 3:
+ __BEGIN_INTERRUPTABLE__
+ f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+ __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]));
+ __END_INTERRUPTABLE__
+ break;
+ case 4:
+ __BEGIN_INTERRUPTABLE__
+ f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+ __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+ __stringVal(ap[3]));
+ __END_INTERRUPTABLE__
+ break;
+ case 5:
+ __BEGIN_INTERRUPTABLE__
+ f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+ __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+ __stringVal(ap[3]), __stringVal(ap[4]));
+ __END_INTERRUPTABLE__
+ break;
+ case 6:
+ __BEGIN_INTERRUPTABLE__
+ f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+ __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+ __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]));
+ __END_INTERRUPTABLE__
+ break;
+ case 7:
+ __BEGIN_INTERRUPTABLE__
+ f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+ __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+ __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
+ __stringVal(ap[6]));
+ __END_INTERRUPTABLE__
+ break;
+ case 8:
+ __BEGIN_INTERRUPTABLE__
+ f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+ __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+ __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
+ __stringVal(ap[6]), __stringVal(ap[7]));
+ __END_INTERRUPTABLE__
+ break;
+ case 9:
+ __BEGIN_INTERRUPTABLE__
+ f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+ __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+ __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
+ __stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]));
+ __END_INTERRUPTABLE__
+ break;
+ case 10:
+ __BEGIN_INTERRUPTABLE__
+ f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode),
+ __stringVal(ap[0]), __stringVal(ap[1]), __stringVal(ap[2]),
+ __stringVal(ap[3]), __stringVal(ap[4]), __stringVal(ap[5]),
+ __stringVal(ap[6]), __stringVal(ap[7]), __stringVal(ap[8]),
+ __stringVal(ap[9]));
+ __END_INTERRUPTABLE__
+ break;
+ default:
+ f = NULL;
+ __threadErrno = E2BIG; /* too many args */
+ goto getOutOfHere;
+ }
+ } else if (attributeSpec != nil) {
+ f = NULL;
+ __threadErrno = EINVAL; /* invalid argument */
+ goto getOutOfHere;
+ } else {
+ /*
+ * create file as sequential streamLF by default.
+ */
+ __BEGIN_INTERRUPTABLE__
+ f = fopen((char *)__stringVal(pathName), (char *)__stringVal(openmode), "rfm=stmlf");
+ __END_INTERRUPTABLE__
+ }
+ }
+ } while ((f == NULL) && (__threadErrno == EINTR));
#else /* not VMS */
# ifdef WIN32
- do {
- __threadErrno = 0;
- f = STX_C_CALL2( "fopen", fopen, (char *)__stringVal(pathName), (char *)__stringVal(openmode));
- if (__threadErrno == EINTR) {
- f = NULL;
- }
- } while ((f == NULL) && (__threadErrno == EINTR));
+ do {
+ __threadErrno = 0;
+ f = STX_C_CALL2( "fopen", fopen, (char *)__stringVal(pathName), (char *)__stringVal(openmode));
+ if (__threadErrno == EINTR) {
+ f = NULL;
+ }
+ } while ((f == NULL) && (__threadErrno == EINTR));
# else /* not WIN32 */
- do {
- __BEGIN_INTERRUPTABLE__
+ do {
+ __BEGIN_INTERRUPTABLE__
# ifdef LINUX
- /*
- * LINUX may ret a non-NULL f even when interrupted.
- * Therefore, check errno and fake a null-ret.
- */
- __threadErrno = 0;
- f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode));
- if (__threadErrno == EINTR)
- f = NULL;
+ /*
+ * LINUX may ret a non-NULL f even when interrupted.
+ * Therefore, check errno and fake a null-ret.
+ */
+ __threadErrno = 0;
+ f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode));
+ if (__threadErrno == EINTR)
+ f = NULL;
# else /* not LINUX */
- f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode));
+ f = fopen((char *) __stringVal(pathName), (char *) __stringVal(openmode));
# endif /* not LINUX */
- __END_INTERRUPTABLE__
- } while ((f == NULL) && (__threadErrno == EINTR));
+ __END_INTERRUPTABLE__
+ } while ((f == NULL) && (__threadErrno == EINTR));
# endif /* not WIN32 */
#endif /* not VMS */
- if (f == NULL) {
- /*
- * If no filedescriptors available, try to finalize
- * possibly collected fd's and try again.
- */
- if (pass == 0 && (__threadErrno == ENFILE || __threadErrno == EMFILE)) {
- pass = 1;
- __SSEND0(@global(ObjectMemory), @symbol(scavenge), 0);
- __SSEND0(@global(ObjectMemory), @symbol(finalize), 0);
- goto retry;
- }
- getOutOfHere: ;
- __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
- __INST(position) = nil;
- } else {
+ if (f == NULL) {
+ /*
+ * If no filedescriptors available, try to finalize
+ * possibly collected fd's and try again.
+ */
+ if (pass == 0 && (__threadErrno == ENFILE || __threadErrno == EMFILE)) {
+ pass = 1;
+ __SSEND0(@global(ObjectMemory), @symbol(scavenge), 0);
+ __SSEND0(@global(ObjectMemory), @symbol(finalize), 0);
+ goto retry;
+ }
+ getOutOfHere: ;
+ __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
+ __INST(position) = nil;
+ } else {
#ifdef __VMS__
- /*
- * check to see if this is positionable ...
- */
- __INST(canPosition) = false;
+ /*
+ * check to see if this is positionable ...
+ */
+ __INST(canPosition) = false;
# ifndef _POSIX_C_SOURCE
- {
- struct stat statBuffer;
+ {
+ struct stat statBuffer;
- if (fstat(fileno(f), &statBuffer) >= 0) {
- switch (statBuffer.st_fab_rfm) {
- case FAB$C_UDF: /* undefined (also stream binary) */
- case FAB$C_VAR: /* variable length records */
- case FAB$C_VFC: /* variable fixed control */
- case FAB$C_STM: /* RMS-11 stream (valid only for sequen> */
- default:
- __INST(canPosition) = false;
- break;
+ if (fstat(fileno(f), &statBuffer) >= 0) {
+ switch (statBuffer.st_fab_rfm) {
+ case FAB$C_UDF: /* undefined (also stream binary) */
+ case FAB$C_VAR: /* variable length records */
+ case FAB$C_VFC: /* variable fixed control */
+ case FAB$C_STM: /* RMS-11 stream (valid only for sequen> */
+ default:
+ __INST(canPosition) = false;
+ break;
- case FAB$C_FIX: /* fixed length records */
- case FAB$C_STMLF: /* LF stream (valid only for sequential> */
- case FAB$C_STMCR: /* CR stream (valid only for sequential> */
- __INST(canPosition) = true;
- break;
- }
- }
- }
+ case FAB$C_FIX: /* fixed length records */
+ case FAB$C_STMLF: /* LF stream (valid only for sequential> */
+ case FAB$C_STMCR: /* CR stream (valid only for sequential> */
+ __INST(canPosition) = true;
+ break;
+ }
+ }
+ }
# endif
#else /* not VMS */
- __INST(canPosition) = true;
+ __INST(canPosition) = true;
#endif /* poor VMS */
- if (@global(FileOpenTrace) == true) {
- fprintf(stderr, "fopen %s [FileStream] -> %x\n", __stringVal(pathName), f);
- }
+ if (@global(FileOpenTrace) == true) {
+ fprintf(stderr, "fopen %s [FileStream] -> %x\n", __stringVal(pathName), f);
+ }
- filePointer = __MKOBJ((INT)f);
- __INST(position) = @global(PositionableStream:ZeroPosition);
- }
+ filePointer = __MKOBJ((INT)f);
+ __INST(position) = @global(PositionableStream:ZeroPosition);
+ }
}
%}.
^ filePointer
@@ -1389,7 +1380,14 @@
ret = fstat(fd, &buf);
} while ((ret < 0) && (__threadErrno == EINTR));
if (ret >= 0) {
- RETURN ( __MKUINT( (int)(buf.st_size) ) );
+ OBJ rslt;
+
+ if (sizeof(buf.st_size) == 8) {
+ rslt = __MKINT64(&buf.st_size);
+ } else {
+ rslt = __MKINT(buf.st_size);
+ }
+ RETURN(rslt);
}
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
}
@@ -1441,7 +1439,7 @@
!FileStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.101 2004-02-05 12:20:13 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.102 2004-02-06 11:40:43 stefan Exp $'
! !
FileStream initialize!