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' || $^O eq 'os2' || $^O eq 'MSWin32' || $^O eq 'dos' ||
14 # should not be able to do negative lengths
15 eval { sysread(I, $x, -1) };
16 print 'not ' unless ($@ =~ /^Negative length /);
20 print 'not ' unless ($x eq 'abc');
23 # should not be able to read before the buffer
24 eval { sysread(I, $x, 1, -4) };
25 print 'not ' unless ($x eq 'abc');
29 print 'not ' unless ($x eq 'abc');
35 print 'not ' unless(sysread(I, $a, 3) == 3);
38 # $a should be as follows
39 print 'not ' unless ($a eq '#!.');
42 # reading past the buffer should zero pad
43 print 'not ' unless(sysread(I, $a, 2, 5) == 2);
46 # the zero pad should be seen now
47 print 'not ' unless ($a eq "#!.\0\0/p");
50 # try changing the last two characters of $a
51 print 'not ' unless(sysread(I, $a, 3, -2) == 3);
54 # the last two characters of $a should have changed (into three)
55 print 'not ' unless ($a eq "#!.\0\0erl");
58 $outfile = 'sysio.out';
60 open(O, ">$outfile") || die "sysio.t: cannot write $outfile: $!";
62 select(O); $|=1; select(STDOUT);
64 # cannot write negative lengths
65 eval { syswrite(O, $x, -1) };
66 print 'not ' unless ($@ =~ /^Negative length /);
70 print 'not ' unless ($x eq 'abc');
73 # $outfile still intact
74 print 'not ' if (-s $outfile);
77 # should not be able to write from after the buffer
78 eval { syswrite(O, $x, 1, 3) };
79 print 'not ' unless ($@ =~ /^Offset outside string /);
83 print 'not ' unless ($x eq 'abc');
86 # $outfile still intact
87 if ($reopen) { # must close file to update EOF marker for stat
88 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
90 print 'not ' if (-s $outfile);
93 # should not be able to write from before the buffer
95 eval { syswrite(O, $x, 1, -4) };
96 print 'not ' unless ($@ =~ /^Offset outside string /);
100 print 'not ' unless ($x eq 'abc');
103 # $outfile still intact
104 if ($reopen) { # must close file to update EOF marker for stat
105 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
107 print 'not ' if (-s $outfile);
111 print 'not ' unless (syswrite(O, $a, 2) == 2);
115 print 'not ' unless ($a eq "#!.\0\0erl");
118 # $outfile should have grown now
119 if ($reopen) { # must close file to update EOF marker for stat
120 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
122 print 'not ' unless (-s $outfile == 2);
126 print 'not ' unless (syswrite(O, $a, 2, 5) == 2);
130 print 'not ' unless ($a eq "#!.\0\0erl");
133 # $outfile should have grown now
134 if ($reopen) { # must close file to update EOF marker for stat
135 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
137 print 'not ' unless (-s $outfile == 4);
140 # with negative offset and a bit too much length
141 print 'not ' unless (syswrite(O, $a, 5, -3) == 3);
145 print 'not ' unless ($a eq "#!.\0\0erl");
148 # $outfile should have grown now
149 if ($reopen) { # must close file to update EOF marker for stat
150 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
152 print 'not ' unless (-s $outfile == 7);
155 # with implicit length argument
156 print 'not ' unless (syswrite(O, $x) == 3);
160 print 'not ' unless ($x eq "abc");
163 # $outfile should have grown now
164 if ($reopen) { # must close file to update EOF marker for stat
165 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
167 print 'not ' unless (-s $outfile == 10);
172 open(I, $outfile) || die "sysio.t: cannot read $outfile: $!";
176 # reading too much only return as much as available
177 print 'not ' unless (sysread(I, $b, 100) == 10);
179 # this we should have
180 print 'not ' unless ($b eq '#!ererlabc');
185 print 'not ' unless sysseek(I, 2, 0) == 2;
188 print 'not ' unless $b eq 'ere';
191 print 'not ' unless sysseek(I, -2, 1) == 3;
194 print 'not ' unless $b eq 'rerl';
197 print 'not ' unless sysseek(I, 0, 0) eq '0 but true';
199 print 'not ' if defined sysseek(I, -1, 1);