--- a/FileStream.st Tue Mar 02 14:06:46 2004 +0100
+++ b/FileStream.st Tue Mar 02 15:16:08 2004 +0100
@@ -1001,7 +1001,7 @@
This is a private entry, but maybe useful to open/create a file in a special mode,
which is proprietrary to the operatingSystem."
- |filePointer|
+ |wasBlocked|
%{
HFILE f;
@@ -1012,220 +1012,226 @@
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
- {
- char _aPathName[MAXPATHLEN];
- char _openMode[64];
+ {
+ char _aPathName[MAXPATHLEN];
+ char _openMode[64];
- strncpy(_aPathName, __stringVal(pathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
- strncpy(_openMode, __stringVal(openmode), sizeof(_openMode)-1); _openMode[sizeof(_openMode)-1] = '\0';
- do {
- __threadErrno = 0;
- f = STX_C_CALL2( "fopen", fopen, _aPathName, _openMode);
- if (__threadErrno == EINTR) {
- f = NULL;
- }
- } while ((f == NULL) && (__threadErrno == EINTR));
- }
+ strncpy(_aPathName, __stringVal(pathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
+ strncpy(_openMode, __stringVal(openmode), sizeof(_openMode)-1); _openMode[sizeof(_openMode)-1] = '\0';
+ do {
+ __threadErrno = 0;
+ f = STX_C_CALL2( "fopen", fopen, _aPathName, _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);
- }
-
- filePointer = __MKOBJ((INT)f);
- __INST(position) = @global(PositionableStream:ZeroPosition);
- }
+ if (@global(FileOpenTrace) == true) {
+ fprintf(stderr, "fopen %s [FileStream] -> %x\n", __stringVal(pathName), f);
+ }
+ if (f != NULL) {
+ wasBlocked = __BLOCKINTERRUPTS();
+ __INST(filePointer) = __MKOBJ((INT)f);
+ }
+ __INST(position) = @global(PositionableStream:ZeroPosition);
+ }
}
%}.
+ filePointer notNil ifTrue:[
+ Lobby register:self.
+ wasBlocked == false ifTrue:[OperatingSystem unblockInterrupts].
+ ].
^ filePointer
!
@@ -1298,14 +1304,13 @@
filePointer := self openFile:pathName withMode:openmode attributes:attributeSpec.
filePointer isNil ifTrue:[
- "
- the open failed for some reason ...
- "
- ^ self openError
+ "
+ the open failed for some reason ...
+ "
+ ^ self openError
].
position := ZeroPosition.
buffered := true. "default is buffered"
- Lobby register:self.
!
pathName:filename
@@ -1443,7 +1448,7 @@
!FileStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.104 2004-02-19 14:13:00 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.105 2004-03-02 14:16:08 ca Exp $'
! !
FileStream initialize!