From b9572f5fe10766e3fcadb15a4bb015a4295d6522 Mon Sep 17 00:00:00 2001 From: drow Date: Thu, 20 Feb 2003 22:13:32 +0000 Subject: [PATCH] * 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. --- libiberty/ChangeLog | 16 ++++++++++++ libiberty/Makefile.in | 3 +++ libiberty/aclocal.m4 | 29 +++++++++++++++++++++ libiberty/configure.in | 3 +++ libiberty/functions.texi | 39 ++++++++++++++++++++-------- libiberty/make-relative-prefix.c | 55 ++++++++++++++++++++++------------------ 6 files changed, 111 insertions(+), 34 deletions(-) diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 50bd29d61a..f4703805c7 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,19 @@ +2003-02-20 Daniel Jacobowitz + + * 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. + 2003-02-20 jmc * cplus_dem.c: Fix typo: intializes -> initializes. diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in index 761c674c40..c5763579a8 100644 --- a/libiberty/Makefile.in +++ b/libiberty/Makefile.in @@ -137,6 +137,7 @@ CFILES = alloca.c argv.c asprintf.c atexit.c \ hashtab.c hex.c \ index.c insque.c \ lbasename.c \ + lrealpath.c \ make-relative-prefix.c \ make-temp-file.c md5.c memchr.c memcmp.c memcpy.c memmove.c \ memset.c mkstemps.c \ @@ -165,6 +166,7 @@ REQUIRED_OFILES = regex.o cplus-dem.o cp-demangle.o md5.o \ getopt.o getopt1.o getpwd.o getruntime.o \ hashtab.o hex.o \ lbasename.o \ + lrealpath.o \ make-relative-prefix.o \ make-temp-file.o \ objalloc.o obstack.o \ @@ -443,6 +445,7 @@ hashtab.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/hashtab.h \ hex.o: $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h lbasename.o: $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \ $(INCDIR)/safe-ctype.h +lrealpath.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h make-relative-prefix.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h make-temp-file.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h md5.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/md5.h diff --git a/libiberty/aclocal.m4 b/libiberty/aclocal.m4 index 103e246de7..6c5dc6ac64 100644 --- a/libiberty/aclocal.m4 +++ b/libiberty/aclocal.m4 @@ -87,6 +87,35 @@ then AC_DEFINE(NEED_DECLARATION_ERRNO, 1, fi ]) +dnl See whether we need a declaration for a function. +AC_DEFUN(libiberty_NEED_DECLARATION, +[AC_MSG_CHECKING([whether $1 must be declared]) +AC_CACHE_VAL(libiberty_cv_decl_needed_$1, +[AC_TRY_COMPILE([ +#include "confdefs.h" +#include +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif], +[char *(*pfn) = (char *(*)) $1], +libiberty_cv_decl_needed_$1=no, libiberty_cv_decl_needed_$1=yes)]) +AC_MSG_RESULT($libiberty_cv_decl_needed_$1) +if test $libiberty_cv_decl_needed_$1 = yes; then + AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]), 1, + [Define if $1 is not declared in system header files.]) +fi +])dnl + # FIXME: We temporarily define our own version of AC_PROG_CC. This is # copied from autoconf 2.12, but does not call AC_PROG_CC_WORKS. We # are probably using a cross compiler, which will not be able to fully diff --git a/libiberty/configure.in b/libiberty/configure.in index 3d8dbf2705..d170a9f7e1 100644 --- a/libiberty/configure.in +++ b/libiberty/configure.in @@ -207,6 +207,7 @@ funcs="$funcs waitpid" vars="sys_errlist sys_nerr sys_siglist" checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gettimeofday" +checkfuncs="$checkfuncs realpath canonicalize_file_name" # These are neither executed nor required, but they help keep # autoheader happy without adding a bunch of text to acconfig.h. @@ -218,6 +219,7 @@ if test "x" = "y"; then AC_CHECK_FUNCS(strtod strtol strtoul tmpnam vasprintf vfprintf vprintf) AC_CHECK_FUNCS(vsprintf waitpid getrusage on_exit psignal strerror strsignal) AC_CHECK_FUNCS(sysconf times sbrk gettimeofday ffs) + AC_CHECK_FUNCS(realpath canonicalize_file_name) AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.]) AC_DEFINE(HAVE_SYS_NERR, 1, [Define if you have the sys_nerr variable.]) AC_DEFINE(HAVE_SYS_SIGLIST, 1, [Define if you have the sys_siglist variable.]) @@ -424,6 +426,7 @@ if test -z "${setobjs}"; then fi done AC_CHECK_FUNCS($checkfuncs) + libiberty_NEED_DECLARATION(canonicalize_file_name) fi # Figure out which version of pexecute to use. diff --git a/libiberty/functions.texi b/libiberty/functions.texi index 18b2480a78..2c7b9e1276 100644 --- a/libiberty/functions.texi +++ b/libiberty/functions.texi @@ -392,19 +392,38 @@ and a path ending in @code{/} returns the empty string after it. @end deftypefn -@c make-relative-prefix.c:24 -@deftypefn Extension {const char*} make_relative_prefix (const char *@var{progname}, const char *@var{bin_prefix}, const char *@var{prefix}) +@c lrealpath.c:25 +@deftypefn Replacement {const char*} lrealpath (const char *@var{name}) + +Given a pointer to a string containing a pathname, returns a canonical +version of the filename. Symlinks will be resolved, and ``.'' and ``..'' +components will be simplified. The returned value will be allocated using +@code{xmalloc} or @code{malloc}. -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}. +@end deftypefn -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/}. +@c make-relative-prefix.c:24 +@deftypefn Extension {const char*} make_relative_prefix (const char *@var{progname}, const char *@var{bin_prefix}, const char *@var{prefix}) -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 diff --git a/libiberty/make-relative-prefix.c b/libiberty/make-relative-prefix.c index c208cdce02..dc4f8d5259 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--; -- 2.11.0