FileStream.st
branchjv
changeset 18678 a9b30d72dff9
parent 18421 5e7e40d367f2
parent 18651 36567dd3b8d1
child 18786 237a87b4fe8f
--- a/FileStream.st	Mon Aug 03 21:05:52 2015 +0100
+++ b/FileStream.st	Wed Aug 05 22:44:27 2015 +0100
@@ -235,18 +235,18 @@
     this and an error is raised, if a position: is attemted.
     I know, this is ugly, but what else could we do ?
     Late note: who cares for VMS these days?
-               (and how much useless effort has been put in the past,
-                to support lousy operating systems?)
+	       (and how much useless effort has been put in the past,
+		to support lousy operating systems?)
 
     [instance variables:]
-        pathName        <String>        the file's path (if known)
-        canPosition     <Boolean>       positionable - read above comment
+	pathName        <String>        the file's path (if known)
+	canPosition     <Boolean>       positionable - read above comment
 
     [author:]
-        Claus Gittinger
+	Claus Gittinger
 
     [see also:]
-        Filename DirectoryStream PipeStream Socket
+	Filename DirectoryStream PipeStream Socket
 "
 !
 
@@ -449,48 +449,48 @@
     |nameString random prevRandom prevNameString newTempFilename stream|
 
     [
-        prevRandom := random.
-        prevNameString := nameString.
+	prevRandom := random.
+	prevNameString := nameString.
 
-        "Use random numbers in order to improve the security
-         by making the generated names less predictable"
-        [
-            random := RandomGenerator new nextInteger.
-        ] doWhile:[random = prevRandom].
+	"Use random numbers in order to improve the security
+	 by making the generated names less predictable"
+	[
+	    random := RandomGenerator new nextInteger.
+	] doWhile:[random = prevRandom].
 
-        nameString := template bindWith:(OperatingSystem getProcessId) with:random.
+	nameString := template bindWith:(OperatingSystem getProcessId) with:random.
 
-        aDirectoryOrNil isNil ifTrue:[
-            newTempFilename := nameString.
-        ] ifFalse:[
-            newTempFilename := aDirectoryOrNil asFilename constructString:nameString.
-        ].
+	aDirectoryOrNil isNil ifTrue:[
+	    newTempFilename := nameString.
+	] ifFalse:[
+	    newTempFilename := aDirectoryOrNil asFilename constructString:nameString.
+	].
 
-        [
-            stream := self open:newTempFilename withMode:#(CREATE_NEW GENERIC_READ_WRITE).
-        ] on:OpenError do:[:ex|
-           ex errorCategory ~~ #existingReferentSignal ifTrue:[
-                "some fundamental error, raise exception"
-                ex reject.
-            ].
-            prevNameString = nameString ifTrue:[
-                "no more names - probably a bad template"
-                ex reject.
-            ].
-            "file exists, retry another one"
-        ].
+	[
+	    stream := self open:newTempFilename withMode:#(CREATE_NEW GENERIC_READ_WRITE).
+	] on:OpenError do:[:ex|
+	   ex errorCategory ~~ #existingReferentSignal ifTrue:[
+		"some fundamental error, raise exception"
+		ex reject.
+	    ].
+	    prevNameString = nameString ifTrue:[
+		"no more names - probably a bad template"
+		ex reject.
+	    ].
+	    "file exists, retry another one"
+	].
     ] doWhile:[
-        stream isNil and:[prevNameString ~= nameString]   "/ if namestring didn't change, the template is bad
+	stream isNil and:[prevNameString ~= nameString]   "/ if namestring didn't change, the template is bad
     ].
     ^ stream
 
     "temp files in '/tmp':
 
-        FileStream newTemporaryIn:'/tmp' asFilename nameTemplate:'foo%1_%2'
+	FileStream newTemporaryIn:'/tmp' asFilename nameTemplate:'foo%1_%2'
 
      This must fail on the second try:
-        FileStream newTemporaryIn:'/tmp' asFilename nameTemplate:'foo'
-        FileStream newTemporaryIn:'c:\temp' asFilename nameTemplate:'foo'
+	FileStream newTemporaryIn:'/tmp' asFilename nameTemplate:'foo'
+	FileStream newTemporaryIn:'c:\temp' asFilename nameTemplate:'foo'
     "
 
     "temp files somewhere
@@ -893,19 +893,19 @@
      Therefore, this method is reimplemented here (from ExternalStream)"
 
     outStream isExternalStream ifTrue:[
-        pos := self position.
-        n := self size - pos.
-        nWritten := OperatingSystem
-                        copyFromFd:self fileDescriptor
-                        toFd:outStream fileDescriptor
-                        startIndex:pos
-                        count:n.
-        nWritten > 0 ifTrue:[
-            self position:pos+nWritten.
-        ].
-        nWritten = n ifTrue:[
-            ^ self
-        ].
+	pos := self position.
+	n := self size - pos.
+	nWritten := OperatingSystem
+			copyFromFd:self fileDescriptor
+			toFd:outStream fileDescriptor
+			startIndex:pos
+			count:n.
+	nWritten > 0 ifTrue:[
+	    self position:pos+nWritten.
+	].
+	nWritten = n ifTrue:[
+	    ^ self
+	].
     ].
     ^ super copyToEndInto:outStream bufferSize:bufferSize.
 
