From: Gisle Aas Date: Sun, 11 Oct 1998 12:53:13 +0000 (+0200) Subject: applied suggested patch with small doc tweak X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=145d37e29b0763362cc1b261774de4506a62c161;p=p5sagit%2Fp5-mst-13.2.git applied suggested patch with small doc tweak Message-ID: Subject: Re: [PATCH 5.005_52] Optional syswrite LENGTH argument p4raw-id: //depot/perl@1992 --- diff --git a/opcode.h b/opcode.h index 37b0516..2abaa47 100644 --- a/opcode.h +++ b/opcode.h @@ -2385,7 +2385,7 @@ EXT U32 opargs[] = { 0x09116504, /* sysopen */ 0x00116504, /* sysseek */ 0x0917651d, /* sysread */ - 0x0911651d, /* syswrite */ + 0x0991651d, /* syswrite */ 0x0911651d, /* send */ 0x0117651d, /* recv */ 0x0000ec14, /* eof */ diff --git a/opcode.pl b/opcode.pl index f9c7503..92330a6 100755 --- a/opcode.pl +++ b/opcode.pl @@ -519,7 +519,7 @@ print print ck_listiob ims@ F? L 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 diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 92a9532..c23aa14 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -3988,8 +3988,11 @@ See L and L for details. =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, C, C, C, or C may cause confusion because stdio usually buffers data. Returns the number of bytes actually written, or C diff --git a/pp_sys.c b/pp_sys.c index 7fa4de2..b613ca8 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -1467,6 +1467,13 @@ PP(pp_sysread) 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); } diff --git a/t/op/sysio.t b/t/op/sysio.t index 826cf38..0318fed 100755 --- a/t/op/sysio.t +++ b/t/op/sysio.t @@ -1,6 +1,6 @@ #!./perl -print "1..36\n"; +print "1..39\n"; chdir('op') || die "sysio.t: cannot look for myself: $!"; @@ -151,6 +151,21 @@ if ($reopen) { # must close file to update EOF marker for stat 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: $!"; @@ -158,30 +173,30 @@ 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); diff --git a/t/op/tiehandle.t b/t/op/tiehandle.t index e3d2472..d7e6a78 100755 --- a/t/op/tiehandle.t +++ b/t/op/tiehandle.t @@ -64,7 +64,7 @@ sub READ { sub WRITE { compare(WRITE => @_); $data = substr($_[1],$_[3] || 0, $_[2]); - 4; + length($data); } sub CLOSE { @@ -77,7 +77,7 @@ package main; use Symbol; -print "1..23\n"; +print "1..29\n"; my $fh = gensym; @@ -132,6 +132,20 @@ $r = syswrite $fh,$buf,4,1; 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);