|
|
On 17 May 2011, at 22:22, Mark Mcvittie wrote:
> I found this bug with getcwd() on Mac, it doesn't happen in Linux and I haven't tried Windows. What happens is that on OSX it always returns a path 'Users/username'. Can anyone confirm or explain?
If you launch your app form the command line, I think you'll find that getcwd returns the "right thing", i.e. the directory that the shell was in.
But if you launch your app by double-clicking it in the finder (or, IIRC from Xcode, though I seldom use Xcode myself) you get a "default" path returned. Which sounds a lot like what you are seeing.
What happens in linux tends to depend on what WM you are running; since I've used quite a few different WM's over the years, I've seen all sorts of behaviours, the two most common ones being to return the apps directory (which is quite useful) or your own home dir (less useful).
WinXX in general tends to return the apps directory.
As to getting something useful, the quick'n'dirty hack is to look at getcwd() AND at the value in argv[0] - usually (not always) the two concatenated will tell you the actual path to your app, and from there you can do useful stuff.
As a better solution (if I remember, it is not on this machine!) I'll post the code I usually use - it has platform specific hooks for getting the "true" path on OSX, linux, win32 and solaris - they all have API's that allow you to get at that stuff, though of course it is different for every one!
Any use?
Actually, if you search the archives here, I've posted it here before, though I can't guess what search terms would lead you to it easily!
[ Direct Link to Message ] | |
|
| |