| 1 | /* Relative (relocatable) prefix support.
|
|---|
| 2 | Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
|
|---|
| 3 | 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
|---|
| 4 |
|
|---|
| 5 | This file is part of libiberty.
|
|---|
| 6 |
|
|---|
| 7 | GCC is free software; you can redistribute it and/or modify it under
|
|---|
| 8 | the terms of the GNU General Public License as published by the Free
|
|---|
| 9 | Software Foundation; either version 2, or (at your option) any later
|
|---|
| 10 | version.
|
|---|
| 11 |
|
|---|
| 12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|---|
| 13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|---|
| 14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|---|
| 15 | for more details.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU General Public License
|
|---|
| 18 | along with GCC; see the file COPYING. If not, write to the Free
|
|---|
| 19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|---|
| 20 | 02111-1307, USA. */
|
|---|
| 21 |
|
|---|
| 22 | /*
|
|---|
| 23 |
|
|---|
| 24 | @deftypefn Extension {const char*} make_relative_prefix (const char *@var{progname}, const char *@var{bin_prefix}, const char *@var{prefix})
|
|---|
| 25 |
|
|---|
| 26 | Given three paths @var{progname}, @var{bin_prefix}, @var{prefix},
|
|---|
| 27 | return the path that is in the same position relative to
|
|---|
| 28 | @var{progname}'s directory as @var{prefix} is relative to
|
|---|
| 29 | @var{bin_prefix}. That is, a string starting with the directory
|
|---|
| 30 | portion of @var{progname}, followed by a relative pathname of the
|
|---|
| 31 | difference between @var{bin_prefix} and @var{prefix}.
|
|---|
| 32 |
|
|---|
| 33 | If @var{progname} does not contain any directory separators,
|
|---|
| 34 | @code{make_relative_prefix} will search @env{PATH} to find a program
|
|---|
| 35 | named @var{progname}. Also, if @var{progname} is a symbolic link,
|
|---|
| 36 | the symbolic link will be resolved.
|
|---|
| 37 |
|
|---|
| 38 | For example, if @var{bin_prefix} is @code{/alpha/beta/gamma/gcc/delta},
|
|---|
| 39 | @var{prefix} is @code{/alpha/beta/gamma/omega/}, and @var{progname} is
|
|---|
| 40 | @code{/red/green/blue/gcc}, then this function will return
|
|---|
| 41 | @code{/red/green/blue/../../omega/}.
|
|---|
| 42 |
|
|---|
| 43 | The return value is normally allocated via @code{malloc}. If no
|
|---|
| 44 | relative prefix can be found, return @code{NULL}.
|
|---|
| 45 |
|
|---|
| 46 | @end deftypefn
|
|---|
| 47 |
|
|---|
| 48 | */
|
|---|
| 49 |
|
|---|
| 50 | #ifdef HAVE_CONFIG_H
|
|---|
| 51 | #include "config.h"
|
|---|
| 52 | #endif
|
|---|
| 53 |
|
|---|
| 54 | #ifdef HAVE_STDLIB_H
|
|---|
| 55 | #include <stdlib.h>
|
|---|
| 56 | #endif
|
|---|
| 57 | #ifdef HAVE_UNISTD_H
|
|---|
| 58 | #include <unistd.h>
|
|---|
| 59 | #endif
|
|---|
| 60 |
|
|---|
| 61 | #include <string.h>
|
|---|
| 62 |
|
|---|
|
|---|