postgres.git / summary / log / commit / refs
commit b5eb07ed78a0e52b392c9b64e01e044a45c1fdb6
Author: Andrew Dunstan <andrew@dunslane.net>
Date: Tue Dec 15 15:00:18 2020 +0000
First released in: 9.5.25, 9.6.21, 10.16, 11.11, 12.6
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.
src/test/perl/TestLib.pm | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm
index 1cbe73f1705..8319727cf6e 100644
--- a/src/test/perl/TestLib.pm
+++ b/src/test/perl/TestLib.pm
@@ -63,6 +63,11 @@ BEGIN
# Must be set early
$windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys';
+ if ($windows_os)
+ {
+ require Win32API::File;
+ Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
+ }
}
INIT
@@ -212,10 +217,24 @@ sub slurp_file
{
my ($filename) = @_;
local $/;
- open(my $in, '<', $filename)
- or die "could not read \"$filename\": $!";
- my $contents = <$in>;
- close $in;
+ my $contents;
+ if ($Config{osname} ne 'MSWin32')
+ {
+ open(my $in, '<', $filename)
+ or die "could not read \"$filename\": $!";
+ $contents = <$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';
return $contents;
}
[parent: f10da1e9c970]