5 chdir('op') || chdir('t/op') || die "sysio.t: cannot look for myself: $!";
7 open(I, 'sysio.t') || die "sysio.t: cannot find myself: $!";
9 $reopen = ($^O eq 'VMS' ||
18 # should not be able to do negative lengths
19 eval { sysread(I, $x, -1) };
20 print 'not ' unless ($@ =~ /^Negative length /);
24 print 'not ' unless ($x eq 'abc');
27 # should not be able to read before the buffer
28 eval { sysread(I, $x, 1, -4) };
29 print 'not ' unless ($x eq 'abc');
33 print 'not ' unless ($x eq 'abc');
39 print 'not ' unless(sysread(I, $a, 3) == 3);
42 # $a should be as follows
43 print 'not ' unless ($a eq '#!.');
46 # reading past the buffer should zero pad
47 print 'not ' unless(sysread(I, $a, 2, 5) == 2);
50 # the zero pad should be seen now
51 print 'not ' unless ($a eq "#!.\0\0/p");
54 # try changing the last two characters of $a
55 print 'not ' unless(sysread(I, $a, 3, -2) == 3);
58 # the last two characters of $a should have changed (into three)
59 print 'not ' unless ($a eq "#!.\0\0erl");
62 $outfile = 'sysio.out';
64 open(O, ">$outfile") || die "sysio.t: cannot write $outfile: $!";
66 select(O); $|=1; select(STDOUT);
68 # cannot write negative lengths
69 eval { syswrite(O, $x, -1) };
70 print 'not ' unless ($@ =~ /^Negative length /);
74 print 'not ' unless ($x eq 'abc');
77 # $outfile still intact
78 print 'not ' if (-s $outfile);
81 # should not be able to write from after the buffer
82 eval { syswrite(O, $x, 1, 3) };
83 print 'not ' unless ($@ =~ /^Offset outside string /);
87 print 'not ' unless ($x eq 'abc');
90 # $outfile still intact
91 if ($reopen) { # must close file to update EOF marker for stat
92 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
94 print 'not ' if (-s $outfile);
97 # should not be able to write from before the buffer
99 eval { syswrite(O, $x, 1, -4) };
100 print 'not ' unless ($@ =~ /^Offset outside string /);
104 print 'not ' unless ($x eq 'abc');
107 # $outfile still intact
108 if ($reopen) { # must close file to update EOF marker for stat
109 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
111 print 'not ' if (-s $outfile);
115 if (syswrite(O, $a, 2) == 2){
118 print "# $!\nnot ok 20\n";
119 # most other tests make no sense after e.g. "No space left on device"
125 print 'not ' unless ($a eq "#!.\0\0erl");
128 # $outfile should have grown now
129 if ($reopen) { # must close file to update EOF marker for stat
130 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
132 print 'not ' unless (-s $outfile == 2);
136 print 'not ' unless (syswrite(O, $a, 2, 5) == 2);
140 print 'not ' unless ($a eq "#!.\0\0erl");
143 # $outfile should have grown now
144 if ($reopen) { # must close file to update EOF marker for stat
145 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
147 print 'not ' unless (-s $outfile == 4);
150 # with negative offset and a bit too much length
151 print 'not ' unless (syswrite(O, $a, 5, -3) == 3);
155 print 'not ' unless ($a eq "#!.\0\0erl");
158 # $outfile should have grown now
159 if ($reopen) { # must close file to update EOF marker for stat
160 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
162 print 'not ' unless (-s $outfile == 7);
165 # with implicit length argument
166 print 'not ' unless (syswrite(O, $x) == 3);
170 print 'not ' unless ($x eq "abc");
173 # $outfile should have grown now
174 if ($reopen) { # must close file to update EOF marker for stat
175 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
177 print 'not ' unless (-s $outfile == 10);
182 open(I, $outfile) || die "sysio.t: cannot read $outfile: $!";
186 # reading too much only return as much as available
187 print 'not ' unless (sysread(I, $b, 100) == 10);
189 # this we should have
190 print 'not ' unless ($b eq '#!ererlabc');
195 print 'not ' unless sysseek(I, 2, 0) == 2;
198 print 'not ' unless $b eq 'ere';
201 print 'not ' unless sysseek(I, -2, 1) == 3;
204 print 'not ' unless $b eq 'rerl';
207 print 'not ' unless sysseek(I, 0, 0) eq '0 but true';
209 print 'not ' if defined sysseek(I, -1, 1);