The POSIX specification for write()
says:
If the value of nbyte
is greater than {SSIZE_MAX}, the result is implementation-defined.
So any attempt to write more than SSIZE_MAX
bytes leads to behaviour that is not mandated by POSIX, but that must be documented by the system (it is implementation-defined, not undefined, behaviour). However, different systems may handle it differently, and there's nothing to stop one system from reporting an error (perhaps errno
set to EINVAL
) and another writing SSIZE_MAX
bytes and reporting that, leaving it to the application to try again on the remainder, and other systems could be inventive and do things differently still.
If you've got a 64-bit system, SSIZE_MAX
is likely larger than the amount of disk space in the biggest single data centre in the world (possibly by an order of magnitude or more, even allowing for the NSA and Google), so you're unlikely to be able to run into real problems with this, but on 32-bit systems, you could easily have more than 2 GiB of space and if ssize_t
is 32-bit, you have to deal with all this. (On Mac OS X 10.10.3, a 32-bit build has a 4-byte size_t
and ssize_t
, at least by default.)