ldd

#!/bin/sh
# OpenMSS ldd customized script.
# Based on glibc-2.3.3 ldd script. Lots of standard ldd-options have been removed 
# to work with Busybox/msh shell.
# Adjust RTLDIST below if needed..
#
# Copyright (C) 1996-2001, 2002, 2003, 2004 Free Software Foundation, Inc.
# This file is part of the GNU C Library.

# This is the `ldd' command, which lists what shared libraries are
# used by given dynamically-linked executables.  It works by invoking the
# run-time dynamic linker as a command and setting the environment
# variable LD_TRACE_LOADED_OBJECTS to a non-empty value.

# We should be able to find the translation right at the beginning.
TEXTDOMAIN=libc
TEXTDOMAINDIR=/usr/share/locale

#RTLDLIST=/lib/ld-linux.so.2
RTLDLIST=/lib/ld.so.1
warn=
bind_now=
verbose=


add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
add_env="$add_env LD_LIBRARY_VERSION=\$verify_out"
add_env="$add_env LD_VERBOSE=$verbose"
case $# in
0)
  echo >&2 'ldd:' $"missing file arguments"
  echo >&2 $"Try \`ldd --help' for more information."
  exit 1
  ;;
1)
  single_file=t
  ;;
*)
  single_file=f
  ;;
esac

result=0
for file do
  # We don't list the file name when there is only one.
  test $single_file = t || echo "${file}:"
  case $file in
  */*) :
       ;;
  *) file=./$file
     ;;
  esac
  if test ! -f "$file"; then
    echo "ldd: ${file}:" $"No such file or directory" >&2
    result=1
  elif test -r "$file"; then
    test -x "$file" || echo 'ldd:' $"\
warning: you do not have execution permission for" "\`$file'" >&2
    RTLD=
    for rtld in ${RTLDLIST}; do
      if test -x $rtld; then
	verify_out=`${rtld} --verify "$file"`
        ret=$?
	case $ret in
	[02]) RTLD=${rtld}; break;;
	esac
      fi
    done
    if test -z "${RTLD}"; then
      set ${RTLDLIST}
      RTLD=$1
      verify_out=`${RTLD} --verify "$file"`
      ret=$?
    fi
    case $ret in
    0)
      eval $add_env '"$file"' || result=1
      ;;
    1)
     # # This can be a non-ELF binary or no binary at all.
     # nonelf "$file" || {
     	echo $"	not a dynamic executable"
     	result=1
     # }
      ;;
    2)
      eval $add_env \${RTLD} '"$file"' || result=1
      ;;
    *)
      echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2
      exit 1
      ;;
    esac
  else
    echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2
    result=1
  fi
done

exit $result