diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2020-12-15 10:00:18 -0500 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2020-12-15 10:00:48 -0500 |
commit | bf88c6d6021c1abbc73197803c98dad0f033b462 (patch) | |
tree | acddf3270e1e7b502b72a990750e96cfeff00057 /src | |
parent | 706d84fe701ef9a8a5b04d2df013e29ea3f7ca74 (diff) | |
download | postgresql-bf88c6d6021c1abbc73197803c98dad0f033b462.tar.gz postgresql-bf88c6d6021c1abbc73197803c98dad0f033b462.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/test/perl/TestLib.pm | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm index 81e3252dcfb..4cb3c765d93 100644 --- a/src/test/perl/TestLib.pm +++ b/src/test/perl/TestLib.pm @@ -79,6 +79,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 @@ -256,10 +261,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; } |