delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1998/03/19/21:19:17

From: jeffdbREMOVETHIS AT netzone DOT com (Mikey)
Subject: Re: cygwinb19.1.dll sh.exe still won't run shell scripts from path + workaround
19 Mar 1998 21:19:17 -0800 :
Message-ID: <3511d0b3.7373047.cygnus.cygwin32.developers@smtp.netzone.com>
References: <199803182047 DOT PAA07586 AT hardy DOT bbc DOT com>
Reply-To: jeffdbREMOVETHIS AT netzone DOT com
Mime-Version: 1.0
To: Christopher Faylor <cgf AT bbc DOT com>
Cc: cygwin32-developers AT cygnus DOT com

--- fhandler.cc	1998/03/19 07:38:31	1.1
+++ fhandler.cc	1998/03/19 07:13:33
@@ -1086,6 +1086,25 @@
 
   res = this->fhandler_base::open (real_path.get_win32 (), flags, mode);
 
+
+  if ((get_os_type () != winNT) && (!real_path.exec_p))
+    {
+    DWORD done;
+    char magic[2];
+    /* FIXME should we use /etc/magic ? */
+    magic[0] = magic[1] = magic[2] = '\0';
+    ReadFile (get_handle (), magic, 3, &done, 0);
+    if (magic[0] == ':' && magic[1] == '\n')
+        real_path.exec_p = 1;
+
+    if (magic[0] == '#' && magic[1] == '!')
+        real_path.exec_p = 1;
+    if (flags & O_APPEND)
+      SetFilePointer (get_handle(), 0, 0, FILE_END);
+    else
+      SetFilePointer (get_handle(), 0, 0, FILE_BEGIN);
+    }
+
   symlink_p_ = real_path.symlink_p;
   execable_p_ = real_path.exec_p;
 
@@ -1255,9 +1274,9 @@
 
   if (strcasecmp (".bat", ch) == 0
       || strcasecmp (".exe", ch) == 0
-      || strcasecmp (".com", ch) == 0)
+      || strcasecmp (".com", ch) == 0
+      || strcasecmp (".shc", ch) == 0) /* file associate sh -c == ShellScript */
     return 1;
-
   return 0;
 }
 

This is fairly quick, I actually didn't notice any difference,
and it seems to work correctly for both : and #! for ash.exe/sh.exe
bash dosen't like :\n for some reason. bash bug?

On Wed, 18 Mar 1998 15:47:15 -0500 (EST), you wrote:

>>Thanks Chris ;^)
>>
>>I'll try your source, and if I figure out a fix for the notfound error
>>I'll post it.
>
>It might be easier to "fix" cygwin32 for Win95 so that stat() either:
>
>1) always returns S_IXOTH|S_IXGRP|S_IXGRP
>
>or
>
>2) scans the first two bytes of a file to see if there is a '#!'.  If so,
>   it sets the above.
>
>cgf


=====================================================
Linux a platform built by, and for users, standing on
the firm legs of reliability, and speed.

Microsoft Windows, a platform without a leg to stand on.

(jeffdbREMOVETHIS AT netzone DOT com)
delete REMOVETHIS from the above to reply
         Mikey

- Raw text -


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