Re: Absolute paths

On Mon, Aug 14, 2000 at 08:52:48AM -0400, Mike Sangrey wrote:
> 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.


--        moo
fork()'ed on 37058400                                                    moo
meatspace place: home  yank?
>>protect privacy: or  encrypted mail preferred<<

PGP signature

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