Win32OperatingSystem.st
changeset 18962 29c5db48dd57
parent 18954 813f1c2c49ca
child 18963 5a18dd0c21ec
child 18964 774cb1e6201e
--- a/Win32OperatingSystem.st	Fri Nov 27 17:16:41 2015 +0100
+++ b/Win32OperatingSystem.st	Fri Nov 27 21:18:20 2015 +0100
@@ -878,7 +878,6 @@
     "Modified: 7.1.1997 / 19:36:11 / stefan"
 ! !
 
-
 !Win32OperatingSystem class methodsFor:'OS signal constants'!
 
 sigABRT
@@ -1624,47 +1623,47 @@
     int    __modeBits = 0;
 
     if (__fileAttr & FILE_ATTRIBUTE_DIRECTORY) {
-	type = @symbol(directory);
-	__modeBits = 0777;   /* executable and WRITABLE - refer to comment in #isWritable: */
+        type = @symbol(directory);
+        __modeBits = 0777;   /* executable and WRITABLE - refer to comment in #isWritable: */
     } else if (__fileAttr & FILE_ATTRIBUTE_REPARSE_POINT) {
-	type = @symbol(symbolicLink);
-	__modeBits = 0777;   /* even in UNIX symlinks have 0777 */
+        type = @symbol(symbolicLink);
+        __modeBits = 0777;   /* even in UNIX symlinks have 0777 */
     } else {
-	type = @symbol(regular);
-	if (__fileAttr & FILE_ATTRIBUTE_READONLY) {
-	    __modeBits = 0444;
-	} else {
-	    __modeBits = 0666;
-	}
+        type = @symbol(regular);
+        if (__fileAttr & FILE_ATTRIBUTE_READONLY) {
+            __modeBits = 0444;
+        } else {
+            __modeBits = 0666;
+        }
     }
     modeBits = __mkSmallInteger(__modeBits);
 
 %}.
     osCrtTime isNil
-	ifTrue: [crtTime := Timestamp now]
-	ifFalse:[crtTime := Timestamp new fromOSTime:(osCrtTime - OperatingSystem osTimeOf19700101)].
+        ifTrue: [crtTime := Timestamp now]
+        ifFalse:[crtTime := Timestamp new fromOSTime:(osCrtTime - OperatingSystem osTimeOf19700101)].
 
     osAccTime isNil
-	ifTrue: [accTime := Timestamp now]
-	ifFalse:[accTime := Timestamp new fromOSTime:(osAccTime - OperatingSystem osTimeOf19700101)].
+        ifTrue: [accTime := Timestamp now]
+        ifFalse:[accTime := Timestamp new fromOSTime:(osAccTime - OperatingSystem osTimeOf19700101)].
 
     osModTime isNil
-	ifTrue: [modTime := accTime]
-	ifFalse:[modTime := Timestamp new fromOSTime:(osModTime - OperatingSystem osTimeOf19700101)].
+        ifTrue: [modTime := accTime]
+        ifFalse:[modTime := Timestamp new fromOSTime:(osModTime - OperatingSystem osTimeOf19700101)].
 
     ^ FileStatusInfo
-		type:type
-		mode:modeBits
-		uid:nil
-		gid:nil
-		size:fileSize
-		id:0
-		accessed:accTime
-		modified:modTime
-		created:crtTime
-		sourcePath:(osPathname asSingleByteStringIfPossible)
-		fullName:nil
-		alternativeName:nil.
+                type:type
+                mode:modeBits
+                uid:nil
+                gid:nil
+                size:fileSize
+                id:0
+                accessed:accTime
+                modified:modTime
+                created:crtTime
+                sourcePath:osPathname
+                fullName:nil
+                alternativeName:nil.
 !
 
 nextLinkInfoFrom:aDirectoryStream dirPointer:dirPointer
