Re: Absolute paths



On Mon, Aug 14, 2000 at 08:52:48AM -0400, Mike Sangrey wrote:
> M.Rogers@cs.ucl.ac.uk said:
> > Doesn't argv[0] give you the full pathname of the executable image of
> > your  application? 
> No.  It gives what is typed on the command line.  `cat' and `/bin/cat' will 
> give "cat" and "/bin/cat", respectively.

trying to get the path of the current executable is a unix faq and the
short answer is "you can't.  don't do it."  the slightly longer answer
is "that's not the way to make your code location independent."

i think the real answer is to have one hard coded path - for a config
file.  offer a way to pass it via commandline so if you put the config
file somewhere besides /etc/foorc, /usr/local/etc/roorc, /opt/etc/foorc,
/opt/foo/etc/foorc or $HOME/.foorc then you can make a shell script
and have it call foo.bin "--conf=/Programs/Configuration Files/The
Foo Application's Configuration File" and make sure foo is installed as
foo.bin in your packaging script.  additionally you could use environment
vars but they're rather subtle and can cause unexpected things if you
forget to check them.

kevin

-- 
kevin@suberic.net        moo
fork()'ed on 37058400                                                    moo
meatspace place: home    http://suberic.net/~kevin/  yank? www.votenader.com
>>protect privacy: www.gnupg.org or www.pgp.com.  encrypted mail preferred<<

PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]