- if test -z "$cpmod"; then
- cp -p "$i" $tmp 2>/dev/null || cp "$i" $tmp
- if test -w $tmp 2>/dev/null; then
- writable=1
- else
- writable=0
- chmod u+w $tmp 2>/dev/null
- fi
+
+ dir=`dirname "$file"` || dir=$TMPDIR
+ test -d "$dir" && test -w "$dir" && test -x "$dir" || dir=/tmp
+ test -n "$tmp" && rm -f "$tmp"
+ if test -z "$mktemp_status"; then
+ type mktemp >/dev/null 2>&1
+ mktemp_status=$?
+ fi
+ case $dir in
+ */) ;;
+ *) dir=$dir/;;
+ esac
+ if test $mktemp_status -eq 0; then
+ tmp=`mktemp "${dir}gzexeXXXXXXXXX"`
+ else
+ tmp=${dir}gzexe$$
+ fi && { cp -p "$file" "$tmp" 2>/dev/null || cp "$file" "$tmp"; } || {
+ res=$?
+ printf >&2 '%s\n' "$0: cannot copy $file"
+ continue
+ }
+ if test -w "$tmp"; then
+ writable=1
+ else
+ writable=0
+ chmod u+w "$tmp" || {
+ res=$?
+ printf >&2 '%s\n' "$0: cannot chmod $tmp"
+ continue
+ }