OSDN Git Service

* path.h (has_exec_chars): Standard function for checking for executable magic
authorcgf <cgf>
Tue, 31 Oct 2000 23:14:29 +0000 (23:14 +0000)
committercgf <cgf>
Tue, 31 Oct 2000 23:14:29 +0000 (23:14 +0000)
numbers.
* path.cc (symlink_info::check): Use the above function.
* fhandler.cc (fhandler_disk_file::open): Ditto.

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler.cc
winsup/cygwin/path.cc
winsup/cygwin/path.h

index c3fd690..dd1e1aa 100644 (file)
@@ -1,3 +1,10 @@
+Tue Oct 31 18:12:56 2000  Christopher Faylor <cgf@cygnus.com>
+
+       * path.h (has_exec_chars): Standard function for checking for
+       executable magic numbers.
+       * path.cc (symlink_info::check): Use the above function.
+       * fhandler.cc (fhandler_disk_file::open): Ditto.
+
 Tue Oct 31 17:57:52 2000  Christopher Faylor <cgf@cygnus.com>
 
        * path.cc (_readlink): Return ENOENT when file does not exist.
index 811b038..d7015b7 100644 (file)
@@ -1227,8 +1227,7 @@ fhandler_disk_file::open (path_conv& real_path, int flags, mode_t mode)
       /* 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') ||
-         (magic[0] == '#' && magic[1] == '!'))
+      if (has_exec_chars (magic, done))
        real_path.set_exec ();
       if (!(flags & O_APPEND))
        SetFilePointer (get_handle(), 0, 0, FILE_BEGIN);
index 7899a05..9303219 100644 (file)
@@ -2319,11 +2319,12 @@ symlink_info::check (const char *in_path, const suffix_info *suffixes)
          else
            {
              /* Not a symlink, see if executable.  */
-             if (!(pflags & PATH_ALL_EXEC) && got >= 2 &&
-                 ((cookie_buf[0] == '#' && cookie_buf[1] == '!') ||
-                  (cookie_buf[0] == ':' && cookie_buf[1] == '\n') ||
-                  (cookie_buf[0] == 'M' && cookie_buf[1] == 'Z')))
+             if (!(pflags & PATH_ALL_EXEC) &&
+                 has_exec_chars (cookie_buf, got))
+{
+debug_printf ("setting exec flag");
                pflags |= PATH_EXEC;
+}
            close_and_return:
              CloseHandle (h);
              goto file_not_symlink;
index 14367c7..70ec2d2 100644 (file)
@@ -122,6 +122,15 @@ const char * __stdcall find_exec (const char *name, path_conv& buf, const char *
 
 #define isdrive(s) (isalpha (*(s)) && (s)[1] == ':')
 
+static inline bool
+has_exec_chars (const char *buf, int len)
+{
+  return len >= 2 &&
+        ((buf[0] == '#' && buf[1] == '!') ||
+         (buf[0] == ':' && buf[1] == '\n') ||
+         (buf[0] == 'M' && buf[1] == 'Z'));
+}
+
 /* cwd cache stuff.  */
 
 class muto;