diff -r 7cb6091c3966 -r bc436b9a1ee3 FileStream.st --- a/FileStream.st Thu Dec 13 15:17:36 2012 +0100 +++ b/FileStream.st Thu Dec 13 15:23:52 2012 +0100 @@ -1015,7 +1015,9 @@ This is a private entry, but maybe useful to open/create a file in a special mode, which is proprietrary to the operatingSystem." - |wasBlocked| + |wasBlocked encodedPathName| + + encodedPathName := OperatingSystem encodePath:pathName. %{ HFILE f; @@ -1023,379 +1025,379 @@ int pass = 0; retry: - if (__isNonNilObject(pathName) && (__isStringLike(openmode) || __isArrayLike(openmode))) + if (__isNonNilObject(encodedPathName) && (__isStringLike(openmode) || __isArrayLike(openmode))) #ifdef __VMS__ - if (__qClass(pathName)==String) { - do { - /* - * allow passing additional RMS arguments. - * stupid: DEC does not seem to offer an interface for passing a char **. - */ - __threadErrno = 0; + if (__isStringLike(pathName)) { + 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; ia_element; - numAttrib = __arraySize(attributeSpec); - __openmode = "rb+"; + if (__isStringLike(openmode)) { + share = FILE_SHARE_READ|FILE_SHARE_WRITE; + __openmode = __stringVal(openmode); + if (strcmp(__openmode, "rb") == 0) { + access = GENERIC_READ; + create = OPEN_EXISTING; + } else if (strcmp(__openmode, "rb+") == 0) { + access = GENERIC_READ | GENERIC_WRITE; + create = OPEN_ALWAYS; + } else if (strcmp(__openmode, "wb") == 0) { + access = GENERIC_WRITE; + create = CREATE_ALWAYS; + } else if (strcmp(__openmode, "wb+") == 0) { + access = GENERIC_READ | GENERIC_WRITE; + create = CREATE_ALWAYS; + } else if (strcmp(__openmode, "ab") == 0) { + access = FILE_APPEND_DATA|FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA| + STANDARD_RIGHTS_WRITE|SYNCHRONIZE; + create = OPEN_ALWAYS; + } else if (strcmp(__openmode, "ab+") == 0) { + access = GENERIC_READ |FILE_APPEND_DATA|FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA| + STANDARD_RIGHTS_WRITE|SYNCHRONIZE; + create = OPEN_ALWAYS; + } else { + console_fprintf(stderr, "Win32OS [warning]: unsupported open mode\n"); + } + } else if (__isArrayLike(openmode)) { + ap = __ArrayInstPtr(attributeSpec)->a_element; + numAttrib = __arraySize(attributeSpec); + __openmode = "rb+"; - for (i=0; i MAXPATHLEN) l = MAXPATHLEN; - for (i=0; i MAXPATHLEN) l = MAXPATHLEN; + for (i=0; i= 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 /* not VMS */ - if (@global(FileOpenTrace) == true) { - console_fprintf(stderr, "fopen %s [FileStream] -> %x\n", __stringVal(pathName), f); - } - if (f != NULL) { - OBJ fp; + if (@global(FileOpenTrace) == true) { + console_fprintf(stderr, "fopen %s [FileStream] -> %x\n", __stringVal(pathName), f); + } + if (f != NULL) { + OBJ fp; - wasBlocked = __BLOCKINTERRUPTS(); + wasBlocked = __BLOCKINTERRUPTS(); #if 0 - // The original code was: - __INST(handle) = fp = __MKEXTERNALADDRESS(f); __STORE(self, fp); - // but for that, gcc generates wrong code, which loads self (volatile) into - // a register (bp), then calls __MKEXTERNALADDRESS, then stores indirect bp. - // That is wrong if a scavenge occurs in __MKEXTERNALADDRESS, as bp is now still pointing to the old - // object. + // The original code was: + __INST(handle) = fp = __MKEXTERNALADDRESS(f); __STORE(self, fp); + // but for that, gcc generates wrong code, which loads self (volatile) into + // a register (bp), then calls __MKEXTERNALADDRESS, then stores indirect bp. + // That is wrong if a scavenge occurs in __MKEXTERNALADDRESS, as bp is now still pointing to the old + // object. #else - fp = __MKEXTERNALADDRESS(f); - __INST(handle) = fp; - __STORE(self, fp); + fp = __MKEXTERNALADDRESS(f); + __INST(handle) = fp; + __STORE(self, fp); #endif - } + } } %}. handle notNil ifTrue:[ - position := ZeroPosition. - handleType := #filePointer. - Lobby register:self. - wasBlocked == false ifTrue:[OperatingSystem unblockInterrupts]. + position := ZeroPosition. + handleType := #filePointer. + Lobby register:self. + wasBlocked == false ifTrue:[OperatingSystem unblockInterrupts]. ]. ^ handle ! @@ -1683,11 +1685,11 @@ !FileStream class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.147 2012-10-26 09:56:21 stefan Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.148 2012-12-13 14:23:52 stefan Exp $' ! version_CVS - ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.147 2012-10-26 09:56:21 stefan Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.148 2012-12-13 14:23:52 stefan Exp $' ! ! FileStream initialize!