How Does a Program Know Where it is Running?

Dave Mielke dave at mielke.cc
Mon May 3 00:59:58 UTC 2004


[quoted lines by Karl Dahlke on 2004/05/02 at 19:58 +0000]

>getcwd()

No, that's not reliable since chdir() might've been called. getcwd() is only
reliable if it's called right at the start before any other code might've
called chdir(). Also, since argv[0] can ultimately be set to anything by the
invoker of the program, it isn't 100% reliable anyway. A common case in which
it, by definition, is wrong is when login prepends a minus sign to the name of
the shell.

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave at mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://familyradio.com/                   | http://mielke.cc/bible/





More information about the Blinux-list mailing list