> -----Original Message-----
> From: Alexandru Palade [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, July 12, 2005 6:14 AM
> To: [email protected]
> Subject: Re: accesing the C-space stdout
>
> I've tried passing a string from Perl to a
> C-function and sprintf'ing to that string, and I saw that you
> can only have as much space as you have "allocated"
> from Perl.
Right, because sprintf() is the plain-old C sprintf(), so all the
documentation in its man page applies. For that reason (as well as that
it doesn't deal well with binary or wide characters), I wouldn't use
sprintf() if I were you.
Note this piece of wise advice from the "perlclib" man page (with which
it's well worth your while to get familiar):
Most of the time, though, you'll want to be dealing
with SVs internally instead of raw "char *" strings:
Instead Of: Use:
strlen(s) sv_len(sv)
strcpy(dt, src) sv_setpv(sv, s)
strncpy(dt, src, n) sv_setpvn(sv, s, n)
strcat(dt, src) sv_catpv(sv, s)
strncat(dt, src) sv_catpvn(sv, s)
sprintf(s, fmt, ...) sv_setpvf(sv, fmt, ...)
Note also the existence of "sv_catpvf" and "sv_vcatpvfn",
combining
concatenation with formatting.
> I can't
> determine how long the string will be, before I print to it,
> since it's a recursive function that keeps adding to the
> string.
Sounds like sv_catpvf() or sv_vcatpvfn() would be perfect, then.
They'll handle the memory allocations for you. If the target string has
magic (e.g. if it's tied), then try sv_catpvf_mg().
-Ken