* handle the fact that GetEnvironmentStringsA returns the environment in the

OEM instead of in the Ansi code page (mantis #22524, #15233)

git-svn-id: branches/cpstrrtl@25092 -
This commit is contained in:
Jonas Maebe 2013-07-12 17:18:28 +00:00
parent a5273abc9c
commit d919794fdf

View File

@ -971,24 +971,30 @@ end;
Function GetEnvironmentVariable(Const EnvVar : String) : String; Function GetEnvironmentVariable(Const EnvVar : String) : String;
var var
s : string; oemenvvar, oemstr : RawByteString;
i : longint; i, hplen : longint;
hp,p : pchar; hp,p : pchar;
begin begin
oemenvvar:=uppercase(envvar);
SetCodePage(oemenvvar,CP_OEMCP);
Result:=''; Result:='';
p:=GetEnvironmentStrings; p:=GetEnvironmentStrings;
hp:=p; hp:=p;
while hp^<>#0 do while hp^<>#0 do
begin begin
s:=strpas(hp); oemstr:=hp;
i:=pos('=',s); { cache length, may change after uppercasing depending on code page }
if uppercase(copy(s,1,i-1))=upcase(envvar) then hplen:=length(oemstr);
{ all environment variables are encoded in the oem code page }
SetCodePage(oemstr,CP_OEMCP,false);
i:=pos('=',oemstr);
if uppercase(copy(oemstr,1,i-1))=oemenvvar then
begin begin
Result:=copy(s,i+1,length(s)-i); Result:=copy(oemstr,i+1,length(oemstr)-i);
break; break;
end; end;
{ next string entry} { next string entry}
hp:=hp+strlen(hp)+1; hp:=hp+hplen+1;
end; end;
FreeEnvironmentStrings(p); FreeEnvironmentStrings(p);
end; end;