Browse Source

* 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 -

Jonas Maebe 12 years ago
parent
commit
42be54a00f
1 changed files with 7 additions and 3 deletions
  1. 7 3
      rtl/nativent/sysutils.pp

+ 7 - 3
rtl/nativent/sysutils.pp

@@ -1050,7 +1050,7 @@ function wstrlen(p: PWideChar): SizeInt; external name 'FPC_PWIDECHAR_LENGTH';
 
 function GetEnvironmentVariable(const EnvVar: String): String;
 var
-   s : string;
+   s, upperenvvar : UTF8String;
    i : longint;
    hp: pwidechar;
    len: sizeint;
@@ -1058,15 +1058,19 @@ begin
    { TODO : test once I know how to execute processes }
    Result:='';
    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
      begin
         len:=UnicodeToUTF8(Nil, hp, 0);
         SetLength(s,len);
         UnicodeToUTF8(PChar(s), hp, len);
-        //s:=strpas(hp);
         i:=pos('=',s);
-        if uppercase(copy(s,1,i-1))=upcase(envvar) then
+        if uppercase(copy(s,1,i-1))=upperenvvar then
           begin
+             { copy() returns a rawbytestring -> will keep UTF-8 encoding }
              Result:=copy(s,i+1,length(s)-i);
              break;
           end;