From 0161769885b1bdcc3d5f6699ade8f2b88c56e570 Mon Sep 17 00:00:00 2001
From: Bdale Garbee <bdale@gag.com>
Date: Tue, 20 Jun 2006 15:02:27 -0600
Subject: [PATCH] Imported Debian patch 1.3.5-14

---
 debian/changelog | 12 ++++++++++++
 debian/control   |  4 ++--
 gzexe.in         |  2 +-
 gzip.c           | 23 ++++++++++++-----------
 zgrep.in         | 19 ++++++++++++++++++-
 5 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 37b6bcd..459e80e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,15 @@
+gzip (1.3.5-14) unstable; urgency=medium
+
+  * update section to match override
+  * patch from Matthew Chapman to avoid deleting input file before we're
+    sure the output file has been written without errors, closes: #366660
+  * patch from Reuben Thomas to fix zgrep return code, 
+    closes: #292896, #192891, #190442
+  * enable gzexe compressed files to work on systems where tempfile is not
+    available while retaining preference for tempfile, closes: #334540
+
+ -- Bdale Garbee <bdale@gag.com>  Tue, 20 Jun 2006 15:02:27 -0600
+
 gzip (1.3.5-13) unstable; urgency=low
 
   * patch from Reuben Thomas fixes problem passing zgrep filenames starting
diff --git a/debian/control b/debian/control
index ff41a34..74a4c22 100644
--- a/debian/control
+++ b/debian/control
@@ -1,9 +1,9 @@
 Source: gzip
-Section: base
+Section: utils
 Priority: required
 Maintainer: Bdale Garbee <bdale@gag.com>
 Build-Depends: debhelper (>= 5), texinfo
-Standards-Version: 3.6.2.2
+Standards-Version: 3.7.2
 
 Package: gzip
 Architecture: any
diff --git a/gzexe.in b/gzexe.in
index d191635..bcd788c 100755
--- a/gzexe.in
+++ b/gzexe.in
@@ -121,7 +121,7 @@ skip=23
 set -C
 umask=`umask`
 umask 77
-tmpfile=`tempfile -p gztmp -d /tmp` || exit 1
+tmpfile=`tempfile -p gztmp -d /tmp` || tmpfile=/tmp/gztmp.$$ || exit 1
 if tail +$skip "$0" | /bin/gzip -cd >> $tmpfile; then
   umask $umask
   /bin/chmod 700 $tmpfile
diff --git a/gzip.c b/gzip.c
index a72cb20..bfab6e7 100644
--- a/gzip.c
+++ b/gzip.c
@@ -882,10 +882,21 @@ local void treat_file(iname)
 
     close(ifd);
     if (!to_stdout) {
-         /* Copy modes, times, ownership, and remove the input file */
+         /* Copy modes, times, and ownership */
          copy_stat(&istat);
          if (close(ofd))
             write_error();
+         remove_ofname = 0;
+
+         /* It's now safe to remove the input file: */
+         if (xunlink (ifname)) {
+           int e = errno;
+           WARN((stderr, "%s: ", progname));
+           if (!quiet) {
+             errno = e;
+             perror(ifname);
+           }
+         }
     }
     if (method == -1) {
 	if (!to_stdout) xunlink (ofname);
@@ -1745,16 +1756,6 @@ local void copy_stat(ifstat)
 #ifndef NO_CHOWN
     fchown(ofd, ifstat->st_uid, ifstat->st_gid);  /* Copy ownership */
 #endif
-    remove_ofname = 0;
-    /* It's now safe to remove the input file: */
-    if (xunlink (ifname)) {
-	int e = errno;
-	WARN((stderr, "%s: ", progname));
-	if (!quiet) {
-	    errno = e;
-	    perror(ifname);
-	}
-    }
 }
 
 #if ! NO_DIR
diff --git a/zgrep.in b/zgrep.in
index 9ddb557..cac4863 100755
--- a/zgrep.in
+++ b/zgrep.in
@@ -107,7 +107,24 @@ for i do
       else
 	sed_script="s|^|${i}:|"
       fi
-      $grep $opt "$pat" | sed "$sed_script"
+      # Hack adapted from GPLed code at
+      # http://home.comcast.net/~j.p.h/cus-faq-2
+      # Has the same effect as the following two lines of bash:
+      #
+      # $grep $opt "$pat" | sed "$sed_script"
+      # exit ${PIPESTATUS[0]}
+      #
+      # Inside the `...`, fd4 goes to the pipe whose other end is read
+      # and passed to eval; fd1 is the normal standard output
+      # preserved the line before with exec 3>&1
+      exec 3>&1
+      eval `
+      exec 4>&1 >&3 3>&-
+      {
+       $grep $opt "$pat" 4>&-; echo "r=$?;" >&4
+      } | sed "$sed_script"
+      `
+      exit $r
     fi
   r=$?
   test $res -lt $r && res=$r
-- 
2.45.2