Work on loader to prepare for passing in a command line.
[pintos-anon] / src / pad
1 #! /usr/bin/perl
2
3 if (@ARGV != 1) {
4     print STDERR "pad, for padding a file out to an even block size\n";
5     print STDERR "usage: pad BLOCKSIZE < INPUT > OUTPUT\n\n";
6     print STDERR "pad copies its input to its output, then writes\n";
7     print STDERR "zeroes to its output as necessary to make the\n";
8     print STDERR "output size an even multiple of BLOCKSIZE bytes\n";
9     exit 1;
10 }
11
12 $blocksize = $ARGV[0];
13 $input_size = 0;
14 while (read (STDIN, $input, 4096)) {
15     $input_size += length ($input);
16     print $input;
17 }
18
19 $odd_bytes = $input_size % $blocksize;
20 print "\0" x ($blocksize - $odd_bytes) if $odd_bytes != 0;