Use native methods to open input in TestLib::slurp_file on Windows.
This is a backport of commits 114541d58e and 6f59826f0 to the remaining live branches.
This commit is contained in:
parent
4ee058a3bd
commit
355f9d2452
@ -77,6 +77,11 @@ BEGIN
|
|||||||
|
|
||||||
# Must be set early
|
# Must be set early
|
||||||
$windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys';
|
$windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys';
|
||||||
|
if ($windows_os)
|
||||||
|
{
|
||||||
|
require Win32API::File;
|
||||||
|
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT
|
INIT
|
||||||
@ -250,10 +255,24 @@ sub slurp_file
|
|||||||
{
|
{
|
||||||
my ($filename) = @_;
|
my ($filename) = @_;
|
||||||
local $/;
|
local $/;
|
||||||
|
my $contents;
|
||||||
|
if ($Config{osname} ne 'MSWin32')
|
||||||
|
{
|
||||||
open(my $in, '<', $filename)
|
open(my $in, '<', $filename)
|
||||||
or die "could not read \"$filename\": $!";
|
or die "could not read \"$filename\": $!";
|
||||||
my $contents = <$in>;
|
$contents = <$in>;
|
||||||
close $in;
|
close $in;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
my $fHandle = createFile($filename, "r", "rwd")
|
||||||
|
or die "could not open \"$filename\": $^E";
|
||||||
|
OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r')
|
||||||
|
or die "could not read \"$filename\": $^E\n";
|
||||||
|
$contents = <$fh>;
|
||||||
|
CloseHandle($fHandle)
|
||||||
|
or die "could not close \"$filename\": $^E\n";
|
||||||
|
}
|
||||||
$contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
|
$contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
|
||||||
return $contents;
|
return $contents;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user