I'm writing and XS perl extension that calls an underlying C function. The C function has prototype 'void fcn(char *output)' and 'output' is null terminated so it is a string. The problem is that I don't seem to be able to get perl to recognize where the end of the 'output' string is. Here is the 'CODE:' section of my .xs file:
CODE: { RETVAL = NEWSV(0, 16); SvPOK_only(RETVAL); SvCUR_set(RETVAL, 16); fcn(SvPV(RETVAL, len)); printf("string: %s length: %d", RETVAL, len); }
If I make use of this code from perl, the length of the string is always 16 even if the C function returns a string has a NULL char at, say, position 8. Can anyone help me? What am I doing wrong?

Thanks!

--mbr

Edit kudra, 2002-08-17 Replaced pre tags


In reply to perl guts and the SvPV() macro by mbr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.