Actually, the S_IFMT can be used as both, a constant and a function, depending on whether you pass in parameters:

void S_IFMT(...) PREINIT: dXSTARG; PPCODE: PUSHu(items ? (SvUV(ST(0)) & S_IFMT) : S_IFMT);

It seems to return the AND-ed value from stat():

#!/usr/bin/env perl use strict; use warnings; use Fcntl qw[]; printf "%08x\n", (stat("/tmp"))[2]; printf "%08x\n", (stat("/etc/passwd"))[2]; printf "%08x\n", Fcntl::S_IFMT( (stat("/tmp"))[2] ); printf "%08x\n", Fcntl::S_IFMT( (stat("/etc/passwd"))[2] ); printf "%08x\n", Fcntl::S_IFMT(); __END__ 000043ff 000081a4 00004000 00008000 0000f000

I think the intended usage is to compare against identity, just like the GNU usage does, and to use lstat if you want to know about the link instead of the link target:

#!/usr/bin/env perl use strict; use warnings; use Fcntl qw[]; for my $file ('/tmp/testlink', '/etc/passwd', '/etc') { print "--- $file is link: ", -l $file, "\n"; my $mode = (stat($file))[2]; my $lmode = (lstat($file))[2]; printf "mode: %016b\n", $mode; printf "lmode: %016b\n", $lmode; printf "S_IFMT(): %016b\n", Fcntl::S_IFMT($lmode); printf "S_IFMT: %016b\n", Fcntl::S_IFMT() & $lmode; printf "S_IFMT: %016b\n", Fcntl::S_IFMT(); printf "S_IFLNK: %016b\n", Fcntl::S_IFLNK(); printf "S_IFLNK: %016b\n", (Fcntl::S_IFLNK() & Fcntl::S_IFMT() & $lmo +de) == Fcntl::S_IFLNK() ; printf "S_ISLNK():%016b\n", Fcntl::S_ISLNK($lmode); print "---\n"; } __END__ --- /tmp/testlink is link: 1 mode: 0100001111111111 lmode: 1010000111111111 S_IFMT(): 1010000000000000 S_IFMT: 1010000000000000 S_IFMT: 1111000000000000 S_IFLNK: 1010000000000000 S_IFLNK: 0000000000000001 S_ISLNK():0000000000000001 --- --- /etc/passwd is link: mode: 1000000110100100 lmode: 1000000110100100 S_IFMT(): 1000000000000000 S_IFMT: 1000000000000000 S_IFMT: 1111000000000000 S_IFLNK: 1010000000000000 S_IFLNK: 0000000000000000 S_ISLNK():0000000000000000 --- --- /etc is link: mode: 0100000111101101 lmode: 0100000111101101 S_IFMT(): 0100000000000000 S_IFMT: 0100000000000000 S_IFMT: 1111000000000000 S_IFLNK: 1010000000000000 S_IFLNK: 0000000000000000 S_ISLNK():0000000000000000 ---

In reply to Re^3: Unexpected Fcntl::S_IFLNK behavior by Corion
in thread Unexpected Fcntl::S_IFLNK behavior by zdm

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.