Recent

Author Topic: [Solved] Output of fpReadLink  (Read 1675 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
[Solved] Output of fpReadLink
« on: September 03, 2022, 02:20:30 am »
Hello.

With this:
Code: Pascal  [Select][+][-]
  1. program fpreadlink_test;
  2.   uses
  3.     baseunix;
  4.   var
  5.     pathexec : string;    
  6.      
  7.   begin
  8.       Fpreadlink('/proc/self/exe',@pathexec[0],high(pathexec));
  9.       writeln(pathexec);
  10.   end.

I get this:
Code: Text  [Select][+][-]
  1. ~> ./fpreadlink_test
  2. home/fred/fpreadlink_test

OK, it works, also if a symlink -s was used.

But why is the first "/" before "home" missing in the output ? (Or I miss something.  :-[ )

Fre;D
« Last Edit: September 03, 2022, 03:25:36 am by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Output of fpReadLink
« Reply #1 on: September 03, 2022, 03:24:43 am »
OK, found solution thanks to /fpcsrc/3.2.2/rtl/linux/system.pp and his SysInitExecPath procedure.

So this:
Code: Pascal  [Select][+][-]
  1.   Program fpreadlink_test;
  2.     uses
  3.       baseunix;
  4.     var
  5.       pathexec : shortstring;  
  6.       i : integer;
  7.      
  8.     begin
  9.       pathexec[0]:=#0;
  10.       i := Fpreadlink('/proc/self/exe',@pathexec[1],high(pathexec));
  11.       if (i>0) and (pathexec[1]='/') then pathexec[0]:=char(i);
  12.      
  13.       writeln(pathexec);
  14.     end.

Gives this (with the "/" at begin):
 
Code: Text  [Select][+][-]
  1. ~> ./fpreadlink_test
  2. /home/fred/fpreadlink_test

 :) ( and sorry for the noise)

Fre;D
« Last Edit: September 03, 2022, 03:34:41 am by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: [Solved] Output of fpReadLink
« Reply #2 on: September 03, 2022, 01:41:49 pm »
Even simpler:

Code: Pascal  [Select][+][-]
  1. Program fpreadlink_test;
  2.    uses
  3.      baseunix;
  4.    var
  5.      pathexec : shortstring;  
  6.    
  7.   begin
  8.     pathexec := Fpreadlink('/proc/self/exe');
  9.     writeln(pathexec);
  10.   end.
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

 

TinyPortal © 2005-2018