Skip to content

Commit ab59fa1

Browse files
authored
tar: fail early for bad options
* Add missing getopts() return value check * This version of tar didn't have a usage string, so add one * Don't list -c in usage string for now because archive creation isn't implemented * Unconditionally use Compress::Zlib because it is a core library
1 parent bee24d7 commit ab59fa1

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

bin/tar

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,21 @@ License:
1313

1414
use strict;
1515

16+
use Compress::Zlib qw(gzopen);
1617
use File::Basename qw(basename);
1718
use Getopt::Std;
1819
use IO::File;
1920

2021
use constant EX_SUCCESS => 0;
2122
use constant EX_FAILURE => 1;
2223

23-
use vars qw($opt);
24-
2524
my $Program = basename($0);
2625

27-
BEGIN
28-
{
29-
$opt = 'ctxvmf:';
30-
eval { require Compress::Zlib };
31-
if ($@)
32-
{
33-
warn "No decompression available: $@\n";
34-
}
35-
else
36-
{
37-
Compress::Zlib->import;
38-
$opt .= 'zZ';
39-
}
40-
}
41-
4226
my %opt;
43-
getopts($opt,\%opt);
27+
getopts('ctxvmf:Zz', \%opt) or do {
28+
warn "usage: tar {-tx} [-mvZz] [-f archive] [file ...]\n";
29+
exit EX_FAILURE;
30+
};
4431

4532
sub fatal
4633
{

0 commit comments

Comments
 (0)