- 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
- : >| $tmp # truncate the file, ignoring set -C
+
+ 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
+ if test $mktemp_status -eq 0; then
+ tmp=`TMPDIR=$dir mktemp`
+ else
+ tmp=$dir/gzexe$$
+ fi && { cp -p "$file" "$tmp" 2>/dev/null || cp "$file" "$tmp"; } || {
+ res=$?
+ echo >&2 "$0: cannot copy $file"
+ continue
+ }
+ if test -w "$tmp"; then
+ writable=1
+ else
+ writable=0
+ chmod u+w "$tmp" || {
+ res=$?
+ echo >&2 "$0: cannot chmod $tmp"
+ continue
+ }