Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bf88c6d

Browse files
committed
Use native methods to open input in TestLib::slurp_file on Windows.
This is a backport of commits 114541d and 6f59826f0 to the remaining live branches.
1 parent 706d84f commit bf88c6d

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/test/perl/TestLib.pm

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ BEGIN
7979

8080
# Must be set early
8181
$windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys';
82+
if ($windows_os)
83+
{
84+
require Win32API::File;
85+
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
86+
}
8287
}
8388

8489
INIT
@@ -256,10 +261,24 @@ sub slurp_file
256261
{
257262
my ($filename) = @_;
258263
local $/;
259-
open(my $in, '<', $filename)
260-
or die "could not read \"$filename\": $!";
261-
my $contents = <$in>;
262-
close $in;
264+
my $contents;
265+
if ($Config{osname} ne 'MSWin32')
266+
{
267+
open(my $in, '<', $filename)
268+
or die "could not read \"$filename\": $!";
269+
$contents = <$in>;
270+
close $in;
271+
}
272+
else
273+
{
274+
my $fHandle = createFile($filename, "r", "rwd")
275+
or die "could not open \"$filename\": $^E";
276+
OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r')
277+
or die "could not read \"$filename\": $^E\n";
278+
$contents = <$fh>;
279+
CloseHandle($fHandle)
280+
or die "could not close \"$filename\": $^E\n";
281+
}
263282
$contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
264283
return $contents;
265284
}

0 commit comments

Comments
 (0)