st_blocks is in 512 byte blocks.
[p5sagit/p5-mst-13.2.git] / t / op / sysio.t
index 94a29c1..22e60e3 100755 (executable)
@@ -1,11 +1,14 @@
 #!./perl
 
-print "1..30\n";
+print "1..39\n";
 
 chdir('op') || die "sysio.t: cannot look for myself: $!";
 
 open(I, 'sysio.t') || die "sysio.t: cannot find myself: $!";
 
+$reopen = ($^O eq 'VMS' || $^O eq 'os2' || $^O eq 'MSWin32' || $^O eq 'dos' ||
+          $^O eq 'mpeix');
+
 $x = 'abc';
 
 # should not be able to do negative lengths
@@ -81,6 +84,9 @@ print 'not ' unless ($x eq 'abc');
 print "ok 15\n";
 
 # $outfile still intact
+if ($reopen) {  # must close file to update EOF marker for stat
+  close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
+}
 print 'not ' if (-s $outfile);
 print "ok 16\n";
 
@@ -95,6 +101,9 @@ print 'not ' unless ($x eq 'abc');
 print "ok 18\n";
 
 # $outfile still intact
+if ($reopen) {  # must close file to update EOF marker for stat
+  close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
+}
 print 'not ' if (-s $outfile);
 print "ok 19\n";
 
@@ -107,6 +116,9 @@ print 'not ' unless ($a eq "#!.\0\0erl");
 print "ok 21\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 == 2);
 print "ok 22\n";
 
@@ -119,6 +131,9 @@ print 'not ' unless ($a eq "#!.\0\0erl");
 print "ok 24\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 == 4);
 print "ok 25\n";
 
@@ -131,9 +146,27 @@ print 'not ' unless ($a eq "#!.\0\0erl");
 print "ok 27\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 == 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: $!";
@@ -141,16 +174,37 @@ 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 34\n";
+sysread(I, $b, 3);
+print 'not ' unless $b eq 'ere';
+print "ok 35\n";
+
+print 'not ' unless sysseek(I, -2, 1) == 3;
+print "ok 36\n";
+sysread(I, $b, 4);
+print 'not ' unless $b eq 'rerl';
+print "ok 37\n";
+
+print 'not ' unless sysseek(I, 0, 0) eq '0 but true';
+print "ok 38\n";
+print 'not ' if defined sysseek(I, -1, 1);
+print "ok 39\n";
 
 close(I);
 
 unlink $outfile;
 
+chdir('..'); 
+
 1;
 
 # eof