]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Use native methods to open input in TestLib::slurp_file on Windows.
authorAndrew Dunstan <andrew@dunslane.net>
Tue, 15 Dec 2020 15:00:18 +0000 (10:00 -0500)
committerAndrew Dunstan <andrew@dunslane.net>
Tue, 15 Dec 2020 15:26:10 +0000 (10:26 -0500)
This is a backport of commits 114541d58e and 6f59826f0 to the remaining
live branches.

src/test/perl/TestLib.pm

index e5684c345237f484e97d53be236c63b988712c99..878369095db134b5a327f961b8a1f0214d062c0a 100644 (file)
@@ -70,6 +70,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
@@ -236,10 +241,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;
 }