4 chdir('op') || chdir('t/op') || die "sysio.t: cannot look for myself: $!";
11 open(I, 'sysio.t') || die "sysio.t: cannot find myself: $!";
13 $reopen = ($^O eq 'VMS' ||
22 # should not be able to do negative lengths
23 eval { sysread(I, $x, -1) };
24 like($@, qr/^Negative length /);
29 # should not be able to read before the buffer
30 eval { sysread(I, $x, 1, -4) };
31 like($@, qr/^Offset outside string /);
39 is(sysread(I, $a, 3), 3);
41 # $a should be as follows
44 # reading past the buffer should zero pad
45 is(sysread(I, $a, 2, 5), 2);
47 # the zero pad should be seen now
50 # try changing the last two characters of $a
51 is(sysread(I, $a, 3, -2), 3);
53 # the last two characters of $a should have changed (into three)
56 $outfile = tempfile();
58 open(O, ">$outfile") || die "sysio.t: cannot write $outfile: $!";
60 select(O); $|=1; select(STDOUT);
62 # cannot write negative lengths
63 eval { syswrite(O, $x, -1) };
64 like($@, qr/^Negative length /);
69 # $outfile still intact
72 # should not be able to write from after the buffer
73 eval { syswrite(O, $x, 1, 3) };
74 like($@, qr/^Offset outside string /);
79 # $outfile still intact
80 if ($reopen) { # must close file to update EOF marker for stat
81 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
85 # should not be able to write from before the buffer
87 eval { syswrite(O, $x, 1, -4) };
88 like($@, qr/^Offset outside string /);
93 # $outfile still intact
94 if ($reopen) { # must close file to update EOF marker for stat
95 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
99 # [perl #67912] syswrite prints garbage if called with empty scalar and non-zero offset
100 eval { my $buf = ''; syswrite(O, $buf, 1, 0) };
101 like($@, qr/^Offset outside string /);
106 # $outfile still intact
107 if ($reopen) { # must close file to update EOF marker for stat
108 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
112 eval { my $buf = 'x'; syswrite(O, $buf, 1, 1) };
113 like($@, qr/^Offset outside string /);
118 # $outfile still intact
119 if ($reopen) { # must close file to update EOF marker for stat
120 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
125 if (syswrite(O, $a, 2) == 2){
130 # most other tests make no sense after e.g. "No space left on device"
136 is($a, "#!.\0\0erl");
138 # $outfile should have grown now
139 if ($reopen) { # must close file to update EOF marker for stat
140 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
145 is(syswrite(O, $a, 2, 5), 2);
148 is($a, "#!.\0\0erl");
150 # $outfile should have grown now
151 if ($reopen) { # must close file to update EOF marker for stat
152 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
156 # with negative offset and a bit too much length
157 is(syswrite(O, $a, 5, -3), 3);
160 is($a, "#!.\0\0erl");
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: $!";
168 # with implicit length argument
169 is(syswrite(O, $x), 3);
174 # $outfile should have grown now
175 if ($reopen) { # must close file to update EOF marker for stat
176 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
182 open(I, $outfile) || die "sysio.t: cannot read $outfile: $!";
186 # reading too much only return as much as available
187 is(sysread(I, $b, 100), 10);
189 # this we should have
190 is($b, '#!ererlabc');
194 is(sysseek(I, 2, 0), 2);
198 is(sysseek(I, -2, 1), 3);
202 ok(sysseek(I, 0, 0) eq '0 but true');
204 ok(not defined sysseek(I, -1, 1));
210 # Check that utf8 IO doesn't upgrade the scalar
211 open(I, ">$outfile") || die "sysio.t: cannot write $outfile: $!";
212 # Will skip harmlessly on stdioperl
213 eval {binmode STDOUT, ":utf8"};
214 die $@ if $@ and $@ !~ /^IO layers \(like ':utf8'\) unavailable/;
216 # y diaresis is \w when UTF8
223 # Should not be upgraded as a side effect of syswrite.
227 eval {syswrite I, 2;};