Delphi 10.3.2 macOS 64 bit how to execute chmod?

As of now, I executed chmod with the following function:

const
	libc = '/usr/lib/libc.dylib';

type
	PIOFile = Pointer;

function popen(const Command: PAnsiChar; Modes: PAnsiChar): PIOFile; cdecl;	external libc name '_popen';
function pclose(Stream: PIOFile): Integer; cdecl; external libc name '_pclose';
function feof(Stream: PIOFile): Integer; cdecl; external libc name '_feof';
function fread(Ptr: Pointer; Size: LongWord; N: LongWord; Stream: PIOFile): LongWord; cdecl; external libc name '_fread';
function wait(__stat_loc: PInteger): Integer; cdecl; external libc name '_wait';

procedure ExecCmdine(const CmdLine: string; CmdResult: TStrings);
var
	Output: PIOFile;
	Buffer: PAnsiChar;
	TempString: ansistring;
	Line: ansistring;
	BytesRead: Integer;
const
	BufferSize: Integer = 8192;
begin
	TempString := '';
	Output := popen(PAnsiChar(ansistring(CmdLine)), 'r');
	GetMem(Buffer, BufferSize);
	if Assigned(Output) then
		try
			while feof(Output) = 0 do
			begin
				BytesRead := fread(Buffer, 1, BufferSize, Output);
				SetLength(TempString, length(TempString) + BytesRead);
				Move(Buffer^, TempString[length(TempString) - (BytesRead - 1)],	BytesRead);
				while Pos(#10, TempString) > 0 do
				begin
					Line := Copy(TempString, 1, Pos(#10, TempString) - 1);
					if CmdResult <> nil then CmdResult.Add(UTF8ToString(Line));
					TempString := Copy(TempString, Pos(#10, TempString) + 1,length(TempString));
				end;
			end;
		finally
			pclose(Output);
			wait(nil);
			FreeMem(Buffer, BufferSize);
		end;
end;

This works for macOS 32 bit, but not anymore for macOS 64 bit, it returns errors:

Error: "__pclose", referenced from:      __ZN9Functions6pcloseEPv in functions.o;
Error: "__popen", referenced from:      __ZN9Functions5popenEPKcPc in functions.o;
Error: "__feof", referenced from:      __ZN9Functions4feofEPv in functions.o;
Error: "__fread", referenced from:      __ZN9Functions5freadEPvmmS0_ in functions.o;
Error: "__wait", referenced from:      __ZN9Functions4waitEPi in functions.o;
ld: symbol(s) not found for architecture x86_64

I am saving and also downloading some files, like youtube-dl, and I need to change their permission so they can be executed. It works fine with macOS 32 bit, but as I wrote, switching to 64 bit, I get the errors above.

Must be the declaration. What am I doing wrong?

Parents
No Data
Reply
  • This requires no additional declarations and works just fine:

    procedure MakeFileExecutable(const aFile: string);
    begin
      _system(PAnsiChar(UTF8Encode('chmod +x ' + AnsiQuotedStr(aFile, #39))));
    end;

Children
No Data