Skip to content

Instantly share code, notes, and snippets.

@avar

avar/pipe_buf_test.pl

Last active Aug 14, 2018
Embed
What would you like to do?
PIPE_BUF test
#!/usr/bin/env perl
use v5.10.1;
use strict;
use warnings;
use Fcntl ':DEFAULT';
# Usage:
# >/tmp/append; perl pipe_buf_test.pl /tmp/append A $((2**12)) 4
# Will write 4 lines of 4095 "A"s and \n to /tmp/append
my ($file, $byte, $length, $times) = @ARGV;
my $str = ($byte x ($length - 1)) . "\n"; # -1 for \n
sysopen my $fh, $file, O_WRONLY|O_APPEND|O_CREAT, 0666 or die $!;
for my $n (1..$times) {
syswrite $fh, $str or die "Failed to write() the ${n}th time: $!";
}
close $fh or die $!;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment