When I do "perldoc -f fcntl" I see:

use Fcntl; fcntl($filehandle, F_GETFL, $packed_return_buffer) or die "can't fcntl F_GETFL: $!";
which shows that F_GETFL "gets" the value into the third argument. I think that when you do:
$cur_opts = fcntl( FH, &F_GETFL, 0 );
Perl passes the address of the constant string, "0", to fcntl(). But fcntl() was expecting the address of a properly sized buffer for it to write the "FL" that you wanted to "GET" into. So fcntl() overwrites the 'constant' string, "0", which is stuff that Perl wasn't expected to be overwritten.

The design of fcntl() (Unix design, not Perl design) requires that the caller know what types are argument(s) to pass for each command code and doesn't provie any good ways to check/enforce that. You didn't obey that rule. This corrupted some data and what Perl does after that could be nearly anything.

                - tye

In reply to Re: printing fcntl( fd, F_GETFL,0 ) return value changes its representation (usage) by tye
in thread printing fcntl( fd, F_GETFL,0 ) return value changes its representation by weinstev

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.