Skip to content

Instantly share code, notes, and snippets.

@avar
Last active August 14, 2018 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avar/4c0347b08968064df96cdaea04db093d to your computer and use it in GitHub Desktop.
Save avar/4c0347b08968064df96cdaea04db093d to your computer and use it in GitHub Desktop.
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