home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1999 February / VPR9902B.ISO / TurboLinux / instimage / usr / bin / ldd < prev    next >
Text File  |  1998-08-27  |  4KB  |  142 lines

  1. #! /bin/sh
  2.  
  3. # Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
  4. # This file is part of the GNU C Library.
  5.  
  6. # The GNU C Library is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU Library General Public License as
  8. # published by the Free Software Foundation; either version 2 of the
  9. # License, or (at your option) any later version.
  10.  
  11. # The GNU C Library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. # Library General Public License for more details.
  15.  
  16. # You should have received a copy of the GNU Library General Public
  17. # License along with the GNU C Library; see the file COPYING.LIB.  If not,
  18. # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. # Boston, MA 02111-1307, USA.
  20.  
  21.  
  22. # This is the `ldd' command, which lists what shared libraries are
  23. # used by given dynamically-linked executables.  It works by invoking the
  24. # run-time dynamic linker as a command and setting the environment
  25. # variable LD_TRACE_LOADED_OBJECTS to a non-empty value.
  26.  
  27. RTLD=/lib/ld-linux.so.2
  28. RELOCS=
  29.  
  30. while test $# -gt 0; do
  31.   case "$1" in
  32.   --v | --ve | --ver | --vers | --versi | --versio | --version)
  33.     echo 'ldd (GNU libc) 2.0.7
  34. Copyright (C) 1996, 1997 Free Software Foundation, Inc.
  35. This is free software; see the source for copying conditions.  There is NO
  36. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.'
  37.     exit 0
  38.     ;;
  39.   --h | --he | --hel | --help)
  40.     echo "ldd [OPTION]... FILE...
  41.       --help              print this help and exit
  42.       --version           print version information and exit
  43.   -d, --data-relocs       process data relocations
  44.   -r, --function-relocs   process data and function relocations
  45. Report bugs using the \`glibcbug' script to <bugs@gnu.ai.mit.edu>."
  46.     exit 0
  47.     ;;
  48.   -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
  49.   --data-rel | --data-relo | --data-reloc | --data-relocs)
  50.     RELOCS='--data-relocs'
  51.     shift
  52.     ;;
  53.   -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
  54.   --function | --function- | --function-r | --function-re | --function-rel | \
  55.   --function-relo | --function-reloc | --function-relocs)
  56.     RELOCS='--function-relocs'
  57.     shift
  58.     ;;
  59.   --)        # Stop option processing.
  60.     shift; break
  61.     ;;
  62.   -*)
  63.     echo >&2 "\
  64. ldd: unrecognized option \`$1'
  65. Try \`ldd --help' for more information."
  66.     exit 1
  67.     ;;
  68.   *)
  69.     break
  70.     ;;
  71.   esac
  72. done
  73.  
  74. case $# in
  75. 0)
  76.   echo >&2 "\
  77. ldd: missing file arguments
  78. Try \`ldd --help' for more information."
  79.   exit 1
  80.   ;;
  81. 1)
  82.   # We don't list the file name when there is only one.
  83.   case "$1" in
  84.   /*) file="$1"
  85.       ;;
  86.   *) file="./$1"
  87.      ;;
  88.   esac
  89.   if test ! -f "$file"; then
  90.     echo "ldd: ${file}: no such file"
  91.     exit 1
  92.   else
  93.     if test -r "$file"; then
  94.       test -x "$file" ||
  95.     echo "ldd: warning: you do not have execution permission for \`$file'"
  96.       if ${RTLD} --verify "$file"; then
  97.     LD_TRACE_LOADED_OBJECTS=1 exec ${RTLD} ${RELOCS} "$file" || exit 1
  98.       else
  99.     echo '    not a dynamic executable'
  100.     exit 1
  101.       fi
  102.     else
  103.       echo "ldd: error: you do not have read permission for \`$file'"
  104.       exit 1
  105.     fi
  106.   fi
  107.   exit
  108.   ;;
  109. *)
  110.   set -e    # Bail out immediately if ${RTLD} loses on any argument.
  111.   result=0
  112.   for file; do
  113.     echo "${file}:"
  114.     case "$file" in
  115.     /*) :
  116.         ;;
  117.     *) file="./$file"
  118.        ;;
  119.     esac
  120.     if test ! -f "$file"; then
  121.       echo "ldd: ${file}: no such file"
  122.       result=1
  123.     else
  124.       if test -r "$file"; then
  125.     test -x "$file" || echo "\
  126. ldd: warning: you do not have execution permission for \`$file'"
  127.     if ${RTLD} --verify "$file"; then
  128.       LD_TRACE_LOADED_OBJECTS=1 ${RTLD} ${RELOCS} "$file" || result=1
  129.     else
  130.       echo '    not a dynamic executable'
  131.       result=1
  132.     fi
  133.       else
  134.     echo "ldd: error: you do not have read permission for \`$file'"
  135.     result=1
  136.       fi
  137.     fi
  138.   done
  139. esac
  140.  
  141. exit $result
  142.