Re: GTK-Function with pathnamestring???



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.
This is not entirely correct. argv[0] is not any different than any of
the other argv[] elements. It is simply whatever was passed 
to the exec system call as argv[0], and it can be totally arbitrary.
argv[0] is not a 100% reliable method of process image path 
determination, though it is true that it will work in many cases.

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.

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.

[ skipped ]

The short answer is that there is no portable (amongst POSIX/UNIX like
systems) way to get a path to your process. On linux, there is a highly 
non-portable solution, that is to use /proc/<pid>/exe. This is a symlink
to a path that leads to the inode of the process's image. Almost every
UNIX like OS has some non portable facility to get this information.

Probably, good idea may be, to have conditional defines for system which
have a solution (Linux, Windows I guess), and use argv[0] for other cases.
That increases the chance.




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