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". ;-)
|