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: $!";
51 foreach my $offset (0, 3, 7, 22, -1, -3, -5, -7) {
52 foreach my $length (0, 2, 5, 10) {
53 # Will read the lesser of the length of the file and the read
55 my $will_read = $value;
56 if ($length < length $will_read) {
57 substr ($will_read, $length) = '';
59 # Going to trash this so need a copy
60 my $buffer = $initial_buffer;
64 # Right pad with NUL bytes
65 $expect .= "\0" x $offset;
66 substr ($expect, $offset) = '';
68 substr ($expect, $offset) = $will_read;
70 open FH, $tmpfile or die "Can't open $tmpfile: $!";
71 printf "# %d into %d l $length o $offset\n",
72 ord $value, ord $buffer;
73 $got = read (FH, $buffer, $length, $offset);
74 is ($got, length $will_read);
75 is ($buffer, $expect);