0a554da48d69106dc1f624e6541744afe64ac4f4
[debian/amanda] / patches / tar-1.12.patch
1 The first hunk in this file was submitted by Craig Wiegert
2 <wiegert@quintessence.uchicago.edu>.  It fixed a problem that causes
3 GNUTAR to issue error messages like the following for sparse files:
4
5 > /bin/tar: Read error at byte 0, reading 512 bytes, in file ./var/log/lastlog: Bad file number
6
7 The others fix an estimate problem in GNUTAR on SunOS 4.1.3, HP/UX and
8 other systems whose C libraries do not support "%lld" in printf format
9 strings for printing long long integers.
10
11 --- tar-1.12/src/create.c       Mon Dec 15 17:26:47 1997
12 +++ tar-1.12/src/create.c       Mon Dec 15 17:50:48 1997
13 @@ -1048,7 +1048,7 @@
14         }
15        if (save_typeflag == GNUTYPE_SPARSE)
16         {
17 -         if (finish_sparse_file (f, &sizeleft, current_stat.st_size, p))
18 +         if (f < 0 || finish_sparse_file (f, &sizeleft, current_stat.st_size, p))
19             goto padit;
20         }
21        else
22 --- tar-1.12/lib/Makefile.am    Wed Apr 16 16:30:04 1997
23 +++ tar-1.12/lib/Makefile.am    Mon Nov 17 06:45:43 1997
24 @@ -37,6 +37,9 @@
25  libtar_a_LIBADD = @ALLOCA@ @LIBOBJS@
26  libtar_a_DEPENDENCIES = $(libtar_a_LIBADD)
27  
28 +$(srcdir)/getdate.h:
29 +       touch $@
30 +
31  # Say $(srcdir), so GNU make does not report an ambiguity with the .y.c rule.
32  $(srcdir)/getdate.c: getdate.y
33         @echo Expect 13 shift/reduce conflicts...
34 --- tar-1.12/src/arith.h        Wed Apr 16 18:02:57 1997
35 +++ tar-1.12/src/arith.h        Mon Nov 17 05:47:33 1997
36 @@ -37,10 +37,10 @@
37  
38  #if BITS_PER_BYTE * SIZEOF_UNSIGNED_LONG >= BITS_PER_TARLONG
39  # define SUPERDIGIT 0
40 -# define TARLONG_FORMAT "%uld"
41 +# define TARLONG_FORMAT "%lu"
42  typedef unsigned long tarlong;
43  #else
44 -# if BITS_PER_BYTE * SIZEOF_LONG_LONG >= BITS_PER_TARLONG + 1
45 +# if PRINTF_LONG_LONG_WORKS && BITS_PER_BYTE * SIZEOF_LONG_LONG >= BITS_PER_TARLONG + 1
46  #  define SUPERDIGIT 0
47  #  define TARLONG_FORMAT "%lld"
48  typedef long long tarlong;
49 @@ -48,12 +48,12 @@
50  #  if BITS_PER_BYTE * SIZEOF_UNSIGNED_LONG >= 64
51  #   define SUPERDIGIT 1000000000L
52  #   define BITS_PER_SUPERDIGIT 29
53 -#   define TARLONG_FORMAT "%09uld"
54 +#   define TARLONG_FORMAT "%09lu"
55  #  else
56  #   if BITS_PER_BYTE * SIZEOF_UNSIGNED_LONG >= 32
57  #    define SUPERDIGIT 10000L
58  #    define BITS_PER_SUPERDIGIT 14
59 -#    define TARLONG_FORMAT "%04uld"
60 +#    define TARLONG_FORMAT "%04lu"
61  #   endif
62  #  endif
63  # endif
64 --- tar-1.12/src/arith.c        Wed Apr 23 23:25:57 1997
65 +++ tar-1.12/src/arith.c        Mon Nov 17 08:11:11 1997
66 @@ -96,7 +96,7 @@
67  void
68  add_to_tarlong_helper (unsigned long *accumulator, int value)
69  {
70 -  int counter;
71 +  int counter, newvalue;
72  
73    if (value < 0)
74      for (counter = 0; counter < LONGS_PER_TARLONG; counter++)
75 @@ -106,8 +106,15 @@
76             accumulator[counter] += value;
77             return;
78           }
79 -       accumulator[counter] += value + SUPERDIGIT;
80 -       value = -1;
81 +       newvalue = - ((-value-1) / SUPERDIGIT) -1;
82 +       value = - ((-value) % SUPERDIGIT);
83 +       accumulator[counter] += SUPERDIGIT + value;
84 +       if (accumulator[counter] >= SUPERDIGIT)
85 +         {
86 +           accumulator[counter] -= SUPERDIGIT;
87 +           ++newvalue;
88 +         }
89 +       value = newvalue;
90        }
91    else
92      for (counter = 0; counter < LONGS_PER_TARLONG; counter++)
93 @@ -117,8 +124,15 @@
94             accumulator[counter] += value;
95             return;
96           }
97 -       accumulator[counter] += value - SUPERDIGIT;
98 -       value = 1;
99 +       newvalue = value / SUPERDIGIT;
100 +       value = value % SUPERDIGIT;
101 +       accumulator[counter] += value;
102 +       if (accumulator[counter] >= SUPERDIGIT)
103 +         {
104 +           accumulator[counter] -= SUPERDIGIT;
105 +           ++newvalue;
106 +         }
107 +       value = newvalue;
108        }
109    FATAL_ERROR ((0, 0, _("Arithmetic overflow")));
110  }
111 @@ -155,7 +169,7 @@
112    while (counter > 0 && accumulator[counter] == 0)
113      counter--;
114  
115 -  fprintf (file, "%uld", accumulator[counter]);
116 +  fprintf (file, "%lu", accumulator[counter]);
117    while (counter > 0)
118      fprintf (file, TARLONG_FORMAT, accumulator[--counter]);
119  }
120 --- tar-1.12/configure.in       Fri Apr 25 17:02:46 1997
121 +++ tar-1.12/configure.in       Mon Nov 17 06:17:49 1997
122 @@ -26,6 +26,35 @@
123  AC_CHECK_SIZEOF(unsigned long, 4)
124  AC_CHECK_SIZEOF(long long, 0)
125  
126 +# SunOS 4.1.3's printf treats %lld as %ld
127 +AC_CACHE_CHECK([whether printf understands %lld],
128 +       tar_cv_printf_long_long_works,
129 +       AC_TRY_RUN([[
130 +#include <stdio.h>
131 +main() {
132 +  long long foo = -1;
133 +  char buf[1024];
134 +  while(foo) {
135 +    long long bar = 0;
136 +    sprintf(buf, "%lld", foo);
137 +    sscanf(buf, "%lld", &bar);
138 +    if (foo != bar)
139 +      return 1;
140 +    foo <<= 1;
141 +  }
142 +  return 0;
143 +}
144 +       ]], 
145 +       tar_cv_printf_long_long_works=yes,
146 +       tar_cv_printf_long_long_works=no,
147 +       if test x"$tar_cv_printf_long_long_works" = x; then
148 +               tar_cv_printf_long_long_works=cross
149 +       fi)
150 +)
151 +if test x"$tar_cv_printf_long_long_works" = x"yes"; then
152 +       AC_DEFINE(PRINTF_LONG_LONG_WORKS)
153 +fi
154 +
155  AC_CHECK_HEADERS(fcntl.h limits.h linux/fd.h memory.h net/errno.h poll.h \
156  sgtty.h string.h stropts.h \
157  sys/buf.h sys/device.h sys/gentape.h sys/inet.h sys/io/trioctl.h sys/ioccom.h \
158 --- tar-1.12/acconfig.h Thu Apr 10 11:37:02 1997
159 +++ tar-1.12/acconfig.h Mon Nov 17 05:53:38 1997
160 @@ -86,3 +86,6 @@
161  
162  /* Define to 1 if GNU regex should be used instead of GNU rx.  */
163  #undef WITH_REGEX
164 +
165 +/* Define to 1 if printf() supports "%lld" */
166 +#undef PRINTF_LONG_LONG_WORKS
167 --- tar-1.12/configure
168 +++ tar-1.12/configure
169 @@ -1,2 +1,4 @@
170  #! /bin/sh
171 +echo You must run autoheader and autoconf after installing this patch
172 +exit 1
173