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 my $tmpfile = 'Op_read.tmp';
30 1 while unlink $tmpfile;
32 my (@values, @buffers) = ('', '');
34 foreach (65, 161, 253) { # 9786) {
35 push @values, join "", map {chr $_} $_ .. $_ + 4;
36 push @buffers, join "", map {chr $_} $_ + 5 .. $_ + 20;
39 foreach my $value (@values) {
40 foreach my $initial_buffer (@buffers) {
42 if ($value !~ tr/\0-\377//c) {
46 foreach my $utf8 (@utf8) {
47 1 while unlink $tmpfile;
48 open FH, ">$tmpfile" or die "Can't open $tmpfile: $!";
49 binmode FH, "utf8" if $utf8;
52 foreach my $offset (0, 3, 7, 22, -1, -3, -5, -7) {
53 foreach my $length (0, 2, 5, 10) {
54 # Will read the lesser of the length of the file and the
56 my $will_read = $value;
57 if ($length < length $will_read) {
58 substr ($will_read, $length) = '';
60 # Going to trash this so need a copy
61 my $buffer = $initial_buffer;
65 # Right pad with NUL bytes
66 $expect .= "\0" x $offset;
67 substr ($expect, $offset) = '';
69 substr ($expect, $offset) = $will_read;
71 open FH, $tmpfile or die "Can't open $tmpfile: $!";
72 binmode FH, "utf8" if $utf8;
73 my $what = sprintf "%d into %d l $length o $offset",
74 ord $value, ord $buffer;
75 $what .= ' u' if $utf8;
76 $got = read (FH, $buffer, $length, $offset);
77 is ($got, length $will_read, "got $what");
78 is ($buffer, $expect, "buffer $what");