3 # $RCSfile: read.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:17 $
14 open(FOO,'op/read.t') || open(FOO,'t/op/read.t') || open(FOO,':op:read.t') || die "Can't open op.read";
15 seek(FOO,4,0) or die "Seek failed: $!";
17 my $got = read(FOO,$buf,4);
22 seek (FOO,0,2) || seek(FOO,20000,0);
23 $got = read(FOO,$buf,4);
28 # This is true if Config is not built, or if PerlIO is enabled
29 # ie assume that PerlIO is present, unless we know for sure otherwise.
30 my $has_perlio = !eval {
33 !$Config::Config{useperlio}
36 my $tmpfile = 'Op_read.tmp';
38 END { 1 while unlink $tmpfile }
40 my (@values, @buffers) = ('', '');
42 foreach (65, 161, 253, 9786) {
43 push @values, join "", map {chr $_} $_ .. $_ + 4;
44 push @buffers, join "", map {chr $_} $_ + 5 .. $_ + 20;
46 my @offsets = (0, 3, 7, 22, -1, -3, -5, -7);
47 my @lengths = (0, 2, 5, 10);
49 foreach my $value (@values) {
50 foreach my $initial_buffer (@buffers) {
52 if ($value !~ tr/\0-\377//c) {
57 foreach my $utf8 (@utf8) {
58 skip "Needs :utf8 layer but no perlio", 2 * @offsets * @lengths
59 if $utf8 and !$has_perlio;
61 1 while unlink $tmpfile;
62 open FH, ">$tmpfile" or die "Can't open $tmpfile: $!";
63 binmode FH, "utf8" if $utf8;
66 foreach my $offset (@offsets) {
67 foreach my $length (@lengths) {
68 # Will read the lesser of the length of the file and the
70 my $will_read = $value;
71 if ($length < length $will_read) {
72 substr ($will_read, $length) = '';
74 # Going to trash this so need a copy
75 my $buffer = $initial_buffer;
79 # Right pad with NUL bytes
80 $expect .= "\0" x $offset;
81 substr ($expect, $offset) = '';
83 substr ($expect, $offset) = $will_read;
85 open FH, $tmpfile or die "Can't open $tmpfile: $!";
86 binmode FH, "utf8" if $utf8;
87 my $what = sprintf "%d into %d l $length o $offset",
88 ord $value, ord $buffer;
89 $what .= ' u' if $utf8;
90 $got = read (FH, $buffer, $length, $offset);
91 is ($got, length $will_read, "got $what");
92 is ($buffer, $expect, "buffer $what");