Rod Evans wrote:
> Ali Bahrami wrote:
>> Peter Lawrence wrote:
>>> All,
>>>      has the data file equivalent to dlopen("$ORIGIN/../lib/foo.so) 
>>> been invented already,
>>> or is there an SOP that I'm not familiar with for accomplishing this ?
>>>  
>>> what I need is for example "$ORIGIN/../etc/foo.conf"
>>>
>>> thanks,
>>> Pete Lawrence.
>>
>>
>> I'm not sure if there's a better way, but one way would be to feed
>> the handle you got from dlopen() to dlinfo() and get the
>> directory (RTLD_DI_ORIGIN). Then, you can add the "../etc/foo.conf"
>> to it to get the path you need.
> 
> And you don't need a handle if you're looking for you're own
> origin:
> 
>     char    buffer[PATH_MAX];
> 
>     if (dlinfo(RTLD_SELF, RTLD_DI_ORIGIN, (void *)&buffer) != -1)
>                 (void) printf("my origin:\t\t%s\n", buffer);
> 
> 

Or even

const char *getexecname(void);

DESCRIPTION
      The getexecname() function returns the pathname  (the  first
      argument  of  one  of  the  exec  family  of  functions; see
      exec(2)) of the executable that started the process.

      Normally this is an absolute pathname, as  the  majority  of
      commands  are executed by the shells that append the command
      name to the user's PATH components.  If this is not an abso-
      lute  path,  the output of getcwd(3C) can be prepended to it
      to create an absolute path, unless the process or one of its
      ancestors  has changed its root directory or current working
      directory since the last successful call to one of the  exec
      family of functions.

- Bart


-- 
Bart Smaalders                  Solaris Kernel Performance
barts at cyber.eng.sun.com              http://blogs.sun.com/barts

Reply via email to