@@ -1679,45 +1678,45 @@
 
     if ((dirPointer != nil)
     && __isExternalAddressLike(dirPointer)) {
-	// __INST(lastErrorNumber) = nil;
-	d = __externalAddressVal(dirPointer);
-
-	do {
-	    __threadErrno = 0;
-	    rslt = STX_API_NOINT_CALL2( "FindNextFileW", FindNextFileW, d, &data );
-	} while ((rslt < 0) && (__threadErrno == EINTR));
-
-	if (rslt > 0) {
-	    fileSize  = __MKLARGEINT64(1, data.nFileSizeLow, data.nFileSizeHigh);
-	    osPathname = __MKU16STRING( data.cFileName );
-	    osFileAttributes = __mkSmallInteger( data.dwFileAttributes );
-
-	    osCrtTime = FileTimeToOsTime(&data.ftCreationTime);
-	    osAccTime = FileTimeToOsTime(&data.ftLastAccessTime);
-	    osModTime = FileTimeToOsTime(&data.ftLastWriteTime);
-
-	} else {
-	    error = __mkSmallInteger( __threadErrno );
-	}
+        // __INST(lastErrorNumber) = nil;
+        d = __externalAddressVal(dirPointer);
+
+        do {
+            __threadErrno = 0;
+            rslt = STX_API_NOINT_CALL2( "FindNextFileW", FindNextFileW, d, &data );
+        } while ((rslt < 0) && (__threadErrno == EINTR));
+
+        if (rslt > 0) {
+            fileSize  = __MKLARGEINT64(1, data.nFileSizeLow, data.nFileSizeHigh);
+            osPathname = __mkStringOrU16String_maxlen( data.cFileName );
+            osFileAttributes = __mkSmallInteger( data.dwFileAttributes );
+
+            osCrtTime = FileTimeToOsTime(&data.ftCreationTime);
+            osAccTime = FileTimeToOsTime(&data.ftLastAccessTime);
+            osModTime = FileTimeToOsTime(&data.ftLastWriteTime);
+
+        } else {
+            error = __mkSmallInteger( __threadErrno );
+        }
     }
 %}.
     (error notNil and:[error ~~ 0]) ifTrue:[
-	^ StreamIOError newException
-	    errorCode:error;
-	    osErrorHolder:(OperatingSystem errorHolderForNumber:error);
-	    parameter:aDirectoryStream;
-	    raiseRequest
+        ^ StreamIOError newException
+            errorCode:error;
+            osErrorHolder:(OperatingSystem errorHolderForNumber:error);
+            parameter:aDirectoryStream;
+            raiseRequest
     ].
 
     osPathname isNil ifTrue:[^ nil].
 
     ^ self
-	linkInfoFor:osPathname
-	fileSize:fileSize
-	fileAttributes:osFileAttributes
-	osCrtTime:osCrtTime
-	osAccTime:osAccTime
-	osModTime:osModTime
+        linkInfoFor:osPathname
+        fileSize:fileSize
+        fileAttributes:osFileAttributes
+        osCrtTime:osCrtTime
+        osAccTime:osAccTime
+        osModTime:osModTime
 ! !
 
 !Win32OperatingSystem class methodsFor:'error messages'!
@@ -5166,18 +5165,16 @@
 getCurrentDirectory
     "get the current directory"
 
-    |dir|
-%{
+%{  /* NOCONTEXT */
     int ret;
     wchar_t _aPathName[MAXPATHLEN+1];
 
     ret = GetCurrentDirectoryW(MAXPATHLEN, _aPathName);
     if (ret == 0) {
-	__threadErrno = __WIN32_ERR(GetLastError());
-    }
-    dir = __MKU16STRING(_aPathName);
-%}.
-    ^ dir asSingleByteStringIfPossible
+        __threadErrno = __WIN32_ERR(GetLastError());
+    }
+    RETURN(__mkStringOrU16String_maxlen(_aPathName));
+%}.
 
     "
      self getCurrentDirectory
