diff options
author | DJ Delorie <dj@redhat.com> | 2012-01-03 16:02:36 +0000 |
---|---|---|
committer | DJ Delorie <dj@redhat.com> | 2012-01-03 16:02:36 +0000 |
commit | dd28faae1ad5b75119da42535c27c9ff8c3635ba (patch) | |
tree | 0a78a0919a1a3d2793d8dbde2c12b95fc756dfa5 /libiberty/make-relative-prefix.c | |
parent | 6e681866279da67c9f07668cd78bfe4e7b30f18e (diff) | |
download | gdb-dd28faae1ad5b75119da42535c27c9ff8c3635ba.zip gdb-dd28faae1ad5b75119da42535c27c9ff8c3635ba.tar.gz gdb-dd28faae1ad5b75119da42535c27c9ff8c3635ba.tar.bz2 |
merge from gcc
Diffstat (limited to 'libiberty/make-relative-prefix.c')
-rw-r--r-- | libiberty/make-relative-prefix.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/libiberty/make-relative-prefix.c b/libiberty/make-relative-prefix.c index 4553a71..7239e7b 100644 --- a/libiberty/make-relative-prefix.c +++ b/libiberty/make-relative-prefix.c @@ -1,6 +1,6 @@ /* Relative (relocatable) prefix support. Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2006 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2006, 2012 Free Software Foundation, Inc. This file is part of libiberty. @@ -58,6 +58,9 @@ relative prefix can be found, return @code{NULL}. #ifdef HAVE_UNISTD_H #include <unistd.h> #endif +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif #include <string.h> @@ -248,7 +251,11 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, if (prefixlen < 2) prefixlen = 2; - nstore = (char *) alloca (prefixlen + strlen (progname) + 1); + nstore = (char *) alloca (prefixlen + strlen (progname) + 1 +#ifdef HAVE_HOST_EXECUTABLE_SUFFIX + + strlen (HOST_EXECUTABLE_SUFFIX) +#endif + ); startp = endp = temp; while (1) @@ -263,7 +270,7 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, } else { - strncpy (nstore, startp, endp - startp); + memcpy (nstore, startp, endp - startp); if (! IS_DIR_SEPARATOR (endp[-1])) { nstore[endp - startp] = DIR_SEPARATOR; @@ -279,8 +286,14 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, #endif ) { - progname = nstore; - break; +#if defined (HAVE_SYS_STAT_H) && defined (S_ISREG) + struct stat st; + if (stat (nstore, &st) >= 0 && S_ISREG (st.st_mode)) +#endif + { + progname = nstore; + break; + } } if (*endp == 0) |