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