Subject: Re: bug#23107: new snapshot available: gzip-1.6.56-9190

From: Paul Eggert <[email-masked]>
Date: Fri, 25 Mar 2016 00:27:12 -0700

Thanks again for checking all that.

Assaf Gordon wrote:

> On NetBSD 7.0, 6.1.4, One test fails (zgrep-f) perhaps due to filename issues?

No, NetBSD's mktemp command is incompatible with GNU's, in terms of the 
interpretation of -t. The simplest fix is to stop using mktemp's -t option 
(which has been "deprecated" in the GNU version for many years anyway).

> I'm adding Alpine Linux to my test suite ( https://alpinelinux.org/ ).
> ...
> On this system, zdiff check fails because busybox's diff does not support the "-c" option

Wow, *that* is stripped down. Well, it shouldn't be that hard to port to. Does 
the attached patch fix the problem (as well as the NetBSD problem)?

diff --git a/Makefile.am b/Makefile.am
index e892cdc..738c63c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -111,11 +111,11 @@ FILES_TO_CHECK = $(bin_SCRIPTS) \
   $(top_srcdir)/ChangeLog $(top_srcdir)/configure $(top_srcdir)/gzip.c
 check-local: $(FILES_TO_CHECK) $(bin_PROGRAMS) gzip.doc.gz
 	$(AM_V_GEN)$(new_path); { test '$(srcdir)' != . \
-				    || zdiff -c gzip.doc.gz; }
-	$(AM_V_at)$(new_path); zdiff -c $(srcdir)/gzip.doc $(srcdir)/gzip.doc
+				    || zdiff gzip.doc.gz; }
+	$(AM_V_at)$(new_path); zdiff $(srcdir)/gzip.doc $(srcdir)/gzip.doc
 	$(AM_V_at)$(new_path); zdiff $(srcdir)/gzip.doc gzip.doc.gz
-	$(AM_V_at)$(new_path); zdiff -c - $(srcdir)/gzip.doc <gzip.doc.gz
-	$(AM_V_at)$(new_path); zdiff -c gzip.doc.gz gzip.doc.gz
+	$(AM_V_at)$(new_path); zdiff - $(srcdir)/gzip.doc <gzip.doc.gz
+	$(AM_V_at)$(new_path); zdiff gzip.doc.gz gzip.doc.gz
 	$(AM_V_at)$(new_path); zgrep -iV >/dev/null
 	$(AM_V_at)$(new_path);				\
 	for opt in --rsyncable '' -1 -9; do		\
diff --git a/gzexe.in b/gzexe.in
index b333993..282e385 100644
--- a/gzexe.in
+++ b/gzexe.in
@@ -119,7 +119,7 @@ for i do
     mktemp_status=$?
   fi
   if test $mktemp_status -eq 0; then
-    tmp=`TMPDIR=$dir mktemp -t gzexeXXXXXX`
+    tmp=`TMPDIR=$dir mktemp`
   else
     tmp=$dir/gzexe$$
   fi && { cp -p "$file" "$tmp" 2>/dev/null || cp "$file" "$tmp"; } || {
@@ -157,7 +157,7 @@ trap 'res=$?
 ' 0 1 2 3 5 10 13 15
 
 if type mktemp >/dev/null 2>&1; then
-  gztmpdir=`mktemp -dt`
+  gztmpdir=`mktemp -d`
 else
   gztmpdir=/tmp/gztmp$$; mkdir $gztmpdir
 fi || { (exit 127); exit 127; }
diff --git a/tests/init.sh b/tests/init.sh
index ee08022..99d4d0b 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -308,13 +308,19 @@ if diff_out_=`exec 2>/dev/null; diff -u "$0" "$0" < /dev/null` \
       fi
     }
   fi
-elif diff_out_=`exec 2>/dev/null; diff -c "$0" "$0" < /dev/null`; then
+elif
+  for diff_opt_ in -U3 -c '' no; do
+    test "$diff_opt_" = no && break
+    diff_out_=`exec 2>/dev/null; diff $diff_opt_ "$0" "$0" </dev/null` && break
+  done
+  test "$diff_opt_" != no
+then
   if test -z "$diff_out_"; then
-    compare_ () { diff -c "$@"; }
+    compare_ () { diff $diff_opt_ "$@"; }
   else
     compare_ ()
     {
-      if diff -c "$@" > diff.out; then
+      if diff $diff_opt_ "$@" > diff.out; then
         # No differences were found, but AIX and HP-UX 'diff' produce output
         # "No differences encountered" or "There are no differences between the
         # files.". Hide this output.
@@ -352,9 +358,6 @@ compare ()
   fi
 }
 
