delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1998/09/16/15:19:01

From: cgf AT cygnus DOT com (Christopher Faylor)
Subject: Re: Forgotten change
16 Sep 1998 15:19:01 -0700 :
Message-ID: <19980916174933.E18510.cygnus.cygwin32.developers@cygnus.com>
References: <36002924 DOT C74CF718 AT cityweb DOT de>
Mime-Version: 1.0
To: Corinna Vinschen <corinna DOT vinschen AT cityweb DOT de>,
cygwin32-developers AT cygnus DOT com

The kind of tests that require reading the file actually slow things
down quite a bit.  I've run benchmarks on this.  I think there is little
to gain for looking at the "magic number" in a file to find out if it is
executable.  It should be very rare that a PE filename does not end in
..exe.

Also, there is already preliminary code in the latest snapshot for handling
extensions in a more flexible way.  Your addition of strcasecmp into
the middle of a run of strcasematch's doesn't look right either.

On Wed, Sep 16, 1998 at 11:09:56PM +0200, Corinna Vinschen wrote:
>I have forgotten the following patch to
>fhandler_disk_file::check_execable(),
>which is sure a point of discussion, but
>if working with tcsh, it's easier, to
>remove all .exe suffixes from the
>files.
>IMHO, the following patch, which checks
>the suffix '.sh' and moreover the first
>bytes in a file, slows down 'ls -l' only
>a little bit, but gives more info.
>
>Corinna
>
>---------- snip ------------
>*** fhandler.cc.orig   Wed Sep 16 23:02:54 1998
>--- fhandler.cc Wed Sep 16 23:02:57 1998
>*************** fhandler_disk_file::check_execable_p (co
>*** 1277,1284 ****
>--- 1277,1303 ----
>    if (strcasematch (".bat", ch)
>        || strcasematch (".exe", ch)
>        || strcasematch (".com", ch)
>+       || strcasecmp (".sh", ch + 1) == 0
>        || strcasematch (".shc", ch)) /* file associate sh -c ==
>ShellScript */
>      return 1;
>+
>+ #if 1
>+   /* We also can test the first bytes in the file. */
>+   { HANDLE fh;
>+     char buf[4];
>+
>+     if ((fh = CreateFileA(path, GENERIC_READ, 0, NULL, OPEN_EXISTING,
>+                           0, 0)) != INVALID_HANDLE_VALUE) {
>+        DWORD bytes_read;
>+        ReadFile(fh, buf, 4, &bytes_read, 0);
>+        CloseHandle(fh);
>+        if (! memcmp(buf, "\x4d\x5a\x90\0", 4) ||
>+            ! memcmp(buf, "#!", 2))
>+          return 1;
>+     }
>+   }
>+ #endif
>+
>    return 0;
>  }

-- 
cgf AT cygnus DOT com
http://www.cygnus.com/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019