else
for (pl = pprefix->plist; pl; pl = pl->next)
{
+ struct stat st;
+
strcpy (temp, pl->prefix);
strcat (temp, name);
- if (access (temp, X_OK) == 0)
+ if (stat (temp, &st) >= 0
+ && ! S_ISDIR (st.st_mode)
+ && access (temp, X_OK) == 0)
return temp;
#ifdef EXECUTABLE_SUFFIX
So try appending that. */
strcat (temp, EXECUTABLE_SUFFIX);
- if (access (temp, X_OK) == 0)
+ if (stat (temp, &st) >= 0
+ && ! S_ISDIR (st.st_mode)
+ && access (temp, X_OK) == 0)
return temp;
#endif
}
static struct compiler *lookup_compiler PROTO((const char *, size_t, const char *));
static char *build_search_list PROTO((struct path_prefix *, const char *, int));
static void putenv_from_prefixes PROTO((struct path_prefix *, const char *));
+static int access_check PROTO((const char *, int));
static char *find_a_file PROTO((struct path_prefix *, const char *, int));
static void add_prefix PROTO((struct path_prefix *, const char *,
const char *, int, int, int *));
putenv (build_search_list (paths, env_var, 1));
}
\f
+/* Check whether NAME can be accessed in MODE. This is like access,
+ except that it never considers directories to be executable. */
+
+static int
+access_check (name, mode)
+ const char *name;
+ int mode;
+{
+ if (mode == X_OK)
+ {
+ struct stat st;
+
+ if (stat (name, &st) < 0
+ || S_ISDIR (st.st_mode))
+ return -1;
+ }
+
+ return access (name, mode);
+}
+
/* Search for NAME using the prefix list PREFIXES. MODE is passed to
access to check permissions.
Return 0 if not found, otherwise return its name, allocated with malloc. */
strcat (temp, machine_suffix);
strcat (temp, name);
strcat (temp, file_suffix);
- if (access (temp, mode) == 0)
+ if (access_check (temp, mode) == 0)
{
if (pl->used_flag_ptr != 0)
*pl->used_flag_ptr = 1;
strcpy (temp, pl->prefix);
strcat (temp, machine_suffix);
strcat (temp, name);
- if (access (temp, mode) == 0)
+ if (access_check (temp, mode) == 0)
{
if (pl->used_flag_ptr != 0)
*pl->used_flag_ptr = 1;
strcat (temp, just_machine_suffix);
strcat (temp, name);
strcat (temp, file_suffix);
- if (access (temp, mode) == 0)
+ if (access_check (temp, mode) == 0)
{
if (pl->used_flag_ptr != 0)
*pl->used_flag_ptr = 1;
strcpy (temp, pl->prefix);
strcat (temp, just_machine_suffix);
strcat (temp, name);
- if (access (temp, mode) == 0)
+ if (access_check (temp, mode) == 0)
{
if (pl->used_flag_ptr != 0)
*pl->used_flag_ptr = 1;
strcpy (temp, pl->prefix);
strcat (temp, name);
strcat (temp, file_suffix);
- if (access (temp, mode) == 0)
+ if (access_check (temp, mode) == 0)
{
if (pl->used_flag_ptr != 0)
*pl->used_flag_ptr = 1;
strcpy (temp, pl->prefix);
strcat (temp, name);
- if (access (temp, mode) == 0)
+ if (access_check (temp, mode) == 0)
{
if (pl->used_flag_ptr != 0)
*pl->used_flag_ptr = 1;