From: Bruno Haible Date: Mon, 19 Sep 2005 15:32:08 +0000 (+0000) Subject: Portability fix: readlink is not portable. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea843c7bcc1ec8b6392d47bfa6c24ec97abdad17;p=pspp Portability fix: readlink is not portable. --- diff --git a/ChangeLog b/ChangeLog index 190700d96b..3b7fb0f5bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-09-18 Bruno Haible + + Portability fix. + * gnulib-tool (func_readlink): New function. + (func_ln_if_changed): Use it. + 2005-09-18 Bruno Haible * gnulib-tool: Revise --dry-run implementation. Use variable $doit diff --git a/gnulib-tool b/gnulib-tool index 44985c9ab5..0bd9eb1182 100755 --- a/gnulib-tool +++ b/gnulib-tool @@ -22,7 +22,7 @@ progname=$0 package=gnulib -cvsdatestamp='$Date: 2005-09-19 15:31:32 $' +cvsdatestamp='$Date: 2005-09-19 15:32:08 $' last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'` version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'` @@ -162,6 +162,23 @@ func_fatal_error () exit 1 } +# func_readlink SYMLINK +# outputs the target of the given symlink. +if (type -p readlink) > /dev/null 2>&1; then + func_readlink () + { + # Use the readlink program from GNU coreutils. + readlink "$1" + } +else + func_readlink () + { + # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p' + # would do the wrong link if the link target contains " -> ". + LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p' + } +fi + # func_ln_if_changed SRC DEST # Like ln -s, but avoids munging timestamps if the link is correct. func_ln_if_changed () @@ -169,7 +186,7 @@ func_ln_if_changed () if test $# -ne 2; then echo "usage: func_ln_if_changed SRC DEST" >&2 fi - if test -L "$2" && test "$1" = "`readlink "$2"`"; then + if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then : else rm -f "$2" @@ -371,9 +388,7 @@ case "$0" in esac while test -h "$self_abspathname"; do # Resolve symbolic link. - sedexpr1='s, -> ,#%%#,' - sedexpr2='s,^.*#%%#\(.*\)$,\1,p' - linkval=`LC_ALL=C ls -l "$self_abspathname" | sed -e "$sedexpr1" | sed -n -e "$sedexpr2"` + linkval=`func_readlink "$self_abspathname"` test -n "$linkval" || break case "$linkval" in /* ) self_abspathname="$linkval" ;;