Converting launch_activate_socket() from C to Pascal - issues lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- trev · 2021-05-04 10:44 After having successfully converted  the SampleD C daemon code into working, non-deprecated C code (ie replacing the deprecated ASL logging with OSLog; replacing the myriad deprecated launch_ functions with launch_activate_socket) my quest to convert it into Pascal has hit a pot hole, er, wall. My working, converted, C code: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #include [...] int *listening_fd_array; size_t listening_fds_count; int err;[...]err = launch_activate_socket("MySocket", &listening_fd_array, &listening_fds_count);if (err != 0) {   os_log_error(OS_LOG_DEFAULT, "launch_activate_socket() failed error %d (%s)", err, strerror(err));} if (NULL == listening_fd_array) {    os_log_error(OS_LOG_DEFAULT, "No known sockets found to answer requests on!");    retval = EXIT_FAILURE;    goto done;} My failed Pascal attempt: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function launch_activate_socket(const name: string; var fds: PInteger; cnt: size_t): integer; external name '_launch_activate_socket'; [...]var  err : integer;  listening_fd_array: PInteger;  listening_fds_count: size_t; [...]err := launch_activate_socket('MySocket', listening_fd_array, listening_fds_count);if(err <> 0) then  begin    if(err = ENOENT) then      writeln('Error: Socket not found in plist file (', err, ')')    else if(err = ESRCH) then      writeln('Error: Calling process is not managed by launchd (', err, ')')    else if(err = EALREADY) then      writeln('Error: Socket already activated (', err, ')')    else      writeln('Error: ', err);  end; if(Nil = listening_fds_count) then  begin    writeln('No known sockets found to answer requests on!');    goto Done;  end; Where did I go wrong? It compiles successfully, but errors out with ESRCH and "No known sockets...". ---------------------------------------------------------------------- PascalDragon · 2021-05-04 11:10 I have really strong doubts that launch_activate_socket as a C function takes a Pascal string instead of a PChar. Also shouldn't your cnt parameter be a var (or out) as well? (Also I doubt that Nil = listening_fds_count does indeed compile) ---------------------------------------------------------------------- trev · 2021-05-04 12:45 Dang (cut 'n paste errors from another version): - Nil should have been 0 - string should have been pchar Thanks - I'd missed the missing var. No more spurious errors ---------------------------------------------------------------------- PascalDragon · 2021-05-05 07:07 Quote from: trev on May 04, 2021, 02:45:51 pmThanks - I'd missed the missing var. No more spurious errors You're welcome.