From: Gurusamy Sarathy Date: Sat, 22 Jan 2000 10:53:06 +0000 (+0000) Subject: truncate(FH) flushes FH before truncating it X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2f3b6ae408a2d23f3c90b00b9fbaa2ad4c9a755a;p=p5sagit%2Fp5-mst-13.2.git truncate(FH) flushes FH before truncating it p4raw-id: //depot/perl@4838 --- diff --git a/pp_sys.c b/pp_sys.c index ea34bae..df0fb42 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -1835,13 +1835,17 @@ PP(pp_truncate) tmpgv = gv_fetchpv(POPpx, FALSE, SVt_PVIO); do_ftruncate: TAINT_PROPER("truncate"); - if (!GvIO(tmpgv) || !IoIFP(GvIOp(tmpgv)) || + if (!GvIO(tmpgv) || !IoIFP(GvIOp(tmpgv))) + result = 0; + else { + PerlIO_flush(IoIFP(GvIOp(tmpgv))); #ifdef HAS_TRUNCATE - ftruncate(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), len) < 0) + if (ftruncate(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), len) < 0) #else - my_chsize(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), len) < 0) + if (my_chsize(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), len) < 0) #endif - result = 0; + result = 0; + } } else { SV *sv = POPs; diff --git a/t/io/fs.t b/t/io/fs.t index 72e9552..0bcf579 100755 --- a/t/io/fs.t +++ b/t/io/fs.t @@ -152,11 +152,12 @@ else { truncate "Iofs.tmp", 0; if (-z "Iofs.tmp") {print "ok 24\n"} else {print "not ok 24\n"} open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp"; + binmode FH; { select FH; $| = 1; select STDOUT } { use strict; - print FH "helloworld\n"; - truncate FH, 5; + print FH "x\n" x 200; + truncate(FH, 200) or die "Can't truncate FH: $!"; } if ($^O eq 'dos' # Not needed on HPFS, but needed on HPFS386 ?! @@ -164,7 +165,7 @@ else { { close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp"; } - if (-s "Iofs.tmp" == 5) {print "ok 25\n"} else {print "not ok 25\n"} + if (-s "Iofs.tmp" == 200) {print "ok 25\n"} else {print "not ok 25\n"} truncate FH, 0; if ($^O eq 'dos' # Not needed on HPFS, but needed on HPFS386 ?!