#QUALITY by stefan
authorStefan Vogel <sv@exept.de>
Thu, 14 Sep 2017 15:10:57 +0200
changeset 22253 e1b728149a94
parent 22252 097e84ab142e
child 22254 30d452a7c004
#QUALITY by stefan class: Win32OperatingSystem class changed: #openFile:attributes: class: Win32OperatingSystem::Win32FileHandle class definition class: Win32OperatingSystem::Win32FileHandle class added: #documentation Introduce and use Win32OperatingSystem::Win32FileHandle (used instead of Win32Handle - which is now a superclass)
Win32OperatingSystem.st
--- a/Win32OperatingSystem.st	Thu Sep 14 12:35:59 2017 +0200
+++ b/Win32OperatingSystem.st	Thu Sep 14 15:10:57 2017 +0200
@@ -180,6 +180,13 @@
 	privateIn:Win32OperatingSystem
 !
 
+Win32OperatingSystem::Win32IOHandle subclass:#Win32FileHandle
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:Win32OperatingSystem
+!
+
 Win32Handle subclass:#Win32MutexHandle
 	instanceVariableNames:''
 	classVariableNames:''
@@ -1009,6 +1016,7 @@
     "Modified: 7.1.1997 / 19:36:11 / stefan"
 ! !
 
+
 !Win32OperatingSystem class methodsFor:'OS signal constants'!
 
 sigABRT
@@ -4780,7 +4788,7 @@
 
     |fileHandle errorNumber argumentError|
 
-    fileHandle := Win32Handle new.
+    fileHandle := Win32FileHandle new.
 
 %{
     HANDLE h;
@@ -4792,19 +4800,19 @@
     DWORD access, share, create, attr;
 
     if (__isStringLike(pathName)) {
-	name = __stringVal(pathName);
+        name = __stringVal(pathName);
     } else if (__isUnicode16String(pathName)) {
-	_makeWchar(pathName, _wPathName, sizeof(_wPathName));
+        _makeWchar(pathName, _wPathName, sizeof(_wPathName));
     } else {
-	fileHandle = nil;
-	argumentError = @symbol(badPathName);
-	goto badArgument;
+        fileHandle = nil;
+        argumentError = @symbol(badPathName);
+        goto badArgument;
     }
 
     if (! __isArrayLike(attributeSpec)) {
-	fileHandle = nil;
-	argumentError = @symbol(badAttributeSpec);
-	goto badArgument;
+        fileHandle = nil;
+        argumentError = @symbol(badAttributeSpec);
+        goto badArgument;
     }
     ap = __ArrayInstPtr(attributeSpec)->a_element;
     numAttrib = __arraySize(attributeSpec);
@@ -4815,79 +4823,79 @@
     attr = 0;
 
     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;
-
-	} else if (attrSym == @symbol(GENERIC_READ)) {
-	    access |= GENERIC_READ;
-	} else if (attrSym == @symbol(GENERIC_WRITE)) {
-	    access |= 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(FILE_ATTRIBUTE_HIDDEN)) {
-	    attr |= FILE_ATTRIBUTE_HIDDEN;
-	} else if (attrSym == @symbol(FILE_ATTRIBUTE_READONLY)) {
-	    attr |= FILE_ATTRIBUTE_READONLY;
-	} 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 {
-	    console_fprintf(stderr, "Win32OS [warning]: unsupported open mode\n");
-	}
+        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;
+
+        } else if (attrSym == @symbol(GENERIC_READ)) {
+            access |= GENERIC_READ;
+        } else if (attrSym == @symbol(GENERIC_WRITE)) {
+            access |= 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(FILE_ATTRIBUTE_HIDDEN)) {
+            attr |= FILE_ATTRIBUTE_HIDDEN;
+        } else if (attrSym == @symbol(FILE_ATTRIBUTE_READONLY)) {
+            attr |= FILE_ATTRIBUTE_READONLY;
+        } 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 {
+            console_fprintf(stderr, "Win32OS [warning]: unsupported open mode\n");
+        }
     }
     if (create == 0) {
-	fileHandle = nil;
-	argumentError = @symbol(missingCreateMode);
-	goto badArgument;
+        fileHandle = nil;
+        argumentError = @symbol(missingCreateMode);
+        goto badArgument;
     }
 #ifdef PROCESSDEBUGWIN32
     if (flag_PROCESSDEBUGWIN32) {
-	console_fprintf(stderr, "name:<%s> access:%x share:%x create:%x attr:%x\n",
-			name, access, share, create, attr);
+        console_fprintf(stderr, "name:<%s> access:%x share:%x create:%x attr:%x\n",
+                        name, access, share, create, attr);
     }
 #endif
     if (__isStringLike(pathName)) {
-	h = CreateFileA(name, access, share, 0 /* sa */, create, attr, 0 /* hTempl */);
+        h = CreateFileA(name, access, share, 0 /* sa */, create, attr, 0 /* hTempl */);
     } else {
-	h = CreateFileW(_wPathName, access, share, 0 /* sa */, create, attr, 0 /* hTempl */);
+        h = CreateFileW(_wPathName, access, share, 0 /* sa */, create, attr, 0 /* hTempl */);
     }
 
     if (h != INVALID_HANDLE_VALUE) {
-	__externalAddressVal(fileHandle) = (void *)h;
+        __externalAddressVal(fileHandle) = (void *)h;
     } else {
-	fileHandle = nil;
-	errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
+        fileHandle = nil;
+        errorNumber = __mkSmallInteger( __WIN32_ERR(GetLastError()) );
     }
 
 badArgument: ;
 %}.
     fileHandle notNil ifTrue:[
-	fileHandle registerForFinalization.
-	^ fileHandle.
+        fileHandle registerForFinalization.
+        ^ fileHandle.
     ].
     errorNumber isNil ifTrue:[
-	self error:'invalid argument(s): ', argumentError.
+        self error:'invalid argument(s): ', argumentError.
     ] ifFalse:[
-	(self errorHolderForNumber:errorNumber) reportError
+        (self errorHolderForNumber:errorNumber) reportError
     ].
 !
 
@@ -17772,6 +17780,17 @@
     self unregisterForFinalization.
 ! !
 
+!Win32OperatingSystem::Win32FileHandle class methodsFor:'documentation'!
+
+documentation
+"
+    I represent a handle of a file in the filesystem.
+
+    [author:]
+        Stefan Vogel
+"
+! !
+
 !Win32OperatingSystem::Win32MutexHandle class methodsFor:'documentation'!
 
 documentation