@@ -5407,41 +5404,41 @@
     wchar_t _aPathName[MAXPATHLEN+1];
 
     if (__isStringLike(aPathName)) {
-	int i;
-	INT l = __stringSize(aPathName);
-
-	if (l > MAXPATHLEN) l = MAXPATHLEN;
-
-	for (i=0; i<l; i++) {
-	    _aPathName[i] = __stringVal(aPathName)[i];
-	}
-	_aPathName[i] = 0;
+        int i;
+        INT l = __stringSize(aPathName);
+
+        if (l > MAXPATHLEN) l = MAXPATHLEN;
+
+        for (i=0; i<l; i++) {
+            _aPathName[i] = __stringVal(aPathName)[i];
+        }
+        _aPathName[i] = 0;
     } else if (__isUnicode16String(aPathName)) {
-	int i;
-
-	INT l = __unicode16StringSize(aPathName);
-	if (l > MAXPATHLEN) l = MAXPATHLEN;
-
-	for (i=0; i<l; i++) {
-	    _aPathName[i] = __unicode16StringVal(aPathName)[i];
-	}
-	_aPathName[i] = 0;
+        int i;
+
+        INT l = __unicode16StringSize(aPathName);
+        if (l > MAXPATHLEN) l = MAXPATHLEN;
+
+        for (i=0; i<l; i++) {
+            _aPathName[i] = __unicode16StringVal(aPathName)[i];
+        }
+        _aPathName[i] = 0;
     } else
-	goto badArgument;
+        goto badArgument;
 
 #ifdef DO_WRAP_CALLS
      do {
-	 __threadErrno = 0;
-	 // do not cast to INT - will loose sign bit then!
-	 ret = STX_API_NOINT_CALL3( "GetLongPathNameW", GetLongPathNameW, _aPathName, _aPathName, MAXPATHLEN);
+         __threadErrno = 0;
+         // do not cast to INT - will loose sign bit then!
+         ret = STX_API_NOINT_CALL3( "GetLongPathNameW", GetLongPathNameW, _aPathName, _aPathName, MAXPATHLEN);
      } while ((ret == 0) && (__threadErrno == EINTR));
 #else
      ret = GetLongPathNameW(_aPathName, _aPathName, MAXPATHLEN);
      if (ret == 0) {
-	 __threadErrno = __WIN32_ERR(GetLastError());
+         __threadErrno = __WIN32_ERR(GetLastError());
      }
 #endif
-     RETURN ( __MKU16STRING(_aPathName));
+     RETURN (__mkStringOrU16String_maxlen(_aPathName));
 
 badArgument:;
 %}.
@@ -5871,16 +5868,16 @@
     "return some object filled with info for the file 'aPathName';
      the info (for which corresponding access methods are understood by
      the returned object) is:
-	 type            - a symbol giving the files type
-	 mode            - numeric access mode
-	 uid             - owners user id
-	 gid             - owners group id
-	 size            - files size
-	 id              - files number (i.e. inode number)
-	 accessed        - last access time (as Timestamp)
-	 modified        - last modification time (as Timestamp)
-	 statusChanged   - last status change time (as Timestamp)
-	 alternativeName - (windows only:) the MSDOS name of the file
+         type            - a symbol giving the files type
+         mode            - numeric access mode
+         uid             - owners user id
+         gid             - owners group id
+         size            - files size
+         id              - files number (i.e. inode number)
+         accessed        - last access time (as Timestamp)
+         modified        - last modification time (as Timestamp)
+         statusChanged   - last status change time (as Timestamp)
+         alternativeName - (windows only:) the MSDOS name of the file
 
      Some of the fields may be returned as nil on systems which do not provide
      all of the information.
