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 ( { map { /^(\w+)/; $1 => $opts->{$_} } keys %$opts }, keys %$opts )
21 or die "Could not parse command-line options\n";
23 while ( my $filename = shift ) {
24 die "$filename is not a file\n" unless -f $filename;
25 my $oldsize = -s $filename;
26 my $newsize = ( ( $oldsize + $blksize - 1 ) & ~( $blksize - 1 ) );
27 my $padsize = ( $newsize - $oldsize );
29 if ( $verbosity >= 1 ) {
30 printf "Padding %s from %d to %d bytes with %d x 0x%02x\n",
31 $filename, $oldsize, $newsize, $padsize, $byte;
34 sysopen ( my $fh, $filename, ( O_WRONLY | O_APPEND ) )
35 or die "Could not open $filename for appending: $!\n";
36 syswrite $fh, ( chr ( $byte ) x $padsize )
37 or die "Could not append to $filename: $!\n";
40 truncate $filename, $newsize
41 or die "Could not resize $filename: $!\n";
43 die "Failed to pad $filename\n" unless -s $filename == $newsize;