Win32OperatingSystem.st
branchjv
changeset 20342 219a5a47e8b1
parent 20248 34ed3b6c7307
parent 20287 35435b0b712c
child 20344 152b525b5c63
--- a/Win32OperatingSystem.st	Sat Aug 13 06:52:18 2016 +0200
+++ b/Win32OperatingSystem.st	Tue Aug 23 09:54:28 2016 +0100
@@ -775,20 +775,22 @@
 
 documentation
 "
-    this class resulted from extracting WIN32 specifics of the old
+    This class resulted from extracting WIN32 specifics of the old
     OperatingSystemClass into this sub-class.
-    You may find some leftover unix stuff, which will go away sooner
-    or later.
-
-    this class realizes access to most (all ?) required operating system services;
-    some of it is very specific for unix, so do not depend on
-    things available here in your applications
-    - some may not be found in other OS's or be slightly different ...
-
-    (On the other hand: I do not want to hide all features
-     from you - in some situations it MAY be interesting to be
-     able to get down to a select or fork system call easily (at least on Unix systems).
-     You decide - portability vs. functionality)
+
+    This class realizes required operating system services for MS-Windows systems.
+    The name is misleading and a historic leftover: it supports both 32bit and 64bit OSes.
+
+    Some of it is very specific for windows, so do not depend on
+    things available here if your application runs under unix/linux/osx
+    Some may not be found in other OS's or be slightly different.
+    On the other hand: I do not want to hide all features
+    from you - in some situations it MAY be interesting to be
+    able to get down to a low level system call easily.
+    If you use sch features, make sure that you wrap the call into a condition,
+    such as 'OperatingSystem isMSWINDOWSlike ifTrue:[...]'
+
+    You decide - portability vs. functionality)
 
     [Class variables:]
 
@@ -1756,10 +1758,11 @@
     if ((dirPointer != nil)
     && __isExternalAddressLike(dirPointer)) {
 	// __INST(lastErrorNumber) = nil;
-	d = __externalAddressVal(dirPointer);
+	d = _HANDLEVal(dirPointer);
 
 	do {
 	    __threadErrno = 0;
+	    // do not cast to INT - will loose sign bit then!
 	    rslt = (int)(STX_API_NOINT_CALL2( "FindNextFileW", FindNextFileW, d, &data ));
 	} while ((rslt < 0) && (__threadErrno == EINTR));
 
@@ -4210,7 +4213,7 @@
 	shExecInfo.lpDirectory   = (lpDirectoryArg != nil) ? __stringVal(lpDirectoryArg) : NULL;
 	if (hwndArg != nil) {
 	    if (__isExternalAddressLike(hwndArg)) {
-		shExecInfo.hwnd = (HANDLE)(__externalAddressVal(hwndArg));
+		shExecInfo.hwnd = _HANDLEVal(hwndArg);
 	    } else
 		goto badArgument;
 	}
@@ -4292,31 +4295,31 @@
     shellAndArgs := self commandAndArgsForOSCommand:aCommandString.
 
     (in := anExternalInStream) isNil ifTrue:[
-        nullStream := Filename nullDevice readWriteStream.
-        in := nullStream.
+	nullStream := Filename nullDevice readWriteStream.
+	in := nullStream.
     ].
     (out := anExternalOutStream) isNil ifTrue:[
-        nullStream isNil ifTrue:[nullStream := Filename nullDevice writeStream].
-        out := nullStream.
+	nullStream isNil ifTrue:[nullStream := Filename nullDevice writeStream].
+	out := nullStream.
     ].
     (err := anExternalErrStream) isNil ifTrue:[
-        err := out
+	err := out
     ].
 
     rslt := self
-        exec:(shellAndArgs at:1)
-        withArguments:(shellAndArgs at:2)
-        environment:anEvironmentDictionary
-        fileDescriptors:(Array with:in fileHandle
-                               with:out fileHandle
-                               with:err fileHandle
-                               with:(anAuxiliaryStream notNil ifTrue:[anAuxiliaryStream fileHandle] ifFalse:[nil]))
-        fork:true
-        newPgrp:true
-        inDirectory:dir.
+	exec:(shellAndArgs at:1)
+	withArguments:(shellAndArgs at:2)
+	environment:anEvironmentDictionary
+	fileDescriptors:(Array with:in fileHandle
+			       with:out fileHandle
+			       with:err fileHandle
+			       with:(anAuxiliaryStream notNil ifTrue:[anAuxiliaryStream fileHandle] ifFalse:[nil]))
+	fork:true
+	newPgrp:true
+	inDirectory:dir.
 
     nullStream notNil ifTrue:[
-        nullStream close.
+	nullStream close.
     ].
     ^ rslt
 
@@ -4342,7 +4345,7 @@
      The following will no longer work. monitorPid has disappeared
 
      pid notNil ifTrue:[
-         Processor monitorPid:pid action:[:OSstatus | sema signal ].
+	 Processor monitorPid:pid action:[:OSstatus | sema signal ].
      ].
      in close.
      out close.
@@ -4356,11 +4359,11 @@
 
      sema := Semaphore new.
 
-     Processor 
-            monitor:[
-                pid := OperatingSystem startProcess:'dir > out 2>err'
-            ]
-            action:[:osStatus | sema signal ].
+     Processor
+	    monitor:[
+		pid := OperatingSystem startProcess:'dir > out 2>err'
+	    ]
+	    action:[:osStatus | sema signal ].
 
      sema wait.
      Transcript showCR:'finished'
@@ -4371,11 +4374,11 @@
 
      sema := Semaphore new.
 
-     Processor 
-            monitor:[
-                pid := OperatingSystem startProcess:'(echo 1 & stx --eval "Delay waitForSeconds:100" & dir) >out' withCRs
-            ]
-            action:[:osStatus | sema signal ].
+     Processor
+	    monitor:[
+		pid := OperatingSystem startProcess:'(echo 1 & stx --eval "Delay waitForSeconds:100" & dir) >out' withCRs
+	    ]
+	    action:[:osStatus | sema signal ].
 
      Delay waitForSeconds:5.
      OperatingSystem terminateProcessGroup:pid.
@@ -4387,11 +4390,11 @@
 
      sema := Semaphore new.
 
-     Processor 
-            monitor:[
-                pid := OperatingSystem startProcess:{ 'C:\Users\cg\work\stx\projects\smalltalk\stx.com' . '--eval' . '"Delay waitForSeconds:100"' }
-            ]
-            action:[:osStatus | sema signal ].
+     Processor
+	    monitor:[
+		pid := OperatingSystem startProcess:{ 'C:\Users\cg\work\stx\projects\smalltalk\stx.com' . '--eval' . '"Delay waitForSeconds:100"' }
+	    ]
+	    action:[:osStatus | sema signal ].
 
      Delay waitForSeconds:5.
      OperatingSystem terminateProcess:pid.
@@ -4415,8 +4418,8 @@
 	RETURN(self);
     }
     if (__isExternalAddressLike(anIntegerOrHandle)) {
-       if (!CloseHandle( __externalAddressVal(anIntegerOrHandle))) {
-	   console_fprintf( stderr, "Win32OS [warning]: Could not close handle : %x\n", __externalAddressVal(anIntegerOrHandle));
+       if (!CloseHandle( _HANDLEVal(anIntegerOrHandle))) {
+	   console_fprintf( stderr, "Win32OS [warning]: Could not close handle : %x\n", _HANDLEVal(anIntegerOrHandle));
        }
        RETURN(self);
     }
@@ -7655,7 +7658,7 @@
     RETURN (nil);
   primitiveFail: ;
 %}.
-    self primitiveFailed
+    ^ self primitiveFailed
 
     "Created: / 27-07-2006 / 11:54:59 / fm"
 !
@@ -7722,7 +7725,7 @@
     RETURN (nil);
   primitiveFail: ;
 %}.
-    self primitiveFailed
+    ^ self primitiveFailed
 
     "Created: / 27-07-2006 / 11:55:25 / fm"
 !
