Given that the bug report suggests only the is_W() function is used from FileHandle::Fmode I don't see why you can't replace the entire dependency with this short sub:
sub is_W { my $fh = shift; return 0 unless defined $fh; return 0 unless defined fileno $fh; local $\ = ''; # just in case no warnings; # temporarily disable warnings #my ($atime,$mtime) = (stat($fh))[8,9]; my $is_w = print $fh ''; #eval{ utime $atime, $mtime, $fh }; # can fail if futimes not avai +lable return $is_w; } my $file = "C:/tmp.txt"; printf "Null fh %d\n", is_W(); open F, ">", $file or die "Can't create $file $!\n"; printf "Writable fh %d\n", is_W(*F); close F; open F, $file or die "Can't create $file $!\n"; printf "Readable fh %d\n", is_W(*F); close F; printf "STDIN %d\n", is_W(*STDIN); printf "STDOUT %d\n", is_W(*STDOUT); printf "STDERR %d\n", is_W(*STDERR); __DATA__ Null fh 0 Writable fh 1 Readable fh 0 STDIN 0 STDOUT 1 STDERR 1
Update added "no warnings;" as per barts suggestion. Added comments containing mtime restoration code (if desired) also per bart.
In reply to Re: Test for writable filehandles on win32
by tachyon-II
in thread Test for writable filehandles on win32
by tsee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |