How to write files > 4GB with pwrite in Mono C# in 32-bit OS?

pedrom71 <[email protected]>
Newsgroups gmane.comp.gnome.mono.devel
Message-ID <[email protected]>
I'm trying to write a new file with size > 64 gb using mono c# and Mono.Posix
library, with the Syscall.pwrite() function. But in a 32-bit OS, I get error
EOVERFLOW when the offset reach 4GB.

This is the example code I'm using:

    public unsafe static void Main (string[] args)
    {
        int fd = Syscall.open("/dev/null", OpenFlags.O_WRONLY);
        long bLen = 4096;
        long fLen = 5368709120;
        byte[] buffer = new byte[bLen];
        long c = 0;
        long res = -1;
        if (fd == -1)
            goto Finish;

        do
        {
            fixed (byte *pb = buffer)
            {

                res = Syscall.pwrite(fd, pb, (ulong)bLen, c);
                if (res == -1)
                    break;
                c+= bLen;
            }
        }
        while (c < fLen);
        Syscall.close(fd);

        Finish:
        if (res == -1)
        {
            Console.WriteLine("Error in offset " + c.ToString());
            Console.WriteLine("Error: " + Stdlib.GetLastError());
        }
        else
        {
            Console.WriteLine("All OK");
        }
        Console.ReadLine();
    }


In C, the solution is compiling the code with gcc with parameter
-D_FILE_OFFSET_BITS=64. But in mono I haven't found the solution yet.

*Note: This error only happens in a 32-bit system. In a 64-bit OS works
correctly.



--
View this message in context: http://mono.1490590.n4.nabble.com/How-to-write-files-4GB-with-pwrite-in-Mono-C-in-32-bit-OS-tp4670286.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.dot.net/mailman/listinfo/mono-devel-list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.