|
82 | 82 | if ($windows_os)
|
83 | 83 | {
|
84 | 84 | require Win32API::File;
|
85 |
| - Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle setFilePointer)); |
| 85 | + Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle)); |
86 | 86 | }
|
87 | 87 | }
|
88 | 88 |
|
@@ -234,33 +234,33 @@ sub slurp_file
|
234 | 234 | my ($filename, $offset) = @_;
|
235 | 235 | local $/;
|
236 | 236 | my $contents;
|
| 237 | + my $fh; |
| 238 | + |
| 239 | + # On windows open file using win32 APIs, to allow us to set the |
| 240 | + # FILE_SHARE_DELETE flag ("d" below), otherwise other accesses to the file |
| 241 | + # may fail. |
237 | 242 | if ($Config{osname} ne 'MSWin32')
|
238 | 243 | {
|
239 |
| - open(my $in, '<', $filename) |
| 244 | + open($fh, '<', $filename) |
240 | 245 | or die "could not read \"$filename\": $!";
|
241 |
| - if (defined($offset)) |
242 |
| - { |
243 |
| - seek($in, $offset, SEEK_SET) |
244 |
| - or die "could not seek \"$filename\": $!"; |
245 |
| - } |
246 |
| - $contents = <$in>; |
247 |
| - close $in; |
248 | 246 | }
|
249 | 247 | else
|
250 | 248 | {
|
251 | 249 | my $fHandle = createFile($filename, "r", "rwd")
|
252 | 250 | or die "could not open \"$filename\": $^E";
|
253 |
| - OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r') |
| 251 | + OsFHandleOpen($fh = IO::Handle->new(), $fHandle, 'r') |
254 | 252 | or die "could not read \"$filename\": $^E\n";
|
255 |
| - if (defined($offset)) |
256 |
| - { |
257 |
| - setFilePointer($fh, $offset, qw(FILE_BEGIN)) |
258 |
| - or die "could not seek \"$filename\": $^E\n"; |
259 |
| - } |
260 |
| - $contents = <$fh>; |
261 |
| - CloseHandle($fHandle) |
262 |
| - or die "could not close \"$filename\": $^E\n"; |
263 | 253 | }
|
| 254 | + |
| 255 | + if (defined($offset)) |
| 256 | + { |
| 257 | + seek($fh, $offset, SEEK_SET) |
| 258 | + or die "could not seek \"$filename\": $!"; |
| 259 | + } |
| 260 | + |
| 261 | + $contents = <$fh>; |
| 262 | + close $fh; |
| 263 | + |
264 | 264 | $contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
|
265 | 265 | return $contents;
|
266 | 266 | }
|
|
0 commit comments