diff -ur gzip-1.3.orig/gzexe.in gzip-1.3/gzexe.in
--- gzip-1.3.orig/gzexe.in	Fri Sep 18 04:43:06 1998
+++ gzip-1.3/gzexe.in	Fri Sep 28 04:35:48 2001
@@ -13,7 +13,7 @@
 # The : is required for some old versions of csh.
 # On Ultrix, /bin/sh is too buggy, change the first line to: #!/bin/sh5
 
-x=`basename $0`
+x=`basename "$0"`
 if test $# = 0; then
   echo compress executables. original file foo is renamed to foo~
   echo usage: ${x} [-d] files...
@@ -21,8 +21,9 @@
   exit 1
 fi
 
-tmp=gz$$
-trap "rm -f $tmp; exit 1" 1 2 3 5 10 13 15
+tmp=`/bin/mktemp ${TMPDIR:-/tmp}/gzexe.XXXXXXXXXX` || exit 1
+trap "rm -f $tmp; exit 1" HUP INT QUIT PIPE TERM
+trap "rm -f $tmp; exit 0" EXIT
 
 decomp=0
 res=0
@@ -32,12 +33,10 @@
   shift
 fi
 
-echo hi > zfoo1$$
-echo hi > zfoo2$$
-if test -z "`(${CPMOD-cpmod} zfoo1$$ zfoo2$$) 2>&1`"; then
-  cpmod=${CPMOD-cpmod}
+cpmod=
+if type ${CPMOD:-cpmod} 2>/dev/null; then
+  cpmod=${CPMOD:-cpmod}
 fi
-rm -f zfoo[12]$$
 
 tail=""
 IFS="${IFS= 	}"; saveifs="$IFS"; IFS="${IFS}:"
@@ -75,7 +74,7 @@
     continue
   fi
   case "`basename $i`" in
-  gzip | tail | chmod | ln | sleep | rm)
+  bash | chmod | gzip | ln | mktemp | rm | sed | sh | tail)
 	echo "${x}: $i would depend on itself"; continue ;;
   esac
   if test -z "$cpmod"; then
@@ -88,27 +87,19 @@
     fi
   fi
   if test $decomp -eq 0; then
-    sed 1q $0 > $tmp
+    sed 1q "$0" > $tmp
     sed "s|^if tail|if $tail|" >> $tmp <<'EOF'
-skip=22
-set -C
-umask=`umask`
-umask 77
-if tail +$skip $0 | "BINDIR"/gzip -cd > /tmp/gztmp$$; then
-  umask $umask
-  /bin/chmod 700 /tmp/gztmp$$
-  prog="`echo $0 | /bin/sed 's|^.*/||'`"
-  if /bin/ln /tmp/gztmp$$ "/tmp/$prog" 2>/dev/null; then
-    trap '/bin/rm -f /tmp/gztmp$$ "/tmp/$prog"; exit $res' 0
-    (/bin/sleep 5; /bin/rm -f /tmp/gztmp$$ "/tmp/$prog") 2>/dev/null &
-    /tmp/"$prog" ${1+"$@"}; res=$?
-  else
-    trap '/bin/rm -f /tmp/gztmp$$; exit $res' 0
-    (/bin/sleep 5; /bin/rm -f /tmp/gztmp$$) 2>/dev/null &
-    /tmp/gztmp$$ ${1+"$@"}; res=$?
-  fi
+skip=14
+tmpdir=`/bin/mktemp -d ${TMPDIR:-/tmp}/gzexe.XXXXXXXXXX` || exit 1
+prog="${tmpdir}/`echo \"$0\" | sed 's|^.*/||'`"
+if tail +$skip "$0" | "BINDIR"/gzip -cd > "$prog"; then
+  /bin/chmod 700 "$prog"
+  trap '/bin/rm -rf $tmpdir; exit $res' EXIT
+  "$prog" ${1+"$@"}; res=$?
 else
-  echo Cannot decompress $0; exit 1
+  echo "Cannot decompress $0"
+  /bin/rm -rf $tmpdir
+  exit 1
 fi; exit $res
 EOF
     gzip -cv9 "$i" >> $tmp || {
diff -ur gzip-1.3.orig/zdiff.in gzip-1.3/zdiff.in
--- gzip-1.3.orig/zdiff.in	Fri Sep 18 06:27:28 1998
+++ gzip-1.3/zdiff.in	Fri Sep 28 04:04:28 2001
@@ -46,13 +46,13 @@
                 case "$2" in
 	        *[-.]gz* | *[-.][zZ] | *.t[ga]z)
 			F=`echo "$2" | sed 's|.*/||;s|[-.][zZtga]*||'`
-			set -C
-			trap 'rm -f /tmp/"$F".$$; exit 2' 1 2 13 15 0
-			gzip -cdfq "$2" > /tmp/"$F".$$ || exit
-                        gzip -cdfq "$1" | $comp $OPTIONS - /tmp/"$F".$$
+			TF=`/bin/mktemp ${TMPDIR:-/tmp}/"$F".XXXXXXXXXX` || exit 1
+			trap 'rm -f "$TF"; exit 2' EXIT HUP INT PIPE TERM
+			gzip -cdfq "$2" > "$TF" || exit
+                        gzip -cdfq "$1" | $comp $OPTIONS - "$TF"
                         STAT="$?"
-			/bin/rm -f /tmp/"$F".$$ || STAT=2
-			trap 1 2 13 15 0
+			rm -f "$TF" || STAT=2
+			trap EXIT HUP INT PIPE TERM
 			exit $STAT;;
 
                 *)      gzip -cdfq "$1" | $comp $OPTIONS - "$2";;
diff -ur gzip-1.3.orig/znew.in gzip-1.3/znew.in
--- gzip-1.3.orig/znew.in	Thu Oct 15 03:37:58 1998
+++ gzip-1.3/znew.in	Fri Sep 28 03:58:18 2001
@@ -14,29 +14,27 @@
 # block is the disk block size (best guess, need not be exact)
 
 warn="(does not preserve modes and timestamp)"
-tmp=/tmp/zfoo.$$
-set -C
-echo hi > $tmp.1
-echo hi > $tmp.2
-if test -z "`(${CPMOD-cpmod} $tmp.1 $tmp.2) 2>&1`"; then
-  cpmod=${CPMOD-cpmod}
+cpmod=
+cpmodarg=
+if type ${CPMOD:-cpmod} 2>/dev/null; then
+  cpmod=${CPMOD:-cpmod}
   warn=""
 fi
 
-if test -z "$cpmod" && ${TOUCH-touch} -r $tmp.1 $tmp.2 2>/dev/null; then
-  cpmod="${TOUCH-touch}"
+if test -z "$cpmod"; then
+  cpmod=touch
   cpmodarg="-r"
   warn="(does not preserve file modes)"
 fi
 
-# check if GZIP env. variable uses -S or --suffix
-gzip -q $tmp.1
-ext=`echo $tmp.1* | sed "s|$tmp.1||"`
-rm -f $tmp.[12]*
-if test -z "$ext"; then
-  echo znew: error determining gzip extension
-  exit 1
-fi
+case "$GZIP" in
+  *-S*) ext=`echo "$GZIP" | sed 's/^.*-S[[:space:]]*\([^[:space:]]*\).*$/\1/'`
+	;;
+  *-suffix*) ext=`echo "$GZIP" | sed 's/^.*--suffix=\([^[:space:]]*\).*$/\1/'`
+	;;
+  *) ext='.gz'
+	;;
+esac
 if test "$ext" = ".Z"; then
   echo znew: cannot use .Z as gzip extension.
   exit 1
