|
90 | 90 | if ($windows_os)
|
91 | 91 | {
|
92 | 92 | require Win32API::File;
|
93 |
| - Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle setFilePointer)); |
| 93 | + Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle)); |
94 | 94 | }
|
95 | 95 | }
|
96 | 96 |
|
@@ -259,33 +259,33 @@ sub slurp_file
|
259 | 259 | my ($filename, $offset) = @_;
|
260 | 260 | local $/;
|
261 | 261 | my $contents;
|
| 262 | + my $fh; |
| 263 | + |
| 264 | + # On windows open file using win32 APIs, to allow us to set the |
| 265 | + # FILE_SHARE_DELETE flag ("d" below), otherwise other accesses to the file |
| 266 | + # may fail. |
262 | 267 | if ($Config{osname} ne 'MSWin32')
|
263 | 268 | {
|
264 |
| - open(my $in, '<', $filename) |
| 269 | + open($fh, '<', $filename) |
265 | 270 | or die "could not read \"$filename\": $!";
|
266 |
| - if (defined($offset)) |
267 |
| - { |
268 |
| - seek($in, $offset, SEEK_SET) |
269 |
| - or die "could not seek \"$filename\": $!"; |
270 |
| - } |
271 |
| - $contents = <$in>; |
272 |
| - close $in; |
273 | 271 | }
|
274 | 272 | else
|
275 | 273 | {
|
276 | 274 | my $fHandle = createFile($filename, "r", "rwd")
|
277 | 275 | or die "could not open \"$filename\": $^E";
|
278 |
| - OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r') |
| 276 | + OsFHandleOpen($fh = IO::Handle->new(), $fHandle, 'r') |
279 | 277 | or die "could not read \"$filename\": $^E\n";
|
280 |
| - if (defined($offset)) |
281 |
| - { |
282 |
| - setFilePointer($fh, $offset, qw(FILE_BEGIN)) |
283 |
| - or die "could not seek \"$filename\": $^E\n"; |
284 |
| - } |
285 |
| - $contents = <$fh>; |
286 |
| - CloseHandle($fHandle) |
287 |
| - or die "could not close \"$filename\": $^E\n"; |
288 | 278 | }
|
| 279 | + |
| 280 | + if (defined($offset)) |
| 281 | + { |
| 282 | + seek($fh, $offset, SEEK_SET) |
| 283 | + or die "could not seek \"$filename\": $!"; |
| 284 | + } |
| 285 | + |
| 286 | + $contents = <$fh>; |
| 287 | + close $fh; |
| 288 | + |
289 | 289 | $contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
|
290 | 290 | return $contents;
|
291 | 291 | }
|
|
0 commit comments