Skip to content

Commit 355f9d2

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 4ee058a commit 355f9d2

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
@@ -77,6 +77,11 @@ BEGIN
7777

7878
# Must be set early
7979
$windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys';
80+
if ($windows_os)
81+
{
82+
require Win32API::File;
83+
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
84+
}
8085
}
8186

8287
INIT
@@ -250,10 +255,24 @@ sub slurp_file
250255
{
251256
my ($filename) = @_;
252257
local $/;
253-
open(my $in, '<', $filename)
254-
or die "could not read \"$filename\": $!";
255-
my $contents = <$in>;
256-
close $in;
258+
my $contents;
259+
if ($Config{osname} ne 'MSWin32')
260+
{
261+
open(my $in, '<', $filename)
262+
or die "could not read \"$filename\": $!";
263+
$contents = <$in>;
264+
close $in;
265+
}
266+
else
267+
{
268+
my $fHandle = createFile($filename, "r", "rwd")
269+
or die "could not open \"$filename\": $^E";
270+
OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r')
271+
or die "could not read \"$filename\": $^E\n";
272+
$contents = <$fh>;
273+
CloseHandle($fHandle)
274+
or die "could not close \"$filename\": $^E\n";
275+
}
257276
$contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
258277
return $contents;
259278
}

0 commit comments

Comments
 (0)