5 chdir('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');
13 # should not be able to do negative lengths
14 eval { sysread(I, $x, -1) };
15 print 'not ' unless ($@ =~ /^Negative length /);
19 print 'not ' unless ($x eq 'abc');
22 # should not be able to read before the buffer
23 eval { sysread(I, $x, 1, -4) };
24 print 'not ' unless ($x eq 'abc');
28 print 'not ' unless ($x eq 'abc');
34 print 'not ' unless(sysread(I, $a, 3) == 3);
37 # $a should be as follows
38 print 'not ' unless ($a eq '#!.');
41 # reading past the buffer should zero pad
42 print 'not ' unless(sysread(I, $a, 2, 5) == 2);
45 # the zero pad should be seen now
46 print 'not ' unless ($a eq "#!.\0\0/p");
49 # try changing the last two characters of $a
50 print 'not ' unless(sysread(I, $a, 3, -2) == 3);
53 # the last two characters of $a should have changed (into three)
54 print 'not ' unless ($a eq "#!.\0\0erl");
57 $outfile = 'sysio.out';
59 open(O, ">$outfile") || die "sysio.t: cannot write $outfile: $!";
61 select(O); $|=1; select(STDOUT);
63 # cannot write negative lengths
64 eval { syswrite(O, $x, -1) };
65 print 'not ' unless ($@ =~ /^Negative length /);
69 print 'not ' unless ($x eq 'abc');
72 # $outfile still intact
73 print 'not ' if (-s $outfile);
76 # should not be able to write from after the buffer
77 eval { syswrite(O, $x, 1, 3) };
78 print 'not ' unless ($@ =~ /^Offset outside string /);
82 print 'not ' unless ($x eq 'abc');
85 # $outfile still intact
86 if ($reopen) { # must close file to update EOF marker for stat
87 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
89 print 'not ' if (-s $outfile);
92 # should not be able to write from before the buffer
94 eval { syswrite(O, $x, 1, -4) };
95 print 'not ' unless ($@ =~ /^Offset outside string /);
99 print 'not ' unless ($x eq 'abc');
102 # $outfile still intact
103 if ($reopen) { # must close file to update EOF marker for stat
104 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
106 print 'not ' if (-s $outfile);
110 print 'not ' unless (syswrite(O, $a, 2) == 2);
114 print 'not ' unless ($a eq "#!.\0\0erl");
117 # $outfile should have grown now
118 if ($reopen) { # must close file to update EOF marker for stat
119 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
121 print 'not ' unless (-s $outfile == 2);
125 print 'not ' unless (syswrite(O, $a, 2, 5) == 2);
129 print 'not ' unless ($a eq "#!.\0\0erl");
132 # $outfile should have grown now
133 if ($reopen) { # must close file to update EOF marker for stat
134 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
136 print 'not ' unless (-s $outfile == 4);
139 # with negative offset and a bit too much length
140 print 'not ' unless (syswrite(O, $a, 5, -3) == 3);
144 print 'not ' unless ($a eq "#!.\0\0erl");
147 # $outfile should have grown now
148 if ($reopen) { # must close file to update EOF marker for stat
149 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
151 print 'not ' unless (-s $outfile == 7);
154 # with implicit length argument
155 print 'not ' unless (syswrite(O, $x) == 3);
159 print 'not ' unless ($x eq "abc");
162 # $outfile should have grown now
163 if ($reopen) { # must close file to update EOF marker for stat
164 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
166 print 'not ' unless (-s $outfile == 10);
171 open(I, $outfile) || die "sysio.t: cannot read $outfile: $!";
175 # reading too much only return as much as available
176 print 'not ' unless (sysread(I, $b, 100) == 10);
178 # this we should have
179 print 'not ' unless ($b eq '#!ererlabc');
184 print 'not ' unless sysseek(I, 2, 0) == 2;
187 print 'not ' unless $b eq 'ere';
190 print 'not ' unless sysseek(I, -2, 1) == 3;
193 print 'not ' unless $b eq 'rerl';
196 print 'not ' unless sysseek(I, 0, 0) eq '0 but true';
198 print 'not ' if defined sysseek(I, -1, 1);