xref: /openbsd-src/gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar/Constant.pm (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
1b39c5158Smillertpackage Archive::Tar::Constant;
2b39c5158Smillert
3eac174f2Safresh1use strict;
4eac174f2Safresh1use warnings;
5eac174f2Safresh1
6eac174f2Safresh1use vars qw[$VERSION @ISA @EXPORT];
7eac174f2Safresh1
8b39c5158SmillertBEGIN {
9b39c5158Smillert    require Exporter;
10b39c5158Smillert
11*3d61058aSafresh1    $VERSION    = '3.02_001';
12b39c5158Smillert    @ISA        = qw[Exporter];
13b39c5158Smillert
14b39c5158Smillert    require Time::Local if $^O eq "MacOS";
15b39c5158Smillert}
16b39c5158Smillert
176fb12b70Safresh1@EXPORT = Archive::Tar::Constant->_list_consts( __PACKAGE__ );
18b39c5158Smillert
19b39c5158Smillertuse constant FILE           => 0;
20b39c5158Smillertuse constant HARDLINK       => 1;
21b39c5158Smillertuse constant SYMLINK        => 2;
22b39c5158Smillertuse constant CHARDEV        => 3;
23b39c5158Smillertuse constant BLOCKDEV       => 4;
24b39c5158Smillertuse constant DIR            => 5;
25b39c5158Smillertuse constant FIFO           => 6;
26b39c5158Smillertuse constant SOCKET         => 8;
27b39c5158Smillertuse constant UNKNOWN        => 9;
28b39c5158Smillertuse constant LONGLINK       => 'L';
29b39c5158Smillertuse constant LABEL          => 'V';
30b39c5158Smillert
31b39c5158Smillertuse constant BUFFER         => 4096;
32b39c5158Smillertuse constant HEAD           => 512;
33b39c5158Smillertuse constant BLOCK          => 512;
34b39c5158Smillert
35b39c5158Smillertuse constant COMPRESS_GZIP  => 9;
36b39c5158Smillertuse constant COMPRESS_BZIP  => 'bzip2';
3756d68f1eSafresh1use constant COMPRESS_XZ    => 'xz';
38b39c5158Smillert
39b39c5158Smillertuse constant BLOCK_SIZE     => sub { my $n = int($_[0]/BLOCK); $n++ if $_[0] % BLOCK; $n * BLOCK };
40b39c5158Smillertuse constant TAR_PAD        => sub { my $x = shift || return; return "\0" x (BLOCK - ($x % BLOCK) ) };
41b39c5158Smillertuse constant TAR_END        => "\0" x BLOCK;
42b39c5158Smillert
43b39c5158Smillertuse constant READ_ONLY      => sub { shift() ? 'rb' : 'r' };
44b39c5158Smillertuse constant WRITE_ONLY     => sub { $_[0] ? 'wb' . shift : 'w' };
45b39c5158Smillertuse constant MODE_READ      => sub { $_[0] =~ /^r/ ? 1 : 0 };
46b39c5158Smillert
47b39c5158Smillert# Pointless assignment to make -w shut up
48b39c5158Smillertmy $getpwuid; $getpwuid = 'unknown' unless eval { my $f = getpwuid (0); };
49b39c5158Smillertmy $getgrgid; $getgrgid = 'unknown' unless eval { my $f = getgrgid (0); };
50b39c5158Smillertuse constant UNAME          => sub { $getpwuid || scalar getpwuid( shift() ) || '' };
51b39c5158Smillertuse constant GNAME          => sub { $getgrgid || scalar getgrgid( shift() ) || '' };
52b39c5158Smillertuse constant UID            => $>;
53b39c5158Smillertuse constant GID            => (split ' ', $) )[0];
54b39c5158Smillert
55b39c5158Smillertuse constant MODE           => do { 0666 & (0777 & ~umask) };
56b39c5158Smillertuse constant STRIP_MODE     => sub { shift() & 0777 };
57b39c5158Smillertuse constant CHECK_SUM      => "      ";
58b39c5158Smillert
599f11ffb7Safresh1use constant UNPACK         => 'a100 a8 a8 a8 a12 a12 a8 a1 a100 A6 a2 a32 a32 a8 a8 a155 x12';	# cdrake - size must be a12 - not A12 - or else screws up huge file sizes (>8gb)
60b39c5158Smillertuse constant PACK           => 'a100 a8 a8 a8 a12 a12 A8 a1 a100 a6 a2 a32 a32 a8 a8 a155 x12';
61b39c5158Smillertuse constant NAME_LENGTH    => 100;
62b39c5158Smillertuse constant PREFIX_LENGTH  => 155;
63b39c5158Smillert
6456d68f1eSafresh1use constant TIME_OFFSET    => ($^O eq "MacOS") ? Time::Local::timelocal(0,0,0,1,0,1970) : 0;
65b39c5158Smillertuse constant MAGIC          => "ustar";
66b39c5158Smillertuse constant TAR_VERSION    => "00";
67b39c5158Smillertuse constant LONGLINK_NAME  => '././@LongLink';
68b39c5158Smillertuse constant PAX_HEADER     => 'pax_global_header';
69b39c5158Smillert
70b39c5158Smillert                            ### allow ZLIB to be turned off using ENV: DEBUG only
71b39c5158Smillertuse constant ZLIB           => do { !$ENV{'PERL5_AT_NO_ZLIB'} and
72b39c5158Smillert                                        eval { require IO::Zlib };
73b39c5158Smillert                                    $ENV{'PERL5_AT_NO_ZLIB'} || $@ ? 0 : 1
74b39c5158Smillert                                };
75b39c5158Smillert
76b39c5158Smillert                            ### allow BZIP to be turned off using ENV: DEBUG only
77b39c5158Smillertuse constant BZIP           => do { !$ENV{'PERL5_AT_NO_BZIP'} and
78b39c5158Smillert                                        eval { require IO::Uncompress::Bunzip2;
79b39c5158Smillert                                               require IO::Compress::Bzip2; };
80b39c5158Smillert                                    $ENV{'PERL5_AT_NO_BZIP'} || $@ ? 0 : 1
81b39c5158Smillert                                };
82b39c5158Smillert
8356d68f1eSafresh1                            ### allow XZ to be turned off using ENV: DEBUG only
8456d68f1eSafresh1use constant XZ             => do { !$ENV{'PERL5_AT_NO_XZ'} and
8556d68f1eSafresh1                                        eval { require IO::Compress::Xz;
8656d68f1eSafresh1                                               require IO::Uncompress::UnXz; };
8756d68f1eSafresh1                                    $ENV{'PERL5_AT_NO_XZ'} || $@ ? 0 : 1
8856d68f1eSafresh1                                };
8956d68f1eSafresh1
90b39c5158Smillertuse constant GZIP_MAGIC_NUM => qr/^(?:\037\213|\037\235)/;
91eac174f2Safresh1
92eac174f2Safresh1                           # ASCII:  B   Z   h    0    9
93eac174f2Safresh1use constant BZIP_MAGIC_NUM => qr/^\x42\x5A\x68[\x30-\x39]/;
94eac174f2Safresh1
9556d68f1eSafresh1use constant XZ_MAGIC_NUM   => qr/^\xFD\x37\x7A\x58\x5A\x00/;
96b39c5158Smillert
97b39c5158Smillertuse constant CAN_CHOWN      => sub { ($> == 0 and $^O ne "MacOS" and $^O ne "MSWin32") };
98b39c5158Smillertuse constant CAN_READLINK   => ($^O ne 'MSWin32' and $^O !~ /RISC(?:[ _])?OS/i and $^O ne 'VMS');
99b39c5158Smillertuse constant ON_UNIX        => ($^O ne 'MSWin32' and $^O ne 'MacOS' and $^O ne 'VMS');
100b39c5158Smillertuse constant ON_VMS         => $^O eq 'VMS';
101b39c5158Smillert
1026fb12b70Safresh1sub _list_consts {
1036fb12b70Safresh1    my $class = shift;
1046fb12b70Safresh1    my $pkg   = shift;
1056fb12b70Safresh1    return unless defined $pkg; # some joker might use '0' as a pkg...
1066fb12b70Safresh1
1076fb12b70Safresh1    my @rv;
1086fb12b70Safresh1    {   no strict 'refs';
1096fb12b70Safresh1        my $stash = $pkg . '::';
1106fb12b70Safresh1
1116fb12b70Safresh1        for my $name (sort keys %$stash ) {
1126fb12b70Safresh1
1136fb12b70Safresh1            ### is it a subentry?
1146fb12b70Safresh1            my $sub = $pkg->can( $name );
1156fb12b70Safresh1            next unless defined $sub;
1166fb12b70Safresh1
1176fb12b70Safresh1            next unless defined prototype($sub) and
1186fb12b70Safresh1                     not length prototype($sub);
1196fb12b70Safresh1
1206fb12b70Safresh1            push @rv, $name;
1216fb12b70Safresh1        }
1226fb12b70Safresh1    }
1236fb12b70Safresh1
1246fb12b70Safresh1    return sort @rv;
1256fb12b70Safresh1}
1266fb12b70Safresh1
127b39c5158Smillert1;
128