@@ -936,35 +936,35 @@
     off_t truncateSize;
 
     if ((fp != nil) && (__INST(mode) != @symbol(readonly))) {
-        if (__isSmallInteger(newSize)) {
-            truncateSize = __intVal(newSize);
-            if (truncateSize < 0) {
-                goto getOutOfHere;
-            }
-        } else {
-            truncateSize = __signedLongIntVal(newSize);
-            if (truncateSize < 0) {
-                goto getOutOfHere;
-            }
-            if (truncateSize == 0) {
-                if (sizeof(truncateSize) == 8) {
-                    if (__signedLong64IntVal(newSize, &truncateSize) == 0 || truncateSize < 0) {
-                        goto getOutOfHere;
-                    }
-                } else {
-                    goto getOutOfHere;
-                }
-            }
-        }
+	if (__isSmallInteger(newSize)) {
+	    truncateSize = __intVal(newSize);
+	    if (truncateSize < 0) {
+		goto getOutOfHere;
+	    }
+	} else {
+	    truncateSize = __signedLongIntVal(newSize);
+	    if (truncateSize < 0) {
+		goto getOutOfHere;
+	    }
+	    if (truncateSize == 0) {
+		if (sizeof(truncateSize) == 8) {
+		    if (__signedLong64IntVal(newSize, &truncateSize) == 0 || truncateSize < 0) {
+			goto getOutOfHere;
+		    }
+		} else {
+		    goto getOutOfHere;
+		}
+	    }
+	}
 
-        f = __FILEVal(fp);
+	f = __FILEVal(fp);
 
-        if (__INST(buffered) == true) {
-            fflush(f);
-            fseek(f, 0L, SEEK_END); /* needed in stdio */
-        }
-        ftruncate(fileno(f), truncateSize);
-        RETURN (self);
+	if (__INST(buffered) == true) {
+	    fflush(f);
+	    fseek(f, 0L, SEEK_END); /* needed in stdio */
+	}
+	ftruncate(fileno(f), truncateSize);
+	RETURN (self);
     }
 getOutOfHere: ;
 #endif
