Skip to content

Instantly share code, notes, and snippets.

@ghedo
Last active Oct 4, 2015
Embed
What would you like to do?
FFI::Raw and stdio's FILE
#!/usr/bin/perl
use strict;
use warnings;
use FFI::Raw;
use IO::Handle;
my $fopen = FFI::Raw -> new(
'libc.so.6', 'fopen',
FFI::Raw::ptr,
FFI::Raw::str, FFI::Raw::str
);
my $fileno = FFI::Raw -> new(
'libc.so.6', 'fileno',
FFI::Raw::int,
FFI::Raw::ptr
);
my $io = IO::Handle -> new;
my $file = $fopen -> call('file.txt', 'w+');
# $file now is a FILE pointer
$io -> fdopen($fileno -> call($file), 'w');
$io -> print("Some text\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment