13 'verbose|v+' => sub { $verbosity++; },
14 'quiet|q+' => sub { $verbosity--; },
15 'blksize|s=o' => sub { $blksize = $_[1]; },
16 'byte|b=o' => sub { $byte = $_[1]; },
19 Getopt
::Long
::Configure
( 'bundling', 'auto_abbrev' );
20 GetOptions
( %opts ) or die "Could not parse command-line options\n";
22 while ( my $filename = shift ) {
23 die "$filename is not a file\n" unless -f
$filename;
24 my $oldsize = -s
$filename;
25 my $padsize = ( ( -$oldsize ) % $blksize );
26 my $newsize = ( $oldsize + $padsize );
28 if ( $verbosity >= 1 ) {
29 printf "Padding %s from %d to %d bytes with %d x 0x%02x\n",
30 $filename, $oldsize, $newsize, $padsize, $byte;
33 sysopen ( my $fh, $filename, ( O_WRONLY
| O_APPEND
) )
34 or die "Could not open $filename for appending: $!\n";
35 syswrite $fh, ( chr ( $byte ) x
$padsize )
36 or die "Could not append to $filename: $!\n";
39 truncate $filename, $newsize
40 or die "Could not resize $filename: $!\n";
42 die "Failed to pad $filename\n"
43 unless ( ( ( -s
$filename ) % $blksize ) == 0 );