Last active
October 4, 2015 00:58
-
-
Save ghedo/2550183 to your computer and use it in GitHub Desktop.
FFI::Raw and stdio's FILE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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