mc ()
{
        # If we're using su then don't use a $HOME/.mc directory:
        if [ "$USER" = "root" -a ! "`id | cut -b1-5`" = "uid=0" ]; then
	  /usr/bin/mc "$@"
        elif [ ! "$USER" = "root" -a "`id | cut -b1-5`" = "uid=0" ]; then
	  /usr/bin/mc "$@"
        else # not using su:
          mkdir -p $HOME/.mc/tmp 2> /dev/null
	  chmod 700 $HOME/.mc/tmp
	  MC=$HOME/.mc/tmp/mc-$$
	  /usr/bin/mc -P "$@" > "$MC"
	  cd "`cat $MC`"
	  rm -f "$MC"
          unset MC;
	fi
}

# Don't use sh-specific syntax with ksh:
if [ "$SHELL" = "/bin/ksh" ]; then
	export mc
else
	export -f mc
fi
