Commit ca606201 by Ian Lance Taylor Committed by Jeff Law

gcc.c (access_check): New static function.

        * gcc.c (access_check): New static function.
        (find_a_file): Use it when searching a directory list.
        * collect2.c (find_a_file): Don't accept directories found when
        searching a directory list.

From-SVN: r28486
parent 0c26b18a
Wed Aug 4 01:43:01 1999 Ian Lance Taylor <ian@zembu.com>
* gcc.c (access_check): New static function.
(find_a_file): Use it when searching a directory list.
* collect2.c (find_a_file): Don't accept directories found when
searching a directory list.
Wed Aug 4 01:40:43 1999 Philippe De Muyter <phdm@macqel.be>
* tlink.c (symbol_hash_lookup): Do not prefix functions used as
......
......@@ -853,10 +853,14 @@ find_a_file (pprefix, name)
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
......@@ -864,7 +868,9 @@ find_a_file (pprefix, name)
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
}
......
......@@ -177,6 +177,7 @@ static void set_spec PROTO((const char *, const char *));
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 *));
......@@ -1954,6 +1955,26 @@ putenv_from_prefixes (paths, env_var)
putenv (build_search_list (paths, env_var, 1));
}
/* 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. */
......@@ -2022,7 +2043,7 @@ find_a_file (pprefix, name, mode)
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;
......@@ -2034,7 +2055,7 @@ find_a_file (pprefix, name, mode)
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;
......@@ -2054,7 +2075,7 @@ find_a_file (pprefix, name, mode)
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;
......@@ -2065,7 +2086,7 @@ find_a_file (pprefix, name, mode)
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;
......@@ -2084,7 +2105,7 @@ find_a_file (pprefix, name, mode)
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;
......@@ -2094,7 +2115,7 @@ find_a_file (pprefix, name, mode)
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment