aboutsummaryrefslogtreecommitdiff
path: root/gcc
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
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')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/collect2.c10
-rw-r--r--gcc/gcc.c33
3 files changed, 42 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ba0a24f..fb4b3a8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+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
diff --git a/gcc/collect2.c b/gcc/collect2.c
index 62a79d3..ea97261 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -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
}
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;