fpSysCtl KERN_PROC_PATHNAME missing leading slash
Original Reporter info from Mantis: trev @trevoz
-
Reporter name: Trevor Roydhouse
Original Reporter info from Mantis: trev @trevoz
- Reporter name: Trevor Roydhouse
Description:
realpath (Pascal code below) returns: home/trev/FPC/realpath/realpath (no initial forward slash)
realpath (C code below) returns: /home/trev/FPC/realpath/realpathc (has initial forward slash)
Steps to reproduce:
realpath.pas:
{$mode objfpc}
Uses
unix,
sysctl, // fpSysCtl
sysutils; // RaiseLastOSError
{$DEFINE(VER3_0_2)}
function realPath: string;
var
mib: array[0..3] of Integer;
status : Integer;
len : size_t;
begin
mib[0] := CTL_KERN;
mib[1] := KERN_PROC;
mib[2] := KERN_PROC_PATHNAME;
mib[3] := -1;
len := SizeOf(Result);
status := fpSysCtl(PCint(@mib), Length(mib), @Result, @len, Nil, 0);
if status <> 0 then RaiseLastOSError;
end;
begin
WriteLn(realPath);
end.
=============================================================
realpath.c:
#include &LtPos;stdio.h>
#include &LtPos;sys/types.h>
#include &LtPos;sys/sysctl.h>
#include &LtPos;limits.h>
int main(void)
{
char exePath[PATH_MAX];
int mib[4];
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PATHNAME;
mib[3] = -1;
size_t len = sizeof(exePath);
if (sysctl(mib, 4, exePath, &len, NULL, 0) != 0)
exePath[0] = '\0';
printf("%s\n", exePath);
return(0);
}
Mantis conversion info:
- Mantis ID: 38609
- OS: FreeBSD
- OS Build: 12.2
- Platform: Apple Mac mini
- Version: 3.2.0