tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: make: ensure ${.MAKE} works

>realpath(3) is not guaranteed to return an absolute path name if it is not
>given one (although in the NetBSD implementation it does).

It can return NULL too - though probably not likely in this case.

>The test should just be:
>        if (argv[0][0] != '/')
>instead of the strchr and the comparison.

I was trying to leave the value alone if it was a bare word (and we
obviously found it ok via $PATH), but always forcing to an absolute path
is ok.

>On the standard realpath(3) implementations it is a no-op. Perhaps
>adding a test afterwards:
>        if (*p1 != '/') {
>            char cwd[MAXPATHLEN];
>            snprintf(p1 = mdpath, "%s/%s", getcwd(cwd, sizeof(cwd)), argv[0]);

If that were guaranteed to be correct, I imagine realpath() would have
succeeded.   I'd opt to use the result of realpath() if it worked, or
just punt and stick with argv[0]:

        if (argv[0][0] == '/') {
            p1 = argv[0];
        } else {
            p1 = realpath(argv[0], mdpath);
            if (!p1 || *p1 != '/') {
                p1 = argv[0];           /* realpath failed */


Home | Main Index | Thread Index | Old Index