5 chdir('op') || die "sysio.t: cannot look for myself: $!";
7 open(I, 'sysio.t') || die "sysio.t: cannot find myself: $!";
11 # should not be able to do negative lengths
12 eval { sysread(I, $x, -1) };
13 print 'not ' unless ($@ =~ /^Negative length /);
17 print 'not ' unless ($x eq 'abc');
20 # should not be able to read before the buffer
21 eval { sysread(I, $x, 1, -4) };
22 print 'not ' unless ($x eq 'abc');
26 print 'not ' unless ($x eq 'abc');
32 print 'not ' unless(sysread(I, $a, 3) == 3);
35 # $a should be as follows
36 print 'not ' unless ($a eq '#!.');
39 # reading past the buffer should zero pad
40 print 'not ' unless(sysread(I, $a, 2, 5) == 2);
43 # the zero pad should be seen now
44 print 'not ' unless ($a eq "#!.\0\0/p");
47 # try changing the last two characters of $a
48 print 'not ' unless(sysread(I, $a, 3, -2) == 3);
51 # the last two characters of $a should have changed (into three)
52 print 'not ' unless ($a eq "#!.\0\0erl");
55 $outfile = 'sysio.out';
57 open(O, ">$outfile") || die "sysio.t: cannot write $outfile: $!";
59 select(O); $|=1; select(STDOUT);
61 # cannot write negative lengths
62 eval { syswrite(O, $x, -1) };
63 print 'not ' unless ($@ =~ /^Negative length /);
67 print 'not ' unless ($x eq 'abc');
70 # $outfile still intact
71 print 'not ' if (-s $outfile);
74 # should not be able to write from after the buffer
75 eval { syswrite(O, $x, 1, 3) };
76 print 'not ' unless ($@ =~ /^Offset outside string /);
80 print 'not ' unless ($x eq 'abc');
83 # $outfile still intact
84 print 'not ' if (-s $outfile);
87 # should not be able to write from before the buffer
89 eval { syswrite(O, $x, 1, -4) };
90 print 'not ' unless ($@ =~ /^Offset outside string /);
94 print 'not ' unless ($x eq 'abc');
97 # $outfile still intact
98 print 'not ' if (-s $outfile);
102 print 'not ' unless (syswrite(O, $a, 2) == 2);
106 print 'not ' unless ($a eq "#!.\0\0erl");
109 # $outfile should have grown now
110 print 'not ' unless (-s $outfile == 2);
114 print 'not ' unless (syswrite(O, $a, 2, 5) == 2);
118 print 'not ' unless ($a eq "#!.\0\0erl");
121 # $outfile should have grown now
122 print 'not ' unless (-s $outfile == 4);
125 # with negative offset and a bit too much length
126 print 'not ' unless (syswrite(O, $a, 5, -3) == 3);
130 print 'not ' unless ($a eq "#!.\0\0erl");
133 # $outfile should have grown now
134 print 'not ' unless (-s $outfile == 7);
139 open(I, $outfile) || die "sysio.t: cannot read $outfile: $!";
143 # reading too much only return as much as available
144 print 'not ' unless (sysread(I, $b, 100) == 7);
146 # this we should have
147 print 'not ' unless ($b eq '#!ererl');