summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp_sys.c12
-rwxr-xr-xt/io/fs.t7
2 files changed, 12 insertions, 7 deletions
diff --git a/pp_sys.c b/pp_sys.c
index ea34bae31e..df0fb42ff1 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 72e9552037..0bcf579162 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 ?!