12 open(FOO,'op/read.t') || open(FOO,'t/op/read.t') || open(FOO,':op:read.t') || die "Can't open op.read";
13 seek(FOO,4,0) or die "Seek failed: $!";
15 my $got = read(FOO,$buf,4);
20 seek (FOO,0,2) || seek(FOO,20000,0);
21 $got = read(FOO,$buf,4);
26 # This is true if Config is not built, or if PerlIO is enabled
27 # ie assume that PerlIO is present, unless we know for sure otherwise.
28 my $has_perlio = !eval {
31 !$Config::Config{useperlio}
34 my $tmpfile = tempfile();
39 foreach (65, 161, 253, 9786) {
40 push @values, join "", map {chr $_} $_ .. $_ + 4;
41 push @buffers, join "", map {chr $_} $_ + 5 .. $_ + 20;
43 my @offsets = (0, 3, 7, 22, -1, -3, -5, -7);
44 my @lengths = (0, 2, 5, 10);
46 foreach my $value (@values) {
47 foreach my $initial_buffer (@buffers) {
49 if ($value !~ tr/\0-\377//c) {
54 foreach my $utf8 (@utf8) {
55 skip "Needs :utf8 layer but no perlio", 2 * @offsets * @lengths
56 if $utf8 and !$has_perlio;
58 open FH, ">$tmpfile" or die "Can't open $tmpfile: $!";
59 binmode FH, "utf8" if $utf8;
62 foreach my $offset (@offsets) {
63 next if !length($initial_buffer) && $offset != 0;
64 foreach my $length (@lengths) {
65 # Will read the lesser of the length of the file and the
67 my $will_read = $value;
68 if ($length < length $will_read) {
69 substr ($will_read, $length) = '';
71 # Going to trash this so need a copy
72 my $buffer = $initial_buffer;
76 # Right pad with NUL bytes
77 $expect .= "\0" x $offset;
78 substr ($expect, $offset) = '';
80 substr ($expect, $offset) = $will_read;
82 open FH, $tmpfile or die "Can't open $tmpfile: $!";
83 binmode FH, "utf8" if $utf8;
84 my $what = sprintf "%d into %d l $length o $offset",
85 ord $value, ord $buffer;
86 $what .= ' u' if $utf8;
87 $got = read (FH, $buffer, $length, $offset);
88 is ($got, length $will_read, "got $what");
89 is ($buffer, $expect, "buffer $what");