@@ -972,7 +972,7 @@
     handle isNil ifTrue:[self errorNotOpen. ^ self].
     (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
     newSize < 0 ifTrue:[
-        self error:'wrong arg'.
+	self error:'wrong arg'.
     ].
     self errorUnsupportedOperation
 
@@ -986,7 +986,7 @@
      s close.
 
      Transcript showCR:(f fileSize).
-     f remove.   
+     f remove.
     "
 ! !
 
@@ -1001,40 +1001,40 @@
     off_t currentPosition;
 
     if (__INST(handle) != nil) {
-        do {
-            f = __FILEVal(__INST(handle));
+	do {
+	    f = __FILEVal(__INST(handle));
 #ifdef WIN32
-            __threadErrno = 0;
-            if (__INST(buffered) == true) {
+	    __threadErrno = 0;
+	    if (__INST(buffered) == true) {
 # if 0
-                currentPosition = STX_C_CALL1( "ftell", ftell, f);
+		currentPosition = STX_C_CALL1( "ftell", ftell, f);
 # else
-                currentPosition = ftell(f);
-                __threadErrno = errno;
+		currentPosition = ftell(f);
+		__threadErrno = errno;
 # endif
-            } else {
-                OBJ rA = __INST(readAhead);
-                off_t offs = 0;
+	    } else {
+		OBJ rA = __INST(readAhead);
+		off_t offs = 0;
 
-                if (rA != nil) {
-                    __INST(readAhead) = nil;
-                    offs = -1;
-                }
+		if (rA != nil) {
+		    __INST(readAhead) = nil;
+		    offs = -1;
+		}
 # if 0
-                currentPosition = STX_C_CALL3( "lseek", lseek, fileno(f), offs, SEEK_CUR);
+		currentPosition = STX_C_CALL3( "lseek", lseek, fileno(f), offs, SEEK_CUR);
 # else
-                currentPosition = lseek(fileno(f), offs, SEEK_CUR);
-                __threadErrno = errno;
+		currentPosition = lseek(fileno(f), offs, SEEK_CUR);
+		__threadErrno = errno;
 # endif
-            }
+	    }
 #else /* !WIN32 */
-            if (__INST(buffered) == true) {
+	    if (__INST(buffered) == true) {
 #ifdef _LFS_LARGEFILE
-                currentPosition = ftello(f);
+		currentPosition = ftello(f);
 #else
-                currentPosition = ftell(f);
+		currentPosition = ftell(f);
 #endif /* ! _LFS_LARGEFILE */
-            } else {
+	    } else {
 		if (sizeof(off_t) == 8) {
                     currentPosition = lseek64(fileno(f), (off_t)0, SEEK_CUR);
                 } else {
@@ -1042,24 +1042,24 @@
                 }
             }
 #endif /* !WIN32 */
-        } while ((currentPosition < 0) && (__threadErrno == EINTR));
+	} while ((currentPosition < 0) && (__threadErrno == EINTR));
 
-        if (currentPosition >= 0) {
-            OBJ rslt;
+	if (currentPosition >= 0) {
+	    OBJ rslt;
 
-            if (sizeof(currentPosition) == 8) {
-                rslt = __MKINT64 (&currentPosition);
-            } else {
-                rslt = __MKINT(currentPosition);
-            }
-            RETURN ( rslt );
-        }
-        error = __mkSmallInteger(__threadErrno);
+	    if (sizeof(currentPosition) == 8) {
+		rslt = __MKINT64 (&currentPosition);
+	    } else {
+		rslt = __MKINT(currentPosition);
+	    }
+	    RETURN ( rslt );
+	}
+	error = __mkSmallInteger(__threadErrno);
     }
 %}.
     error notNil ifTrue:[
-        lastErrorNumber := error.
-        ^ self ioError:error.
+	lastErrorNumber := error.
+	^ self ioError:error.
     ].
     handle isNil ifTrue:[^ self errorNotOpen].
     ^ self primitiveFailed
@@ -1075,101 +1075,101 @@
     OBJ fp;
 
     if ((__INST(canPosition) != false) || (newPos == __mkSmallInteger(0))) {
-        if ((fp = __INST(handle)) != nil) {
+	if ((fp = __INST(handle)) != nil) {
 
 #if defined(_LFS_LARGE_FILE) && !defined(WIN32)
 # define FSEEK fseeko
-            off_t nP;
+	    off_t nP;
 #else
 #define FSEEK fseek
-            long nP;
+	    long nP;
 #endif
 
-            if (__isSmallInteger(newPos)) {
-                nP = __intVal(newPos);
-                if (nP < 0) {
-                    __INST(lastErrorNumber) = __mkSmallInteger(EINVAL);
-                    goto getOutOfHere;
-                }
-            } else {
-                nP = __signedLongIntVal(newPos);
-                if (nP < 0) {
-                    __INST(lastErrorNumber) = __mkSmallInteger(EINVAL);
-                    goto getOutOfHere;
-                }
-                if (nP == 0) {
-                    if (sizeof(nP) == 8) {
-                        if (__signedLong64IntVal(newPos, &nP) == 0 || nP < 0) {
-                            __INST(lastErrorNumber) = __mkSmallInteger(EINVAL);
-                            goto getOutOfHere;
-                        }
-                    } else {
-                        __INST(lastErrorNumber) = __mkSmallInteger(EINVAL);
-                        goto getOutOfHere;
-                    }
-                }
-            }
+	    if (__isSmallInteger(newPos)) {
+		nP = __intVal(newPos);
+		if (nP < 0) {
+		    __INST(lastErrorNumber) = __mkSmallInteger(EINVAL);
+		    goto getOutOfHere;
+		}
+	    } else {
+		nP = __signedLongIntVal(newPos);
+		if (nP < 0) {
+		    __INST(lastErrorNumber) = __mkSmallInteger(EINVAL);
+		    goto getOutOfHere;
+		}
+		if (nP == 0) {
+		    if (sizeof(nP) == 8) {
+			if (__signedLong64IntVal(newPos, &nP) == 0 || nP < 0) {
+			    __INST(lastErrorNumber) = __mkSmallInteger(EINVAL);
+			    goto getOutOfHere;
+			}
+		    } else {
+			__INST(lastErrorNumber) = __mkSmallInteger(EINVAL);
+			goto getOutOfHere;
+		    }
+		}
+	    }
 
-            f = __FILEVal(fp);
+	    f = __FILEVal(fp);
 
-            do {
+	    do {
 #if defined(DO_WRAP_CALL_FSEEK)
-                __threadErrno = 0;
-                if (__INST(buffered) == true) {
-                    ret = STX_C_CALL3( "fseek", fseek, f, nP, SEEK_SET);
-                } else {
-                    __INST(readAhead) = nil;
-                    ret = STX_C_CALL3( "lseek", lseek, fileno(f), nP, SEEK_SET);
-                }
+		__threadErrno = 0;
+		if (__INST(buffered) == true) {
+		    ret = STX_C_CALL3( "fseek", fseek, f, nP, SEEK_SET);
+		} else {
+		    __INST(readAhead) = nil;
+		    ret = STX_C_CALL3( "lseek", lseek, fileno(f), nP, SEEK_SET);
+		}
 #else
-                if (__INST(buffered) == true) {
-                    ret = FSEEK(f, nP, SEEK_SET);
-                } else {
+		if (__INST(buffered) == true) {
+		    ret = FSEEK(f, nP, SEEK_SET);
+		} else {
  #if !defined(__BORLANDC__)                
                     if (sizeof(nP) == 8)
                         ret = lseek64(fileno(f), nP, SEEK_SET);
                     else
 #endif
-                        ret = lseek(fileno(f), nP, SEEK_SET);      
-                }
-                __threadErrno = errno;
+		    ret = lseek(fileno(f), nP, SEEK_SET);
+		}
+		__threadErrno = errno;
 #endif
-            } while ((ret < 0) && (__threadErrno == EINTR));
-            if (ret >= 0) {
-                __INST(position) = newPos; __STORE(self, newPos);
-                /*
-                 * just to make certain ...
-                 */
-                __INST(hitEOF) = false;
-                RETURN ( self );
-            }
-            error = __mkSmallInteger(__threadErrno);
-        }
+	    } while ((ret < 0) && (__threadErrno == EINTR));
+	    if (ret >= 0) {
+		__INST(position) = newPos; __STORE(self, newPos);
+		/*
+		 * just to make certain ...
+		 */
+		__INST(hitEOF) = false;
+		RETURN ( self );
+	    }
+	    error = __mkSmallInteger(__threadErrno);
+	}
     }
     getOutOfHere: ;
 #undef FSEEK
 %}.
     canPosition == false ifTrue:[
-        "/ position by rewinding & re-reading everything up-to
-        "/ that point.
-        ^ self slowPosition:newPos
+	"/ position by rewinding & re-reading everything up-to
+	"/ that point.
+	^ self slowPosition:newPos
     ].
     error notNil ifTrue:[
-        lastErrorNumber := error.
-        (OperatingSystem errorSymbolForNumber:error) == #EINVAL ifTrue:[
-            "/ invalid position
-            ^ self positionError.
-        ].
-        "/ assume I/O error
-        ^ self ioError:error.
+	lastErrorNumber := error.
+	(OperatingSystem errorSymbolForNumber:error) == #EINVAL ifTrue:[
+	    "/ invalid position
+	    ^ self positionError.
+	].
+	"/ assume I/O error
+	^ self ioError:error.
     ].
     handle isNil ifTrue:[^ self errorNotOpen].
 
     rslt := self positionFile:handle position:newPos.
     rslt >= 0 ifTrue:[
-        position := newPos.
+	position := newPos.
     ] ifFalse:[
-        hitEOF := true.
+	hitEOF := true.
     ]
 !
 
