in reply to Re^2: 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?

Three notes.

So here's what we have in C-ish Perl:

use Fcntl qw( O_APPEND O_RDONLY O_WRONLY O_RDWR O_ACCMODE ); sub file_mode_from_c { my ($c_mode) = @_; $c_mode &= O_ACCMODE | O_APPEND; my $p_mode; if ( $c_mode == O_RDONLY ) { $p_mode = '<'; } elsif ( $c_mode == O_WRONLY ) { $p_mode = '>'; } elsif ( $c_mode == (O_WRONLY|O_APPEND) ) { $p_mode = '>>'; } elsif ( $c_mode == O_RDWR ) { $p_mode = '+>'; } elsif ( $c_mode == (O_RDWR|O_APPEND) ) { $p_mode = '+>>'; } return $p_mode; } my $p_mode = file_mode_from_c($c_mode) or die("..."); open(my $fh, "$p_mode=", $fd) or die("...: $!");

So again, all you need to know is how to call open. I don't know the XS equivalent of open though. (Upd: Looks like PerlIO *PerlIO_fdopen(int fd, const char *mode);, thanks to Anonymous Monk's link to perlapio )