Peta::FFI::Libc#
Call common libc functions from Perl without writing a single line of FFI glue.
Pre-baked libc bindings: each function here calls the C library directly, so there is no handle to open and no signature string to write. Reach for Peta::FFI when you need a function this module does not cover.
use Peta::FFI::Libc qw(getpid strlen strerror gethostname uname access R_OK);
print getpid() == $$ ? "getpid is \$\$\n" : "?\n";
print strlen("hello"), " ", strerror(2), "\n"; # 5 No such file or directory
my ($sys, $node) = uname();
print "$sys on $node\n" if gethostname() eq $node;
print access("/etc/passwd", R_OK) == 0 ? "readable\n" : "not readable: $!\n";
The functions keep C’s conventions: the ones that report success return 0 for it and -1 for failure, with $! set to the C errno. Nothing is exported by default; name what you want.
Function | Returns |
|---|---|
| the process id, the parent’s |
| the real user and group id |
| the effective user and group id |
| the length of |
| the system’s message for an error number |
| the value, or undef when unset |
| 0 / -1; |
| 0 / -1 |
| the absolute value, as an int / a long |
| seconds left unslept / 0 or -1 |
| the host name |
| (sysname, nodename, release, version, machine) |
| 0 / -1, |
| 0 / -1 |
| 0 / -1 |
| 0 / -1 |
| 0 / -1 |
| seconds since the epoch |
| processor time used, in |
Peta::FFI::Libc is pperl’s own module, version 0.2.0.