Why do you think you need the source code to the getpagesize
function? You just link to the system's version. I haven't tried it, but something like this should work:
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <unistd.h> /* man 2 getpagesize says to use this */
MODULE = Sys::Getpagesize PACKAGE = Sys::Getpagesize
int
getpagesize()
But in this case, you shouldn't need to write XS at all. man 2 getpagesize
says "Portable applications should employ sysconf(_SC_PAGESIZE)
instead of getpagesize()
."
Perl's standard POSIX module has sysconf
already:
use POSIX qw(sysconf _SC_PAGESIZE);
print sysconf( _SC_PAGESIZE );