1) How can I get the open()'d modes for a filehandle on Win32 ? fcntl() doesn't work there, and I can't seem to find a Win32 module to do it...

From what I can tell, this isn't a Win32::API problem, more a CRT problem as the rules regarding open modes are imposed/enforced by the CRT (or possibly the PerlIO layer if you're using that).

There does not appear to be anything in the VC++ CRT library for retrieving the open mode from an existing open file. Once you've dup()'d a file, you have to associate it with a FILE* stream, and Perl's open does not provide a mechanism for doing this without also supplying the mode--probably because there is no mechanism in the CRT for re-constituting a stream with it's original mode.

About the best you could do is use '+>' and position the pointer at the end-of-file to cater for an original append mode and hope/assume that if the user wishes to read from or write to any other position in the file, they will do a seek first.

This leaves one hole in the logic. If they originally opened it '+>>', the docs say that all writes will go to the end of file regardless of whether there have been intervening reads at other positions. If the programmer is relying on this behaviour, (he's probably unwise if he does), then he could be caught out.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Can't open($newfh, $mode_layers, '&' . fileno($fh)) by BrowserUk
in thread Can't open($newfh, $mode_layers, '&' . fileno($fh)) by renodino

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.