- /* 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;
-
- result = read (fd, ptr, nbytes_to_read);
- if (result < 0)
- {
-#ifdef EINTR
- if (errno == EINTR)
- continue;
-#endif
- return result;
- }
- total_read += result;
- ptr += result;
- count -= result;
- }
- while (count > 0);
+ if (0 <= result)
+ return result;
+ else if (IS_EINTR (errno))
+ continue;
+ else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count)
+ count = BUGGY_READ_MAXIMUM;
+ else
+ return result;