diff options
Diffstat (limited to 'findcmd.c')
-rw-r--r-- | findcmd.c | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -160,6 +160,16 @@ is_directory (file) return (file_status (file) & FS_DIRECTORY); } +int +executable_or_directory (file) + char *file; +{ + int s; + + s = file_status (file); + return ((s & FS_EXECABLE) || (s & FS_DIRECTORY)); +} + /* Locate the executable file referenced by NAME, searching along the contents of the shell PATH variable. Return a new string which is the full pathname to the file, or NULL if the file @@ -305,12 +315,12 @@ search_for_command (pathname) /* If $PATH is in the temporary environment, we've already retrieved it, so don't bother trying again. */ if (temp_path) - { + { command = find_user_command_in_path (pathname, value_cell (path), FS_EXEC_PREFERRED|FS_NODIRS); if (tempvar_p (path)) dispose_variable (path); - } + } else command = find_user_command (pathname); if (command && hashing_enabled && temp_path == 0) @@ -557,6 +567,14 @@ find_user_command_in_path (name, path_list, flags) /* We didn't find exactly what the user was looking for. Return the contents of FILE_TO_LOSE_ON which is NULL when the search required an executable, or non-NULL if a file was found and the - search would accept a non-executable as a last resort. */ + search would accept a non-executable as a last resort. If the + caller specified FS_NODIRS, and file_to_lose_on is a directory, + return NULL. */ + if (file_to_lose_on && (flags & FS_NODIRS) && is_directory (file_to_lose_on)) + { + free (file_to_lose_on); + file_to_lose_on = (char *)NULL; + } + return (file_to_lose_on); } |