File: mkbuf

package info (click to toggle)
inn2 2.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,720 kB
  • ctags: 8,983
  • sloc: ansic: 92,499; sh: 13,509; perl: 12,921; makefile: 2,985; yacc: 842; python: 342; lex: 255
file content (29 lines) | stat: -rwxr-xr-x 436 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/perl

sub usage {
	print STDERR "Usage: $0 <size in KB> <filename>\n";
	exit 1;
}

usage if(@ARGV != 2);

$buf1k = "\0"x1024;
$buf1m = "$buf1k"x1024;

$kb = $ARGV[0] * 1;
&usage if($kb == 0);

if($ARGV[1] eq '-') {
	open(FILE, "|cat") or die;
} else {
	open(FILE, ">$ARGV[1]") or die;
}

for($i = 0; $i+1024 <= $kb; $i+=1024) {
	print FILE $buf1m or die;
}
if($i < $kb) {
	print FILE "$buf1k"x($kb-$i) or die;
}

close FILE;