[Mono-dev] How to write files > 4GB with pwrite in Mono C# in 32-bit OS?
pedrom71
pedrosanzm71 at gmail.com
Sat Mar 18 21:47:57 UTC 2017
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.
More information about the Mono-devel-list
mailing list