in reply to printing fcntl( fd, F_GETFL,0 ) return value changes its representation
When I do "perldoc -f fcntl" I see:
which shows that F_GETFL "gets" the value into the third argument. I think that when you do:use Fcntl; fcntl($filehandle, F_GETFL, $packed_return_buffer) or die "can't fcntl F_GETFL: $!";
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.$cur_opts = fcntl( FH, &F_GETFL, 0 );
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: printing fcntl( fd, F_GETFL,0 ) return value changes its representation (usage)
by weinstev (Initiate) on Jun 06, 2003 at 18:00 UTC | |
by tye (Sage) on Jun 06, 2003 at 19:35 UTC |