@@ -5907,138 +5904,132 @@
     wchar_t _aPathName[MAXPATHLEN+1];
 
     if (__isStringLike(aPathName)) {
-	int i;
-	int l = __stringSize(aPathName);
-	if (l > MAXPATHLEN) l = MAXPATHLEN;
-
-	for (i=0; i<l; i++) {
-	    _aPathName[i] = __stringVal(aPathName)[i];
-	}
-	_aPathName[i] = 0;
+        int i;
+        int l = __stringSize(aPathName);
+        if (l > MAXPATHLEN) l = MAXPATHLEN;
+
+        for (i=0; i<l; i++) {
+            _aPathName[i] = __stringVal(aPathName)[i];
+        }
+        _aPathName[i] = 0;
     } else if (__isUnicode16String(aPathName)) {
-	int i;
-	int l = __unicode16StringSize(aPathName);
-	if (l > MAXPATHLEN) l = MAXPATHLEN;
-
-	for (i=0; i<l; i++) {
-	    _aPathName[i] = __unicode16StringVal(aPathName)[i];
-	}
-	_aPathName[i] = 0;
+        int i;
+        int l = __unicode16StringSize(aPathName);
+        if (l > MAXPATHLEN) l = MAXPATHLEN;
+
+        for (i=0; i<l; i++) {
+            _aPathName[i] = __unicode16StringVal(aPathName)[i];
+        }
+        _aPathName[i] = 0;
     } else
