[Mono-dev] Syscall.mmap problem

Jonathan Pryor jonpryor at vt.edu
Thu Oct 25 08:50:57 EDT 2007

On Wed, 2007-10-24 at 22:07 -0300, Mauricio Henriquez wrote:
> do you see some mistake?

Yes.  Your error handling is completely wrong. :-)

You have:

        if((fdin = Syscall.open("/pr.txt",  OpenFlags.O_RDONLY)) < 0)
                Console.WriteLine("open crash");
                Console.WriteLine("open fine");

So if "/pr.txt" doesn't exist -- and it doesn't on my machine --
fdin==-1, you write "open crash", and -- the key point -- you continue

What you should instead do is this:

        if((fdin = Syscall.open("/pr.txt",  OpenFlags.O_RDONLY)) < 0) {
                Syscall.perror ("open");

That way you won't continue executing with an invalid file descriptor.

See the attached program, which works w/o error for me.

 - Jon

-------------- next part --------------
A non-text attachment was scrubbed...
Name: mmap.cs
Type: text/x-csharp
Size: 1140 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20071025/fc344a72/attachment.bin 

More information about the Mono-devel-list mailing list