|
99 | 99 | if ($windows_os)
|
100 | 100 | {
|
101 | 101 | require Win32API::File;
|
102 |
| - Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle setFilePointer)); |
| 102 | + Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle)); |
103 | 103 | }
|
104 | 104 | }
|
105 | 105 |
|
@@ -280,33 +280,33 @@ sub slurp_file
|
280 | 280 | my ($filename, $offset) = @_;
|
281 | 281 | local $/;
|
282 | 282 | my $contents;
|
| 283 | + my $fh; |
| 284 | + |
| 285 | + # On windows open file using win32 APIs, to allow us to set the |
| 286 | + # FILE_SHARE_DELETE flag ("d" below), otherwise other accesses to the file |
| 287 | + # may fail. |
283 | 288 | if ($Config{osname} ne 'MSWin32')
|
284 | 289 | {
|
285 |
| - open(my $in, '<', $filename) |
| 290 | + open($fh, '<', $filename) |
286 | 291 | or die "could not read \"$filename\": $!";
|
287 |
| - if (defined($offset)) |
288 |
| - { |
289 |
| - seek($in, $offset, SEEK_SET) |
290 |
| - or die "could not seek \"$filename\": $!"; |
291 |
| - } |
292 |
| - $contents = <$in>; |
293 |
| - close $in; |
294 | 292 | }
|
295 | 293 | else
|
296 | 294 | {
|
297 | 295 | my $fHandle = createFile($filename, "r", "rwd")
|
298 | 296 | or die "could not open \"$filename\": $^E";
|
299 |
| - OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r') |
| 297 | + OsFHandleOpen($fh = IO::Handle->new(), $fHandle, 'r') |
300 | 298 | or die "could not read \"$filename\": $^E\n";
|
301 |
| - if (defined($offset)) |
302 |
| - { |
303 |
| - setFilePointer($fh, $offset, qw(FILE_BEGIN)) |
304 |
| - or die "could not seek \"$filename\": $^E\n"; |
305 |
| - } |
306 |
| - $contents = <$fh>; |
307 |
| - CloseHandle($fHandle) |
308 |
| - or die "could not close \"$filename\": $^E\n"; |
309 | 299 | }
|
| 300 | + |
| 301 | + if (defined($offset)) |
| 302 | + { |
| 303 | + seek($fh, $offset, SEEK_SET) |
| 304 | + or die "could not seek \"$filename\": $!"; |
| 305 | + } |
| 306 | + |
| 307 | + $contents = <$fh>; |
| 308 | + close $fh; |
| 309 | + |
310 | 310 | $contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
|
311 | 311 | return $contents;
|
312 | 312 | }
|
|
0 commit comments