0x09116504, /* sysopen */
0x00116504, /* sysseek */
0x0917651d, /* sysread */
- 0x0911651d, /* syswrite */
+ 0x0991651d, /* syswrite */
0x0911651d, /* send */
0x0117651d, /* recv */
0x0000ec14, /* eof */
sysopen sysopen ck_fun s@ F S S S?
sysseek sysseek ck_fun s@ F S S
sysread sysread ck_fun imst@ F R S S?
-syswrite syswrite ck_fun imst@ F S S S?
+syswrite syswrite ck_fun imst@ F S S? S?
send send ck_fun imst@ F S S S?
recv recv ck_fun imst@ F R S S
=item syswrite FILEHANDLE,SCALAR,LENGTH
+=item syswrite FILEHANDLE,SCALAR
+
Attempts to write LENGTH bytes of data from variable SCALAR to the
-specified FILEHANDLE, using the system call write(2). It bypasses
+specified FILEHANDLE, using the system call write(2). If LENGTH is
+not specified, writes whole SCALAR. It bypasses
stdio, so mixing this with reads (other than C<sysread())>, C<print()>,
C<write()>, C<seek()>, or C<tell()> may cause confusion because stdio usually
buffers data. Returns the number of bytes actually written, or C<undef>
PP(pp_syswrite)
{
+ djSP;
+ int items = (SP - PL_stack_base) - TOPMARK;
+ if (items == 2) {
+ EXTEND(SP, 1);
+ PUSHs(sv_2mortal(newSViv(sv_len(*SP))));
+ PUTBACK;
+ }
return pp_send(ARGS);
}
#!./perl
-print "1..36\n";
+print "1..39\n";
chdir('op') || die "sysio.t: cannot look for myself: $!";
print 'not ' unless (-s $outfile == 7);
print "ok 28\n";
+# with implicit length argument
+print 'not ' unless (syswrite(O, $x) == 3);
+print "ok 29\n";
+
+# $a still intact
+print 'not ' unless ($x eq "abc");
+print "ok 30\n";
+
+# $outfile should have grown now
+if ($reopen) { # must close file to update EOF marker for stat
+ close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
+}
+print 'not ' unless (-s $outfile == 10);
+print "ok 31\n";
+
close(O);
open(I, $outfile) || die "sysio.t: cannot read $outfile: $!";
$b = 'xyz';
# reading too much only return as much as available
-print 'not ' unless (sysread(I, $b, 100) == 7);
-print "ok 29\n";
+print 'not ' unless (sysread(I, $b, 100) == 10);
+print "ok 32\n";
# this we should have
-print 'not ' unless ($b eq '#!ererl');
-print "ok 30\n";
+print 'not ' unless ($b eq '#!ererlabc');
+print "ok 33\n";
# test sysseek
print 'not ' unless sysseek(I, 2, 0) == 2;
-print "ok 31\n";
+print "ok 34\n";
sysread(I, $b, 3);
print 'not ' unless $b eq 'ere';
-print "ok 32\n";
+print "ok 35\n";
print 'not ' unless sysseek(I, -2, 1) == 3;
-print "ok 33\n";
+print "ok 36\n";
sysread(I, $b, 4);
print 'not ' unless $b eq 'rerl';
-print "ok 34\n";
+print "ok 37\n";
print 'not ' unless sysseek(I, 0, 0) eq '0 but true';
-print "ok 35\n";
+print "ok 38\n";
print 'not ' if defined sysseek(I, -1, 1);
-print "ok 36\n";
+print "ok 39\n";
close(I);
sub WRITE {
compare(WRITE => @_);
$data = substr($_[1],$_[3] || 0, $_[2]);
- 4;
+ length($data);
}
sub CLOSE {
use Symbol;
-print "1..23\n";
+print "1..29\n";
my $fh = gensym;
ok($r == 4);
ok($data eq "wert");
+$buf = "qwerty";
+@expect = (WRITE => $ob, $buf, 4);
+$data = "";
+$r = syswrite $fh,$buf,4;
+ok($r == 4);
+ok($data eq "qwer");
+
+$buf = "qwerty";
+@expect = (WRITE => $ob, $buf, 6);
+$data = "";
+$r = syswrite $fh,$buf;
+ok($r == 6);
+ok($data eq "qwerty");
+
@expect = (CLOSE => $ob);
$r = close $fh;
ok($r == 5);