- 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;
-
- result = read (fd, ptr, nbytes_to_read);
- if (result == 0)
- break;
- if (result < 0)
- {
-#ifdef EINTR
- if (errno == EINTR)
- continue;
-#endif
- return SAFE_READ_ERROR;
- }
- total_read += result;
- ptr += result;
- count -= result;