@@ -1201,43 +1201,43 @@
     off_t ret;
 
     if (__INST(handle) != nil) {
-        f = __FILEVal(__INST(handle));
-        __INST(position) = nil;    /* i.e. unknown */
-        do {
+	f = __FILEVal(__INST(handle));
+	__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) {
+	    if (__INST(buffered) == true) {
 #ifdef _LFS_LARGE_FILE
-                ret = fseeko(f, (off_t)0, SEEK_END);
+		ret = fseeko(f, (off_t)0, SEEK_END);
 #else
-                ret = fseek(f, 0L, SEEK_END);
+		ret = fseek(f, 0L, SEEK_END);
 #endif
-            } else {
+	    } else {
                 if (sizeof(off_t) == 8) {
                     ret = lseek64(fileno(f), (off_t)0, SEEK_END);
                 } else {
-                    ret = lseek(fileno(f), (off_t)0, SEEK_END);
+		ret = lseek(fileno(f), (off_t)0, SEEK_END);
                 }
-            }
+	    }
 #endif
-        } while ((ret < 0) && (__threadErrno == EINTR));
-        if (ret >= 0) {
-            RETURN ( self );
-        }
-        error = __mkSmallInteger(__threadErrno);
+	} while ((ret < 0) && (__threadErrno == EINTR));
+	if (ret >= 0) {
+	    RETURN ( self );
+	}
+	error = __mkSmallInteger(__threadErrno);
     }
 %}.
     error notNil ifTrue:[
-        lastErrorNumber := error.
-        self ioError:error.
-        ^ self.    
+	lastErrorNumber := error.
+	self ioError:error.
+	^ self.
     ].
     handle isNil ifTrue:[^ self errorNotOpen].
     ^ self primitiveFailed
@@ -1249,28 +1249,28 @@
      This is required to reposition nonPositionable streams, such
      as tape-streams or variable-record-RMS files under VMS.
      Caveat:
-         This should really be done transparently by the stdio library."
+	 This should really be done transparently by the stdio library."
 
     |buffer amount pos0Based|
 
     self isReadable ifFalse:[
-        "/ sorry
-        ^ self positionError
+	"/ sorry
+	^ self positionError
     ].
 
     buffer := ByteArray new:8*1024.
 
     (position isNil "/ i.e. unknown
     or:[newPos < (pos0Based := self position)]) ifTrue:[
-        self reset.
-        pos0Based := self position.
+	self reset.
+	pos0Based := self position.
     ].
     [pos0Based < newPos] whileTrue:[
-        amount := (buffer size) min:(newPos-pos0Based).
-        (self nextBytes:amount into:buffer startingAt:1) ~~ amount ifTrue:[
-            ^ self positionError
-        ].
-        pos0Based := self position.
+	amount := (buffer size) min:(newPos-pos0Based).
+	(self nextBytes:amount into:buffer startingAt:1) ~~ amount ifTrue:[
+	    ^ self positionError
+	].
+	pos0Based := self position.
     ].
     "/ ('FileStream [info]: slow position - please convert ''' , pathName printString , ''' to streamLF format') infoPrintCR.
 ! !
