write(2) fails for large sizes in 64 bit applications
write(2) fails for large sizes in 64 bit applications
- Subject: write(2) fails for large sizes in 64 bit applications
- From: Robert Homann <email@hidden>
- Date: Thu, 28 May 2009 11:22:05 +0200 (MEST)
Hi all!
I have just discovered that write(2) fails when trying to write blocks
larger than 2^31-1 in a program compiled for 64 bit mode (gcc -m64).
Maybe I am doing something wrong, but I suspect a bug in the
implementation of write().
When nbytes is set to 2^31 or greater, write() returns -1 and sets
errno to EINVAL. This behavior would probably be OK in 32 bit mode,
but I don't see how it would be correct in a 64 bit application. I
would expect write() to either return the number of bytes written, or
-1 with errno set to EINTR in case of an interrupted system call (or
an errno value different from EINVAL in case of other kinds of
failures).
I can work around this problem when calling write() in a loop while
limiting the number of bytes written at a time to 2^31-1; the
resulting file is as large as it should be, so it is not a file system
limitation. The same code (without the workaround) works well on 64 bit
Solaris and Linux.
Therefore, I think the implementation of write() is buggy; or at
least, its unexpected behavior in 64 bit mode should be documented on
the man page. What do you think?
Best regards,
Robert Homann
--
Windows is not the answer.
Windows is the question.
The answer is "No".
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden