diff options
author | Daniel Jacobowitz <dan@debian.org> | 2003-02-20 22:14:18 +0000 |
---|---|---|
committer | Daniel Jacobowitz <dan@debian.org> | 2003-02-20 22:14:18 +0000 |
commit | 91fd4842ccb83d297de8ace613bb086e8812c8cc (patch) | |
tree | da722b66c0271fcf72d0c8e9d8c4b4e55798a38c /libiberty/make-relative-prefix.c | |
parent | e874e5b08ca8ba5af2bafc0a55b78393039f7f57 (diff) | |
download | gdb-91fd4842ccb83d297de8ace613bb086e8812c8cc.tar.gz |
* Makefile.in (CFILES): Add lrealpath.c.
(REQUIRED_OFILES): Add lrealpath.o.
(lrealpath.o): Add rule.
* aclocal.m4 (libiberty_NEED_DECLARATION): Add.
* configure.in: Add realpath and canonicalize_file_name to
checkfuncs and AC_CHECK_FUNCS. Use libiberty_NEED_DECLARATION
for canonicalize_file_name.
* lrealpath.c: New file.
* make-relative-prefix.c: Update documentation.
(make_relative_prefix): Simplify. Use lbasename and lrealpath.
* config.in: Regenerated.
* configure: Regenerated.
* functions.texi: Regenerated.
Diffstat (limited to 'libiberty/make-relative-prefix.c')
-rw-r--r-- | libiberty/make-relative-prefix.c | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/libiberty/make-relative-prefix.c b/libiberty/make-relative-prefix.c index c208cdce024..dc4f8d5259d 100644 --- a/libiberty/make-relative-prefix.c +++ b/libiberty/make-relative-prefix.c @@ -23,16 +23,25 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA @deftypefn Extension {const char*} make_relative_prefix (const char *@var{progname}, const char *@var{bin_prefix}, const char *@var{prefix}) -Given three strings @var{progname}, @var{bin_prefix}, @var{prefix}, return a string -that gets to @var{prefix} starting with the directory portion of @var{progname} and -a relative pathname of the difference between @var{bin_prefix} and @var{prefix}. - -For example, if @var{bin_prefix} is @code{/alpha/beta/gamma/gcc/delta}, @var{prefix} -is @code{/alpha/beta/gamma/omega/}, and @var{progname} is @code{/red/green/blue/gcc}, -then this function will return @code{/red/green/blue/../../omega/}. - -The return value is normally allocated via @code{malloc}. If no relative prefix -can be found, return @code{NULL}. +Given three paths @var{progname}, @var{bin_prefix}, @var{prefix}, +return the path that is in the same position relative to +@var{progname}'s directory as @var{prefix} is relative to +@var{bin_prefix}. That is, a string starting with the directory +portion of @var{progname}, followed by a relative pathname of the +difference between @var{bin_prefix} and @var{prefix}. + +If @var{progname} does not contain any directory separators, +@code{make_relative_prefix} will search @env{PATH} to find a program +named @var{progname}. Also, if @var{progname} is a symbolic link, +the symbolic link will be resolved. + +For example, if @var{bin_prefix} is @code{/alpha/beta/gamma/gcc/delta}, +@var{prefix} is @code{/alpha/beta/gamma/omega/}, and @var{progname} is +@code{/red/green/blue/gcc}, then this function will return +@code{/red/green/blue/../../omega/}. + +The return value is normally allocated via @code{malloc}. If no +relative prefix can be found, return @code{NULL}. @end deftypefn @@ -223,19 +232,14 @@ make_relative_prefix (progname, bin_prefix, prefix) int prog_num, bin_num, prefix_num; int i, n, common; int needed_len; - char *ret, *ptr; + char *ret, *ptr, *full_progname = NULL; if (progname == NULL || bin_prefix == NULL || prefix == NULL) return NULL; - prog_dirs = split_directories (progname, &prog_num); - bin_dirs = split_directories (bin_prefix, &bin_num); - if (bin_dirs == NULL || prog_dirs == NULL) - return NULL; - /* If there is no full pathname, try to find the program by checking in each of the directories specified in the PATH environment variable. */ - if (prog_num == 1) + if (lbasename (progname) == progname) { char *temp; @@ -278,14 +282,7 @@ make_relative_prefix (progname, bin_prefix, prefix) #endif ) { - free_split_directories (prog_dirs); progname = nstore; - prog_dirs = split_directories (progname, &prog_num); - if (prog_dirs == NULL) - { - free_split_directories (bin_dirs); - return NULL; - } break; } @@ -299,6 +296,16 @@ make_relative_prefix (progname, bin_prefix, prefix) } } + full_progname = lrealpath (progname); + if (full_progname == NULL) + return NULL; + + prog_dirs = split_directories (full_progname, &prog_num); + bin_dirs = split_directories (bin_prefix, &bin_num); + free (full_progname); + if (bin_dirs == NULL || prog_dirs == NULL) + return NULL; + /* Remove the program name from comparison of directory names. */ prog_num--; |