Actually, the path we really need is the location of librexxapi. It looks
like dladdr1() might give me the information I want, The main process
executable might be an app that is just linked to the interpreter (for
example bsfoorexx used from java).

http://man7.org/linux/man-pages/man3/dladdr.3.html

But I don't know how portable it is or whether there are alternatives for
the other platforms. The post that referenced this included all sorts of
complications such as links that might be problematic.

Rick

On Sat, Jan 5, 2019 at 7:25 AM Enrico Sorichetti via Oorexx-devel <
oorexx-devel@lists.sourceforge.net> wrote:

> here are three snippets that show how to do it
>
> APPLE
>
> #include <stdio.h>
> #include <string.h>
> #include <stdlib.h>
> #include <unistd.h>
>
> #include <libproc.h>
>
>
> int main()
> {
>     pid_t pid;
>
>     char path[1024];
>
>     int RC;
>     char *cp;
>
>     pid = getpid();
>     RC  = proc_pidpath (pid, path, sizeof(path));
>     if ( RC <= 0 )
>     {
>         exit(-1);
>     }
>     else
>     {
>         cp = strrchr(path,'/');
>         *cp=0;
>         printf("path '%s'\n",path ) ;
>         exit(0);
>     }
>     exit(-1);
> }
>
> Freebsd
> /*  FreeBSD
> */
> #include <stdio.h>
> #include <unistd.h>
>
> int main()
> {
> char path[1024];
> int  size;
>
>     size = readlink( "/proc/curproc/file", path, sizeof(path)-1);
>
>     path[size] = '\0';
>
>     printf("***** '%s'\n", path );
>
>     return(0);
> }
>
> linux
>
> #include <stdio.h>
> #include <unistd.h>
>
> int main()
> {
> char path[1024];
> int  size;
>
>     size = readlink( "/proc/self/exe", path, sizeof(path)-1);
>
>     path[size] = '\0';
>
>     printf("***** '%s'\n", path );
>
>     return(0);
> }
>
> enrico
>
>
> On 5 Jan 2019, at 13:07, Rick McGuire <object.r...@gmail.com> wrote:
>
> My understanding on unix systems is that it is not possible determine the
> location of the binary. Please correct me if I'm wrong on this point, but
> David Ashley was quite insistent that it was not possible
>
>
> _______________________________________________
> Oorexx-devel mailing list
> Oorexx-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/oorexx-devel
>
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to