aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@zembu.com>1999-08-04 07:45:10 +0000
committerJeff Law <law@gcc.gnu.org>1999-08-04 01:45:10 -0600
commitca6062011d6bf45dbf4c2f9a7d12f671a58f50b7 (patch)
tree89008bf231e3566bf6c5354c788a05cf2957f413 /gcc/gcc.c
parent0c26b18a0dbb2225f7524b1c83f9d88ad1966bdc (diff)
downloadgcc-ca6062011d6bf45dbf4c2f9a7d12f671a58f50b7.zip
gcc-ca6062011d6bf45dbf4c2f9a7d12f671a58f50b7.tar.gz
gcc-ca6062011d6bf45dbf4c2f9a7d12f671a58f50b7.tar.bz2
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
Diffstat (limited to 'gcc/gcc.c')
-rw-r--r--gcc/gcc.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/gcc/gcc.c b/gcc/gcc.c
index b5910c5..cf84e51 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -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;