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 = 'Op_read.tmp';
36 END { 1 while unlink $tmpfile }
38 my (@values, @buffers) = ('', '');
40 foreach (65, 161, 253, 9786) {
41 push @values, join "", map {chr $_} $_ .. $_ + 4;
42 push @buffers, join "", map {chr $_} $_ + 5 .. $_ + 20;
44 my @offsets = (0, 3, 7, 22, -1, -3, -5, -7);
45 my @lengths = (0, 2, 5, 10);
47 foreach my $value (@values) {
48 foreach my $initial_buffer (@buffers) {
50 if ($value !~ tr/\0-\377//c) {
55 foreach my $utf8 (@utf8) {
56 skip "Needs :utf8 layer but no perlio", 2 * @offsets * @lengths
57 if $utf8 and !$has_perlio;
59 1 while unlink $tmpfile;
60 open FH, ">$tmpfile" or die "Can't open $tmpfile: $!";
61 binmode FH, "utf8" if $utf8;
64 foreach my $offset (@offsets) {
65 foreach my $length (@lengths) {
66 # Will read the lesser of the length of the file and the
68 my $will_read = $value;
69 if ($length < length $will_read) {
70 substr ($will_read, $length) = '';
72 # Going to trash this so need a copy
73 my $buffer = $initial_buffer;
77 # Right pad with NUL bytes
78 $expect .= "\0" x $offset;
79 substr ($expect, $offset) = '';
81 substr ($expect, $offset) = $will_read;
83 open FH, $tmpfile or die "Can't open $tmpfile: $!";
84 binmode FH, "utf8" if $utf8;
85 my $what = sprintf "%d into %d l $length o $offset",
86 ord $value, ord $buffer;
87 $what .= ' u' if $utf8;
88 $got = read (FH, $buffer, $length, $offset);
89 is ($got, length $will_read, "got $what");
90 is ($buffer, $expect, "buffer $what");