New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strawberry Perl fails to truncate large file #14737
Comments
From ntysdd@gmail.comThe 64-bit Portable version of Strawberry Perl fail to `truncate' It should handle large file correctly, or it should be documented in |
From @tonycozOn Sun Jun 07 03:12:34 2015, ntysdd@gmail.com wrote:
How much larger? It seems to work truncating an 8GB file down to 6GB: C:\Users\tony>perl -e "$size = 0x200000000; open my $fh, '+<', 'testfile' or die C:\Users\tony>dir testfile Directory of C:\Users\tony 08/06/2015 11:19 AM 8,589,934,592 testfile C:\Users\tony>perl -e "$size = 0x180000000; open my $fh, '+<', 'testfile' or die C:\Users\tony>dir testfile Directory of C:\Users\tony 08/06/2015 11:19 AM 6,442,450,944 testfile Tony |
The RT System itself - Status changed from 'new' to 'open' |
From ntysdd@gmail.comSorry so late. 2015-06-08 9:20 GMT+08:00 Tony Cook via RT <perlbug-followup@perl.org>:
|
From @tonycozOn Mon Jun 08 04:58:25 2015, ntysdd@gmail.com wrote:
Thanks, now I can reproduce it. The PerlLIO_open() was failing due to MSVCRT failing to seek on The attached fixes it for me. Tony |
From @tonycoz0001-perl-125347-allow-truncate-to-work-on-large-files-on.patchFrom e48b3f83b9e08c0987b4486e07c511ee9ea3d229 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Tue, 9 Jun 2015 10:48:28 +1000
Subject: [PATCH] [perl #125347] allow truncate to work on large files on Win32
truncate($filename, $size) was using a simple PerlIO_open() to open
the file, which on Win32 defaults to a text mode open.
Unfortunately, on a text mode open(), MSVCRT attempts to seek to the
end of file using only 32-bit offsets, which fails.
For good measure, add in O_LARGEFILE if it's available, which may
prevent similar issues on other platforms.
Also, remove the erroneous SETERRNO() added by 375ed12a to the open
failure branch, PerlLIO_open() should already set errno on failure, so
we get sane error messages when the open fails.
---
pp_sys.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/pp_sys.c b/pp_sys.c
index 7c20f52..922b897 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2304,10 +2304,22 @@ PP(pp_truncate)
result = 0;
#else
{
- const int tmpfd = PerlLIO_open(name, O_RDWR);
+ int mode = O_RDWR;
+ int tmpfd = PerlLIO_open(name, O_RDWR);
+
+#if defined(USE_64_BIT_RAWIO) && defined(O_LARGEFILE)
+ mode |= O_LARGEFILE; /* Transparently largefiley. */
+#endif
+#ifdef O_BINARY
+ /* On open(), the Win32 CRT tries to seek around text
+ * files using 32-bit offsets, which causes the open()
+ * to fail on large files, so open in binary mode.
+ */
+ mode |= O_BINARY;
+#endif
+ tmpfd = PerlLIO_open(name, mode);
if (tmpfd < 0) {
- SETERRNO(EBADF,RMS_IFI);
result = 0;
} else {
if (my_chsize(tmpfd, len) < 0)
--
1.9.5.msysgit.0
|
From ntysdd@gmail.comWhy is the function PerlLIO_open called twice? 2015-06-09 8:51 GMT+08:00, Tony Cook via RT <perlbug-followup@perl.org>:
|
From @tonycozOn Tue, Jun 09, 2015 at 06:42:55PM +0800, ntysdd wrote:
Sigh, you're right. I remember typing that correctly, but I guess it was in the wrong Tony |
@tonycoz - Status changed from 'open' to 'pending release' |
From @khwilliamsonThank you for submitting this report. You have helped make Perl better. Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0 |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#125347 (status was 'resolved')
Searchable as RT125347$
The text was updated successfully, but these errors were encountered: