On Thu, 28 Feb 2002, Rob Clark wrote:

> 
> 
> I have a C function that allocates a buffer and returns a pointer to it
> as follows:
>   
> int foo(char **buf, int *n , ...)
> 
> The function allocates a buffer and fills with data. Fills in the 
> pointer to it and its length before returning.
> 
> Can someone tell me or point me to a reference showing how to 
> wrap this with perlxs? I'm new to perlxs but can follow the perlxs 
> tutorials.
> 
> ok.
> 
> I'm flexible concerning what type of structure holds the data at the perl 
> end, as long as I can process it byte by byte.

>From perl or from C?

> int &len obviously works for the length but
> char * &buf   doesn't work as for the buffer as it contains zeros.

Actually, Perl scalars may contain arbitrary binary data.  Just be sure
that you don't use strlen() to describe the length <g>.  This should work 
just fine:


char *buf;
int n;
SV *my_sv;

foo( &buf, &n );

my_sv = newSVpv( buf, n );

(pass back the SV* somehow..)

-----

In Perl:

length $my_sv

will give you 'n', and you can operate on the string using substr().


Does this help?

Steve

Reply via email to