I want to pass a Perl array as an argument to an xsub subroutine. The xsub will then pass it on to a C library function that expects int xyz[]. How do I code the xsub?
If you need a more concrete example, what I'm trying to do is make a Perl version of setgroups(), which is int setgroups(size_t size, const gid_t *list) in C.
I can't find any documentation other than overview of the xsub interface and typemap file.
int
setgroups(...)
PREINIT:
int i;
gid_t *glist;
CODE:
if( items > 0 ) {
glist = (gid_t *)malloc(items * sizeof(gid_t));
for (i = 0; i < items; i++)
glist[i] = SvIV(ST(i));
RETVAL = setgroups( items, glist );
free (glist);
}
OUTPUT:
RETVAL
--------------------------
- Sapa