1 diff --git a/src/common.h b/src/common.h
2 index 42fd539..fe032ec 100644
5 @@ -906,4 +906,7 @@ void finish_deferred_unlinks (void);
7 extern void (*fatal_exit_hook) (void);
9 +GLOBAL int debian_longlink_hack;
10 +GLOBAL int pristine_tar_compat;
13 diff --git a/src/create.c b/src/create.c
14 index 4344a24..de10cae 100644
21 +extern int debian_longlink_hack;
22 +extern int pristine_tar_compat;
24 /* Error number to use when an impostor is discovered.
25 Pretend the impostor isn't there. */
26 enum { IMPOSTOR_ERRNO = ENOENT };
27 @@ -534,6 +537,11 @@ write_short_name (struct tar_stat_info *st)
31 +#define FILL(field,byte) do { \
32 + memset(field, byte, sizeof(field)-1); \
33 + (field)[sizeof(field)-1] = 0; \
36 /* Write a GNUTYPE_LONGLINK or GNUTYPE_LONGNAME block. */
38 write_gnu_long_link (struct tar_stat_info *st, const char *p, char type)
39 @@ -544,6 +552,11 @@ write_gnu_long_link (struct tar_stat_info *st, const char *p, char type)
42 header = start_private_header ("././@LongLink", size, 0);
43 + if (pristine_tar_compat) {
44 + FILL (header->header.mtime, '0');
45 + FILL (header->header.mode, '0');
48 uid_to_uname (0, &tmpname);
49 UNAME_TO_CHARS (tmpname, header->header.uname);
51 @@ -724,7 +737,7 @@ write_header_name (struct tar_stat_info *st)
52 return write_short_name (st);
54 else if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
55 - < strlen (st->file_name))
56 + < strlen (st->file_name) + debian_longlink_hack)
57 return write_long_name (st);
59 return write_short_name (st);
60 @@ -1476,7 +1489,7 @@ dump_hard_link (struct tar_stat_info *st)
61 block_ordinal = current_block_ordinal ();
62 assign_string (&st->link_name, link_name);
63 if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
64 - < strlen (link_name))
65 + < strlen (link_name) + debian_longlink_hack)
69 diff --git a/src/tar.c b/src/tar.c
70 index 4f5017d..b72e25b 100644
73 @@ -1246,6 +1246,26 @@ expand_pax_option (struct tar_args *targs, const char *arg)
77 +/* Debian specific environment variable used by pristine-tar to enable use of
78 + * longlinks for filenames exactly 100 bytes long. */
79 +void debian_longlink_hack_init (void) {
80 + char *s=getenv ("TAR_LONGLINK_100");
81 + if (s && strcmp(s, "1") == 0)
82 + debian_longlink_hack=1;
84 + debian_longlink_hack=0;
87 +/* pristine-tar sets this environment variable to force fields in longlinks
88 + * to be zeroed as was the case in tar 1.26. */
89 +void pristine_tar_compat_init (void) {
90 + char *s=getenv ("PRISTINE_TAR_COMPAT");
91 + if (s && strcmp(s, "1") == 0)
92 + pristine_tar_compat=1;
94 + pristine_tar_compat=0;
99 parse_owner_group (char *arg, uintmax_t field_max, char const **name_option)
100 @@ -2626,6 +2646,9 @@ main (int argc, char **argv)
101 filename_terminator = '\n';
102 set_quoting_style (0, DEFAULT_QUOTING_STYLE);
104 + debian_longlink_hack_init ();
105 + pristine_tar_compat_init ();
107 /* Make sure we have first three descriptors available */