Re: GTK-Function with pathnamestring???

On Tue, Oct 07, 2003 at 01:31:31PM -0700, Pawel S. Veselov wrote:
                      Hello, Christian !

[ This is not GTK ]

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.

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.

On Tue, Oct 07, 2003 at 10:15:30PM +0200, Christian Schneider wrote:

is there a function with GTk which returns a string
(or a pointer) with the pathname where the executable
file is placed?
For example my compiled executable is called test.exe.
If the test.exe is placed at the position
c:\programs\test.exe (under Windows) I want to get the
string (pointer) "c:\programs\".
If I copy this test.exe to c:\kopiert\test.exe I want
to get the string "c:\kopiert\".
My programm should be able to be compiled with linux
and windows. Therefore I ask for a GTK-function.
If there is not a GTK-function do you know a function
for windows and for linux?

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.

More importantly, you probably need to rethink what you are
trying to do. In fact, your question is a FAQ. I urge you to follow 
the advice given in 1.14 and 1.14.1 of the Unix Programming FAQ. 
Here is a link:


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