all flavours of Unix

Well, I could take some generic linux and patch stat() out. Would it still be a Unix flavour? Perhaps. Does that imaginary patch make sense? Most likely not.

So, what is a "flavour of Unix"?

As a first rule of thumb, I would ask for POSIX compatibility. Not every Unix implements all of POSIX, and not every POSIX compatible system is a Unix. But:

POSIX defines how stat and friends should behave. It also defines a minimal struct stat.

In fact, for such old and essential functions like stat(), POSIX usually just documents what has been done for ages, and most operating systems derived from Unix in one or the other way behave reasonable similar.

If you happen to run perl on Windows, you will find that many functions still work as if you were on a Unix, but there are some differences. For stat, the st_dev field seems to work, at least for volumes mapped to drive letters:

C:\Users\alex>perl -MFile::stat -E "for my $d (qw( C: D: H: I: M: T: X +: )) { my $st=stat(qq<$d\\.>); say $d,' ',$st->dev() }" C: 2 D: 3 H: 7 I: 8 M: 12 T: 19 X: 23 C:\Users\alex>

(Tested with Strawberry Perl 5.14.2 on Windows 7)

Things go wrong when you remap directories to other drive letters using the subst command from the old days of MS-DOS:

C:\Users\alex>subst n: c:\ C:\Users\alex>perl -MFile::stat -E "for my $d (qw( C: D: H: I: M: N: T +: X: )) { my $st=stat(qq<$d\\.>); say $d,' ',$st->dev() }" C: 2 D: 3 H: 7 I: 8 M: 12 N: 13 T: 19 X: 23 C:\Users\alex>

C: and N: refer to the same volume on the same device, but the st_dev field returns different device numbers (2 vs. 13). I think it's just the drive letter, minus 'A' (i.e. 0=A:, 1=B:, ..., 25=Z:).

Other parts of stat() are emulated in a way that is a little bit surprising, but still compatible enough for most cases, see Re^3: Inline.pm and untainting.

(Note that other good things from Unix can't be emulated that well on Windows, notably fork(), exec(), and signals. Windows simply lacks the required APIs.)

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^5: Restrict file search within current filessystem using wanted subroutine by afoken
in thread Restrict file search within current filessystem using wanted subroutine by madparu

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.