1 diff --git a/src/common.h b/src/common.h
2 index eb801bb..30f8cf5 100644
5 @@ -907,4 +907,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 e14e13d..d6e8ea7 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,10 @@ write_gnu_long_link (struct tar_stat_info *st, const char *p, char type)
42 header = start_private_header ("././@LongLink", size, start_time.tv_sec);
43 + if (pristine_tar_compat) {
44 + FILL (header->header.mtime, '0');
45 + FILL (header->header.mode, '0');
47 uid_to_uname (0, &tmpname);
48 UNAME_TO_CHARS (tmpname, header->header.uname);
50 @@ -724,7 +736,7 @@ write_header_name (struct tar_stat_info *st)
51 return write_short_name (st);
53 else if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
54 - < strlen (st->file_name))
55 + < strlen (st->file_name) + debian_longlink_hack)
56 return write_long_name (st);
58 return write_short_name (st);
59 @@ -1476,7 +1488,7 @@ dump_hard_link (struct tar_stat_info *st)
60 block_ordinal = current_block_ordinal ();
61 assign_string (&st->link_name, link_name);
62 if (NAME_FIELD_SIZE - (archive_format == OLDGNU_FORMAT)
63 - < strlen (link_name))
64 + < strlen (link_name) + debian_longlink_hack)
68 diff --git a/src/tar.c b/src/tar.c
69 index 4f5017d..b72e25b 100644
72 @@ -1246,6 +1246,26 @@ expand_pax_option (struct tar_args *targs, const char *arg)
76 +/* Debian specific environment variable used by pristine-tar to enable use of
77 + * longlinks for filenames exactly 100 bytes long. */
78 +void debian_longlink_hack_init (void) {
79 + char *s=getenv ("TAR_LONGLINK_100");
80 + if (s && strcmp(s, "1") == 0)
81 + debian_longlink_hack=1;
83 + debian_longlink_hack=0;
86 +/* pristine-tar sets this environment variable to force fields in longlinks
87 + * to be zeroed as was the case in tar 1.26. */
88 +void pristine_tar_compat_init (void) {
89 + char *s=getenv ("PRISTINE_TAR_COMPAT");
90 + if (s && strcmp(s, "1") == 0)
91 + pristine_tar_compat=1;
93 + pristine_tar_compat=0;
98 parse_owner_group (char *arg, uintmax_t field_max, char const **name_option)
99 @@ -2626,6 +2646,9 @@ main (int argc, char **argv)
100 filename_terminator = '\n';
101 set_quoting_style (0, DEFAULT_QUOTING_STYLE);
103 + debian_longlink_hack_init ();
104 + pristine_tar_compat_init ();
106 /* Make sure we have first three descriptors available */