summaryrefslogtreecommitdiff
path: root/findcmd.c
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>2001-04-06 19:14:31 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:53 +0000
commit28ef6c316f1aff914bb95ac09787a3c83c1815fd (patch)
tree2812fe7ffc9beec4f99856906ddfcafda54cf16a /findcmd.c
parentbb70624e964126b7ac4ff085ba163a9c35ffa18f (diff)
downloadbash-28ef6c316f1aff914bb95ac09787a3c83c1815fd.tar.gz
Imported from ../bash-2.05.tar.gz.
Diffstat (limited to 'findcmd.c')
-rw-r--r--findcmd.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/findcmd.c b/findcmd.c
index 7d0bc72b..4c47c042 100644
--- a/findcmd.c
+++ b/findcmd.c
@@ -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);
}