@@ -7734,7 +7737,7 @@
     extern void *__getHInstance();
 
     RETURN (__MKEXTERNALADDRESS(__getHInstance()));
-%}
+%}.
 
     "
      Win32OperatingSystem hInstance
@@ -7771,7 +7774,7 @@
 
 playSound:fileName mode:modeInteger
     <apicall: void "sndPlaySoundA" ( lpstr uint32) module: "winmm.dll" >
-    self primitiveFailed.
+    ^ self primitiveFailed.
 
 "/#define SND_SYNC            0x0000  /* play synchronously (default) */
 "/#define SND_ASYNC           0x0001  /* play asynchronously */
@@ -7802,12 +7805,13 @@
     dwOptions:dwOptions
 
     <apicall: bool "DuplicateHandle" ( handle, handle, handle, pointer, dword, bool, dword) module: "kernel32.dll" >
-    self primitiveFailed.
+    ^ self primitiveFailed.
 
     "Created: / 18-09-2007 / 16:31:23 / cg"
 !
 
 primGetLastError
+    "get the last error code"
 %{  /* NOCONTEXT */
     DWORD e;
 
@@ -7823,37 +7827,49 @@
 !
 
 primSetLastError: i
+    "mostly used to clear the last error code"
+
 %{  /* NOCONTEXT */
     if (__isSmallInteger(i)) {
 	SetLastError(__intVal(i));
 	RETURN(self);
     }
 %}.
-    self primitiveFailed.
-
    "/ <apicall: void "SetLastError" (dword) module: "kernel32.dll" >
-
-    "
-	self primSetLastError: 0
-    "
-!
-
-primWritePrivateProfileString: appName keyName: keyName profileString: profString fileName: aString
-
-    <apicall: bool "WritePrivateProfileStringA" ( lpstr lpstr lpstr lpstr ) module: "Kernel32.dll" >
-    ^self primitiveFailed
+    ^ self primitiveFailed.
+
+    "
+     self primSetLastError: 0
+    "
+!
+
+primWritePrivateProfileString:appName keyName:keyName profileString:profString fileName:fnString
+%{  /* NOCONTEXT */
+    if (__isString(appName)
+     && __isString(keyName)
+     && __isString(profString)
+     && __isString(fnString)) {
+	BOOL ret;
+
+	ret = WritePrivateProfileStringA(__stringVal(appName), __stringVal(keyName), __stringVal(profString), __stringVal(fnString));
+	RETURN( ret == 0 ? false : true);
+    }
+%}.
+
+    "/ <apicall: bool "WritePrivateProfileStringA" ( lpstr lpstr lpstr lpstr ) module: "Kernel32.dll" >
+    ^ self primitiveFailed
 
     "Created: / 18-12-2006 / 13:01:41 / User"
 !
 
-writePrivateProfileString: appName keyName: keyName profileString: profString fileName: aString
-
-   ^self primWritePrivateProfileString: appName keyName: keyName profileString: profString fileName: aString
+writePrivateProfileString:appName keyName:keyName profileString:profString fileName:aString
+
+   ^self primWritePrivateProfileString:appName keyName:keyName profileString:profString fileName:aString
 
 "
     |profileStringToWrite recoveredProfileString|
     profileStringToWrite :=  'c:\vsw311'.
-    self writePrivateProfileString: 'PAV-Editor' keyName: 'ExportPath' profileString: profileStringToWrite fileName: 'C:\vsw311\dapas.ini'.
+    self writePrivateProfileString:'PAV-Editor' keyName:'ExportPath' profileString:profileStringToWrite fileName:'C:\vsw311\dapas.ini'.
     recoveredProfileString := self getProfileString:'PAV-Editor' key:'ExportPath' default:'@@@nil@@@' fileName:'C:\vsw311\dapas.ini' private:true.
     self assert: (profileStringToWrite = recoveredProfileString).
 "
@@ -7870,15 +7886,15 @@
 
     "/ "Without clear reasons, before creating the mutex we must call #printCR"
     "/ 'Creating mutex' printCR.
-    self primSetLastError: 0.
+    self primSetLastError:0.
     self primGetLastError.
-    handle := self primCreateMutex:nil initialOwner: true name: name.
+    handle := self primCreateMutex:nil initialOwner:true name:name.
     lastErrorCode := self primGetLastError.
     "/ lastErrorCode printCR.
 
-"/    self assert: lastErrorCode == 0.
-"/    lastErrorCode == 5 "ERROR_ACCESS_DENIED" ifTrue:[Transcript showCR: 'Mutex not accesible (GetLastError = ERROR_ACCESS_DENIED)'.].
-"/    lastErrorCode == 183 "ERROR_ALREADY_EXISTS" ifTrue:[Transcript showCR: 'Mutex already exists (GetLastError = ERROR_ALREADY_EXISTS)'.].
+    "/    self assert: lastErrorCode == 0.
+    "/    lastErrorCode == 5 "ERROR_ACCESS_DENIED" ifTrue:[Transcript showCR: 'Mutex not accesible (GetLastError = ERROR_ACCESS_DENIED)'.].
+    "/    lastErrorCode == 183 "ERROR_ALREADY_EXISTS" ifTrue:[Transcript showCR: 'Mutex already exists (GetLastError = ERROR_ALREADY_EXISTS)'.].
     (handle isNil or:[handle address ~~ 0]) ifFalse:[
 	Transcript showCR: 'CreateMutexNamed: "', name printString, '" failed'.
 	handle := nil.
@@ -7896,10 +7912,10 @@
 existsMutexNamed: name
     |handle lastErrorCode handleAndLastErrorCode|
 
-    handleAndLastErrorCode := self createMutexNamed: name.
+    handleAndLastErrorCode := self createMutexNamed:name.
     handle := handleAndLastErrorCode first.
     lastErrorCode := handleAndLastErrorCode second.
-"/    self assert: lastErrorCode == 0.
+    "/  self assert: lastErrorCode == 0.
     ^ handle isNil
 	or:[lastErrorCode == 183 "ERROR_ALREADY_EXISTS"
 	    or:[ lastErrorCode == 5 "ERROR_ACCESS_DENIED"]]
@@ -7914,59 +7930,135 @@
 
     |handle |
 
-    handle := self primOpenMutex:nil initialOwner: true name: name.
-"/    lastErrorCode := self primGetLastError.
-"/    lastErrorCode = 2 ifTrue:[Transcript showCR: 'Mutex does not exist (GetLastError = ERROR_FILE_NOT_FOUND)'.].
-"/    lastErrorCode = 5 ifTrue:[Transcript showCR: 'Mutex not accesible (GetLastError = ERROR_ACCESS_DENIED)'.].
+    handle := self primOpenMutex:nil initialOwner:true name:name.
+    "/    lastErrorCode := self primGetLastError.
+    "/    lastErrorCode = 2 ifTrue:[Transcript showCR: 'Mutex does not exist (GetLastError = ERROR_FILE_NOT_FOUND)'.].
+    "/    lastErrorCode = 5 ifTrue:[Transcript showCR: 'Mutex not accessable (GetLastError = ERROR_ACCESS_DENIED)'.].
     (handle isNil or:[handle address ~~ 0]) ifFalse:[
 	Transcript showCR: 'OpenMutexNamed: "', name printString, '" failed'.
 	^ nil.
     ].
-
     ^ handle
 
-
-    "
-    self openMutexNamed: '8906f5e0-54ed-11dd-9da4-001558137da0'
+    "
+     self openMutexNamed: '8906f5e0-54ed-11dd-9da4-001558137da0'
     "
 
     "Modified: / 03-08-2010 / 16:59:37 / cg"
 !
 
-primCreateMutex:lpSecurityDescriptor initialOwner: bInitialOwner name: lpName
+primCreateMutex:lpSecurityDescriptor initialOwner:bInitialOwner name:lpName
     "If the function succeeds, the return value is a handle to the newly created mutex object.
      If the function fails, the return value is NULL.
      If the mutex is a named mutex and the object existed before this function call, the return value is a handle to the existing object."
 
-    <apicall: handle "CreateMutexA" (lpstr bool lpstr) module: "kernel32.dll" >
+    |handle|
+
+    handle := Win32Handle new.
+%{
+    if (__isString(lpName)
+     && ((bInitialOwner == true) || (bInitialOwner == false))) {
+	void *c_descr = NULL;
+	char *c_name;
+	BOOL c_initialOwner = (bInitialOwner == true);
+	HANDLE c_handle;
+
+	c_name = __stringVal(lpName);
+
+	if (lpSecurityDescriptor != nil) {
+	    if (__isExternalAddressLike(lpSecurityDescriptor)
+	     || __isExternalBytesLike(lpSecurityDescriptor) ) {
+		c_descr = __externalAddressVal(lpSecurityDescriptor);
+	    } else
+		goto badArg;
+	}
+	c_handle = CreateMutexA(c_descr, c_initialOwner, c_name);
+	__externalAddressVal(handle) = c_handle;
+	RETURN(handle);
+    }
+    badArg: ;
+%}.
+    "/ <apicall: handle "CreateMutexA" (lpstr bool lpstr) module: "kernel32.dll" >
+    ^ self primitiveFailed
 
     "Modified: / 03-08-2010 / 16:59:26 / cg"
 !
 
-primOpenMutex:lpSecurityDescriptor initialOwner: bInitialOwner name: lpName
+primOpenMutex:dwDesiredAccess initialOwner:bInitialOwner name:lpName
     "If the function succeeds, the return value is a handle to the mutex object.
      If the function fails, the return value is NULL. To get extended error information, call GetLastError.
      If a named mutex does not exist, the function fails and GetLastError returns ERROR_FILE_NOT_FOUND."
 
-    <apicall: handle "OpenMutexA" (lpstr bool lpstr) module: "kernel32.dll" >
+    |handle|
+
+    handle := Win32Handle new.
+%{
+    if (__isString(lpName)
+     && ((bInitialOwner == true) || (bInitialOwner == false))) {
+	DWORD c_dwDesiredAccess = 0;
+	char *c_name;
+	BOOL c_initialOwner = (bInitialOwner == true);
+	HANDLE c_handle;
+
+	c_name = __stringVal(lpName);
+
+	if (dwDesiredAccess != nil) {
+	    if (! __isSmallInteger(dwDesiredAccess)) {
+		goto badArg;
+	    }
+	    c_dwDesiredAccess = __intVal(dwDesiredAccess);
+	}
+	c_handle = OpenMutexA(c_dwDesiredAccess, c_initialOwner, c_name);
+	__externalAddressVal(handle) = c_handle;
+	RETURN(handle);
+    }
+    badArg: ;
+%}.
+    "/ <apicall: handle "OpenMutexA" (lpstr bool lpstr) module: "kernel32.dll" >
+    ^ self primitiveFailed
 
     "Modified: / 03-08-2010 / 16:59:11 / cg"
 !
 
-primReleaseMutex: hMutex
+primReleaseMutex:hMutex
     "If the function succeeds, the return value is nonzero.
      If the function fails, the return value is zero."
-
-    <apicall: bool "ReleaseMutex" (handle) module: "kernel32.dll" >
+%{
+    if (__isExternalAddressLike(hMutex)
+     || __isExternalBytesLike(hMutex) ) {
+	HANDLE _handle = _HANDLEVal(hMutex);
+	BOOL _ret;
+
+	_ret = ReleaseMutex(_handle);
+	RETURN(_ret == 0 ? false : true);
+    }
+%}.
+    "/ <apicall: bool "ReleaseMutex" (handle) module: "kernel32.dll" >
+    ^ self primitiveFailed
 
     "Modified: / 03-08-2010 / 16:59:55 / cg"
 !
 
-primWaitForSingleObject: handle milliseconds: dwMilliseconds
+primWaitForSingleObject:handle milliseconds:dwMilliseconds
     "If the function succeeds, the return value indicates the event that caused the function to return.
      If the function fails, the return value is WAIT_FAILED ((DWORD)0xFFFFFFFF)."
 
-    <apicall: dword "WaitForSingleObject" (handle dword) module: "kernel32.dll" >
+%{
+    if (__isExternalAddressLike(handle)
+     || __isExternalBytesLike(handle) ) {
+	HANDLE _handle = _HANDLEVal(handle);
+
+	if (__isSmallInteger(dwMilliseconds)) {
+	    DWORD _millis = __intVal(dwMilliseconds);
+	    DWORD _ret;
+
+	    _ret = ReleaseMutex(_handle);
+	    RETURN( __mkSmallInteger(_ret));
+	}
+    }
+%}.
+    "/ <apicall: dword "WaitForSingleObject" (handle dword) module: "kernel32.dll" >
+    ^ self primitiveFailed
 
     "Modified: / 03-08-2010 / 17:00:02 / cg"
 !
@@ -8084,27 +8176,27 @@
 
     count := aString size + 128.
     [
-        aString isWideString ifTrue:[
-            resultString := Unicode16String new:count.
-            resultCount := self primExpandEnvironmentStringsW:aString into:resultString size:count.
-        ] ifFalse:[
-            resultString := String new:count.
-            resultCount := self primExpandEnvironmentStringsA:aString into:resultString size:count.
-        ].
-        resultCount <= count ifTrue:[
-            true
-        ] ifFalse:[
-            "resultString was too small. resultCount is the required buffer size"
-            count := resultCount.
-            false
-        ].
+	aString isWideString ifTrue:[
+	    resultString := Unicode16String new:count.
+	    resultCount := self primExpandEnvironmentStringsW:aString into:resultString size:count.
+	] ifFalse:[
+	    resultString := String new:count.
+	    resultCount := self primExpandEnvironmentStringsA:aString into:resultString size:count.
+	].
+	resultCount <= count ifTrue:[
+	    true
+	] ifFalse:[
+	    "resultString was too small. resultCount is the required buffer size"
+	    count := resultCount.
+	    false
+	].
     ] whileFalse.
     ^ resultString copyTo:resultCount-1.
 
 
     "
-        self expandEnvironmentStrings:'%ProgramFiles%\test\x'
-        self expandEnvironmentStrings:'%ProgramFiles%\test\x' asUnicode16String
+	self expandEnvironmentStrings:'%ProgramFiles%\test\x'
+	self expandEnvironmentStrings:'%ProgramFiles%\test\x' asUnicode16String
     "
 !
 
@@ -8205,8 +8297,7 @@
     RETURN (ret);
 
 badArgument:;
-%}
-.
+%}.
     ^ nil
 
     "
