11 open(I, 'op/sysio.t') || die "sysio.t: cannot find myself: $!";
13 $reopen = ($^O eq 'VMS' ||
21 # should not be able to do negative lengths
22 eval { sysread(I, $x, -1) };
23 like($@, qr/^Negative length /);
28 # should not be able to read before the buffer
29 eval { sysread(I, $x, 1, -4) };
30 like($@, qr/^Offset outside string /);
38 is(sysread(I, $a, 3), 3);
40 # $a should be as follows
43 # reading past the buffer should zero pad
44 is(sysread(I, $a, 2, 5), 2);
46 # the zero pad should be seen now
49 # try changing the last two characters of $a
50 is(sysread(I, $a, 3, -2), 3);
52 # the last two characters of $a should have changed (into three)
55 $outfile = tempfile();
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 like($@, qr/^Negative length /);
68 # $outfile still intact
71 # should not be able to write from after the buffer
72 eval { syswrite(O, $x, 1, 4) };
73 like($@, qr/^Offset outside string /);
78 # but it should be ok to write from the end of the buffer
79 syswrite(O, $x, 0, 3);
80 syswrite(O, $x, 1, 3);
82 # $outfile still intact
83 if ($reopen) { # must close file to update EOF marker for stat
84 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
88 # should not be able to write from before the buffer
90 eval { syswrite(O, $x, 1, -4) };
91 like($@, qr/^Offset outside string /);
96 # $outfile still intact
97 if ($reopen) { # must close file to update EOF marker for stat
98 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
102 # [perl #67912] syswrite prints garbage if called with empty scalar and non-zero offset
103 eval { my $buf = ''; syswrite(O, $buf, 1, 1) };
104 like($@, qr/^Offset outside string /);
109 # $outfile still intact
110 if ($reopen) { # must close file to update EOF marker for stat
111 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
115 eval { my $buf = 'x'; syswrite(O, $buf, 1, 2) };
116 like($@, qr/^Offset outside string /);
121 # $outfile still intact
122 if ($reopen) { # must close file to update EOF marker for stat
123 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
128 if (syswrite(O, $a, 2) == 2){
133 # most other tests make no sense after e.g. "No space left on device"
139 is($a, "#!.\0\0erl");
141 # $outfile should have grown now
142 if ($reopen) { # must close file to update EOF marker for stat
143 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
148 is(syswrite(O, $a, 2, 5), 2);
151 is($a, "#!.\0\0erl");
153 # $outfile should have grown now
154 if ($reopen) { # must close file to update EOF marker for stat
155 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
159 # with negative offset and a bit too much length
160 is(syswrite(O, $a, 5, -3), 3);
163 is($a, "#!.\0\0erl");
165 # $outfile should have grown now
166 if ($reopen) { # must close file to update EOF marker for stat
167 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
171 # with implicit length argument
172 is(syswrite(O, $x), 3);
177 # $outfile should have grown now
178 if ($reopen) { # must close file to update EOF marker for stat
179 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
185 open(I, $outfile) || die "sysio.t: cannot read $outfile: $!";
189 # reading too much only return as much as available
190 is(sysread(I, $b, 100), 10);
192 # this we should have
193 is($b, '#!ererlabc');
197 is(sysseek(I, 2, 0), 2);
201 is(sysseek(I, -2, 1), 3);
205 ok(sysseek(I, 0, 0) eq '0 but true');
207 ok(not defined sysseek(I, -1, 1));
213 # Check that utf8 IO doesn't upgrade the scalar
214 open(I, ">$outfile") || die "sysio.t: cannot write $outfile: $!";
215 # Will skip harmlessly on stdioperl
216 eval {binmode STDOUT, ":utf8"};
217 die $@ if $@ and $@ !~ /^IO layers \(like ':utf8'\) unavailable/;
219 # y diaresis is \w when UTF8
226 # Should not be upgraded as a side effect of syswrite.
230 eval {syswrite I, 2;};