Jelajahi Sumber

* get paramstr(0) only if really needed

git-svn-id: trunk@43898 -
florian 5 tahun lalu
induk
melakukan
3335104da2
1 mengubah file dengan 14 tambahan dan 15 penghapusan
  1. 14 15
      rtl/linux/system.pp

+ 14 - 15
rtl/linux/system.pp

@@ -425,12 +425,26 @@ end;}
 var
  execpathstr : shortstring;
 
+procedure SysInitExecPath;
+var
+  i    : longint;
+begin
+  execpathstr[0]:=#0;
+  i:=Fpreadlink('/proc/self/exe',@execpathstr[1],high(execpathstr));
+  { it must also be an absolute filename, linux 2.0 points to a memory
+    location so this will skip that }
+  if (i>0) and (execpathstr[1]='/') then
+     execpathstr[0]:=char(i);
+end;
+
 function paramstr(l: longint) : string;
  begin
    { stricly conforming POSIX applications  }
    { have the executing filename as argv[0] }
    if l=0 then
      begin
+       if execpathstr='' then
+         SysInitExecPath;
        paramstr := execpathstr;
      end
    else if (l < argc) then
@@ -600,19 +614,6 @@ begin
   FpSigAction(SIGILL,@oldsigill,nil);
 end;
 
-
-procedure SysInitExecPath;
-var
-  i    : longint;
-begin
-  execpathstr[0]:=#0;
-  i:=Fpreadlink('/proc/self/exe',@execpathstr[1],high(execpathstr));
-  { it must also be an absolute filename, linux 2.0 points to a memory
-    location so this will skip that }
-  if (i>0) and (execpathstr[1]='/') then
-     execpathstr[0]:=char(i);
-end;
-
 function GetProcessID: SizeUInt;
 begin
  GetProcessID := SizeUInt (fpGetPID);
@@ -690,8 +691,6 @@ begin
   initunicodestringmanager;
   { Setup stdin, stdout and stderr }
   SysInitStdIO;
-  { Arguments }
-  SysInitExecPath;
   { Reset IO Error }
   InOutRes:=0;
   { threading }