[Mono-list] Mono.Unix.Native.Syscall.(l)stat weirdness
mondalaci at gmail.com
Thu Feb 16 18:36:55 EST 2006
On Wed, 2006-02-15 at 07:15 -0500, Jonathan Pryor wrote:
> On Wed, 2006-02-15 at 12:15 +0100, László Monda wrote:
> > I've been playing with stat() and lstat() in the past few days and
> > things seem to be weird.
> > I made two test programs to demonstrate the problem. The first is
> > written in C and behaves correctly, the second is written in C# and is
> > quite abnormal. I attached both of them.
> What's wrong is that this C code:
> is *not* equivalent to this C# code you use:
> (stat.st_mode & MUN.FilePermissions.S_IFREG) ==
> If you read /usr/include/sys/stat.h, S_ISREG is this:
> #define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
> #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
> In short, S_ISREG is equivalent to this C# code:
> (stat.st_mode & MUN.FilePermissions.S_IFMT) ==
> Ditto for all the other S_IS* macro calls.
> So your C# code is buggy. :-)
That's apparent to me now. ;-)
> You might try looking at the internal method
> Mono.Unix.UnixFileSystemInfo.IsFileType(), which is used by the public
> properties IsDirectory, IsFifo, etc.
UnixFileSystemInfo seems to be a well-designed abstraction on top of the
Unix VFS API, but I'll stick with syscalls, because I don't like
UnixFileSystemInfo's exception policy.
Thanks for your (extremely clear and conscise) explanation.
More information about the Mono-list