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