@@ -1362,369 +1362,369 @@
     int pass = 0;
 
     if (!__isNonNilObject(encodedPathName)
-        || !(__isStringLike(openmode) || __isArrayLike(openmode)))
-            goto badArgument;
+	|| !(__isStringLike(openmode) || __isArrayLike(openmode)))
+	    goto badArgument;
 
 retry:
 #ifdef __VMS__
       if (__isStringLike(encodedPathName)) {
-        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 (! __isStringLike(ap[i])) {
-                            __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:
-                            __threadErrno = E2BIG; /* too many args */
-                            goto getOutOfHere;
-                    }
-                } else if (attributeSpec != nil) {
-                    __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 (! __isStringLike(ap[i])) {
+			    __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:
+			    __threadErrno = E2BIG; /* too many args */
+			    goto getOutOfHere;
+		    }
+		} else if (attributeSpec != nil) {
+		    __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
     {
-          DWORD share = 0, access = 0, create = 0, attr = 0;
-          char * __openmode;
-          HANDLE handle;
-          SECURITY_ATTRIBUTES sa;
+	  DWORD share = 0, access = 0, create = 0, attr = 0;
+	  char * __openmode;
+	  HANDLE handle;
+	  SECURITY_ATTRIBUTES sa;
 
-          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_EXISTING;
-              } 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)) {
-              OBJ *ap = __arrayVal(openmode);
-              int numAttrib = __arraySize(openmode);
-              int i;
+	  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_EXISTING;
+	      } 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)) {
+	      OBJ *ap = __arrayVal(openmode);
+	      int numAttrib = __arraySize(openmode);
+	      int i;
 
-              __openmode = "rb+";
+	      __openmode = "rb+";
 
-              for (i=0; i<numAttrib; i++) {
-                  OBJ attrSym = ap[i];
+	      for (i=0; i<numAttrib; i++) {
+		  OBJ attrSym = ap[i];
 
-                  if (attrSym == @symbol(FILE_SHARE_READ)) {
-                      share |= FILE_SHARE_READ;
-                  } else if (attrSym == @symbol(FILE_SHARE_WRITE)) {
-                      share |= FILE_SHARE_WRITE;
+		  if (attrSym == @symbol(FILE_SHARE_READ)) {
+		      share |= FILE_SHARE_READ;
+		  } else if (attrSym == @symbol(FILE_SHARE_WRITE)) {
+		      share |= FILE_SHARE_WRITE;
 
-                  } else if (attrSym == @symbol(GENERIC_READ)) {
-                      access |= GENERIC_READ;
-                  } else if (attrSym == @symbol(GENERIC_WRITE)) {
-                      access |= GENERIC_WRITE;
-                  } else if (attrSym == @symbol(GENERIC_READ_WRITE)) {
-                      access |= GENERIC_READ|GENERIC_WRITE;
+		  } else if (attrSym == @symbol(GENERIC_READ)) {
+		      access |= GENERIC_READ;
+		  } else if (attrSym == @symbol(GENERIC_WRITE)) {
+		      access |= GENERIC_WRITE;
+		  } else if (attrSym == @symbol(GENERIC_READ_WRITE)) {
+		      access |= GENERIC_READ|GENERIC_WRITE;
 
-                  } else if (attrSym == @symbol(CREATE_NEW)) {
-                      create |= CREATE_NEW;
-                  } else if (attrSym == @symbol(CREATE_ALWAYS)) {
-                      create |= CREATE_ALWAYS;
-                  } else if (attrSym == @symbol(OPEN_EXISTING)) {
-                      create |= OPEN_EXISTING;
-                  } else if (attrSym == @symbol(OPEN_ALWAYS)) {
-                      create |= OPEN_ALWAYS;
-                  } else if (attrSym == @symbol(TRUNCATE_EXISTING)) {
-                      create |= TRUNCATE_EXISTING;
+		  } else if (attrSym == @symbol(CREATE_NEW)) {
+		      create |= CREATE_NEW;
+		  } else if (attrSym == @symbol(CREATE_ALWAYS)) {
+		      create |= CREATE_ALWAYS;
+		  } else if (attrSym == @symbol(OPEN_EXISTING)) {
+		      create |= OPEN_EXISTING;
+		  } else if (attrSym == @symbol(OPEN_ALWAYS)) {
+		      create |= OPEN_ALWAYS;
+		  } else if (attrSym == @symbol(TRUNCATE_EXISTING)) {
+		      create |= TRUNCATE_EXISTING;
 
-                  } else if (attrSym == @symbol(FILE_ATTRIBUTE_HIDDEN)) {
-                      attr |= FILE_ATTRIBUTE_HIDDEN;
-                  } else if (attrSym == @symbol(FILE_ATTRIBUTE_READONLY)) {
-                      attr |= FILE_ATTRIBUTE_READONLY;
-                  } else if (attrSym == @symbol(FILE_FLAG_WRITE_THROUGH)) {
-                      attr |= FILE_FLAG_WRITE_THROUGH;
-                  } else if (attrSym == @symbol(FILE_FLAG_SEQUENTIAL_SCAN)) {
-                      attr |= FILE_FLAG_SEQUENTIAL_SCAN;
-                  } else if (attrSym == @symbol(FILE_FLAG_DELETE_ON_CLOSE)) {
-                      attr |= FILE_FLAG_DELETE_ON_CLOSE;
-                  } else if (!__isSymbol(attrSym) && __isStringLike(attrSym)) {
-                      __openmode = __stringVal(attrSym);
-                  } else {
-                      console_fprintf(stderr, "Win32OS [warning]: unsupported open mode\n");
-                  }
-              }
-          }
-          if (create == 0) {
+		  } else if (attrSym == @symbol(FILE_ATTRIBUTE_HIDDEN)) {
+		      attr |= FILE_ATTRIBUTE_HIDDEN;
+		  } else if (attrSym == @symbol(FILE_ATTRIBUTE_READONLY)) {
+		      attr |= FILE_ATTRIBUTE_READONLY;
+		  } else if (attrSym == @symbol(FILE_FLAG_WRITE_THROUGH)) {
+		      attr |= FILE_FLAG_WRITE_THROUGH;
+		  } else if (attrSym == @symbol(FILE_FLAG_SEQUENTIAL_SCAN)) {
+		      attr |= FILE_FLAG_SEQUENTIAL_SCAN;
+		  } else if (attrSym == @symbol(FILE_FLAG_DELETE_ON_CLOSE)) {
+		      attr |= FILE_FLAG_DELETE_ON_CLOSE;
+		  } else if (!__isSymbol(attrSym) && __isStringLike(attrSym)) {
+		      __openmode = __stringVal(attrSym);
+		  } else {
+		      console_fprintf(stderr, "Win32OS [warning]: unsupported open mode\n");
+		  }
+	      }
+	  }
+	  if (create == 0) {
 //              argumentError = @symbol(missingCreateMode);
-              goto badArgument;
-          }
-          if (attr == 0) {
-              attr = FILE_ATTRIBUTE_NORMAL;
-          }
+	      goto badArgument;
+	  }
+	  if (attr == 0) {
+	      attr = FILE_ATTRIBUTE_NORMAL;
+	  }
 
-          /*
-           * create security attributes - make handle inheritable by subprocesses
-           */
-          memset(&sa, 0, sizeof (sa));
-          sa.nLength = sizeof( sa );
-          // sa.bInheritHandle = TRUE;
-          sa.bInheritHandle = FALSE;
+	  /*
+	   * create security attributes - make handle inheritable by subprocesses
+	   */
+	  memset(&sa, 0, sizeof (sa));
+	  sa.nLength = sizeof( sa );
+	  // sa.bInheritHandle = TRUE;
+	  sa.bInheritHandle = FALSE;
 
