[Mono-list] Mono.Unix.Native.Syscall.(l)stat weirdness
jonpryor at vt.edu
Wed Feb 15 07:15:54 EST 2006
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. :-)
You might try looking at the internal method
Mono.Unix.UnixFileSystemInfo.IsFileType(), which is used by the public
properties IsDirectory, IsFifo, etc.
More information about the Mono-list