> Mark Mcvittie wrote:
> > I found this bug with getcwd() on Mac,
>
>       Do you mean with fl_getcwd()?
>       Which version of OSX?

I mean with getcwd() I didn't know about fl_getcwd(). I have OSX 10.4.

> > 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?
>
>       From what I can tell, it seems to operate the way I'd expect,
>       but let's see how you're encountering it.
>
>       Here's what I get just casually exercising it against getcwd(),
>       seems to do what I'd expect:

I tried the foo.cxx code and then I edited it so I could double-click on the 
app and see the urls (see code posted below). In OSX I get different results 
between double-clicking the app and running it from the command line but these 
results were the same in ubuntu. Also, fl_getcwd() always gave the same results 
as getcwd().

// hellofoo.cxx
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/param.h>

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>

int main(int argc, char **argv) {
    Fl_Window *window = new Fl_Window(720,120);
    char buf[MAXPATHLEN];

    getcwd(buf, sizeof(buf));
    Fl_Box *box = new Fl_Box(FL_UP_BOX,10,20,200,20,"getcwd(buf) returned:");
    box = new Fl_Box(FL_UP_BOX,210,20,500,20,buf);
    buf[0] = 0; // clear after use for next call

    fl_getcwd(buf, sizeof(buf));
    box = new Fl_Box(FL_UP_BOX,10,40,200,20,"fl_getcwd(buf) returned:");
    box = new Fl_Box(FL_UP_BOX,210,40,500,20,buf);

    char *cwd = getcwd(0, MAXPATHLEN);
    box = new Fl_Box(FL_UP_BOX,10,60,200,20,"getcwd(0,0) returned:");
    box = new Fl_Box(FL_UP_BOX,210,60,500,20,cwd);
    free((void*)cwd);

    cwd = fl_getcwd(0, MAXPATHLEN);
    box = new Fl_Box(FL_UP_BOX,10,80,200,20,"fl_getcwd(0,0) returned:");
    box = new Fl_Box(FL_UP_BOX,210,80,500,20,cwd);
    free((void*)cwd);

    window->end();
    window->show(argc, argv);
    return Fl::run();
}

> 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.

Thanks, that's what I was doing, double-clicking the app in test/help and it 
was returning the wrong working directory. If I run it from the command line it 
works but I didn't know to try that.

> 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.

So then it is not a bug but a feature left to the disgression of the programmer 
to solve. Wouldn't it be better if fl_getcwd() could do this for us, or is 
there some reason it doesn't?

> 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!

> > OK - here's a version of the code for determing the "true" app path...

Thanks for the code. In fl_help_view, getcwd() is used twice but I think this 
needs to be fixed. I am going to try making your platform-specific code into a 
function to replace out getcwd().
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to