Heiko Voigt <hvo...@hvoigt.net> writes:

> Since the code for cygwin and windows in general is almost the same I would
> extract one function for them where I leave in one ifdef for cygwin.
>
> E.g. like this:
>
>
>       static int is_executable(const char *name)
>       {
>               struct stat st;
>
>               if (stat(name, &st) || /* stat, not lstat */
>                   !S_ISREG(st.st_mode))
>                       return 0;
>
>               fill_platform_stat(name, &st);
>
>               return st.st_mode & S_IXUSR;
>       }
>
> which I could then define to a no op on posix. That way we avoid code
> duplication in the platform specific functions.
>
> What do you think?

Does having the "stat()" help on Windows in any way?  Does it ever
return an executable bit by itself?

If not, Windows compat/ implementation may want to skip issuing a
useless stat() and write it as

        if (has_extension(".exe"))
                return 1;
        if (contents_begins_with("MZ") || contents_begins_with("#!"))
                return 1;
        return 0;

without ever talking about stat() which is POSIXism compat/
implementation for Windows does not have to worry about.

And that was the reason I suggested making the whole implementation
of path_is_executable() overridable by compat/ layer.

But if having "stat()" helps on Windows, then your counterproposal
is good enough for me.

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to