GP2X Full Path Of Program


GernotFrisch

Member
Joined
Jan 2, 2007
Messages
445
How can I get the full path to my executable?
Someone stated, that his program always thinks it's in "/usr/gp2x" when started from gp2xmenu. It works on my machine, though.

So- what is the most failproof way of getting the pathname of my program?
 
Tell him to upgrade his firmware, 2.1 and above always changes dir to the dir of your program before running it.
 
KungPhoo said:
So- what is the most failproof way of getting the pathname of my program?
At the command line the which command is what you need.

CODE
which mycommand
 
Last edited by a moderator:
in c, argv[0], _may_ have the fullpath+execname, but often on unix it just has the name that was invoked, so if gp2xmenu invoked 'blah' then all you will get is blah, but if it was execd as /mnt/sd/blah/BLAHBLAH then thats what you will get.

getcwd isnt garunteed to be the direction the exec is in, just the directory it was execed from.

my app opens its files as ./ and always succeeds, so one can assume that gp2xmenu cd's to the executables directory then invokes it.

you could always investigate /proc/self/exe + /proc/self/cwd

/proc/self/exe should be the full path+name of the running executable.
 
Back
Top