-	goto badArgument;
+        goto badArgument;
 
 #ifdef DO_WRAP_CALLS
     {
-	do {
-	    __threadErrno = 0;
-	    // do not cast to INT - will loose sign bit then!
-	    result = STX_API_NOINT_CALL3( "GetFileAttributesExW", GetFileAttributesExW, _aPathName, GetFileExInfoStandard, &fileAttributeData);
-	} while (!result && (__threadErrno == EINTR));
+        do {
+            __threadErrno = 0;
+            // do not cast to INT - will loose sign bit then!
+            result = STX_API_NOINT_CALL3( "GetFileAttributesExW", GetFileAttributesExW, _aPathName, GetFileExInfoStandard, &fileAttributeData);
+        } while (!result && (__threadErrno == EINTR));
     }
 #else
     result = GetFileAttributesExW(_aPathName, GetFileExInfoStandard, &fileAttributeData);
     if (!result) {
-	__threadErrno = __WIN32_ERR(GetLastError());
+        __threadErrno = __WIN32_ERR(GetLastError());
     }
 #endif
 
     if (!result) {
-	@global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
+        @global(LastErrorNumber) = __mkSmallInteger(__threadErrno);
     } else {
-	id = __mkSmallInteger(0);   /* could get it by opening ... */
-	size = __MKLARGEINT64(1, fileAttributeData.nFileSizeLow, fileAttributeData.nFileSizeHigh);
+        id = __mkSmallInteger(0);   /* could get it by opening ... */
+        size = __MKLARGEINT64(1, fileAttributeData.nFileSizeLow, fileAttributeData.nFileSizeHigh);
 
 //        if (fileAttributeData.cFileName[0] != '\0') {
 //            bcopy(fileAttributeData.cFileName, fileNameBuffer, MAXPATHLEN*sizeof(wchar_t));
 //            fileNameBuffer[MAXPATHLEN] = '\0';
-//            fileName = __MKU16STRING(fileNameBuffer);             /* FULL name */
+//            fileName = __mkStringOrU16String_maxlen(fileNameBuffer);             /* FULL name */
 //        }
 
 //        if (fileAttributeData.cAlternateFileName[0] != '\0') {
 //            bcopy(fileAttributeData.cAlternateFileName, alternativeFileNameBuffer, 14*sizeof(wchar_t));
 //            alternativeFileNameBuffer[14] = '\0';
-//            alternativeName = __MKU16STRING(alternativeFileNameBuffer); /* DOS name */
+//            alternativeName = __mkStringOrU16String_maxlen(alternativeFileNameBuffer); /* DOS name */
 //        }
 
-	/*
-	 * simulate access bits
-	 */
-	if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
-	    modeBits = 0444;
-	} else {
-	    modeBits = 0666;
-	}
-
-	if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
-	    type = @symbol(directory);
-	    modeBits = 0777;   /* executable and WRITABLE - refer to comment in #isWritable: */
-	} else if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
-	    type = @symbol(symbolicLink);
-	    modeBits = 0777;   /* even in UNIX symlinks have 0777 */
-	} else {
-	    type = @symbol(regular);
-	}
-
-	mode = __mkSmallInteger(modeBits);
-
-	cOsTime = FileTimeToOsTime(&fileAttributeData.ftCreationTime);
-	aOsTime = FileTimeToOsTime(&fileAttributeData.ftLastAccessTime);
-	mOsTime = FileTimeToOsTime(&fileAttributeData.ftLastWriteTime);
+        /*
+         * simulate access bits
+         */
+        if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
+            modeBits = 0444;
+        } else {
+            modeBits = 0666;
+        }
+
+        if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+            type = @symbol(directory);
+            modeBits = 0777;   /* executable and WRITABLE - refer to comment in #isWritable: */
+        } else if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
+            type = @symbol(symbolicLink);
+            modeBits = 0777;   /* even in UNIX symlinks have 0777 */
+        } else {
+            type = @symbol(regular);
+        }
+
+        mode = __mkSmallInteger(modeBits);
+
+        cOsTime = FileTimeToOsTime(&fileAttributeData.ftCreationTime);
+        aOsTime = FileTimeToOsTime(&fileAttributeData.ftLastAccessTime);
+        mOsTime = FileTimeToOsTime(&fileAttributeData.ftLastWriteTime);
     }
 
   badArgument: ;
 %}.
 
     (aPathName endsWith:'.lnk') ifTrue:[
-	type := #symbolicLink.
-	"/ now done lazyly in FileStatusInfo, when the path is accessed
-	"/ path := self getLinkTarget:aPathName.
+        type := #symbolicLink.
+        "/ now done lazyly in FileStatusInfo, when the path is accessed
+        "/ path := self getLinkTarget:aPathName.
     ].
 
     mode isNil ifTrue:[
-	(self isDirectory:aPathName) ifTrue:[
-	    "/ the code above fails for root directories (these do not exist).
-	    "/ simulate here
-	    mode := 8r777.
-	    type := #directory.
-	    uid := gid := 0.
-	    size := 0.
-	    id := 0.
-	    atime := mtime := ctime := Timestamp now.
-	].
+        (self isDirectory:aPathName) ifTrue:[
+            "/ the code above fails for root directories (these do not exist).
+            "/ simulate here
+            mode := 8r777.
+            type := #directory.
+            uid := gid := 0.
+            size := 0.
+            id := 0.
+            atime := mtime := ctime := Timestamp now.
+        ].
     ].
     mode notNil ifTrue:[
-	atime isNil ifTrue:[
-	    "/ rebias to 1970 by subtracting the number of millis from 1.1.1601 to 1.1.1970
-	    aOsTime := aOsTime - self osTimeOf19700101.
-	    atime := Timestamp new fromOSTime:aOsTime.
-	].
-	mtime isNil ifTrue:[
-	    "/ rebias to 1970 by subtracting the number of millis from 1.1.1601 to 1.1.1970
-	    mOsTime := mOsTime - self osTimeOf19700101.
-	    mtime := Timestamp new fromOSTime:mOsTime.
-	].
-	ctime isNil ifTrue:[
-	    "/ rebias to 1970 by subtracting the number of millis from 1.1.1601 to 1.1.1970
-	    cOsTime := cOsTime - self osTimeOf19700101.
-	    ctime := Timestamp new fromOSTime:cOsTime.
-	].
-	fileName notNil ifTrue:[
-	    fileName := fileName asSingleByteStringIfPossible
-	].
-	alternativeName notNil ifTrue:[
-	    alternativeName := alternativeName asSingleByteStringIfPossible
-	].
-
-	info := FileStatusInfo
-		    type:type mode:mode
-		    uid:uid gid:gid
-		    size:size
-		    id:id
-		    accessed:atime modified:mtime created:ctime
-		    sourcePath:aPathName
-		    fullName:fileName alternativeName:alternativeName.
-	^ info
+        atime isNil ifTrue:[
+            "/ rebias to 1970 by subtracting the number of millis from 1.1.1601 to 1.1.1970
+            aOsTime := aOsTime - self osTimeOf19700101.
+            atime := Timestamp new fromOSTime:aOsTime.
+        ].
+        mtime isNil ifTrue:[
+            "/ rebias to 1970 by subtracting the number of millis from 1.1.1601 to 1.1.1970
+            mOsTime := mOsTime - self osTimeOf19700101.
+            mtime := Timestamp new fromOSTime:mOsTime.
+        ].
+        ctime isNil ifTrue:[
+            "/ rebias to 1970 by subtracting the number of millis from 1.1.1601 to 1.1.1970
+            cOsTime := cOsTime - self osTimeOf19700101.
+            ctime := Timestamp new fromOSTime:cOsTime.
+        ].
+
+        info := FileStatusInfo
+                    type:type mode:mode
+                    uid:uid gid:gid
+                    size:size
+                    id:id
+                    accessed:atime modified:mtime created:ctime
+                    sourcePath:aPathName
+                    fullName:fileName alternativeName:alternativeName.
+        ^ info
    ].
    ^ nil
 
