Re: GTK-Function with pathnamestring???
- From: John K Luebs <jkluebs luebsphoto com>
- To: "Pawel S. Veselov" <Pawel Veselov sun com>
- Cc: Christian Schneider <christian_schneider_2000 yahoo de>, gtk-app-devel-list gnome org
- Subject: Re: GTK-Function with pathnamestring???
- Date: Wed, 8 Oct 2003 22:20:41 -0400
On Wed, Oct 08, 2003 at 09:41:02AM -0700, Pawel S. Veselov wrote:
On Wed, Oct 08, 2003 at 12:53:52AM -0400, John K Luebs wrote:
argv[0] is always a pointer to a executable. If it's relative, use getcwd(),
to append to get full pathname.
Well, this is true. But I haven't really seen any code which doesn't
set argv[0] to executable path. There is also a lot of code out there which
depends on it's validity.
I don't know about this. The behavior of many programs depends on the
content of argv[0] being valid as a *filename*, but not necessarily a
path to the executable itself. I think that it is more common that an
app will use argv[0] as a switch for its behavior rather than a way to
find itself, no?
It is perfectly valid to prepend some location to form a path to an
executable, but only pass the basename for argv[0]. This may not be
common, because the typical sh derivative does not do this, but it is
not unheard of. If a program requires that argv[0] be a valid *path*
(either ./, absolute, or in $PATH) to itself, then that fact should be
clearly documented.
Furthermore, in the cases that argv[0] is not arbitrary, it will almost
never be relative. It will either be absolute, or it will be within
one of the directories in $PATH. The upshot is that all you can do
with argv[0] is pass it to exec and hope for the best.
I won't say it is so. How many times people invoke binaries using
relative pathname ( ./test, ./bin/start ), then argv[0] is relative.
Right, but names like "./test" and "./bin/start" can be
passed directly to exec, one doesn't need to use getcwd() (which is
why I got confused when it was mentioned). IOW, all you can do is
just pass argv[0] to exec and hope for the best.
If you were suggesting using getcwd() along with argv[0] to use
the full path for something other than exec, then that was what the
rest of my post was about. I just wanted the OP to realize that
using the executable path for anything other than self exec is usually
a Bad Idea.
He didn't say why he needed to know the executable path, so I could
only assume it was for evil purposes ;-).
--jkl
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]