--- In [email protected], Praveen S <mailprave...@...> wrote:

> I have a executable file at a particular location in the 
filesystem. From
> root directory i run this exe. This exe will load a shared object 
from
> another location (say /usr/lib). Now the shared object wants to 
read a
> config file which is in the directory where the exe is located. How 
can it
> get that path.

  See here for an example of how to get executable location on 
windows, linux, solaris and os-x (each platform is different):
 
http://svn.codehaus.org/groovy/trunk/groovy/modules/native_launcher/
source/jst_fileutils.c
 
  Look for function called getExecutableHome
 
 
  Consider at least twice before resorting to using this - it may 
create security problems if the executable is run w/ higher 
privileges than the user running it has. It is easy for the user to 
twist the executable location into something different by e.g. 
creating a hard link to the executable and running the program via 
that (the location of the hard link will show as the exec location) 
and that way make the app load whatever he provides.
  On *nixes you can often rely on "well known locations", i.e. hard 
code the location to the binary at compile time and just assume the 
stuff you need is there.
 
 
 
     ::Antti::
 
 

Reply via email to