#!/usr/athena/bin/perl

if ($#ARGV < 0) {
	print STDERR "Usage: $0 <file1> <file2> ...\n";
	exit (1);
}

foreach $file (@ARGV) {
	local (@statinfo) = lstat ($file);
	if (! defined @statinfo) {
		die "$0: $file: $!";
	}
	local ($size) = $statinfo[7];
	local ($blksize) = $statinfo[11];
	local ($nblocks) = $size / $blksize;
	local ($leftover) = $size % $blksize;
	local ($buf) = "\0" x $blksize;

	print "file = $file, size = $size, blksize = $blksize\n";

	if (! -f _) {
		die "$0: $file is not a plain file\n";
	}
	if (! open (FILE, ">$file")) {
		die "$0: error opening $file: $!\n";
	} 
	for (1..$nblocks) {
		syswrite (FILE, $buf, $blksize) == $blksize
			|| die "$0: error writing to $file: $!";
	}
	$buf = "\0" x $leftover;
	syswrite (FILE, $buf, $leftover) == $leftover
		|| die "$0: error writing to $file: $!";

	unlink ($file) || die "$0: can't unlink $file: $!";
	close (FILE) || die "$0: can't close $file: $!";
}