@@ -7792,56 +7783,43 @@
 getDomainName
     "return the DNS domain this host is in.
      Notice:
-	not all systems support this; on some, 'unknown' is returned."
+        not all systems support this; on some, 'unknown' is returned."
 
     |domainName idx hostName k|
 
     DomainName notNil ifTrue:[
-	^ DomainName
+        ^ DomainName
     ].
 
     "/ sometimes, we can extract the domainName from the hostName ...
     hostName := self getHostName.
     hostName notEmptyOrNil ifTrue:[
-	idx := hostName indexOf:$..
-	idx ~~ 0 ifTrue:[
-	    domainName := hostName copyFrom:idx+1.
-	]
+        idx := hostName indexOf:$..
+        idx ~~ 0 ifTrue:[
+            domainName := hostName copyFrom:idx+1.
+        ]
     ].
 
     domainName isNil ifTrue:[
-	domainName := self getEnvironment:'DOMAIN'.
-	domainName isNil ifTrue:[
-	    domainName := self getEnvironment:'DOMAINNAME'.
-	].
-
-	domainName isNil ifTrue:[
-	    "/ ok, search the registry ...
-	    "/ under NT and later, it is found there ...
-	    k := RegistryEntry key:'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters'.
-	    k notNil ifTrue:[
-		domainName := k valueNamed:'Domain'.
-		k close.
-	    ].
-	].
-
-	domainName isNil ifTrue:[
-	    "/ under Win95/Win98, it is found there ...
-	    k := RegistryEntry key:'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP'.
-	    k notNil ifTrue:[
-		domainName := k valueNamed:'Domain'.
-		k close.
-	    ]
-	].
-
-	domainName isNil ifTrue:[
-	    "/ only warn once - the warning can be ignored, if you do not use the domain name
-	    ObjectMemory debugPrinting ifTrue:[
-		'Win32OperatingSystem [warning]: cannot find out domainName' infoPrintCR.
-	    ].
-	    domainName := 'unknown'.
-	].
-	DomainName := domainName.     "cache only, if it is fixed"
+        domainName := self getEnvironment:'DOMAIN'.
+        domainName isNil ifTrue:[
+            domainName := self getEnvironment:'DOMAINNAME'.
+        ].
+
+        domainName isNil ifTrue:[
+            "/ ok, search the registry ...
+            "/ under NT and later, it is found there ...
+            k := RegistryEntry key:'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters'.
+            k notNil ifTrue:[
+                domainName := k valueNamed:'Domain'.
+                k close.
+            ].
+        ].
+
+        domainName isNil ifTrue:[
+            ^ 'unknown'.
+        ].
+        DomainName := domainName.     "cache only, if it is fixed"
     ].
     ^ domainName
 
@@ -7858,42 +7836,50 @@
     "get an environment string"
 
 %{  /* NOCONTEXT */
-    char *env;
+    WCHAR _varName[1024];
+    WCHAR buff[1024];
+    int nNeeded;
+    OBJ ret = nil;
+    int i, l;
 
     if (__isStringLike(aStringOrSymbol)) {
-	char buff[1024];
-	int nNeeded;
-	OBJ ret = nil;
-
-	nNeeded = GetEnvironmentVariableA(__stringVal(aStringOrSymbol),
-					  buff,
-					  sizeof(buff));
-	if (nNeeded > sizeof(buff)) {
-	    char *buff2;
-
-	    buff2 = (char *)malloc(nNeeded);
-	    GetEnvironmentVariableA(__stringVal(aStringOrSymbol),
-				    buff2,
-				    nNeeded);
-	    ret = __MKSTRING(buff2);
-	    free(buff2);
-	} else {
-	    if (nNeeded > 0) {
-		ret = __MKSTRING(buff);
-	    }
-	}
-	RETURN (ret);
-    }
+        l = __stringSize(aStringOrSymbol);
+        if (l > sizeof(_varName)-1) 
+            goto badArgument;
+        for (i=0; i<l; i++) {
+            _varName[i] = __stringVal(aStringOrSymbol)[i];
+        }
+    } else if (__isUnicode16String(aStringOrSymbol)) {
+        l = __unicode16StringSize(aStringOrSymbol);
+        if (l > sizeof(_varName)-1) 
+            goto badArgument;
+        for (i=0; i<l; i++) {
+            _varName[i] = __unicode16StringVal(aStringOrSymbol)[i];
+        }
+    } else
+        goto badArgument;
+
+    _varName[l] = 0;
+
+    nNeeded = GetEnvironmentVariableW(_varName, buff, sizeof(buff));
+    if (nNeeded > sizeof(buff)) {
+        WCHAR *buff2;
+
+        buff2 = (char *)malloc(nNeeded * sizeof(WCHAR));
+        GetEnvironmentVariableW(_varName, buff2, nNeeded);
+        ret = __mkStringOrU16String_maxlen(buff2, nNeeded);
+        free(buff2);
+    } else if (nNeeded > 0) {
+        ret = __mkStringOrU16String_maxlen(buff, nNeeded);
+    }
+    RETURN (ret);
+
+badArgument:;
 %}
 .
     ^ nil
 
     "
-     OperatingSystem getEnvironment:'LANG'
-     OperatingSystem getEnvironment:'LOGIN'
-     OperatingSystem getEnvironment:'HOME'
-     OperatingSystem getEnvironment:'NNTPSERVER'
-     OperatingSystem getEnvironment:'MAIL'
      OperatingSystem getEnvironment:'PATH'
     "
 
@@ -7918,18 +7904,14 @@
     // Note: GetComputerNameExA can fail in certain locales!
 #if defined(__MINGW32__)
     if (GetComputerNameA(bufferA, &buffSize) == TRUE) {
-	hostName = __MKSTRING_L(bufferA, buffSize);
+        RETURN(__MKSTRING_L(bufferA, buffSize));
     }
 #else
     if (GetComputerNameExW(ComputerNameDnsFullyQualified, buffer, &buffSize) == TRUE) {
-	hostName = __MKU16STRING_MAXLEN(buffer, buffSize);
-    }
-#endif
-%}.
-    hostName isNil ifTrue:[
-	^ nil.
-    ].
-    ^ hostName asSingleByteStringIfPossible
+        RETURN(__mkStringOrU16String_maxlen(buffer, buffSize));
+    }
+#endif
+%}.
 
     "
      OperatingSystem getHostName
@@ -12212,14 +12194,14 @@
 
     "/ access lazily...
     fullPathName isNil ifTrue:[
-	fullPathName := (OperatingSystem getLongPathName:sourcePath) asSingleByteStringIfPossible.
+        fullPathName := OperatingSystem getLongPathName:sourcePath.
     ].
 
     ^ fullPathName
 
     "
-	'C:\' asFilename info fullPathName
-	'C:\Dokumente und Einstellungen' asFilename info fullPathName
+        'C:\' asFilename info fullPathName
+        'C:\Dokumente und Einstellungen' asFilename info fullPathName
     "
 !