diff options
author | Christopher Faylor <me@cgf.cx> | 2000-11-01 02:14:29 +0300 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2000-11-01 02:14:29 +0300 |
commit | b12796a06d220e56474d2b28158fda9a193d9f37 (patch) | |
tree | 1333fe686fd71dd00c822095dc09969cd59a6c4f | |
parent | 772e2322bd066c72b8af0f82f82c51306088bacc (diff) |
* 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.
-rw-r--r-- | winsup/cygwin/ChangeLog | 7 | ||||
-rw-r--r-- | winsup/cygwin/fhandler.cc | 3 | ||||
-rw-r--r-- | winsup/cygwin/path.cc | 9 | ||||
-rw-r--r-- | 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 <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. 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; |