-          if (__isStringLike(pathName)) {
-                char _aPathName[MAXPATHLEN];
+	  if (__isStringLike(pathName)) {
+		char _aPathName[MAXPATHLEN];
 
-                strncpy(_aPathName, __stringVal(pathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
-                do {
-                    __threadErrno = 0;
-                    handle = STX_API_NOINT_CALL7( "CreateFileA", CreateFileA, _aPathName, access, share, &sa, create, attr, 0 /* hTempl */);
-                    if (__threadErrno == EINTR) {
-                        handle = INVALID_HANDLE_VALUE;
-                    }
-                } while ((handle == INVALID_HANDLE_VALUE) && (__threadErrno == EINTR));
-          } else if (__isUnicode16String(pathName)) {
-                wchar_t _aPathName[MAXPATHLEN+1];
-                int i, l;
+		strncpy(_aPathName, __stringVal(pathName), MAXPATHLEN-1); _aPathName[MAXPATHLEN-1] = '\0';
+		do {
+		    __threadErrno = 0;
+		    handle = STX_API_NOINT_CALL7( "CreateFileA", CreateFileA, _aPathName, access, share, &sa, create, attr, 0 /* hTempl */);
+		    if (__threadErrno == EINTR) {
+			handle = INVALID_HANDLE_VALUE;
+		    }
+		} while ((handle == INVALID_HANDLE_VALUE) && (__threadErrno == EINTR));
+	  } else if (__isUnicode16String(pathName)) {
+		wchar_t _aPathName[MAXPATHLEN+1];
+		int i, l;
 
-                l = __unicode16StringSize(pathName);
-                if (l > MAXPATHLEN) l = MAXPATHLEN;
-                for (i=0; i<l; i++) {
-                    _aPathName[i] = __unicode16StringVal(pathName)[i];
-                }
-                _aPathName[i] = 0;
+		l = __unicode16StringSize(pathName);
+		if (l > MAXPATHLEN) l = MAXPATHLEN;
+		for (i=0; i<l; i++) {
+		    _aPathName[i] = __unicode16StringVal(pathName)[i];
+		}
+		_aPathName[i] = 0;
 
-                do {
-                    __threadErrno = 0;
-                    handle = STX_API_NOINT_CALL7( "CreateFileW", CreateFileW, _aPathName, access, share, &sa, create, attr, 0 /* hTempl */);
-                    if (__threadErrno == EINTR) {
-                        handle = INVALID_HANDLE_VALUE;
-                    }
-                } while ((handle == INVALID_HANDLE_VALUE) && (__threadErrno == EINTR));
-          }
-          if (handle != INVALID_HANDLE_VALUE) {
-              int fd;
-              extern void __stxWrapApiEnterCritical(), __stxWrapApiLeaveCritical();
+		do {
+		    __threadErrno = 0;
+		    handle = STX_API_NOINT_CALL7( "CreateFileW", CreateFileW, _aPathName, access, share, &sa, create, attr, 0 /* hTempl */);
+		    if (__threadErrno == EINTR) {
+			handle = INVALID_HANDLE_VALUE;
+		    }
+		} while ((handle == INVALID_HANDLE_VALUE) && (__threadErrno == EINTR));
+	  }
+	  if (handle != INVALID_HANDLE_VALUE) {
+	      int fd;
+	      extern void __stxWrapApiEnterCritical(), __stxWrapApiLeaveCritical();
 
-              __stxWrapApiEnterCritical();
-              fd = _open_osfhandle((long)handle, O_BINARY);
-              if (fd < 0) {
-                  if (__threadErrno == 0) {
-                      // no more file descriptors
-                      __threadErrno = EMFILE;
-                  }
-                  CloseHandle(handle);
-              } else {
-                  f = fdopen(fd, __openmode);
-              }
-              __stxWrapApiLeaveCritical();
-          }  else {
-            __threadErrno = __WIN32_ERR(GetLastError());
-          }
+	      __stxWrapApiEnterCritical();
+	      fd = _open_osfhandle((long)handle, O_BINARY);
+	      if (fd < 0) {
+		  if (__threadErrno == 0) {
+		      // no more file descriptors
+		      __threadErrno = EMFILE;
+		  }
+		  CloseHandle(handle);
+	      } else {
+		  f = fdopen(fd, __openmode);
+	      }
+	      __stxWrapApiLeaveCritical();
+	  }  else {
+	    __threadErrno = __WIN32_ERR(GetLastError());
+	  }
       }
 # else /* not WIN32 */
 
       if (__isStringLike(encodedPathName)) {
-          int accessMode = 0666;        // default access mode of fopen(), relies on umask()
-          int flags = 0;
-          int fd;
-          char * __openmode;
+	  int accessMode = 0666;        // default access mode of fopen(), relies on umask()
+	  int flags = 0;
+	  int fd;
+	  char * __openmode;
 
-          if (__isStringLike(openmode)) {
-              __openmode = __stringVal(openmode);
-              if (strcmp(__openmode, "r") == 0) {
-                  flags = O_RDONLY;
-              } else if (strcmp(__openmode, "r+") == 0) {
-                  flags = O_RDWR;
-              } else if (strcmp(__openmode, "w") == 0) {
-                  flags = O_WRONLY | O_CREAT | O_TRUNC;
-              } else if (strcmp(__openmode, "w+") == 0) {
-                  flags = O_RDWR | O_CREAT | O_TRUNC;
-              } else if (strcmp(__openmode, "a") == 0) {
-                  flags = O_WRONLY | O_CREAT | O_APPEND;
-              } else if (strcmp(__openmode, "a+") == 0) {
-                  flags = O_RDWR | O_CREAT| O_APPEND;
-              } else {
-                  console_fprintf(stderr, "UNIXOS [warning]: unsupported open mode\n");
-              }
-          } else if (__isArrayLike(openmode)) {
-              OBJ *ap = __arrayVal(openmode);
-              int numAttrib = __arraySize(openmode);
-              int i;
+	  if (__isStringLike(openmode)) {
+	      __openmode = __stringVal(openmode);
+	      if (strcmp(__openmode, "r") == 0) {
+		  flags = O_RDONLY;
+	      } else if (strcmp(__openmode, "r+") == 0) {
+		  flags = O_RDWR;
+	      } else if (strcmp(__openmode, "w") == 0) {
+		  flags = O_WRONLY | O_CREAT | O_TRUNC;
+	      } else if (strcmp(__openmode, "w+") == 0) {
+		  flags = O_RDWR | O_CREAT | O_TRUNC;
+	      } else if (strcmp(__openmode, "a") == 0) {
+		  flags = O_WRONLY | O_CREAT | O_APPEND;
+	      } else if (strcmp(__openmode, "a+") == 0) {
+		  flags = O_RDWR | O_CREAT| O_APPEND;
+	      } else {
+		  console_fprintf(stderr, "UNIXOS [warning]: unsupported open mode\n");
+	      }
+	  } else if (__isArrayLike(openmode)) {
+	      OBJ *ap = __arrayVal(openmode);
+	      int numAttrib = __arraySize(openmode);
+	      int i;
 
-              __openmode = "r+";
+	      __openmode = "r+";
 
-              for (i=0; i<numAttrib; i++) {
-                  OBJ attrSym = ap[i];
+	      for (i=0; i<numAttrib; i++) {
+		  OBJ attrSym = ap[i];
 
-                  if (attrSym == @symbol(FILE_SHARE_READ)) {
-                      // ignore
-                  } else if (attrSym == @symbol(FILE_SHARE_WRITE)) {
-                     // ignore
-                  } else if (attrSym == @symbol(GENERIC_READ)) {
-                      flags |= O_RDONLY;
-                  } else if (attrSym == @symbol(GENERIC_WRITE)) {
-                      flags |= O_WRONLY;
-                  } else if (attrSym == @symbol(GENERIC_READ_WRITE)) {
-                      flags |= O_RDWR;
+		  if (attrSym == @symbol(FILE_SHARE_READ)) {
+		      // ignore
+		  } else if (attrSym == @symbol(FILE_SHARE_WRITE)) {
+		     // ignore
+		  } else if (attrSym == @symbol(GENERIC_READ)) {
+		      flags |= O_RDONLY;
+		  } else if (attrSym == @symbol(GENERIC_WRITE)) {
+		      flags |= O_WRONLY;
+		  } else if (attrSym == @symbol(GENERIC_READ_WRITE)) {
+		      flags |= O_RDWR;
 
-                  } else if (attrSym == @symbol(CREATE_NEW)) {
-                      flags |= O_CREAT|O_EXCL;
-                      accessMode = 0600;     // simulate mkstemp()
-                  } else if (attrSym == @symbol(CREATE_ALWAYS)) {
-                      flags |= O_CREAT|O_TRUNC;
-                  } else if (attrSym == @symbol(OPEN_EXISTING)) {
-                      // nothing to be set
-                  } else if (attrSym == @symbol(OPEN_ALWAYS)) {
-                      flags |= O_CREAT;
-                  } else if (attrSym == @symbol(TRUNCATE_EXISTING)) {
-                      flags |= O_TRUNC;
+		  } else if (attrSym == @symbol(CREATE_NEW)) {
+		      flags |= O_CREAT|O_EXCL;
+		      accessMode = 0600;     // simulate mkstemp()
+		  } else if (attrSym == @symbol(CREATE_ALWAYS)) {
+		      flags |= O_CREAT|O_TRUNC;
+		  } else if (attrSym == @symbol(OPEN_EXISTING)) {
+		      // nothing to be set
+		  } else if (attrSym == @symbol(OPEN_ALWAYS)) {
+		      flags |= O_CREAT;
+		  } else if (attrSym == @symbol(TRUNCATE_EXISTING)) {
+		      flags |= O_TRUNC;
 
-                  } else if (attrSym == @symbol(FILE_ATTRIBUTE_HIDDEN)) {
-                      // ignore
-                  } else if (attrSym == @symbol(FILE_ATTRIBUTE_READONLY)) {
-                      accessMode &= 0444;
-                  } else if (attrSym == @symbol(FILE_FLAG_WRITE_THROUGH)) {
+		  } else if (attrSym == @symbol(FILE_ATTRIBUTE_HIDDEN)) {
+		      // ignore
+		  } else if (attrSym == @symbol(FILE_ATTRIBUTE_READONLY)) {
+		      accessMode &= 0444;
+		  } else if (attrSym == @symbol(FILE_FLAG_WRITE_THROUGH)) {
 #ifdef O_DIRECT
-                      flags |= O_DIRECT;
+		      flags |= O_DIRECT;
 #endif
-                  } else if (attrSym == @symbol(FILE_FLAG_SEQUENTIAL_SCAN)) {
-                      // ignore
-                  } else if (attrSym == @symbol(FILE_FLAG_DELETE_ON_CLOSE)) {
-                      // ignore;
-                  } else if (!__isSymbol(attrSym) && __isStringLike(attrSym)) {
-                      __openmode = __stringVal(attrSym);
-                  } else {
-                      console_fprintf(stderr, "UNIXOS [warning]: unsupported open mode\n");
-                  }
-              }
-          }
-          do {
-              __BEGIN_INTERRUPTABLE__
-              fd = open((char *) __stringVal(encodedPathName), flags, accessMode);
-              __END_INTERRUPTABLE__
-          } while ((fd < 0) && (__threadErrno == EINTR));
+		  } else if (attrSym == @symbol(FILE_FLAG_SEQUENTIAL_SCAN)) {
+		      // ignore
+		  } else if (attrSym == @symbol(FILE_FLAG_DELETE_ON_CLOSE)) {
+		      // ignore;
+		  } else if (!__isSymbol(attrSym) && __isStringLike(attrSym)) {
+		      __openmode = __stringVal(attrSym);
+		  } else {
+		      console_fprintf(stderr, "UNIXOS [warning]: unsupported open mode\n");
+		  }
+	      }
+	  }
+	  do {
+	      __BEGIN_INTERRUPTABLE__
+	      fd = open((char *) __stringVal(encodedPathName), flags, accessMode);
+	      __END_INTERRUPTABLE__
+	  } while ((fd < 0) && (__threadErrno == EINTR));
 
-          if (fd >= 0) {
-              __threadErrno = 0;
-              f = fdopen(fd, __openmode);
-              if (f == NULL) {
-                  close(fd);            // fdopen failed, close before retry.
-              }
-          }
+	  if (fd >= 0) {
+	      __threadErrno = 0;
+	      f = fdopen(fd, __openmode);
+	      if (f == NULL) {
+		  close(fd);            // fdopen failed, close before retry.
+	      }
+	  }
       }
 
 # endif /* not WIN32 */
@@ -1732,81 +1732,81 @@
 
 
     if (f == NULL) {
-        /*
-         * If no filedescriptors available, try to finalize
-         * possibly collected fd's and try again.
-         */
-        if ((__threadErrno == ENFILE || __threadErrno == EMFILE) && pass == 0) {
-            pass = 1;
-            __SSEND0(@global(ObjectMemory), @symbol(scavenge), 0);
-            __SSEND0(@global(ObjectMemory), @symbol(finalize), 0);
-            goto retry;
-        }
+	/*
+	 * If no filedescriptors available, try to finalize
+	 * possibly collected fd's and try again.
+	 */
+	if ((__threadErrno == ENFILE || __threadErrno == EMFILE) && pass == 0) {
+	    pass = 1;
+	    __SSEND0(@global(ObjectMemory), @symbol(scavenge), 0);
+	    __SSEND0(@global(ObjectMemory), @symbol(finalize), 0);
+	    goto retry;
+	}
     badArgument:
     getOutOfHere:
-        error = __mkSmallInteger(__threadErrno);
-        __INST(position) = nil;
+	error = __mkSmallInteger(__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 /* 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] -> %"_lx_"\n", __stringVal(pathName), (INT)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
-        }
+	}
     }
 %}.
     error notNil ifTrue:[
-        lastErrorNumber := error.
-        ^ self openError:error.
+	lastErrorNumber := error.
+	^ self openError:error.
     ].
     handle isNil ifTrue:[
-        ^ self openError:0.
+	^ self openError:0.
     ].
 
     position := 0.
@@ -1886,12 +1886,12 @@
 
     handle := self openFile:pathName withMode:openmode attributes:attributeSpec.
     handle isNil ifTrue:[
-        "this happens, if proceeding from an OpenError raised in #openFile..."
-        ^ nil.
+	"this happens, if proceeding from an OpenError raised in #openFile..."
+	^ nil.
     ].
     position := 0.
     buffered isNil ifTrue:[
-        buffered := true.       "default is buffered"
+	buffered := true.       "default is buffered"
     ].
 !
 
@@ -2026,10 +2026,10 @@
     unsigned int size;
 
     if (__INST(handle) != nil) {
-        f = __FILEVal(__INST(handle));
-        if ((size = filesize(fileno(f))) >= 0) {
-            RETURN ( __MKUINT(size) );
-        }
+	f = __FILEVal(__INST(handle));
+	if ((size = filesize(fileno(f))) >= 0) {
+	    RETURN ( __MKUINT(size) );
+	}
     }
 #else
     struct stat buf;
@@ -2037,38 +2037,38 @@
     int fd;
 
     if (__INST(handle) != nil) {
-        f = __FILEVal(__INST(handle));
-        fd = fileno(f);
-        do {
-            ret = fstat(fd, &buf);
-        } while ((ret < 0) && (__threadErrno == EINTR));
-        if (ret >= 0) {
-            OBJ rslt;
+	f = __FILEVal(__INST(handle));
+	fd = fileno(f);
+	do {
+	    ret = fstat(fd, &buf);
+	} while ((ret < 0) && (__threadErrno == EINTR));
+	if (ret >= 0) {
+	    OBJ rslt;
 
-            if (sizeof(buf.st_size) == 8) {
-                rslt = __MKINT64(&buf.st_size);
-            } else {
-                rslt = __MKINT(buf.st_size);
-            }
-            RETURN(rslt);
-        }
-        error = __mkSmallInteger(__threadErrno);
+	    if (sizeof(buf.st_size) == 8) {
+		rslt = __MKINT64(&buf.st_size);
+	    } else {
+		rslt = __MKINT(buf.st_size);
+	    }
+	    RETURN(rslt);
+	}
+	error = __mkSmallInteger(__threadErrno);
     }
 #endif
 %}.
 
     "could add a fall-back here:
 
-        oldPosition := self position.
-        self setToEnd.
-        sz := self position.
-        self position:oldPosition.
-        ^ sz
+	oldPosition := self position.
+	self setToEnd.
+	sz := self position.
+	self position:oldPosition.
+	^ sz
     "
     error notNil ifTrue:[
-        lastErrorNumber := error.
-        self ioError:error.
-        ^ self.    
+	lastErrorNumber := error.
+	self ioError:error.
+	^ self.
     ].
     handle isNil ifTrue:[^ self errorNotOpen].
     ^ self primitiveFailed
@@ -2119,11 +2119,11 @@
 !FileStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.180 2015-03-12 13:52:37 stefan Exp $'
+    ^ '$Header$'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.180 2015-03-12 13:52:37 stefan Exp $'
+    ^ '$Header$'
 ! !