-# An arbitrary prefix to help distinguish test directories.
-testdir_prefix_ () { printf gt; }
-
 # Run the user-overridable cleanup_ function, remove the temporary
 # directory and exit with the incoming value of $?.
 remove_tmp_ ()
@@ -468,8 +471,7 @@ setup_ ()
   initial_cwd_=$PWD
   fail=0
 
-  pfx_=`testdir_prefix_`
-  test_dir_=`mktempd_ "$initial_cwd_" "$pfx_-$ME_.XXXX"` \
+  test_dir_=`mktempd_ "$initial_cwd_"` \
     || fail_ "failed to create temporary directory in $initial_cwd_"
   cd "$test_dir_" || fail_ "failed to cd to temporary directory"
 
@@ -490,7 +492,7 @@ setup_ ()
 # Create a temporary directory, much like mktemp -d does.
 # Written by Jim Meyering.
 #
-# Usage: mktempd_ /tmp phoey.XXXXXXXXXX
+# Usage: mktempd_ /tmp
 #
 # First, try to use the mktemp program.
 # Failing that, we'll roll our own mktemp-like function:
@@ -538,12 +540,16 @@ rand_bytes_ ()
 mktempd_ ()
 {
   case $# in
-  2);;
-  *) fail_ "Usage: mktempd_ DIR TEMPLATE";;
+  1);;
+  *) fail_ "Usage: mktempd_ DIR";;
   esac
 
   destdir_=$1
-  template_=$2
+  base_template_=tmp.
+  template_=$base_template_.XXXXXXXXXX
+
+  # How many X's are at the end of the template.
+  nx_=10
 
   MAX_TRIES_=4
 
@@ -554,14 +560,8 @@ mktempd_ ()
   */) fail_ "invalid destination dir: remove trailing slash(es)";;
   esac
 
-  case $template_ in
-  *XXXX) ;;
-  *) fail_ \
-       "invalid template: $template_ (must have a suffix of at least 4 X's)";;
-  esac
-
   # First, try to use mktemp.
-  d=`unset TMPDIR; { mktemp -d -t -p "$destdir_" "$template_"; } 2>/dev/null` \
+  d=`unset TMPDIR; { mktemp -d -p "$destdir_"; } 2>/dev/null` \
     || fail=1
 
   # The resulting name must be in the specified directory.
@@ -581,14 +581,6 @@ mktempd_ ()
 
   # If we reach this point, we'll have to create a directory manually.
 
-  # Get a copy of the template without its suffix of X's.
-  base_template_=`echo "$template_"|sed 's/XX*$//'`
-
-  # Calculate how many X's we've just removed.
-  template_length_=`echo "$template_" | wc -c`
-  nx_=`echo "$base_template_" | wc -c`
-  nx_=`expr $template_length_ - $nx_`
-
   err_=
   i_=1
   while :; do
@@ -602,8 +594,7 @@ mktempd_ ()
   fail_ "$err_"
 }
 
-# If you want to override the testdir_prefix_ function,
-# or to add more utility functions, use this file.
+# To add more utility functions, use this file.
 test -f "$srcdir/init.cfg" \
   && . "$srcdir/init.cfg"
 
diff --git a/zdiff.in b/zdiff.in
index f2f5435..12de3a1 100644
--- a/zdiff.in
+++ b/zdiff.in
@@ -111,15 +111,15 @@ elif test $# -eq 2; then
                         esac
                         (exit $cmp_status)
                     else
-                        F=`expr "/$2" : '.*/\(.*\)[-.][zZtga]*$'` || F=$prog
                         tmp=
                         trap '
                           test -n "$tmp" && rm -f "$tmp"
                           (exit 2); exit 2
                         ' HUP INT PIPE TERM 0
                         if type mktemp >/dev/null 2>&1; then
-                          tmp=`mktemp -t -- "$F.XXXXXX"` || exit 2
+                          tmp=`mktemp` || exit 2
                         else
+                          F=`expr "/$2" : '.*/\(.*\)[-.][zZtga]*$'` || F=$prog
                           set -C
                           tmp=${TMPDIR-/tmp}/$F.$$
                         fi
diff --git a/zgrep.in b/zgrep.in
index 99ace59..7ce45ae 100644
--- a/zgrep.in
+++ b/zgrep.in
@@ -134,7 +134,7 @@ while test $# -ne 0; do
         (exit 2); exit 2
       ' HUP INT PIPE TERM 0
       if type mktemp >/dev/null 2>&1; then
-        pattmp=$(mktemp -t -- "zgrep.XXXXXX") || exit 2
+        pattmp=$(mktemp) || exit 2
       else
         set -C
         pattmp=${TMPDIR-/tmp}/zgrep.$$