Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: "executable suffixes" for -x on win32 (perlport)

by pryrt (Abbot)
on Apr 27, 2017 at 18:05 UTC ( [id://1189075]=note: print w/replies, xml ) Need Help??


in reply to Re: "executable suffixes" for -x on win32 (perlport)
in thread "executable suffixes" for -x on win32 (perlport)

Interesting. Reading the context behind those SEARCH_EXTS definitions, it's in the Perl_find_script() function (aliased to macro find_script), and (to my reading) doesn't seem to be in the context of the -x ftest, that I can tell

Your .cmd search found (among others) the EU::MM instance where the four qw(.com .exe .bat .cmd) are shown, but that's in the EU::MM module, not in the -x ftest.

Some more searching for the ftest led me to pp_sys.c:PP(pp_ftrread) and the associated S_try_amagic_ftest() a few lines up. I eventually found the win32_fstat(), which I think calls the MSVCRT fstat(), so I don't think I can blame the port of perl for this: it looks like that might be due to the underlying library.

I've also verified that it is really just the four extensions (at least up to 3character extensions) that are considered "executable" to win32 perl:

use warnings; use strict; foreach my $ext ('a' .. 'zzz') { my $fn = 'x.'.$ext; open my $fh, '>', $fn or die "$fn $!"; close $fh; printf STDERR "%-15s %d\n", $fn, -x $fn if -x $fn; unlink $fn; } __END__ x.bat 1 x.cmd 1 x.com 1 x.exe 1

I made an equivalent program in c using the sys/stat.h's _stat(), and it was the same four extensions, only. I guess this one really can be blamed on Microsoft. :-)

Replies are listed 'Best First'.
Re^3: "executable suffixes" for -x on win32 (perlport)
by BrowserUk (Patriarch) on Apr 27, 2017 at 20:54 UTC
    I guess this one really can be blamed on Microsoft. :-)

    That's one take on it. Here's another.

    Under POSIX, -x determines if the file tested can be passed to exec(3) in order to load a new executable image into the current process.

    By that criteria, only two of the four extensions you list ought to test as executable, because .cmd & .bat aren't binary image files, thus cannot be loaded directly as executable images. The other two are equivalent to (b|c|z)sh scripts which require execl("/bin/sh", "sh", "-c", command, (char *) 0) or similar to be run; ie. system.

    The MSVCRT 'extension' of the POSIX definition of -x is a (perhaps silly) convenience from days of yore that's never been seen as important enough to rescind.

    But then, the entire idea of the -x test on windows doesn't make a whole heap of sense as there is no such thing as the "executable" bit in Windows -- the permissions system is far more fine grained and extensive.

    And, the concept of a files executability being defined by its extension a throwback to dos. An executable file can have any extension and it will still run:

    C:\test>junk.exe as int: 9218868437227405313 as dbl: 1.#SNAN0 as dbl: 1.#QNAN0 as int: 9221120237041090561 C:\test>ren junk.exe junk.garbage C:\test>junk.garbage as int: 9218868437227405313 as dbl: 1.#SNAN0 as dbl: 1.#QNAN0 as int: 9221120237041090561

    In reality, the mistake is that .cmd & .bat test as executable, not that .pl/.js/.whatever do not. It is the equivalent of *nix allowing you to pass a shell script filename to exec() and have it start the shell and then pass the script filename to it. (Ie. what system does.) And if you pass .pl/.js/.whatever (anything in pathext) to system on windows, it will execute them.

    The bottom line is that you do not have to mark .cmd or .bat (or .exe or .com or .garbage) files executable, so there is no executable bit to test; so MSVCRT attempts to do something vaguely sensible as a substitute; but what was vaguely sensible all those years ago, perhaps looks less sensible now.

    The bottom line is that where the two different worlds collide, there is no right solution; and whatever compromise is implemented it will be useful and convenient in one scenario and broken in another.

    Similarly with the users/groups/network stuff. It isn't possible to map them transparently between OSs.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1189075]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-03-28 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found