> First, if you're installing a software package on the system, and
> you're not making all its binaries accessible via a standard location
> such as /usr, *and* you're not adding the binaries' location to your
> services' PATH, you are not making the software package functional.
> 

To be fair, the complication stems from my desire to run things 
location-independent, going against the philosophy of having programs in a 
known location, and requiring “just-in-time" wrangling of PATH.

Still, a revealing corner case: one naively expects all OSs would make it as 
simple as Linux to let a binary find its real path.

Would a dladdr solution be more elegant and Solaris-friendly?

  #ifdef __APPLE__
  #define _DARWIN_C_SOURCE 1
  #endif
  #include <dlfcn.h>
  ...
  
  Dl_info info;

  if (!dladdr((void *)main, &info)) strerr_diefu1sys(111, "getdirname”) ;

  if (stralloc_copys(&sa, info.dli_fname) < 0 || !stralloc_0(&sa)) 
    strerr_diefu1sys(111, "getdirname") ;

  stralloc dirname = STRALLOC_ZERO ;

  if (!sadirname(&dirname, sa.s, sa.len))
    strerr_diefu2sys(111, "get dirname of ", sa.s) ;


Reply via email to