@@ -8683,12 +8774,12 @@
 getNumberOfProcessors
     "answer the number of physical processors in the system"
 
-    %{
+%{
 	SYSTEM_INFO sInfo;
 	GetSystemInfo(&sInfo);
 
 	return __mkSmallInteger(sInfo.dwNumberOfProcessors);
-    %}.
+%}.
 
     "
 	self getNumberOfProcessors
@@ -8704,7 +8795,7 @@
 
     pid = GetCurrentProcessId() & 0x3FFFFFFF;
     RETURN ( __mkSmallInteger(pid) );
-%}
+%}.
     "
      OperatingSystem getProcessId
     "
@@ -9099,7 +9190,7 @@
 
     pid = GetCurrentThreadId() & 0x3FFFFFFF;
     RETURN ( __mkSmallInteger(pid) );
-%}
+%}.
     "
      OperatingSystem getThreadId
     "
@@ -10352,13 +10443,26 @@
     "Created: / 12.6.1998 / 16:30:43 / cg"
 !
 
-primExpandEnvironmentStringsA:inString into:outString size:outBuffer
-
-    <apicall: ulongReturn "ExpandEnvironmentStringsA" (pointer pointer ulong) module: "kernel32.dll" >
+primExpandEnvironmentStringsA:inString into:outString size:outBufferSize
+%{
+    if (__isString(inString)
+     && __isString(outString)
+     && __isSmallInteger(outBufferSize)) {
+	unsigned long c_outBufferSize = __intVal(outBufferSize);
+
+	if (__stringSize(outString) <= c_outBufferSize) {
+	    unsigned long c_ret;
+
+	    c_ret = ExpandEnvironmentStringsA(__stringVal(inString), __stringVal(outString), c_outBufferSize);
+	    RETURN( __mkSmallInteger(c_ret) );
+	}
+    }
+%}.
+    "/ <apicall: ulongReturn "ExpandEnvironmentStringsA" (pointer pointer ulong) module: "kernel32.dll" >
     ^self primitiveFailed
 
     "
