mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 04:29:17 +02:00
* fixed codepage of result of GetEnvironmentVariable(ansistring)
* don't uppercase the name of the environment variable we are looking for in every loop iteration git-svn-id: branches/cpstrrtl@25104 -
This commit is contained in:
parent
8b77f62873
commit
42be54a00f
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user