- if (count > 0)
- {
- char *ptr = (char *) buf;
- do
- {
- size_t nbytes_to_read = count;
- ssize_t result;
-
- /* Limit the number of bytes to read in one round, to avoid running
- into unspecified behaviour. But keep the file pointer block
- aligned when doing so. */
- if (nbytes_to_read > MAX_BYTES_TO_READ)
- nbytes_to_read = MAX_BYTES_TO_READ & ~8191;
+ /* POSIX limits COUNT to SSIZE_MAX, but we limit it further, requiring
+ that COUNT <= INT_MAX, to avoid triggering a bug in Tru64 5.1.
+ When decreasing COUNT, keep the file pointer block-aligned.
+ Note that in any case, read(write) may succeed, yet read(write)
+ fewer than COUNT bytes, so the caller must be prepared to handle
+ partial results. */
+ if (count > INT_MAX)
+ count = INT_MAX & ~8191;