From b12796a06d220e56474d2b28158fda9a193d9f37 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 31 Oct 2000 23:14:29 +0000 Subject: [PATCH] * 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. --- winsup/cygwin/ChangeLog | 7 +++++++ winsup/cygwin/fhandler.cc | 3 +-- winsup/cygwin/path.cc | 9 +++++---- winsup/cygwin/path.h | 9 +++++++++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index c3fd690d7..dd1e1aa9c 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +Tue Oct 31 18:12:56 2000 Christopher Faylor + + * 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 * path.cc (_readlink): Return ENOENT when file does not exist. diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 811b03888..d7015b7ab 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -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); diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 7899a0520..93032199f 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -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; diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h index 14367c7f4..70ec2d229 100644 --- a/winsup/cygwin/path.h +++ b/winsup/cygwin/path.h @@ -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;