in reply to Re: How to convert a file descriptor plus access mode bits into a perl filehandle?
in thread How to convert a file descriptor plus access mode bits into a perl filehandle?
How about the equivalent XS?sub open_fd { my ($fd, $flags)=@_; use Fcntl qw/O_APPEND O_RDONLY O_WRONLY O_RDWR O_ACCMODE/; use POSIX (); use IO::Handle (); if( ($flags & O_ACCMODE) == O_RDONLY ) { $flags='<'; } elsif( ($flags & O_ACCMODE) == O_WRONLY ) { if( $flags & O_APPEND ) { $flags='>>'; } else { $flags='>'; } } elsif( ($flags & O_ACCMODE) == O_RDWR ) { if( $flags & O_APPEND ) { $flags='+>>'; } else { $flags='+>'; } } else { POSIX::close($fd); return undef; } return IO::Handle->new_from_fd($fd, $flags); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How to convert a file descriptor plus access mode bits into a perl filehandle?
by ikegami (Patriarch) on Sep 10, 2008 at 22:52 UTC |