|
@@ -1050,7 +1050,7 @@ function wstrlen(p: PWideChar): SizeInt; external name 'FPC_PWIDECHAR_LENGTH';
|
|
|
|
|
|
function GetEnvironmentVariable(const EnvVar: String): String;
|
|
function GetEnvironmentVariable(const EnvVar: String): String;
|
|
var
|
|
var
|
|
- s : string;
|
|
|
|
|
|
+ s, upperenvvar : UTF8String;
|
|
i : longint;
|
|
i : longint;
|
|
hp: pwidechar;
|
|
hp: pwidechar;
|
|
len: sizeint;
|
|
len: sizeint;
|
|
@@ -1058,15 +1058,19 @@ begin
|
|
{ TODO : test once I know how to execute processes }
|
|
{ TODO : test once I know how to execute processes }
|
|
Result:='';
|
|
Result:='';
|
|
hp:=PPEB(CurrentPEB)^.ProcessParameters^.Environment;
|
|
hp:=PPEB(CurrentPEB)^.ProcessParameters^.Environment;
|
|
|
|
+ { first convert to UTF-8, then uppercase in order to avoid potential data
|
|
|
|
+ loss }
|
|
|
|
+ upperenvvar:=EnvVar;
|
|
|
|
+ upperenvvar:=UpperCase(upperenvvar);
|
|
while hp^<>#0 do
|
|
while hp^<>#0 do
|
|
begin
|
|
begin
|
|
len:=UnicodeToUTF8(Nil, hp, 0);
|
|
len:=UnicodeToUTF8(Nil, hp, 0);
|
|
SetLength(s,len);
|
|
SetLength(s,len);
|
|
UnicodeToUTF8(PChar(s), hp, len);
|
|
UnicodeToUTF8(PChar(s), hp, len);
|
|
- //s:=strpas(hp);
|
|
|
|
i:=pos('=',s);
|
|
i:=pos('=',s);
|
|
- if uppercase(copy(s,1,i-1))=upcase(envvar) then
|
|
|
|
|
|
+ if uppercase(copy(s,1,i-1))=upperenvvar then
|
|
begin
|
|
begin
|
|
|
|
+ { copy() returns a rawbytestring -> will keep UTF-8 encoding }
|
|
Result:=copy(s,i+1,length(s)-i);
|
|
Result:=copy(s,i+1,length(s)-i);
|
|
break;
|
|
break;
|
|
end;
|
|
end;
|