Last active
August 14, 2018 07:46
-
-
Save avar/4c0347b08968064df96cdaea04db093d to your computer and use it in GitHub Desktop.
PIPE_BUF test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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