From ee60ee4132a0a69518f1b774d4ee1ce7fc12d665 Mon Sep 17 00:00:00 2001 From: Chris Fields Date: Mon, 1 Aug 2016 23:17:21 -0500 Subject: [PATCH] possible fix for #187 --- Bio/Root/IO.pm | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Bio/Root/IO.pm b/Bio/Root/IO.pm index df680786c..541a8ed1b 100644 --- a/Bio/Root/IO.pm +++ b/Bio/Root/IO.pm @@ -7,6 +7,9 @@ use File::Copy; use Fcntl; use base qw(Bio::Root::Root); +# as of 2016, worked on most systems, but will test this in a RC +my %modes = ( 0 => 'r', 1 => 'w', 2 => 'rw' ); + =head1 SYNOPSIS # Use stream I/O in your module @@ -350,16 +353,22 @@ sub mode { my $mode; my $fh = $self->_fh; if (defined $fh) { - # Determine read/write status of filehandle - no warnings 'io'; - if ( defined( read $fh, my $content, 0 ) ) { - # Successfully read 0 bytes - $mode = 'r' - } - if ( defined( syswrite $fh, '') ) { - # Successfully wrote 0 bytes - $mode ||= ''; - $mode .= 'w'; + # use fcntl if not Windows-based + if ($^O !~ /MSWin32/) { + my $m = fcntl($fh, F_GETFL, 0); + $mode = exists $modes{$m & 3} ? $modes{$m & 3} : '?'; + } else { + # Determine read/write status of filehandle + no warnings 'io'; + if ( defined( read $fh, my $content, 0 ) ) { + # Successfully read 0 bytes + $mode = 'r' + } + if ( defined( syswrite $fh, '') ) { + # Successfully wrote 0 bytes + $mode ||= ''; + $mode .= 'w'; + } } } else { # Stream does not have a filehandle... cannot determine mode -- 2.11.4.GIT