Work on loader to prepare for passing in a command line.
[pintos-anon] / src / pad
diff --git a/src/pad b/src/pad
new file mode 100755 (executable)
index 0000000..82f35d3
--- /dev/null
+++ b/src/pad
@@ -0,0 +1,20 @@
+#! /usr/bin/perl
+
+if (@ARGV != 1) {
+    print STDERR "pad, for padding a file out to an even block size\n";
+    print STDERR "usage: pad BLOCKSIZE < INPUT > OUTPUT\n\n";
+    print STDERR "pad copies its input to its output, then writes\n";
+    print STDERR "zeroes to its output as necessary to make the\n";
+    print STDERR "output size an even multiple of BLOCKSIZE bytes\n";
+    exit 1;
+}
+
+$blocksize = $ARGV[0];
+$input_size = 0;
+while (read (STDIN, $input, 4096)) {
+    $input_size += length ($input);
+    print $input;
+}
+
+$odd_bytes = $input_size % $blocksize;
+print "\0" x ($blocksize - $odd_bytes) if $odd_bytes != 0;