Current working dir?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
turkeyman
Posts: 75
Joined: Wed Oct 20, 2004 7:38 pm
Location: Brisbane, Australia
Contact:

Current working dir?

Post by turkeyman »

Can anyone tell me how to get the current working directory? or rather, since there doesnt seem to be one (all paths seem to be absolute), the directory the elf lives in?
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

you can find it inside argv[0]
User avatar
turkeyman
Posts: 75
Joined: Wed Oct 20, 2004 7:38 pm
Location: Brisbane, Australia
Contact:

Post by turkeyman »

sure?
that was the first thing i tried, but it didnt work..
does that rely on the launcher? or the homebrew libs?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Depends, argv[0] is setup by the program which loaded the module, if the launcher doesn't do it correct it will not work. The Sony shell does it, psplink does it, not idea about any other launcher.

The libc which comes with the toolchain _should_ extract the current directory information for you and allow you to call open/opendir etc. with relative paths, but best print out argv[0] to see if you have actually got the path to the executable in there.
PeterM
Posts: 125
Joined: Sat Dec 31, 2005 7:25 pm
Location: Edinburgh, UK
Contact:

Post by PeterM »

You can get the current dir using the getcwd function. I think it lives in unistd.h, but I'm not sure.
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

eLoader also passes the correct argv[0] by default. You can turn that behaviour off so that it passes NULL, but it's unlikely you've done that.

Note that the stdlib functions all rely on the module being passed the correct argv[] in the first place, if that didn't happen then all standard functions (such as cwd()) will have problems.
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
User avatar
turkeyman
Posts: 75
Joined: Wed Oct 20, 2004 7:38 pm
Location: Brisbane, Australia
Contact:

Post by turkeyman »

fair call, if you say the sony shell does set it up, then i must have just screwed something up myself..
thanks guys! :P
Post Reply