-        self primExpandEnvironmentStringsA:'%ProgramFiles%\test\x' into:(String new:256) inspect size:256
+	self primExpandEnvironmentStringsA:'%ProgramFiles%\test\x' into:(String new:256) inspect size:256
     "
 !
 
@@ -10368,7 +10472,7 @@
     ^self primitiveFailed
 
     "
-        self primExpandEnvironmentStringsW:'%ProgramFiles%\test\x' asUnicodeString into:(Unicode16String new:256) inspect size:256
+	self primExpandEnvironmentStringsW:'%ProgramFiles%\test\x' asUnicodeString into:(Unicode16String new:256) inspect size:256
     "
 ! !
 
@@ -11609,10 +11713,10 @@
     info := IdentityDictionary new.
     loginName := self getLoginName.
     (aNameOrID == self getUserID or:[aNameOrID = loginName]) ifTrue:[
-        userName := loginName.
-        info at:#dir put:self getHomeDirectory.
+	userName := loginName.
+	info at:#dir put:self getHomeDirectory.
     ] ifFalse:[
-        userName := 'unknown'.
+	userName := 'unknown'.
     ].
     info at:#name put:userName.
     "/ uid notNil ifTrue:[info at:#uid put:uid].
@@ -11733,15 +11837,15 @@
     unsigned long bytes_available;
 
     if (__Class(fd) == @global(Win32SocketHandle)) {
-        if (ioctlsocket((SOCKET)_HANDLEVal(fd), FIONREAD, &bytes_available) == 0) {
-            if (bytes_available > _MAX_INT) bytes_available = _MAX_INT;
-            RETURN(__mkSmallInteger(bytes_available));
-        }
+	if (ioctlsocket((SOCKET)_HANDLEVal(fd), FIONREAD, &bytes_available) == 0) {
+	    if (bytes_available > _MAX_INT) bytes_available = _MAX_INT;
+	    RETURN(__mkSmallInteger(bytes_available));
+	}
     } else if (__isSmallInteger(fd)) {
-        if (PeekNamedPipe(_get_osfhandle(__intVal(fd)), NULL, 0, NULL, &bytes_available, NULL) != 0){
-            if (bytes_available > _MAX_INT) bytes_available = _MAX_INT;
-            RETURN(__mkSmallInteger(bytes_available));
-        }
+	if (PeekNamedPipe(_get_osfhandle(__intVal(fd)), NULL, 0, NULL, &bytes_available, NULL) != 0){
+	    if (bytes_available > _MAX_INT) bytes_available = _MAX_INT;
+	    RETURN(__mkSmallInteger(bytes_available));
+	}
     }
 %}.
 
@@ -18495,7 +18599,7 @@
 
     char host[NI_MAXHOST];
     char service[NI_MAXSERV];
-    char *hp = 0, *sp = 0;
+    char *hp = NULL, *sp = NULL;
     int hsz = 0, ssz = 0;
     int ret;
     int __flags;
@@ -18510,7 +18614,7 @@
 	sp = service;
 	ssz = sizeof(service);
     }
-    if (hp == 0 && sp == 0) {
+    if (hp == NULL && sp == NULL) {
 	error = @symbol(badArgument);
 	goto err;
     }