From e078408dcf76a282a7336afeb5476c75779817cd Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Wed, 6 Oct 2021 06:12:58 +0300 Subject: [PATCH] + implemented SysUtils.GetEnvironmentVariable, GetEnvironmentVariableCount and GetEnvironmentString for WASI --- rtl/wasi/sysutils.pp | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/rtl/wasi/sysutils.pp b/rtl/wasi/sysutils.pp index af9e38e961..9a3525f074 100644 --- a/rtl/wasi/sysutils.pp +++ b/rtl/wasi/sysutils.pp @@ -253,15 +253,62 @@ end; ****************************************************************************} Function GetEnvironmentVariable(Const EnvVar : String) : String; +var + hp : ppchar; + hs : string; + eqpos : longint; begin + result:=''; + hp:=envp; + if hp<>nil then + while assigned(hp^) do + begin + hs:=strpas(hp^); + eqpos:=pos('=',hs); + if copy(hs,1,eqpos-1)=envvar then + begin + result:=copy(hs,eqpos+1,length(hs)-eqpos); + break; + end; + inc(hp); + end; end; Function GetEnvironmentVariableCount : Integer; +var + p: ppchar; begin + result:=0; + p:=envp; {defined in system} + if p<>nil then + while p^<>nil do + begin + inc(result); + inc(p); + end; end; Function GetEnvironmentString(Index : Integer) : {$ifdef FPC_RTL_UNICODE}UnicodeString{$else}AnsiString{$endif}; +Var + i : longint; + p : ppchar; begin + if (Index <= 0) or (envp=nil) then + result:='' + else + begin + p:=envp; {defined in system} + i:=1; + while (inil) do + begin + inc(i); + inc(p); + end; + if p^=nil then + result:='' + else + result:=strpas(p^) + end; end;